Skip to content

Commit 712f4ee

Browse files
committed
Merge branch 'for-next/selftests' into for-next/core
* for-next/selftests: kselftest/arm64: Add lsfe to the hwcaps test kselftest/arm64: Check that unsupported regsets fail in sve-ptrace kselftest/arm64: Verify that we reject out of bounds VLs in sve-ptrace kselftest/arm64/gcs/basic-gcs: Respect parent directory CFLAGS selftests/arm64: Fix grammatical error in string literals kselftest/arm64: Add parentheses around sizeof for clarity kselftest/arm64: Supress warning and improve readability kselftest/arm64: Remove extra blank line kselftest/arm64/gcs: Use nolibc's getauxval() kselftest/arm64/gcs: Correctly check return value when disabling GCS selftests: arm64: Fix -Waddress warning in tpidr2 test kselftest/arm64: Log error codes in sve-ptrace selftests: arm64: Check fread return value in exec_target
2 parents f2d64a2 + 777fb19 commit 712f4ee

14 files changed

Lines changed: 144 additions & 32 deletions

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <asm/sigcontext.h>
1818
#include <asm/unistd.h>
1919

20+
#include <linux/auxvec.h>
21+
2022
#include "../../kselftest.h"
2123

2224
#define TESTS_PER_HWCAP 3
@@ -55,7 +57,6 @@ static void cmpbr_sigill(void)
5557
/* Not implemented, too complicated and unreliable anyway */
5658
}
5759

58-
5960
static void crc32_sigill(void)
6061
{
6162
/* CRC32W W0, W0, W1 */
@@ -169,6 +170,18 @@ static void lse128_sigill(void)
169170
: "cc", "memory");
170171
}
171172

173+
static void lsfe_sigill(void)
174+
{
175+
float __attribute__ ((aligned (16))) mem;
176+
register float *memp asm ("x0") = &mem;
177+
178+
/* STFADD H0, [X0] */
179+
asm volatile(".inst 0x7c20801f"
180+
: "+r" (memp)
181+
:
182+
: "memory");
183+
}
184+
172185
static void lut_sigill(void)
173186
{
174187
/* LUTI2 V0.16B, { V0.16B }, V[0] */
@@ -762,6 +775,13 @@ static const struct hwcap_data {
762775
.cpuinfo = "lse128",
763776
.sigill_fn = lse128_sigill,
764777
},
778+
{
779+
.name = "LSFE",
780+
.at_hwcap = AT_HWCAP3,
781+
.hwcap_bit = HWCAP3_LSFE,
782+
.cpuinfo = "lsfe",
783+
.sigill_fn = lsfe_sigill,
784+
},
765785
{
766786
.name = "LUT",
767787
.at_hwcap = AT_HWCAP2,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ int main(int argc, char **argv)
227227
ret = open("/proc/sys/abi/sme_default_vector_length", O_RDONLY, 0);
228228
if (ret >= 0) {
229229
ksft_test_result(default_value(), "default_value\n");
230-
ksft_test_result(write_read, "write_read\n");
231-
ksft_test_result(write_sleep_read, "write_sleep_read\n");
232-
ksft_test_result(write_fork_read, "write_fork_read\n");
233-
ksft_test_result(write_clone_read, "write_clone_read\n");
230+
ksft_test_result(write_read(), "write_read\n");
231+
ksft_test_result(write_sleep_read(), "write_sleep_read\n");
232+
ksft_test_result(write_fork_read(), "write_fork_read\n");
233+
ksft_test_result(write_clone_read(), "write_clone_read\n");
234234

235235
} else {
236236
ksft_print_msg("SME support not present\n");

tools/testing/selftests/arm64/bti/assembler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)
1515
#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1)
1616

17-
1817
.macro startfn name:req
1918
.globl \name
2019
\name:

tools/testing/selftests/arm64/fp/fp-ptrace.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,6 @@ static void run_sve_tests(void)
15681568
&test_config);
15691569
}
15701570
}
1571-
15721571
}
15731572

15741573
static void run_sme_tests(void)

tools/testing/selftests/arm64/fp/fp-stress.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ static void child_start(struct child_data *child, const char *program)
105105

106106
/*
107107
* Read from the startup pipe, there should be no data
108-
* and we should block until it is closed. We just
109-
* carry on on error since this isn't super critical.
108+
* and we should block until it is closed. We just
109+
* carry-on on error since this isn't super critical.
110110
*/
111111
ret = read(3, &i, sizeof(i));
112112
if (ret < 0)
@@ -549,7 +549,7 @@ int main(int argc, char **argv)
549549

