Skip to content

Commit 76e9f68

Browse files
committed
Merge branch 'for-next/selftests' into for-next/core
* for-next/selftests: kselftest/arm64: Raise default number of loops in fp-pidbench kselftest/arm64: Add a no-SVE loop after SVE in fp-pidbench kselftest/arm64: Add missing file in .gitignore kselftest/arm64: Add HWCAP test for FEAT_LS64 kselftest/arm64: Use syscall() macro over nolibc my_syscall() kselftest/arm64: Support FORCE_TARGETS
2 parents d4cfa05 + b661d75 commit 76e9f68

6 files changed

Lines changed: 76 additions & 29 deletions

File tree

tools/testing/selftests/arm64/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ all:
3030
@for DIR in $(ARM64_SUBTARGETS); do \
3131
BUILD_TARGET=$(OUTPUT)/$$DIR; \
3232
mkdir -p $$BUILD_TARGET; \
33-
make OUTPUT=$$BUILD_TARGET -C $$DIR $@; \
33+
make OUTPUT=$$BUILD_TARGET -C $$DIR $@ \
34+
$(if $(FORCE_TARGETS),|| exit); \
3435
done
3536

3637
install: all
3738
@for DIR in $(ARM64_SUBTARGETS); do \
3839
BUILD_TARGET=$(OUTPUT)/$$DIR; \
39-
make OUTPUT=$$BUILD_TARGET -C $$DIR $@; \
40+
make OUTPUT=$$BUILD_TARGET -C $$DIR $@ \
41+
$(if $(FORCE_TARGETS),|| exit); \
4042
done
4143

4244
run_tests: all

tools/testing/selftests/arm64/abi/hwcap.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <stdlib.h>
1212
#include <string.h>
1313
#include <unistd.h>
14+
#include <linux/auxvec.h>
15+
#include <linux/compiler.h>
1416
#include <sys/auxv.h>
1517
#include <sys/prctl.h>
1618
#include <asm/hwcap.h>
@@ -595,6 +597,45 @@ static void lrcpc3_sigill(void)
595597
: "=r" (data0), "=r" (data1) : "r" (src) :);
596598
}
597599

600+
static void ignore_signal(int sig, siginfo_t *info, void *context)
601+
{
602+
ucontext_t *uc = context;
603+
604+
uc->uc_mcontext.pc += 4;
605+
}
606+
607+
static void ls64_sigill(void)
608+
{
609+
struct sigaction ign, old;
610+
char src[64] __aligned(64) = { 1 };
611+
612+
/*
613+
* LS64 requires target memory to be Device/Non-cacheable (if
614+
* FEAT_LS64WB not supported) and the completer supports these
615+
* instructions, otherwise we'll receive a SIGBUS. Since we are only
616+
* testing the ABI here, so just ignore the SIGBUS and see if we can
617+
* execute the instructions without receiving a SIGILL. Restore the
618+
* handler of SIGBUS after this test.
619+
*/
620+
ign.sa_sigaction = ignore_signal;
621+
ign.sa_flags = SA_SIGINFO | SA_RESTART;
622+
sigemptyset(&ign.sa_mask);
623+
sigaction(SIGBUS, &ign, &old);
624+
625+
register void *xn asm ("x8") = src;
626+
register u64 xt_1 asm ("x0");
627+
628+
/* LD64B x0, [x8] */
629+
asm volatile(".inst 0xf83fd100" : "=r" (xt_1) : "r" (xn)
630+
: "x1", "x2", "x3", "x4", "x5", "x6", "x7");
631+
632+
/* ST64B x0, [x8] */
633+
asm volatile(".inst 0xf83f9100" : : "r" (xt_1), "r" (xn)
634+
: "x1", "x2", "x3", "x4", "x5", "x6", "x7");
635+
636+
sigaction(SIGBUS, &old, NULL);
637+
}
638+
598639
static const struct hwcap_data {
599640
const char *name;
600641
unsigned long at_hwcap;
@@ -1134,6 +1175,14 @@ static const struct hwcap_data {
11341175
.hwcap_bit = HWCAP3_MTE_STORE_ONLY,
11351176
.cpuinfo = "mtestoreonly",
11361177
},
1178+
{
1179+
.name = "LS64",
1180+
.at_hwcap = AT_HWCAP3,
1181+
.hwcap_bit = HWCAP3_LS64,
1182+
.cpuinfo = "ls64",
1183+
.sigill_fn = ls64_sigill,
1184+
.sigill_reliable = true,
1185+
},
11371186
};
11381187

11391188
typedef void (*sighandler_fn)(int, siginfo_t *, void *);

tools/testing/selftests/arm64/abi/tpidr2.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ static int sys_clone(unsigned long clone_flags, unsigned long newsp,
128128
int *parent_tidptr, unsigned long tls,
129129
int *child_tidptr)
130130
{
131-
return my_syscall5(__NR_clone, clone_flags, newsp, parent_tidptr, tls,
132-
child_tidptr);
131+
return syscall(__NR_clone, clone_flags, newsp, parent_tidptr, tls, child_tidptr);
133132
}
134133

135134
#define __STACK_SIZE (8 * 1024 * 1024)

tools/testing/selftests/arm64/fp/fp-pidbench.S

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
function _start
3434
puts "Iterations per test: "
3535
mov x20, #10000
36-
lsl x20, x20, #8
36+
lsl x20, x20, #12
3737
mov x0, x20
3838
bl putdec
3939
puts "\n"
@@ -63,6 +63,10 @@ function _start
6363
puts "SVE used per syscall: "
6464
test_loop "rdvl x0, #8"
6565

