Skip to contentSkip to conversation

kselftest/arm64: Vector length configuration tests

PATCH Superseded Mark Brown 2 participants 7 messages Jul 29, 2021 – Aug 3, 2021

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

v4 cover kselftest/arm64: Vector length configuration tests

Currently we don't have full automated tests for the vector length configuation ABIs offered for SVE, we have a helper binary for setting the vector length which can be used for manual tests and we use the prctl() interface to enumerate the vector lengths but don't actually verify that the vector lengths enumerated were set.

This patch series provides a small helper which allows us to get the currently configured vector length using the RDVL instruction via either a library call or stdout of a process and then uses this to both add verification of enumerated vector lengths to our existing tests and also add a new test program which exercises both the prctl() and sysfs interfaces.

In preparation for the forthcomng support for the Scalable Matrix Extension (SME) [1] which introduces a new vector length managed via a very similar hardware interface the helper and new test program are parameterised with the goal of allowing reuse for SME.

[1] https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/scalable-matrix-extension-armv9-a-architecture

v3:
- Add BTI landing pads to the asm helper functions.
- Clean up pipes used to talk to children.
- Remove another unneeded include.
- Make functions in the main executable static.
- Match the newline when parsing vector length from the child.
- Factor out the fscanf() and fclose() from parsing integers from file descriptors.
- getauxval() returns unsigned long.
v2:
- Tweak log message on failure in sve-probe-vls.
- Stylistic changes in vec-syscfg.
- Flush stdout before forking in vec-syscfg.
- Use EXIT_FAILURE.
- Use fdopen() to get child output.
- Replace a bunch of UNIX API usage with stdio.
- Add a TODO list.
- Verify that we're root before testing writes to /proc.

Mark Brown (4):
kselftest/arm64: Provide a helper binary and "library" for SVE RDVL kselftest/arm64: Validate vector lengths are set in sve-probe-vls kselftest/arm64: Add tests for SVE vector configuration kselftest/arm64: Add a TODO list for floating point tests

 tools/testing/selftests/arm64/fp/.gitignore   |   2 +
 tools/testing/selftests/arm64/fp/Makefile     |  11 +-
 tools/testing/selftests/arm64/fp/TODO         |   3 +
 tools/testing/selftests/arm64/fp/rdvl-sve.c   |  14 +
 tools/testing/selftests/arm64/fp/rdvl.S       |  10 +
 tools/testing/selftests/arm64/fp/rdvl.h       |   8 +
 .../selftests/arm64/fp/sve-probe-vls.c        |   5 +
 tools/testing/selftests/arm64/fp/vec-syscfg.c | 594 ++++++++++++++++++
 8 files changed, 644 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/arm64/fp/TODO
 create mode 100644 tools/testing/selftests/arm64/fp/rdvl-sve.c
 create mode 100644 tools/testing/selftests/arm64/fp/rdvl.S
 create mode 100644 tools/testing/selftests/arm64/fp/rdvl.h
 create mode 100644 tools/testing/selftests/arm64/fp/vec-syscfg.c

base-commit: ff1176468d368232b684f75e82563369208bc371

Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v4 1/4 kselftest/arm64: Provide a helper binary and "library" for SVE RDVL

SVE provides an instruction RDVL which reports the currently configured vector length. In order to validate that our vector length configuration interfaces are working correctly without having to build the C code for our test programs with SVE enabled provide a trivial assembly library with a C callable function that executes RDVL. Since these interfaces also control behaviour on exec*() provide a trivial wrapper program which reports the currently configured vector length on stdout, tests can use this to verify that behaviour on exec*() is as expected.

In preparation for providing similar helper functionality for SME, the Scalable Matrix Extension, which allows separately configured vector lengths to be read back both the assembler function and wrapper binary have SVE included in their name.

