mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
kasan, arm64: tests supports for HW_TAGS async mode
This change adds KASAN-KUnit tests support for the async HW_TAGS mode. In async mode, tag fault aren't being generated synchronously when a bad access happens, but are instead explicitly checked for by the kernel. As each KASAN-KUnit test expect a fault to happen before the test is over, check for faults as a part of the test handler. Acked-by: Catalin Marinas <catalin.marinas@arm.com> Acked-by: Andrey Konovalov <andreyknvl@google.com> Tested-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Link: https://lore.kernel.org/r/20210315132019.33202-10-vincenzo.frascino@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
This commit is contained in:
parent
eab0e6e17d
commit
e80a76aa1a
5 changed files with 29 additions and 6 deletions
|
@ -69,10 +69,10 @@ static void kasan_test_exit(struct kunit *test)
|
|||
* resource named "kasan_data". Do not use this name for KUnit resources
|
||||
* outside of KASAN tests.
|
||||
*
|
||||
* For hardware tag-based KASAN, when a tag fault happens, tag checking is
|
||||
* normally auto-disabled. When this happens, this test handler reenables
|
||||
* tag checking. As tag checking can be only disabled or enabled per CPU, this
|
||||
* handler disables migration (preemption).
|
||||
* For hardware tag-based KASAN in sync mode, when a tag fault happens, tag
|
||||
* checking is auto-disabled. When this happens, this test handler reenables
|
||||
* tag checking. As tag checking can be only disabled or enabled per CPU,
|
||||
* this handler disables migration (preemption).
|
||||
*
|
||||
* Since the compiler doesn't see that the expression can change the fail_data
|
||||
* fields, it can reorder or optimize away the accesses to those fields.
|
||||
|
@ -80,7 +80,8 @@ static void kasan_test_exit(struct kunit *test)
|
|||
* expression to prevent that.
|
||||
*/
|
||||
#define KUNIT_EXPECT_KASAN_FAIL(test, expression) do { \
|
||||
if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) \
|
||||
if (IS_ENABLED(CONFIG_KASAN_HW_TAGS) && \
|
||||
!kasan_async_mode_enabled()) \
|
||||
migrate_disable(); \
|
||||
WRITE_ONCE(fail_data.report_expected, true); \
|
||||
WRITE_ONCE(fail_data.report_found, false); \
|
||||
|
@ -92,10 +93,14 @@ static void kasan_test_exit(struct kunit *test)
|
|||
barrier(); \
|
||||
expression; \
|
||||
barrier(); \
|
||||
if (kasan_async_mode_enabled()) \
|
||||
kasan_force_async_fault(); \
|
||||
barrier(); \
|
||||
KUNIT_EXPECT_EQ(test, \
|
||||
READ_ONCE(fail_data.report_expected), \
|
||||
READ_ONCE(fail_data.report_found)); \
|
||||
if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) { \
|
||||
if (IS_ENABLED(CONFIG_KASAN_HW_TAGS) && \
|
||||
!kasan_async_mode_enabled()) { \
|
||||
if (READ_ONCE(fail_data.report_found)) \
|
||||
kasan_enable_tagging_sync(); \
|
||||
migrate_enable(); \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue