Maintainer workflows discussions
 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 2/4] kcsan: add debugfs target control
Date: Wed, 14 Oct 2026 18:52:36 +0900	[thread overview]
Message-ID: <20261014095238.2132580-3-sh_def@163.com> (raw)

Expose targeted sampling through the KCSAN debugfs file. Accept address
and kallsyms targets, including module:symbol names, and allow sampling
to be disabled with target=off.

Use KSYM_SYMBOL_LEN for the input buffer so documented module symbols fit,
and return -E2BIG for oversized writes.

Signed-off-by: Hui Su <sh_def@163.com>
---
 kernel/kcsan/debugfs.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/kernel/kcsan/debugfs.c b/kernel/kcsan/debugfs.c
index 2af39ba5b70b..47becde9f1ae 100644
--- a/kernel/kcsan/debugfs.c
+++ b/kernel/kcsan/debugfs.c
@@ -191,6 +191,7 @@ static ssize_t insert_report_filterlist(const char *func)
 static int show_info(struct seq_file *file, void *v)
 {
 	int i;
+	unsigned long target;
 	unsigned long flags;
 
 	/* show stats */
@@ -199,6 +200,12 @@ static int show_info(struct seq_file *file, void *v)
 		seq_printf(file, "%s: %ld\n", counter_names[i],
 			   atomic_long_read(&kcsan_counters[i]));
 	}
+	target = kcsan_target_get();
+	if (target)
+		seq_printf(file, "\ntarget: %pK (%pS)\n", (void *)target,
+			   (void *)target);
+	else
+		seq_puts(file, "\ntarget: none\n");
 
 	/* show filter functions, and filter type */
 	raw_spin_lock_irqsave(&report_filterlist_lock, flags);
@@ -220,10 +227,13 @@ static int debugfs_open(struct inode *inode, struct file *file)
 static ssize_t
 debugfs_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
 {
-	char kbuf[KSYM_NAME_LEN];
+	char kbuf[KSYM_SYMBOL_LEN + sizeof("target=")];
 	char *arg;
 	const size_t read_len = min(count, sizeof(kbuf) - 1);
 
+	if (count > sizeof(kbuf) - 1)
+		return -E2BIG;
+
 	if (copy_from_user(kbuf, buf, read_len))
 		return -EFAULT;
 	kbuf[read_len] = '\0';
@@ -239,6 +249,22 @@ debugfs_write(struct file *file, const char __user *buf, size_t count, loff_t *o
 		if (kstrtoul(&arg[strlen("microbench=")], 0, &iters))
 			return -EINVAL;
 		microbenchmark(iters);
+	} else if (str_has_prefix(arg, "target=")) {
+		char *target = &arg[strlen("target=")];
+		unsigned long addr;
+
+		if (!strcmp(target, "off")) {
+			kcsan_target_set(0);
+		} else if (!kstrtoul(target, 0, &addr)) {
+			if (!addr)
+				return -EINVAL;
+			kcsan_target_set(addr);
+		} else {
+			addr = kallsyms_lookup_name(target);
+			if (!addr)
+				return -ENOENT;
+			kcsan_target_set(addr);
+		}
 	} else if (!strcmp(arg, "whitelist")) {
 		set_report_filterlist_whitelist(true);
 	} else if (!strcmp(arg, "blacklist")) {
-- 
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-3-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