---
 tools/testing/selftests/arm64/fp/.gitignore |  1 +
 tools/testing/selftests/arm64/fp/Makefile   |  6 +++++-
 tools/testing/selftests/arm64/fp/rdvl-sve.c | 14 ++++++++++++++
 tools/testing/selftests/arm64/fp/rdvl.S     | 10 ++++++++++
 tools/testing/selftests/arm64/fp/rdvl.h     |  8 ++++++++
 5 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/arm64/fp/rdvl-sve.c
 create mode 100644 tools/testing/selftests/arm64/fp/rdvl.S
 create mode 100644 tools/testing/selftests/arm64/fp/rdvl.h
tools/testing/selftests/arm64/fp/.gitignore +1 -0
index d66f76d2a650..6b53a7b60fee 100644
@@ -1,4 +1,5 @@
 fpsimd-test
+rdvl-sve
 sve-probe-vls
 sve-ptrace
 sve-test
tools/testing/selftests/arm64/fp/Makefile +5 -1
index a57009d3a0dc..ed62e7003b96 100644
@@ -2,12 +2,16 @@
 
 CFLAGS += -I../../../../../usr/include/
 TEST_GEN_PROGS := sve-ptrace sve-probe-vls
-TEST_PROGS_EXTENDED := fpsimd-test fpsimd-stress sve-test sve-stress vlset
+TEST_PROGS_EXTENDED := fpsimd-test fpsimd-stress \
+	rdvl-sve \
+	sve-test sve-stress \
+	vlset
 
 all: $(TEST_GEN_PROGS) $(TEST_PROGS_EXTENDED)
 
 fpsimd-test: fpsimd-test.o
 	$(CC) -nostdlib $^ -o $@
+rdvl-sve: rdvl-sve.o rdvl.o
 sve-ptrace: sve-ptrace.o sve-ptrace-asm.o
 sve-probe-vls: sve-probe-vls.o
 sve-test: sve-test.o
tools/testing/selftests/arm64/fp/rdvl-sve.c new file +14 -0
new file mode 100644
index 000000000000..7f8a13a18f5d
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <stdio.h>
+
+#include "rdvl.h"
+
+int main(void)
+{
+	int vl = rdvl_sve();
+
+	printf("%d\n", vl);
+
+	return 0;
+}
tools/testing/selftests/arm64/fp/rdvl.S new file +10 -0
new file mode 100644
index 000000000000..c916c1c9defd
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright (C) 2021 ARM Limited.
+
+.arch_extension sve
+
+.globl rdvl_sve
+rdvl_sve:
+	hint	34			// BTI C
+	rdvl	x0, #1
+	ret
tools/testing/selftests/arm64/fp/rdvl.h new file +8 -0
new file mode 100644
index 000000000000..7c9d953fc9e7
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef RDVL_H
+#define RDVL_H
+
+int rdvl_sve(void);
+
+#endif
Signature · 1 line
2.20.1
author
#2 lore raw

PATCH v4 2/4 kselftest/arm64: Validate vector lengths are set in sve-probe-vls

In reply to Mark Brown

Currently sve-probe-vls does not verify that the vector lengths reported by the prctl() interface are actually what is reported by the architecture, use the rdvl_sve() helper to validate this.

---
 tools/testing/selftests/arm64/fp/Makefile        | 2 +-
 tools/testing/selftests/arm64/fp/sve-probe-vls.c | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/arm64/fp/Makefile +1 -1
index ed62e7003b96..fa3a0167db2d 100644
@@ -13,7 +13,7 @@ fpsimd-test: fpsimd-test.o
 	$(CC) -nostdlib $^ -o $@
 rdvl-sve: rdvl-sve.o rdvl.o
 sve-ptrace: sve-ptrace.o sve-ptrace-asm.o
-sve-probe-vls: sve-probe-vls.o
+sve-probe-vls: sve-probe-vls.o rdvl.o
 sve-test: sve-test.o
 	$(CC) -nostdlib $^ -o $@
 vlset: vlset.o
tools/testing/selftests/arm64/fp/sve-probe-vls.c +5 -0
index 76e138525d55..a24eca7a4ecb 100644
@@ -13,6 +13,7 @@
 #include <asm/sigcontext.h>
 
 #include "../../kselftest.h"
