mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hui Su <sh_def@163.com>
To: elver@google.com, dvyukov@google.com
Cc: kasan-dev@googlegroups.com, corbet@lwn.net,
	skhan@linuxfoundation.org, rdunlap@infradead.org,
	workflows@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 3/4] kcsan: add targeted watchpoint selftest
Date: Wed, 14 Oct 2026 18:52:37 +0900	[thread overview]
Message-ID: <20261014095238.2132580-4-sh_def@163.com> (raw)

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


                 reply	other threads:[~2026-10-14  9:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014095238.2132580-4-sh_def@163.com \
    --to=sh_def@163.com \
    --cc=corbet@lwn.net \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=workflows@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®