550550
evs = calloc(tests, sizeof(*evs));
551551
if (!evs)
552-
ksft_exit_fail_msg("Failed to allocated %d epoll events\n",
552+
ksft_exit_fail_msg("Failed to allocate %d epoll events\n",
553553
tests);
554554

555555
for (i = 0; i < cpus; i++) {

tools/testing/selftests/arm64/fp/kernel-test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ static bool create_socket(void)
188188

189189
ref = malloc(digest_len);
190190
if (!ref) {
191-
printf("Failed to allocated %d byte reference\n", digest_len);
191+
printf("Failed to allocate %d byte reference\n", digest_len);
192192
return false;
193193
}
194194

195195
digest = malloc(digest_len);
196196
if (!digest) {
197-
printf("Failed to allocated %d byte digest\n", digest_len);
197+
printf("Failed to allocate %d byte digest\n", digest_len);
198198
return false;
199199
}
200200

tools/testing/selftests/arm64/fp/sve-ptrace.c

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static const struct vec_type vec_types[] = {
6666
};
6767

6868
#define VL_TESTS (((TEST_VQ_MAX - SVE_VQ_MIN) + 1) * 4)
69-
#define FLAG_TESTS 2
69+
#define FLAG_TESTS 4
7070
#define FPSIMD_TESTS 2
7171

7272
#define EXPECTED_TESTS ((VL_TESTS + FLAG_TESTS + FPSIMD_TESTS) * ARRAY_SIZE(vec_types))
@@ -95,28 +95,37 @@ static int do_child(void)
9595
static int get_fpsimd(pid_t pid, struct user_fpsimd_state *fpsimd)
9696
{
9797
struct iovec iov;
98+
int ret;
9899

99100
iov.iov_base = fpsimd;
100101
iov.iov_len = sizeof(*fpsimd);
101-
return ptrace(PTRACE_GETREGSET, pid, NT_PRFPREG, &iov);
102+
ret = ptrace(PTRACE_GETREGSET, pid, NT_PRFPREG, &iov);
103+
if (ret == -1)
104+
ksft_perror("ptrace(PTRACE_GETREGSET)");
105+
return ret;
102106
}
103107

104108
static int set_fpsimd(pid_t pid, struct user_fpsimd_state *fpsimd)
105109
{
106110
struct iovec iov;
111+
int ret;
107112

108113
iov.iov_base = fpsimd;
109114
iov.iov_len = sizeof(*fpsimd);
110-
return ptrace(PTRACE_SETREGSET, pid, NT_PRFPREG, &iov);
115+
ret = ptrace(PTRACE_SETREGSET, pid, NT_PRFPREG, &iov);
116+
if (ret == -1)
117+
ksft_perror("ptrace(PTRACE_SETREGSET)");
118+
return ret;
111119
}
112120

113121
static struct user_sve_header *get_sve(pid_t pid, const struct vec_type *type,
114122
void **buf, size_t *size)
115123
{
116124
struct user_sve_header *sve;
117125
void *p;
118-
size_t sz = sizeof *sve;
126+
size_t sz = sizeof(*sve);
119127
struct iovec iov;
128+
int ret;
120129

121130
while (1) {
122131
if (*size < sz) {
@@ -132,8 +141,11 @@ static struct user_sve_header *get_sve(pid_t pid, const struct vec_type *type,
132141

133142
iov.iov_base = *buf;
134143
iov.iov_len = sz;
135-
if (ptrace(PTRACE_GETREGSET, pid, type->regset, &iov))
144+
ret = ptrace(PTRACE_GETREGSET, pid, type->regset, &iov);
145+
if (ret) {
146+
ksft_perror("ptrace(PTRACE_GETREGSET)");
136147
goto error;
148+
}
137149

138150
sve = *buf;
139151
if (sve->size <= sz)
@@ -152,10 +164,46 @@ static int set_sve(pid_t pid, const struct vec_type *type,
152164
const struct user_sve_header *sve)
153165
{
154166
struct iovec iov;
167+
int ret;
155168

156169
iov.iov_base = (void *)sve;
157170
iov.iov_len = sve->size;
158-
return ptrace(PTRACE_SETREGSET, pid, type->regset, &iov);
171+
ret = ptrace(PTRACE_SETREGSET, pid, type->regset, &iov);
172+
if (ret == -1)
173+
ksft_perror("ptrace(PTRACE_SETREGSET)");
174+
return ret;
175+
}
176+
177+
/* A read operation fails */
178+
static void read_fails(pid_t child, const struct vec_type *type)
179+
{
180+
struct user_sve_header *new_sve = NULL;
181+
size_t new_sve_size = 0;
182+
void *ret;
183+
184+
ret = get_sve(child, type, (void **)&new_sve, &new_sve_size);
185+
186+
ksft_test_result(ret == NULL, "%s unsupported read fails\n",
187+
type->name);
188+
189+
free(new_sve);
190+
}
191+
192+
/* A write operation fails */
193+
static void write_fails(pid_t child, const struct vec_type *type)
194+
{
195+
struct user_sve_header sve;
196+
int ret;
197+
198+
/* Just the header, no data */
199+
memset(&sve, 0, sizeof(sve));
200+
sve.size = sizeof(sve);
201+
sve.flags = SVE_PT_REGS_SVE;
202+
sve.vl = SVE_VL_MIN;
203+
ret = set_sve(child, type, &sve);
204+
205+
ksft_test_result(ret != 0, "%s unsupported write fails\n",
206+
type->name);
159207
}
160208

161209
/* Validate setting and getting the inherit flag */
@@ -270,6 +318,25 @@ static void check_u32(unsigned int vl, const char *reg,
270318
}
271319
}
272320

321+
/* Set out of range VLs */
322+
static void ptrace_set_vl_ranges(pid_t child, const struct vec_type *type)
323+
{
324+
struct user_sve_header sve;
325+
int ret;
326+
327+
memset(&sve, 0, sizeof(sve));
328+
sve.flags = SVE_PT_REGS_SVE;
329+
sve.size = sizeof(sve);
330+
331+
ret = set_sve(child, type, &sve);
332+
ksft_test_result(ret != 0, "%s Set invalid VL 0\n", type->name);
333+
334+
sve.vl = SVE_VL_MAX + SVE_VQ_BYTES;
335+
ret = set_sve(child, type, &sve);
336+
ksft_test_result(ret != 0, "%s Set invalid VL %d\n", type->name,
337+
SVE_VL_MAX + SVE_VQ_BYTES);
338+
}
339+
273340
/* Access the FPSIMD registers via the SVE regset */
274341
static void ptrace_sve_fpsimd(pid_t child, const struct vec_type *type)
275342
{
@@ -683,6 +750,20 @@ static int do_parent(pid_t child)
683750
}
684751

685752
for (i = 0; i < ARRAY_SIZE(vec_types); i++) {
753+
/*
754+
* If the vector type isn't supported reads and writes
755+
* should fail.
756+
*/
757+
if (!(getauxval(vec_types[i].hwcap_type) & vec_types[i].hwcap)) {
758+
read_fails(child, &vec_types[i]);
759+
write_fails(child, &vec_types[i]);
760+
} else {
761+
ksft_test_result_skip("%s unsupported read fails\n",
762+
vec_types[i].name);
763+
ksft_test_result_skip("%s unsupported write fails\n",
764+
vec_types[i].name);
765+
}
766+
686767
/* FPSIMD via SVE regset */
687768
if (getauxval(vec_types[i].hwcap_type) & vec_types[i].hwcap) {
688769
ptrace_sve_fpsimd(child, &vec_types[i]);
@@ -703,6 +784,17 @@ static int do_parent(pid_t child)
703784
vec_types[i].name);
704785
}
705786

787+
/* Setting out of bounds VLs should fail */
788+
if (getauxval(vec_types[i].hwcap_type) & vec_types[i].hwcap) {
789+
ptrace_set_vl_ranges(child, &vec_types[i]);
790+
} else {
791+
ksft_test_result_skip("%s Set invalid VL 0\n",
792+
vec_types[i].name);
793+
ksft_test_result_skip("%s Set invalid VL %d\n",
794+
vec_types[i].name,
795+
SVE_VL_MAX + SVE_VQ_BYTES);
796+
}
797+
706798
/* Step through every possible VQ */
707799
for (vq = SVE_VQ_MIN; vq <= TEST_VQ_MAX; vq++) {
708800
vl = sve_vl_from_vq(vq);

tools/testing/selftests/arm64/fp/vec-syscfg.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ static inline void smstop(void)
690690
asm volatile("msr S0_3_C4_C6_3, xzr");
691691
}
692692

693-
694693
/*
695694
* Verify we can change the SVE vector length while SME is active and
696695
* continue to use SME afterwards.

tools/testing/selftests/arm64/fp/zt-ptrace.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ static int get_zt(pid_t pid, char zt[ZT_SIG_REG_BYTES])
108108
return ptrace(PTRACE_GETREGSET, pid, NT_ARM_ZT, &iov);
109109
}
110110

111-
112111
static int set_zt(pid_t pid, const char zt[ZT_SIG_REG_BYTES])
113112
{
114113
struct iovec iov;

tools/testing/selftests/arm64/gcs/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ LDLIBS+=-lpthread
1414
include ../../lib.mk
1515

1616
$(OUTPUT)/basic-gcs: basic-gcs.c
17-
$(CC) -g -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \
18-
-static -include ../../../../include/nolibc/nolibc.h \
17+
$(CC) $(CFLAGS) -fno-asynchronous-unwind-tables -fno-ident -s -nostdlib -nostdinc \
18+
-static -I../../../../include/nolibc -include ../../../../include/nolibc/nolibc.h \
1919
-I../../../../../usr/include \
2020
-std=gnu99 -I../.. -g \
21-
-ffreestanding -Wall $^ -o $@ -lgcc
21+
-ffreestanding $^ -o $@ -lgcc
2222

2323
$(OUTPUT)/gcs-stress-thread: gcs-stress-thread.S
2424
$(CC) -nostdlib $^ -o $@

0 commit comments

Comments
 (0)