+#include "rdvl.h"
 
 int main(int argc, char **argv)
 {
@@ -38,6 +39,10 @@ int main(int argc, char **argv)
 
 		vl &= PR_SVE_VL_LEN_MASK;
 
+		if (rdvl_sve() != vl)
+			ksft_exit_fail_msg("PR_SVE_SET_VL reports %d, RDVL %d\n",
+					   vl, rdvl_sve());
+
 		if (!sve_vl_valid(vl))
 			ksft_exit_fail_msg("VL %d invalid\n", vl);
 		vq = sve_vq_from_vl(vl);
Signature · 1 line
2.20.1
author
#3 lore raw

PATCH v4 3/4 kselftest/arm64: Add tests for SVE vector configuration

In reply to Mark Brown

We provide interfaces for configuring the SVE vector length seen by processes using prctl and also via /proc for configuring the default values. Provide tests that exercise all these interfaces and verify that they take effect as expected, though at present no test fully enumerates all the possible vector lengths.

A subset of this is already tested via sve-probe-vls but the /proc interfaces are not currently covered at all.

In preparation for the forthcoming support for SME, the Scalable Matrix Extension, which has separately but similarly configured vector lengths which we expect to offer similar userspace interfaces for, all the actual files and prctls used are parameterised and we don't validate that the architectural minimum vector length is the minimum we see.

---
 tools/testing/selftests/arm64/fp/.gitignore   |   1 +
 tools/testing/selftests/arm64/fp/Makefile     |   3 +-
 tools/testing/selftests/arm64/fp/vec-syscfg.c | 594 ++++++++++++++++++
 3 files changed, 597 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/arm64/fp/vec-syscfg.c
tools/testing/selftests/arm64/fp/.gitignore +1 -0
index 6b53a7b60fee..b67395903b9b 100644
@@ -3,4 +3,5 @@ rdvl-sve
 sve-probe-vls
 sve-ptrace
 sve-test
+vec-syscfg
 vlset
tools/testing/selftests/arm64/fp/Makefile +2 -1
index fa3a0167db2d..f2abdd6ba12e 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 CFLAGS += -I../../../../../usr/include/
-TEST_GEN_PROGS := sve-ptrace sve-probe-vls
+TEST_GEN_PROGS := sve-ptrace sve-probe-vls vec-syscfg
 TEST_PROGS_EXTENDED := fpsimd-test fpsimd-stress \
 	rdvl-sve \
 	sve-test sve-stress \
@@ -16,6 +16,7 @@ sve-ptrace: sve-ptrace.o sve-ptrace-asm.o
 sve-probe-vls: sve-probe-vls.o rdvl.o
 sve-test: sve-test.o
 	$(CC) -nostdlib $^ -o $@
+vec-syscfg: vec-syscfg.o rdvl.o
 vlset: vlset.o
 
 include ../../lib.mk
tools/testing/selftests/arm64/fp/vec-syscfg.c new file +594 -0

594 lines not on this page · raw message

Signature · 1 line
2.20.1
Reviewed-by on v4 3/4
#4 lore raw

Re: [PATCH v4 3/4] kselftest/arm64: Add tests for SVE vector configuration

Quoted 22 lines · Mark Brown

We provide interfaces for configuring the SVE vector length seen by processes using prctl and also via /proc for configuring the default values. Provide tests that exercise all these interfaces and verify that they take effect as expected, though at present no test fully enumerates all the possible vector lengths.

A subset of this is already tested via sve-probe-vls but the /proc interfaces are not currently covered at all.

In preparation for the forthcoming support for SME, the Scalable Matrix Extension, which has separately but similarly configured vector lengths which we expect to offer similar userspace interfaces for, all the actual files and prctls used are parameterised and we don't validate that the architectural minimum vector length is the minimum we see.

---
 tools/testing/selftests/arm64/fp/.gitignore   |   1 +
 tools/testing/selftests/arm64/fp/Makefile     |   3 +-
 tools/testing/selftests/arm64/fp/vec-syscfg.c | 594 ++++++++++++++++++
 3 files changed, 597 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/arm64/fp/vec-syscfg.c

[...]

Quoted 5 lines
tools/testing/selftests/arm64/fp/vec-syscfg.c new file +0 -0
new file mode 100644
index 000000000000..15fec1aaeec6

[...]

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

Quoted 4 lines
tools/testing/selftests/arm64/fp/vec-syscfg.c new file +4 -0
+static int stdio_read_integer(FILE *f, const char *what, int *val)
+{
+	int ret, n;
+

n needs to be initialised to 0, since fscanf won't touch it if there is a matching failure before it reaches the %n conversion.

With that,

(One minor coment below, but that's just in relation to a possibly future test.)

Quoted 9 lines
tools/testing/selftests/arm64/fp/vec-syscfg.c new file +9 -0
+	ret = fscanf(f, "%d%*1[\n]%n", val, &n);
+	if (ret < 1 || n < 1) {
+		ksft_print_msg("%d %d %d\n", ret, n, *val);
+		ksft_print_msg("failed to parse VL from %s\n", what);
+		return -1;
+	}
+
+	return 0;
+}

[...]

Quoted 21 lines
tools/testing/selftests/arm64/fp/vec-syscfg.c new file +21 -0
+/* If we didn't request it a new VL shouldn't affect the child */
+static void prctl_set_for_child(struct vec_data *data)
+{
+	int ret, child_vl;
+
+	if (data->min_vl == data->max_vl) {
+		ksft_test_result_skip("%s only one VL supported\n",
+				      data->name);
+		return;
+	}
+
+	ret = prctl(data->prctl_set, data->min_vl | PR_SVE_VL_INHERIT);
+	if (ret < 0) {
+		ksft_test_result_fail("%s prctl set failed for %d: %d (%s)\n",
+				      data->name, data->min_vl,
+				      errno, strerror(errno));
+		return;
+	}
+
+	/* The _INHERIT flag should be present when we read the VL */
+	ret = prctl(data->prctl_get);

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

Quoted 10 lines
tools/testing/selftests/arm64/fp/vec-syscfg.c new file +10 -0
+	if (ret == -1) {
+		ksft_test_result_fail("%s prctl() read failed: %d (%s)\n",
+				      data->name, errno, strerror(errno));
+		return;
+	}
+	if (!(ret & PR_SVE_VL_INHERIT)) {
+		ksft_test_result_fail("%s prctl() does not report _INHERIT\n",
+				      data->name);
+		return;
+	}

It occurs to me that tt would make sense to test that the PR_SVE_VL_INHERIT flag (or lack thereof) does the right thing for further execs in the child. If reposting, it could make sense to add this as a TODO, but don't sweat it otherwise.

[...]

Cheers
---Dave

author
#5 lore raw

PATCH v4 4/4 kselftest/arm64: Add a TODO list for floating point tests

In reply to Mark Brown

Write down some ideas for additional coverage for floating point in case someone feels inspired to look into them.

---
 tools/testing/selftests/arm64/fp/TODO | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 tools/testing/selftests/arm64/fp/TODO
tools/testing/selftests/arm64/fp/TODO new file +3 -0
new file mode 100644
index 000000000000..eada915227cf
@@ -0,0 +1,3 @@
+- Test unsupported values in the ABIs
+- More coverage for ptrace (eg, vector length conversions).
+- Coverage for signals.
Signature · 1 line
2.20.1
author
#6 lore raw
In reply to Mark Brown
Quoted 2 lines · Mark Brown

v3:
- Add BTI landing pads to the asm helper functions.

Sorry, forgot to hit save before I sent: the v4 changelog is:

v4:
- Fix fscanf() format string handling to properly confirm the newline.
- Pull fclose() out of stdio read helper.
- Change style of child monitoring loop.