66+
// Test non-SVE execution after SVE
67+
puts "No SVE after SVE: "
68+
test_loop
69+
6670
// And we're done
6771
out:
6872
mov x0, #0

tools/testing/selftests/arm64/gcs/basic-gcs.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static size_t page_size = 65536;
2222
static __attribute__((noinline)) void valid_gcs_function(void)
2323
{
2424
/* Do something the compiler can't optimise out */
25-
my_syscall1(__NR_prctl, PR_SVE_GET_VL);
25+
syscall(__NR_prctl, PR_SVE_GET_VL);
2626
}
2727

2828
static inline int gcs_set_status(unsigned long mode)
@@ -36,20 +36,18 @@ static inline int gcs_set_status(unsigned long mode)
3636
* other 3 values passed in registers to the syscall are zero
3737
* since the kernel validates them.
3838
*/
39-
ret = my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, mode,
40-
0, 0, 0);
39+
ret = syscall(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, mode, 0, 0, 0);
4140

4241
if (ret == 0) {
43-
ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
44-
&new_mode, 0, 0, 0);
42+
ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &new_mode, 0, 0, 0);
4543
if (ret == 0) {
4644
if (new_mode != mode) {
4745
ksft_print_msg("Mode set to %lx not %lx\n",
4846
new_mode, mode);
4947
ret = -EINVAL;
5048
}
5149
} else {
52-
ksft_print_msg("Failed to validate mode: %d\n", ret);
50+
ksft_print_msg("Failed to validate mode: %d\n", errno);
5351
}
5452

5553
if (enabling != chkfeat_gcs()) {
@@ -69,10 +67,9 @@ static bool read_status(void)
6967
unsigned long state;
7068
int ret;
7169

72-
ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
73-
&state, 0, 0, 0);
70+
ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &state, 0, 0, 0);
7471
if (ret != 0) {
75-
ksft_print_msg("Failed to read state: %d\n", ret);
72+
ksft_print_msg("Failed to read state: %d\n", errno);
7673
return false;
7774
}
7875

@@ -188,9 +185,8 @@ static bool map_guarded_stack(void)
188185
int elem;
189186
bool pass = true;
190187

191-
buf = (void *)my_syscall3(__NR_map_shadow_stack, 0, page_size,
192-
SHADOW_STACK_SET_MARKER |
193-
SHADOW_STACK_SET_TOKEN);
188+
buf = (void *)syscall(__NR_map_shadow_stack, 0, page_size,
189+
SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN);
194190
if (buf == MAP_FAILED) {
195191
ksft_print_msg("Failed to map %lu byte GCS: %d\n",
196192
page_size, errno);
@@ -257,8 +253,7 @@ static bool test_fork(void)
257253
valid_gcs_function();
258254
get_gcspr();
259255

260-
ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
261-
&child_mode, 0, 0, 0);
256+
ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &child_mode, 0, 0, 0);
262257
if (ret == 0 && !(child_mode & PR_SHADOW_STACK_ENABLE)) {
263258
ksft_print_msg("GCS not enabled in child\n");
264259
ret = -EINVAL;
@@ -321,8 +316,7 @@ static bool test_vfork(void)
321316
valid_gcs_function();
322317
get_gcspr();
323318

324-
ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
325-
&child_mode, 0, 0, 0);
319+
ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &child_mode, 0, 0, 0);
326320
if (ret == 0 && !(child_mode & PR_SHADOW_STACK_ENABLE)) {
327321
ksft_print_msg("GCS not enabled in child\n");
328322
ret = EXIT_FAILURE;
@@ -390,17 +384,15 @@ int main(void)
390384
if (!(getauxval(AT_HWCAP) & HWCAP_GCS))
391385
ksft_exit_skip("SKIP GCS not supported\n");
392386

393-
ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
394-
&gcs_mode, 0, 0, 0);
387+
ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &gcs_mode, 0, 0, 0);
395388
if (ret != 0)
396-
ksft_exit_fail_msg("Failed to read GCS state: %d\n", ret);
389+
ksft_exit_fail_msg("Failed to read GCS state: %d\n", errno);
397390

398391
if (!(gcs_mode & PR_SHADOW_STACK_ENABLE)) {
399392
gcs_mode = PR_SHADOW_STACK_ENABLE;
400-
ret = my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS,
401-
gcs_mode, 0, 0, 0);
393+
ret = syscall(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, gcs_mode, 0, 0, 0);
402394
if (ret != 0)
403-
ksft_exit_fail_msg("Failed to enable GCS: %d\n", ret);
395+
ksft_exit_fail_msg("Failed to enable GCS: %d\n", errno);
404396
}
405397

406398
ksft_set_plan(ARRAY_SIZE(tests));
@@ -410,9 +402,9 @@ int main(void)
410402
}
411403

412404
/* One last test: disable GCS, we can do this one time */
413-
ret = my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, 0, 0, 0, 0);
405+
ret = syscall(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, 0, 0, 0, 0);
414406
if (ret != 0)
415-
ksft_print_msg("Failed to disable GCS: %d\n", ret);
407+
ksft_print_msg("Failed to disable GCS: %d\n", errno);
416408

417409
ksft_finished();
418410

tools/testing/selftests/arm64/mte/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ check_mmap_options
66
check_prctl
77
check_ksm_options
88
check_user_mem
9+
check_hugetlb_options

0 commit comments

Comments
 (0)