kselftest/arm64: Miscelaneous MTE test updates
cover kselftest/arm64: Miscelaneous MTE test updates
This series is just a set of minor tweaks and improvements for the MTE tests that I did while working on the asymmetric mode support for userspace which seemed like they might be worth keeping even though the prctl() for asymmetric mode got removed.
Mark Brown (4):
kselftest/arm64: Handle more kselftest result codes in MTE helpers kselftest/arm64: Log unexpected asynchronous MTE faults kselftest/arm64: Refactor parameter checking in mte_switch_mode() kselftest/arm64: Add simple test for MTE prctl
tools/testing/selftests/arm64/mte/.gitignore | 1 + .../testing/selftests/arm64/mte/check_prctl.c | 123 ++++++++++++++++++ .../selftests/arm64/mte/mte_common_util.c | 17 ++- .../selftests/arm64/mte/mte_common_util.h | 15 ++- 4 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 tools/testing/selftests/arm64/mte/check_prctl.c
base-commit: dfd42facf1e4ada021b939b4e19c935dcdd55566
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/4 kselftest/arm64: Handle more kselftest result codes in MTE helpers
The MTE selftests have a helper evaluate_test() which translates a return code into a call to ksft_test_result_*(). Currently this only handles pass and fail, silently ignoring any other code. Update the helper to support skipped tests and log any unknown return codes as an error so we get at least some diagnostic if anything goes wrong.
--- .../testing/selftests/arm64/mte/mte_common_util.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
tools/testing/selftests/arm64/mte/mte_common_util.h +13 -2
@@ -75,10 +75,21 @@ unsigned int mte_get_pstate_tco(void);/* Test framework static inline functions/macros */ static inline void evaluate_test (int err,const char *msg) { -if (err ==KSFT_PASS ) +switch (err) { +case KSFT_PASS :ksft_test_result_pass (msg); -else if (err ==KSFT_FAIL ) +break ; +case KSFT_FAIL :ksft_test_result_fail (msg); +break ; +case KSFT_SKIP : +ksft_test_result_skip (msg); +break ; +default : +ksft_test_result_error ("Unknown return code %d from %s" , + err, msg); +break ; + } } static inline int check_allocated_memory(void *ptr, size_t size,
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 1/4] kselftest/arm64: Handle more kselftest result codes in MTE helpers
Quoted 30 lines · Mark Brown
The MTE selftests have a helper
evaluate_test()which translates a return code into a call to ksft_test_result_*(). Currently this only handles pass and fail, silently ignoring any other code. Update the helper to support skipped tests and log any unknown return codes as an error so we get at least some diagnostic if anything goes wrong.Signed-off-by Mark Brown <[email protected]>--- .../testing/selftests/arm64/mte/mte_common_util.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)tools/testing/selftests/arm64/mte/mte_common_util.h +6
-2@@ -75,10 +75,21 @@ unsigned int mte_get_pstate_tco(void);/* Test framework static inline functions/macros */ static inline void evaluate_test (int err,const char *msg) { -if (err ==KSFT_PASS ) +switch (err) { +case KSFT_PASS :ksft_test_result_pass (msg); -else if (err ==KSFT_FAIL ) +break ; +case KSFT_FAIL :ksft_test_result_fail (msg); +break ; +case KSFT_SKIP :
tools/testing/selftests/arm64/mte/mte_common_util.h unsigned int mte_get_pstate_tco(void); · line 95
Quoted 10 lines
tools/testing/selftests/arm64/mte/mte_common_util.h +7
-0+ksft_test_result_skip (msg); +break ; +default : +ksft_test_result_error ("Unknown return code %d from %s" , + err, msg); +break ; + } } static inline int check_allocated_memory(void *ptr, size_t size,
Nice. Thank you for doing this.
thanks,
-- Shuah
PATCH 2/4 kselftest/arm64: Log unexpected asynchronous MTE faults
In reply to Mark BrownHelp people figure out problems by printing a diagnostic when we get an unexpected asynchronous fault.
--- tools/testing/selftests/arm64/mte/mte_common_util.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/arm64/mte/mte_common_util.c +2 -0
@@ -37,6 +37,8 @@ void mte_default_handler(int signum, siginfo_t *si, void *uc)if (si->si_code ==SEGV_MTEAERR ) {if (cur_mte_cxt.trig_si_code == si->si_code) cur_mte_cxt.fault_valid = true; +else +ksft_print_msg ("Got unexpected SEGV_MTEAERR\n" );return ; }/* Compare the context for precise error */
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 2/4] kselftest/arm64: Log unexpected asynchronous MTE faults
Quoted 13 lines · Mark Brown
Help people figure out problems by printing a diagnostic when we get an unexpected asynchronous fault.
Signed-off-by Mark Brown <[email protected]>--- tools/testing/selftests/arm64/mte/mte_common_util.c | 2 ++ 1 file changed, 2 insertions(+)tools/testing/selftests/arm64/mte/mte_common_util.c +0
-0
tools/testing/selftests/arm64/mte/mte_common_util.c void mte_default_handler(int signum, siginfo_t *si, void *uc) · line 41
Quoted 5 lines
tools/testing/selftests/arm64/mte/mte_common_util.c +2
-0@@ -37,6 +37,8 @@ void mte_default_handler(int signum, siginfo_t *si, void *uc)if (si->si_code ==SEGV_MTEAERR ) {if (cur_mte_cxt.trig_si_code == si->si_code) cur_mte_cxt.fault_valid = true; +else +ksft_print_msg ("Got unexpected SEGV_MTEAERR\n" );
This is good. Would it make sense to add more info. - I see this in the doc? Would it make sense to also check si_addr?
- *Asynchronous* - The kernel raises a ``SIGSEGV``, in the offending thread, asynchronously following one or multiple tag check faults, with ``.si_code = SEGV_MTEAERR`` and ``.si_addr = 0`` (the faulting address is unknown).
tools/testing/selftests/arm64/mte/mte_common_util.c void mte_default_handler(int signum, siginfo_t *si, void *uc) · line 44
Quoted 4 lines
tools/testing/selftests/arm64/mte/mte_common_util.c +0
-0return ; }/* Compare the context for precise error */
Looks good to me as such.
thanks,
-- Shuah
PATCH 3/4 kselftest/arm64: Refactor parameter checking in mte_switch_mode()
In reply to Mark BrownCurrently we just have a big if statement with a non-specific diagnostic checking both the mode and the tag. Since we'll need to dynamically check for asymmetric mode support in the system and to improve debugability split these checks out.
--- .../testing/selftests/arm64/mte/mte_common_util.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
tools/testing/selftests/arm64/mte/mte_common_util.c +12 -3
@@ -271,9 +271,18 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask) {unsigned long en =0 ; -if (!(mte_option ==MTE_SYNC_ERR || mte_option ==MTE_ASYNC_ERR || - mte_option ==MTE_NONE_ERR || incl_mask <=MTE_ALLOW_NON_ZERO_TAG )) { -ksft_print_msg ("FAIL: Invalid mte config option\n" ); +switch (mte_option) { +case MTE_NONE_ERR : +case MTE_SYNC_ERR : +case MTE_ASYNC_ERR : +break ; +default : +ksft_print_msg ("FAIL: Invalid MTE option %x\n" , mte_option); +return -EINVAL ; + } + +if (!(incl_mask <=MTE_ALLOW_NON_ZERO_TAG )) { +ksft_print_msg ("FAIL: Invalid incl_mask %lx\n" , incl_mask);return -EINVAL ; } en =PR_TAGGED_ADDR_ENABLE ;
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 3/4] kselftest/arm64: Refactor parameter checking in mte_switch_mode()
Quoted 27 lines · Mark Brown
Currently we just have a big if statement with a non-specific diagnostic checking both the mode and the tag. Since we'll need to dynamically check for asymmetric mode support in the system and to improve debugability split these checks out.
Signed-off-by Mark Brown <[email protected]>--- .../testing/selftests/arm64/mte/mte_common_util.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)tools/testing/selftests/arm64/mte/mte_common_util.c +5
-3@@ -271,9 +271,18 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask) {unsigned long en =0 ; -if (!(mte_option ==MTE_SYNC_ERR || mte_option ==MTE_ASYNC_ERR || - mte_option ==MTE_NONE_ERR || incl_mask <=MTE_ALLOW_NON_ZERO_TAG )) { -ksft_print_msg ("FAIL: Invalid mte config option\n" ); +switch (mte_option) { +case MTE_NONE_ERR : +case MTE_SYNC_ERR : +case MTE_ASYNC_ERR : +break ;
tools/testing/selftests/arm64/mte/mte_common_util.c int mte_switch_mode(int mte_option, unsigned long incl_mask) · line 288
Quoted 10 lines
tools/testing/selftests/arm64/mte/mte_common_util.c +7
-0+default : +ksft_print_msg ("FAIL: Invalid MTE option %x\n" , mte_option); +return -EINVAL ; + } + +if (!(incl_mask <=MTE_ALLOW_NON_ZERO_TAG )) { +ksft_print_msg ("FAIL: Invalid incl_mask %lx\n" , incl_mask);return -EINVAL ; } en =PR_TAGGED_ADDR_ENABLE ;
Looks good to me.
thanks,
-- Shuah
PATCH 4/4 kselftest/arm64: Add simple test for MTE prctl
In reply to Mark BrownThe current tests use the prctls for various things but there's no coverage of the edges of the interface so add some basics. This isn't hugely useful as it is (it originally had some coverage for the combinations with asymmetric mode but we removed the prctl() for that) but it might be a helpful starting point for future work, for example covering error handling.
--- tools/testing/selftests/arm64/mte/.gitignore | 1 + .../testing/selftests/arm64/mte/check_prctl.c | 123 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 tools/testing/selftests/arm64/mte/check_prctl.c
tools/testing/selftests/arm64/mte/.gitignore +1 -0
@@ -3,5 +3,6 @@ check_gcr_el1_cswitch check_tags_inclusion check_child_memory check_mmap_options +check_prctl check_ksm_options check_user_mem
tools/testing/selftests/arm64/mte/check_prctl.c new file +123 -0
123 lines not on this page · raw message
Signature · 7 lines
2.30.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v1 4/4] kselftest/arm64: Add simple test for MTE prctl
Hi Mark,
Quoted 9 lines · Mark Brown
The current tests use the prctls for various things but there's no coverage of the edges of the interface so add some basics. This isn't hugely useful as it is (it originally had some coverage for the combinations with asymmetric mode but we removed the
prctl()for that) but it might be a helpful starting point for future work, for example covering error handling.Signed-off-by Mark Brown <[email protected]>---
[..]
Quoted 11 lines
tools/testing/selftests/arm64/mte/check_prctl.c new file +5
-0@@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2022 ARM Limited + +#include <stdbool.h> +#include <stdio.h>
tools/testing/selftests/arm64/mte/check_prctl.c line 15
Quoted 10 lines
tools/testing/selftests/arm64/mte/check_prctl.c new file +10
-0+#include <string.h> + +#include <sys/auxv.h> +#include <sys/prctl.h> + +#include <asm/hwcap.h> + +#include "kselftest.h" + +static bool system_has_mte;
This looks unused (apart from being set in main()).
Thanks,
Joey
Re: [PATCH v1 4/4] kselftest/arm64: Add simple test for MTE prctl
Quoted 5 lines · Joey Gouly
Quoted 1 line · Mark Brown
+static bool
system_has_mte;This looks unused (apart from being set in
main()).
It is, it was used in the asymmetric bits of the test.
Re: [PATCH v1 4/4] kselftest/arm64: Add simple test for MTE prctl
In reply to Mark BrownQuoted 7 lines · Mark Brown
The current tests use the prctls for various things but there's no coverage of the edges of the interface so add some basics. This isn't hugely useful as it is (it originally had some coverage for the combinations with asymmetric mode but we removed the
prctl()for that) but it might be a helpful starting point for future work, for example covering error handling.
Quoted 7 lines
Signed-off-by Mark Brown <[email protected]>--- tools/testing/selftests/arm64/mte/.gitignore | 1 + .../testing/selftests/arm64/mte/check_prctl.c | 123 ++++++++++++++++++ 2 files changed, 124 insertions(+)create mode 100644
tools/testing/selftests/arm64/mte/check_prctl.c
Looks good to me.
thanks,
-- Shuah