mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kunwu Chan <kunwu.chan@gmail.com>
To: jiangshanlai@gmail.com, paulmck@kernel.org,
	josh@joshtriplett.org, work@onurozkan.dev, frederic@kernel.org,
	neeraj.upadhyay@kernel.org, joelagnelf@nvidia.com,
	boqun@kernel.org, urezki@gmail.com
Cc: rostedt@goodmis.org, mathieu.desnoyers@efficios.com,
	qiang.zhang@linux.dev, rcu@vger.kernel.org,
	linux-kernel@vger.kernel.org, Kunwu Chan <kunwu.chan@gmail.com>,
	Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH 9/9] rcu-tasks: Detect duplicate callback enqueue
Date: Fri, 23 Oct 2026 18:18:41 +0800	[thread overview]
Message-ID: <20261023101841.2910719-10-kunwu.chan@gmail.com> (raw)
In-Reply-To: <20261023101841.2910719-1-kunwu.chan@gmail.com>

Detect duplicate callback enqueue attempts in the generic
RCU Tasks callback registration path.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 kernel/rcu/tasks.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h
index 5d7f234795b4..49b716feb31d 100644
--- a/kernel/rcu/tasks.h
+++ b/kernel/rcu/tasks.h
@@ -6,6 +6,7 @@
  */
 
 #ifdef CONFIG_TASKS_RCU_GENERIC
+#include <linux/mm.h>
 #include "rcu_segcblist.h"
 
 ////////////////////////////////////////////////////////////////////////
@@ -339,9 +340,12 @@ static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp)
 }
 
 // Enqueue a callback for the specified flavor of Tasks RCU.
+static void rcu_tasks_leak_callback(struct rcu_head *rhp) { }
+
 static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
 				   struct rcu_tasks *rtp)
 {
+	static atomic_t doublefrees;
 	int chosen_cpu;
 	unsigned long flags;
 	bool havekthread = smp_load_acquire(&rtp->kthread_ptr);
@@ -358,6 +362,16 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
 	if (WARN_ON_ONCE(!func))
 		return;
 
+	if (debug_rcu_head_queue(rhp)) {
+		if (atomic_inc_return(&doublefrees) < 4) {
+			pr_err("%s(): Duplicate call_rcu_%s() CB %p->%pS()\n",
+			       __func__, rtp->name, rhp, rhp->func);
+			mem_dump_obj(rhp);
+		}
+		WRITE_ONCE(rhp->func, rcu_tasks_leak_callback);
+		return;
+	}
+
 	rhp->next = NULL;
 	rhp->func = func;
 	local_irq_save(flags);
@@ -586,6 +600,7 @@ static void rcu_tasks_invoke_cbs(struct rcu_tasks *rtp, struct rcu_tasks_percpu
 	raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
 	len = rcl.len;
 	for (rhp = rcu_cblist_dequeue(&rcl); rhp; rhp = rcu_cblist_dequeue(&rcl)) {
+		debug_rcu_head_unqueue(rhp);
 		debug_rcu_head_callback(rhp);
 		local_bh_disable();
 		rhp->func(rhp);
-- 
2.43.0


      parent reply	other threads:[~2026-10-23 10:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 10:18 [PATCH 0/9] rcu: Improve callback diagnostics and validation Kunwu Chan
2026-10-23 10:18 ` [PATCH 1/9] srcu: Record callback registration stack for KASAN Kunwu Chan
2026-10-23 10:18 ` [PATCH 2/9] srcutiny: " Kunwu Chan
2026-10-23 10:18 ` [PATCH 3/9] rcu: Record callback registration stack for Tiny RCU Kunwu Chan
2026-10-23 10:18 ` [PATCH 4/9] srcu: Validate callback arguments Kunwu Chan
2026-10-23 10:18 ` [PATCH 5/9] rcu: Validate callback arguments in Tiny RCU Kunwu Chan
2026-10-23 10:18 ` [PATCH 6/9] rcu-tasks: Validate callback arguments Kunwu Chan
2026-10-23 10:18 ` [PATCH 7/9] srcu: Detect duplicate callback enqueue at registration Kunwu Chan
2026-10-23 10:18 ` [PATCH 8/9] srcutiny: Detect duplicate callback enqueue Kunwu Chan
2026-10-23 10:18 ` Kunwu Chan [this message]

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=20261023101841.2910719-10-kunwu.chan@gmail.com \
    --to=kunwu.chan@gmail.com \
    --cc=boqun@kernel.org \
    --cc=chentao@kylinos.cn \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=joelagnelf@nvidia.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=urezki@gmail.com \
    --cc=work@onurozkan.dev \
    /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®