2023-01-10 20:51:58

by Mark Brown

[permalink] [raw]
Subject: [PATCH 0/2] kselftest/arm64: Improvements to BTI tests on non-BTI systems

While looking at the BTI selftest results on a non-BTI system I noticed
that not only are we printing invalid test numbers in that case, we're
skipping running the tests entirely even though there's a well defined
ABI we could be verifying and the code already knows what the results
should be.

The first patch here is a fix to the reporting of test numbers when
skipping, the second one just removes the skipping entirely in favour of
a runtime check for what the result of a BTI binary should be.

To: Catalin Marinas <[email protected]>
To: Will Deacon <[email protected]>
To: Shuah Khan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Mark Brown <[email protected]>

---
Mark Brown (2):
kselftest/arm64: Fix test numbering when skipping tests
kselftest/arm64: Run BTI selftests on systems without BTI

tools/testing/selftests/arm64/bti/test.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
---
base-commit: b7bfaa761d760e72a969d116517eaa12e404c262
change-id: 20230110-arm64-bti-selftest-skip-9fdf5e94fb62

Best regards,
--
Mark Brown <[email protected]>


2023-01-10 21:15:57

by Mark Brown

[permalink] [raw]
Subject: [PATCH 2/2] kselftest/arm64: Run BTI selftests on systems without BTI

The BTI selftests are built both with and without BTI support, validating
both the generation of BTI signals as expected for binaries without BTI
support. Both versions of the binary currently skip all their tests when
the system does not support BTI, however this is excessive since we do have
a defined ABI for how the programs should function in this case (especially
for the non-BTI binary). Update the test program to run all the tests
unconditionally, adding a runtime adjustment of the expected results on
systems that don't support BTI where we currently handle the build time
case.

The tests all use HINT space instructions, BTI itself is a HINT as is
are the PAC instructions that function as landing pads, so nothing in the
tests depends on support for BTI in the kernel or hardware.

Signed-off-by: Mark Brown <[email protected]>
---
tools/testing/selftests/arm64/bti/test.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/arm64/bti/test.c b/tools/testing/selftests/arm64/bti/test.c
index 4b6dda987c58..2cd8dcee5aec 100644
--- a/tools/testing/selftests/arm64/bti/test.c
+++ b/tools/testing/selftests/arm64/bti/test.c
@@ -6,6 +6,7 @@

#include "system.h"

+#include <stdbool.h>
#include <stddef.h>
#include <linux/errno.h>
#include <linux/auxvec.h>
@@ -101,7 +102,8 @@ static void handler(int n, siginfo_t *si __always_unused,
uc->uc_mcontext.pstate &= ~PSR_BTYPE_MASK;
}

-static int skip_all;
+/* Does the system have BTI? */
+static bool have_bti;

static void __do_test(void (*trampoline)(void (*)(void)),
void (*fn)(void),
@@ -109,19 +111,11 @@ static void __do_test(void (*trampoline)(void (*)(void)),
const char *name,
int expect_sigill)
{
- if (skip_all) {
- test_skipped++;
- putstr("ok ");
- putnum(test_num++);
- putstr(" ");
- puttestname(name, trampoline_name);
- putstr(" # SKIP\n");
-
- return;
- }
-
- /* Branch Target exceptions should only happen in BTI binaries: */
- if (!BTI)
+ /*
+ * Branch Target exceptions should only happen for BTI
+ * binaries running on a system with BTI:
+ */
+ if (!BTI || !have_bti)
expect_sigill = 0;

sigill_expected = expect_sigill;
@@ -199,9 +193,10 @@ void start(int *argcp)
putstr("# HWCAP2_BTI present\n");
if (!(hwcap & HWCAP_PACA))
putstr("# Bad hardware? Expect problems.\n");
+ have_bti = true;
} else {
putstr("# HWCAP2_BTI not present\n");
- skip_all = 1;
+ have_bti = false;
}

putstr("# Test binary");

--
2.30.2

2023-01-10 21:15:58

by Mark Brown

[permalink] [raw]
Subject: [PATCH 1/2] kselftest/arm64: Fix test numbering when skipping tests

Currently when skipping tests in the BTI testsuite we assign the same
number to every test since we forget to increment the current test number
as we skip, causing warnings about not running the expected test count and
potentially otherwise confusing result parsers. Fix this by adding an
appropriate increment.

Signed-off-by: Mark Brown <[email protected]>
---
tools/testing/selftests/arm64/bti/test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/arm64/bti/test.c b/tools/testing/selftests/arm64/bti/test.c
index 67b77ab83c20..4b6dda987c58 100644
--- a/tools/testing/selftests/arm64/bti/test.c
+++ b/tools/testing/selftests/arm64/bti/test.c
@@ -112,7 +112,7 @@ static void __do_test(void (*trampoline)(void (*)(void)),
if (skip_all) {
test_skipped++;
putstr("ok ");
- putnum(test_num);
+ putnum(test_num++);
putstr(" ");
puttestname(name, trampoline_name);
putstr(" # SKIP\n");

--
2.30.2

2023-01-12 18:26:07

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH 0/2] kselftest/arm64: Improvements to BTI tests on non-BTI systems

On Tue, 10 Jan 2023 20:49:58 +0000, Mark Brown wrote:
> While looking at the BTI selftest results on a non-BTI system I noticed
> that not only are we printing invalid test numbers in that case, we're
> skipping running the tests entirely even though there's a well defined
> ABI we could be verifying and the code already knows what the results
> should be.
>
> The first patch here is a fix to the reporting of test numbers when
> skipping, the second one just removes the skipping entirely in favour of
> a runtime check for what the result of a BTI binary should be.
>
> [...]

Applied to arm64 (for-next/kselftest), thanks!

[1/2] kselftest/arm64: Fix test numbering when skipping tests
https://git.kernel.org/arm64/c/30792e7c18b6
[2/2] kselftest/arm64: Run BTI selftests on systems without BTI
https://git.kernel.org/arm64/c/1c3b614548b5

--
Catalin