* [RFC PATCH 3/4] kcsan: add targeted watchpoint selftest
@ 2026-10-14 9:52 Hui Su
0 siblings, 0 replies; only message in thread
From: Hui Su @ 2026-10-14 9:52 UTC (permalink / raw)
To: elver, dvyukov
Cc: kasan-dev, corbet, skhan, rdunlap, workflows, linux-doc, linux-kernel
Test targeted address matching for exact and containing access ranges,
adjacent ranges, zero-sized accesses, and boundary addresses at ULONG_MAX.
These cases cover subtraction-based matching without runtime debugfs setup.
Signed-off-by: Hui Su <sh_def@163.com>
---
kernel/kcsan/selftest.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/kernel/kcsan/selftest.c b/kernel/kcsan/selftest.c
index 84a1200271af..8da1ba2ba25a 100644
--- a/kernel/kcsan/selftest.c
+++ b/kernel/kcsan/selftest.c
@@ -12,6 +12,7 @@
#include <linux/init.h>
#include <linux/kcsan-checks.h>
#include <linux/kernel.h>
+#include <linux/limits.h>
#include <linux/printk.h>
#include <linux/random.h>
#include <linux/sched.h>
@@ -101,6 +102,33 @@ static bool __init test_matching_access(void)
return true;
}
+/* Test whether an access contains the selected target byte. */
+static bool __init test_target_matching(void)
+{
+ const unsigned long target = 0x1004;
+
+ if (WARN_ON(!kcsan_target_matches(target, 0x1004, 1)))
+ return false;
+ if (WARN_ON(!kcsan_target_matches(target, 0x1000, 8)))
+ return false;
+ if (WARN_ON(kcsan_target_matches(target, 0x1000, 4)))
+ return false;
+ if (WARN_ON(kcsan_target_matches(target, 0x1005, 1)))
+ return false;
+ if (WARN_ON(kcsan_target_matches(target, 0x1004, 0)))
+ return false;
+ if (WARN_ON(!kcsan_target_matches(ULONG_MAX, ULONG_MAX, 1)))
+ return false;
+ if (WARN_ON(!kcsan_target_matches(ULONG_MAX, ULONG_MAX - 3, 4)))
+ return false;
+ if (WARN_ON(kcsan_target_matches(ULONG_MAX, ULONG_MAX - 1, 1)))
+ return false;
+ if (WARN_ON(kcsan_target_matches(0, ULONG_MAX - 1, 4)))
+ return false;
+
+ return true;
+}
+
/*
* Correct memory barrier instrumentation is critical to avoiding false
* positives: simple test to check at boot certain barriers are always properly
@@ -251,6 +279,7 @@ static int __init kcsan_selftest(void)
RUN_TEST(test_encode_decode);
RUN_TEST(test_matching_access);
+ RUN_TEST(test_target_matching);
RUN_TEST(test_barrier);
pr_info("selftest: %d/%d tests passed\n", passed, total);
--
2.55.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-14 9:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-14 9:52 [RFC PATCH 3/4] kcsan: add targeted watchpoint selftest Hui Su
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®