Possible debug objects issue with: rcu: Make call_rcu() safe to call from any context
Joel Fernandes
maintainerHello Puranjay,
My local LLM flagged a debug objects issue with the Make call_rcu() safe to call patch.
Apparently, it is possible that a double call_rcu can result in corruption of the deferred list before debug_objects gets a chance to look at it.
Can you take a look at my AI slop patch below that fixes this, and do some testing on this if it is a real issue and send a proper patch? Thank you so much.
---8<-----------------------
From 1a550f5c8386761aa9c5c5bf2ec28dcd74ecebec Mon Sep 17 00:00:00 2001
From: Joel Fernandes <[email protected]>
Date: Wed, 28 Oct 2026 06:50:58 -0400
Subject: [PATCH] [TBC] rcu: Preserve deferred lists while checking duplicate
callbacks
The deferred call_rcu() path uses the callback head as its lockless list node. Registering that head twice can self-link the list and lose other callbacks before rcu_do_enqueue() checks for duplicates. The IRQ-disabled object_debug test reports a missing valid callback on both Tree and Tiny RCU, and an invoked duplicate on Tiny RCU.
With DEBUG_OBJECTS_RCU_HEAD, stage callbacks in independent entries so duplicate heads cannot corrupt the list before the existing checker runs. Keep the checker in the drain instead of moving its blocking locks into NMI/reentrant registration. Use kmalloc_nolock()/kfree_nolock() for the entries, and drain them through the existing irq_work, barrier and CPU-offline paths. Match Tree RCU's leak callback handling in Tiny RCU.
This costs one small allocation per deferred registration in debug builds. If metadata cannot be allocated, retain the original intrusive path rather than dropping valid callbacks. Duplicate containment is therefore best-effort in that fallback, as with failed debug tracking. Non-debug builds do not allocate entries.
--- kernel/rcu/rcu.h | 30 ++++++++++++++++++++++++++++++ kernel/rcu/tiny.c | 28 ++++++++++++++++++++++++++-- kernel/rcu/tree.c | 25 ++++++++++++++++++++++--- kernel/rcu/tree.h | 1 + 4 files changed, 79 insertions(+), 5 deletions(-)
kernel/rcu/rcu.h +30 -0
@@ -10,6 +10,7 @@#ifndef __LINUX_RCU_H#define __LINUX_RCU_H +#include <linux/llist.h> #include <linux/slab.h> #include <trace/events/rcu.h>
@@ -583,6 +584,35 @@ static inline bool should_rcu_defer(void) rcu_scheduler_active !=RCU_SCHEDULER_INACTIVE ; } +/* +* Debug checking must run after deferral, where it can take locks. Use a +* separate list node so duplicate heads cannot corrupt the deferred list +* before debug_rcu_head_queue() gets a chance to reject them. +* Allocation failure falls back to the intrusive list to preserve valid +* callbacks; duplicate containment is best-effort in that case. +*/ +struct rcu_defer_entry { +struct llist_node node; +struct rcu_head *head; +rcu_callback_t func; +}; + +static inline struct rcu_defer_entry *rcu_defer_entry_alloc (struct rcu_head *head, +rcu_callback_t func) +{ +struct rcu_defer_entry *entry; + +if (!IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) +return NULL ; + + entry =kmalloc_nolock (sizeof (*entry),0 ,NUMA_NO_NODE ); +if (entry) { + entry->head = head; + entry->func = func; + } +return entry; +} +/* Drain an outgoing CPU's deferred SRCU callbacks; see rcutree_migrate_callbacks(). */ void srcu_offline_drain (int cpu);
kernel/rcu/tiny.c +26 -2
@@ -48,14 +48,17 @@ static struct rcu_ctrlblk rcu_ctrlblk = {/* * The callback list is only accessed with interrupts disabled, so a call_rcu() * that arrives with interrupts off stages the callback on a lockless list that -* an irq_work re-issues later. One global list and irq_work suffice, as Tiny -* RCU is uniprocessor. +* an irq_work re-issues later. Tiny RCU is uniprocessor, so the normal and +* debug lists share one global irq_work. */ static void rcu_defer_drain (struct irq_work *iw);static LLIST_HEAD (rcu_defer_list); +static LLIST_HEAD (rcu_defer_debug_list);static struct irq_work rcu_defer_iw =IRQ_WORK_INIT_HARD (rcu_defer_drain);static bool rcu_defer_draining; +static void rcu_leak_callback (struct rcu_head *head) { } +/* * Also called by __rcu_defer_drain() to re-issue a deferred callback, so it * must not re-check the deferral condition.
@@ -70,6 +73,7 @@ static void rcu_do_enqueue(struct rcu_head *head, rcu_callback_t func)pr_err ("%s(): Double-freed CB %p->%pS()!!! " , __func__, head, head->func);mem_dump_obj (head); } +WRITE_ONCE (head->func, rcu_leak_callback);return ; }
@@ -108,6 +112,17 @@ static void __rcu_defer_drain(void)rcu_do_enqueue (head, head->func); drained = true; } +if (IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) { +llist_for_each_safe (node, next,llist_del_all (&rcu_defer_debug_list)) { +struct rcu_defer_entry *entry; + + entry = llist_entry(node, struct rcu_defer_entry, node); + +rcu_do_enqueue (entry->head, entry->func); +kfree_nolock (entry); + drained = true; + } + }local_irq_restore (flags);if (drained)
@@ -124,12 +139,21 @@ static void rcu_defer_drain(struct irq_work *iw)static void call_rcu_defer (struct rcu_head *head,rcu_callback_t func) { +struct rcu_defer_entry *entry; +/* A re-entrant call_rcu() during the drain would livelock it; drop it. */ if (READ_ONCE (rcu_defer_draining) && !in_nmi ()) {WARN_ONCE (IS_ENABLED (CONFIG_PROVE_RCU ),"call_rcu() re-entered during callback drain; leaking callback\n" );return ; } + entry =rcu_defer_entry_alloc (head, func); +if (entry) { +if (llist_add (&entry->node, &rcu_defer_debug_list)) +irq_work_queue (&rcu_defer_iw); +return ; + } +/* Keep valid callbacks working even if debug metadata cannot be allocated. */ head->func = func;if (llist_add ((struct llist_node *)head, &rcu_defer_list))irq_work_queue (&rcu_defer_iw);
kernel/rcu/tree.c +22 -3
@@ -3229,6 +3229,16 @@ static void __rcu_defer_drain(struct rcu_data *rdp) head->next =NULL ;rcu_do_enqueue (head, head->func, false); } +if (IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) { +llist_for_each_safe (node, next,llist_del_all (&rdp->defer_debug_head)) { +struct rcu_defer_entry *entry; + + entry = llist_entry(node, struct rcu_defer_entry, node); + +rcu_do_enqueue (entry->head, entry->func, false); +kfree_nolock (entry); + } + }raw_spin_unlock_irqrestore (&rdp->defer_lock, flags); }
@@ -3248,12 +3258,13 @@ static void rcu_defer_drain(struct irq_work *iw) }/* -* Stage @head for this CPU's irq_work to re-issue once interrupts are on. Only -* the drain side takes a lock, so this stays safe from NMI. +* Stage @head for this CPU's irq_work to re-issue once interrupts are on. +* Allocation uses nonblocking trylocks, and list insertion is lockless. */ static void call_rcu_defer (struct rcu_head *head,rcu_callback_t func) {struct rcu_data *rdp =this_cpu_ptr (&rcu_data); +struct rcu_defer_entry *entry;/* * Instrumentation on the enqueue path can re-enter here from inside the
@@ -3265,6 +3276,13 @@ static void call_rcu_defer(struct rcu_head *head, rcu_callback_t func) "call_rcu() re-entered during callback drain; leaking callback\n");return ; } + entry =rcu_defer_entry_alloc (head, func); +if (entry) { +if (llist_add (&entry->node, &rdp->defer_debug_head)) +irq_work_queue (&rdp->defer_work); +return ; + } +/* Keep valid callbacks working even if debug metadata cannot be allocated. */ head->func = func;if (llist_add ((struct llist_node *)head, &rdp->defer_head))irq_work_queue (&rdp->defer_work);
@@ -4345,6 +4363,7 @@ rcu_boot_init_percpu_data(int cpu) rdp->last_sched_clock = jiffies; rdp->cpu = cpu;init_llist_head (&rdp->defer_head); +init_llist_head (&rdp->defer_debug_head);raw_spin_lock_init (&rdp->defer_lock); rdp->defer_work =IRQ_WORK_INIT_HARD (rcu_defer_drain);rcu_boot_init_nocb_percpu_data (rdp);
@@ -4646,7 +4665,7 @@ void rcutree_migrate_callbacks(int cpu)/* * Callbacks deferred past the point the outgoing CPU's irq_work can run -* sit on ->defer_head, which the ->cblist migration below does not +* sit on the deferred lists, which the ->cblist migration below does not * cover. Drain them here, before the early returns. */ __rcu_defer_drain (rdp);
kernel/rcu/tree.h +1 -0
@@ -231,6 +231,7 @@ struct rcu_data {/* Deferral of an NMI/reentrant call_rcu(); see __call_rcu_common(). */ struct llist_head defer_head; +struct llist_head defer_debug_head;struct irq_work defer_work;raw_spinlock_t defer_lock;bool defer_draining;
Signature · 1 line
2.54.0
Quoted 6 lines · Joel Fernandes
Hello Puranjay,
My local LLM flagged a debug objects issue with the Make
call_rcu()safe to call patch.
Quoted 6 lines
Apparently, it is possible that a double
call_rcucan result in corruption of the deferred list beforedebug_objectsgets a chance to look at it.Can you take a look at my AI slop patch below that fixes this, and do some testing on this if it is a real issue and send a proper patch? Thank you so much.
Thanks for finding this, I will look into it and send a patch soon.
Thanks,
Puranjay
Quoted 241 lines
---8<-----------------------
From
1a550f5c8386761aa9c5c5bf2ec28dcd74ecebecMon Sep 17 00:00:00 2001
From: Joel Fernandes <[email protected]>
Date: Wed, 28 Oct 2026 06:50:58 -0400
Subject: [PATCH] [TBC] rcu: Preserve deferred lists while checking duplicate
callbacksThe deferred
call_rcu()path uses the callback head as its lockless list node. Registering that head twice can self-link the list and lose other callbacks beforercu_do_enqueue()checks for duplicates. The IRQ-disabledobject_debugtest reports a missing valid callback on both Tree and Tiny RCU, and an invoked duplicate on Tiny RCU.With
DEBUG_OBJECTS_RCU_HEAD, stage callbacks in independent entries so duplicate heads cannot corrupt the list before the existing checker runs. Keep the checker in the drain instead of moving its blocking locks into NMI/reentrant registration. Use kmalloc_nolock()/kfree_nolock() for the entries, and drain them through the existingirq_work, barrier and CPU-offline paths. Match Tree RCU's leak callback handling in Tiny RCU.This costs one small allocation per deferred registration in debug builds. If metadata cannot be allocated, retain the original intrusive path rather than dropping valid callbacks. Duplicate containment is therefore best-effort in that fallback, as with failed debug tracking. Non-debug builds do not allocate entries.
Fixes af78eca13b03 ("rcu: Make call_rcu() safe to call from any context")Fixes 0ed912d346fd ("rcu: Make Tiny call_rcu() safe to call from any context")Not-Signed-off-by Joel Fernandes <[email protected]>--- kernel/rcu/rcu.h | 30 ++++++++++++++++++++++++++++++ kernel/rcu/tiny.c | 28 ++++++++++++++++++++++++++-- kernel/rcu/tree.c | 25 ++++++++++++++++++++++--- kernel/rcu/tree.h | 1 + 4 files changed, 79 insertions(+), 5 deletions(-)kernel/rcu/rcu.h +30
-0@@ -10,6 +10,7 @@#ifndef __LINUX_RCU_H#define __LINUX_RCU_H +#include <linux/llist.h> #include <linux/slab.h> #include <trace/events/rcu.h> @@ -583,6 +584,35 @@ static inline bool should_rcu_defer(void) rcu_scheduler_active !=RCU_SCHEDULER_INACTIVE ; } +/* +* Debug checking must run after deferral, where it can take locks. Use a +* separate list node so duplicate heads cannot corrupt the deferred list +* before debug_rcu_head_queue() gets a chance to reject them. +* Allocation failure falls back to the intrusive list to preserve valid +* callbacks; duplicate containment is best-effort in that case. +*/ +struct rcu_defer_entry { +struct llist_node node; +struct rcu_head *head; +rcu_callback_t func; +}; + +static inline struct rcu_defer_entry *rcu_defer_entry_alloc (struct rcu_head *head, +rcu_callback_t func) +{ +struct rcu_defer_entry *entry; + +if (!IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) +return NULL ; + + entry =kmalloc_nolock (sizeof (*entry),0 ,NUMA_NO_NODE ); +if (entry) { + entry->head = head; + entry->func = func; + } +return entry; +} +/* Drain an outgoing CPU's deferred SRCU callbacks; see rcutree_migrate_callbacks(). */ void srcu_offline_drain (int cpu);kernel/rcu/tiny.c +26
-2@@ -48,14 +48,17 @@ static struct rcu_ctrlblk rcu_ctrlblk = {/* * The callback list is only accessed with interrupts disabled, so a call_rcu() * that arrives with interrupts off stages the callback on a lockless list that -* an irq_work re-issues later. One global list and irq_work suffice, as Tiny -* RCU is uniprocessor. +* an irq_work re-issues later. Tiny RCU is uniprocessor, so the normal and +* debug lists share one global irq_work. */ static void rcu_defer_drain (struct irq_work *iw);static LLIST_HEAD (rcu_defer_list); +static LLIST_HEAD (rcu_defer_debug_list);static struct irq_work rcu_defer_iw =IRQ_WORK_INIT_HARD (rcu_defer_drain);static bool rcu_defer_draining; +static void rcu_leak_callback (struct rcu_head *head) { } +/* * Also called by __rcu_defer_drain() to re-issue a deferred callback, so it * must not re-check the deferral condition. @@ -70,6 +73,7 @@ static void rcu_do_enqueue(struct rcu_head *head, rcu_callback_t func)pr_err ("%s(): Double-freed CB %p->%pS()!!! " , __func__, head, head->func);mem_dump_obj (head); } +WRITE_ONCE (head->func, rcu_leak_callback);return ; }@@ -108,6 +112,17 @@ static void __rcu_defer_drain(void)rcu_do_enqueue (head, head->func); drained = true; } +if (IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) { +llist_for_each_safe (node, next,llist_del_all (&rcu_defer_debug_list)) { +struct rcu_defer_entry *entry; + + entry = llist_entry(node, struct rcu_defer_entry, node); + +rcu_do_enqueue (entry->head, entry->func); +kfree_nolock (entry); + drained = true; + } + }local_irq_restore (flags);if (drained)@@ -124,12 +139,21 @@ static void rcu_defer_drain(struct irq_work *iw)static void call_rcu_defer (struct rcu_head *head,rcu_callback_t func) { +struct rcu_defer_entry *entry; +/* A re-entrant call_rcu() during the drain would livelock it; drop it. */ if (READ_ONCE (rcu_defer_draining) && !in_nmi ()) {WARN_ONCE (IS_ENABLED (CONFIG_PROVE_RCU ),"call_rcu() re-entered during callback drain; leaking callback\n" );return ; } + entry =rcu_defer_entry_alloc (head, func); +if (entry) { +if (llist_add (&entry->node, &rcu_defer_debug_list)) +irq_work_queue (&rcu_defer_iw); +return ; + } +/* Keep valid callbacks working even if debug metadata cannot be allocated. */ head->func = func;if (llist_add ((struct llist_node *)head, &rcu_defer_list))irq_work_queue (&rcu_defer_iw);kernel/rcu/tree.c +22
-3@@ -3229,6 +3229,16 @@ static void __rcu_defer_drain(struct rcu_data *rdp) head->next =NULL ;rcu_do_enqueue (head, head->func, false); } +if (IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) { +llist_for_each_safe (node, next,llist_del_all (&rdp->defer_debug_head)) { +struct rcu_defer_entry *entry; + + entry = llist_entry(node, struct rcu_defer_entry, node); + +rcu_do_enqueue (entry->head, entry->func, false); +kfree_nolock (entry); + } + }raw_spin_unlock_irqrestore (&rdp->defer_lock, flags); }@@ -3248,12 +3258,13 @@ static void rcu_defer_drain(struct irq_work *iw) }/* -* Stage @head for this CPU's irq_work to re-issue once interrupts are on. Only -* the drain side takes a lock, so this stays safe from NMI. +* Stage @head for this CPU's irq_work to re-issue once interrupts are on. +* Allocation uses nonblocking trylocks, and list insertion is lockless. */ static void call_rcu_defer (struct rcu_head *head,rcu_callback_t func) {struct rcu_data *rdp =this_cpu_ptr (&rcu_data); +struct rcu_defer_entry *entry;/* * Instrumentation on the enqueue path can re-enter here from inside the @@ -3265,6 +3276,13 @@ static void call_rcu_defer(struct rcu_head *head, rcu_callback_t func) "call_rcu() re-entered during callback drain; leaking callback\n");return ; } + entry =rcu_defer_entry_alloc (head, func); +if (entry) { +if (llist_add (&entry->node, &rdp->defer_debug_head)) +irq_work_queue (&rdp->defer_work); +return ; + } +/* Keep valid callbacks working even if debug metadata cannot be allocated. */ head->func = func;if (llist_add ((struct llist_node *)head, &rdp->defer_head))irq_work_queue (&rdp->defer_work);@@ -4345,6 +4363,7 @@ rcu_boot_init_percpu_data(int cpu) rdp->last_sched_clock = jiffies; rdp->cpu = cpu;init_llist_head (&rdp->defer_head); +init_llist_head (&rdp->defer_debug_head);raw_spin_lock_init (&rdp->defer_lock); rdp->defer_work =IRQ_WORK_INIT_HARD (rcu_defer_drain);rcu_boot_init_nocb_percpu_data (rdp);@@ -4646,7 +4665,7 @@ void rcutree_migrate_callbacks(int cpu)/* * Callbacks deferred past the point the outgoing CPU's irq_work can run -* sit on ->defer_head, which the ->cblist migration below does not +* sit on the deferred lists, which the ->cblist migration below does not * cover. Drain them here, before the early returns. */ __rcu_defer_drain (rdp);kernel/rcu/tree.h +1
-1@@ -231,6 +231,7 @@ struct rcu_data {/* Deferral of an NMI/reentrant call_rcu(); see __call_rcu_common(). */ struct llist_head defer_head; +struct llist_head defer_debug_head;struct irq_work defer_work;raw_spinlock_t defer_lock;bool defer_draining; --2.54.0
Joel Fernandes
maintainerQuoted 11 lines · Puranjay Mohan
Quoted 6 lines · Joel Fernandes
Hello Puranjay,
My local LLM flagged a debug objects issue with the Make
call_rcu()safe to call patch.
Quoted 8 lines
Quoted 6 lines
Apparently, it is possible that a double
call_rcucan result in corruption of the deferred list beforedebug_objectsgets a chance to look at it.Can you take a look at my AI slop patch below that fixes this, and do some testing on this if it is a real issue and send a proper patch? Thank you so much.
Thanks for finding this, I will look into it and send a patch soon.
Thanks, I appreciate that. Assuming it fixes the issue, happy to take it for 7.5.
Quoted 245 lines
Thanks,
PuranjayQuoted 241 lines
---8<-----------------------
From
1a550f5c8386761aa9c5c5bf2ec28dcd74ecebecMon Sep 17 00:00:00 2001
From: Joel Fernandes <[email protected]>
Date: Wed, 28 Oct 2026 06:50:58 -0400
Subject: [PATCH] [TBC] rcu: Preserve deferred lists while checking duplicate callbacksThe deferred
call_rcu()path uses the callback head as its lockless list node. Registering that head twice can self-link the list and lose other callbacks beforercu_do_enqueue()checks for duplicates. The IRQ-disabledobject_debugtest reports a missing valid callback on both Tree and Tiny RCU, and an invoked duplicate on Tiny RCU.With
DEBUG_OBJECTS_RCU_HEAD, stage callbacks in independent entries so duplicate heads cannot corrupt the list before the existing checker runs. Keep the checker in the drain instead of moving its blocking locks into NMI/reentrant registration. Use kmalloc_nolock()/kfree_nolock() for the entries, and drain them through the existingirq_work, barrier and CPU-offline paths. Match Tree RCU's leak callback handling in Tiny RCU.This costs one small allocation per deferred registration in debug builds. If metadata cannot be allocated, retain the original intrusive path rather than dropping valid callbacks. Duplicate containment is therefore best-effort in that fallback, as with failed debug tracking. Non-debug builds do not allocate entries.
Fixes af78eca13b03 ("rcu: Make call_rcu() safe to call from any context")Fixes 0ed912d346fd ("rcu: Make Tiny call_rcu() safe to call from any context")Not-Signed-off-by Joel Fernandes <[email protected]>---
kernel/rcu/rcu.h | 30 ++++++++++++++++++++++++++++++ kernel/rcu/tiny.c | 28 ++++++++++++++++++++++++++-- kernel/rcu/tree.c | 25 ++++++++++++++++++++++--- kernel/rcu/tree.h | 1 + 4 files changed, 79 insertions(+), 5 deletions(-)kernel/rcu/rcu.h +30
-0@@ -10,6 +10,7 @@#ifndef __LINUX_RCU_H#define __LINUX_RCU_H +#include <linux/llist.h> #include <linux/slab.h> #include <trace/events/rcu.h> @@ -583,6 +584,35 @@ static inline bool should_rcu_defer(void) rcu_scheduler_active !=RCU_SCHEDULER_INACTIVE ; } +/* +* Debug checking must run after deferral, where it can take locks. Use a +* separate list node so duplicate heads cannot corrupt the deferred list +* before debug_rcu_head_queue() gets a chance to reject them. +* Allocation failure falls back to the intrusive list to preserve valid +* callbacks; duplicate containment is best-effort in that case. +*/ +struct rcu_defer_entry { +struct llist_node node; +struct rcu_head *head; +rcu_callback_t func; +}; + +static inline struct rcu_defer_entry *rcu_defer_entry_alloc (struct rcu_head *head, +rcu_callback_t func) +{ +struct rcu_defer_entry *entry; + +if (!IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) +return NULL ; + + entry =kmalloc_nolock (sizeof (*entry),0 ,NUMA_NO_NODE ); +if (entry) { + entry->head = head; + entry->func = func; + } +return entry; +} +/* Drain an outgoing CPU's deferred SRCU callbacks; see rcutree_migrate_callbacks(). */ void srcu_offline_drain (int cpu);kernel/rcu/tiny.c +26
-2@@ -48,14 +48,17 @@ static struct rcu_ctrlblk rcu_ctrlblk = {/* * The callback list is only accessed with interrupts disabled, so a call_rcu() * that arrives with interrupts off stages the callback on a lockless list that -* an irq_work re-issues later. One global list and irq_work suffice, as Tiny -* RCU is uniprocessor. +* an irq_work re-issues later. Tiny RCU is uniprocessor, so the normal and +* debug lists share one global irq_work. */ static void rcu_defer_drain (struct irq_work *iw);static LLIST_HEAD (rcu_defer_list); +static LLIST_HEAD (rcu_defer_debug_list);static struct irq_work rcu_defer_iw =IRQ_WORK_INIT_HARD (rcu_defer_drain);static bool rcu_defer_draining; +static void rcu_leak_callback (struct rcu_head *head) { } +/* * Also called by __rcu_defer_drain() to re-issue a deferred callback, so it * must not re-check the deferral condition. @@ -70,6 +73,7 @@ static void rcu_do_enqueue(struct rcu_head *head, rcu_callback_t func)pr_err ("%s(): Double-freed CB %p->%pS()!!! " , __func__, head, head->func);mem_dump_obj (head); } +WRITE_ONCE (head->func, rcu_leak_callback);return ; }@@ -108,6 +112,17 @@ static void __rcu_defer_drain(void)rcu_do_enqueue (head, head->func); drained = true; } +if (IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) { +llist_for_each_safe (node, next,llist_del_all (&rcu_defer_debug_list)) { +struct rcu_defer_entry *entry; + + entry = llist_entry(node, struct rcu_defer_entry, node); + +rcu_do_enqueue (entry->head, entry->func); +kfree_nolock (entry); + drained = true; + } + }local_irq_restore (flags);if (drained)@@ -124,12 +139,21 @@ static void rcu_defer_drain(struct irq_work *iw)static void call_rcu_defer (struct rcu_head *head,rcu_callback_t func) { +struct rcu_defer_entry *entry; +/* A re-entrant call_rcu() during the drain would livelock it; drop it. */ if (READ_ONCE (rcu_defer_draining) && !in_nmi ()) {WARN_ONCE (IS_ENABLED (CONFIG_PROVE_RCU ),"call_rcu() re-entered during callback drain; leaking callback\n" );return ; } + entry =rcu_defer_entry_alloc (head, func); +if (entry) { +if (llist_add (&entry->node, &rcu_defer_debug_list)) +irq_work_queue (&rcu_defer_iw); +return ; + } +/* Keep valid callbacks working even if debug metadata cannot be allocated. */ head->func = func;if (llist_add ((struct llist_node *)head, &rcu_defer_list))irq_work_queue (&rcu_defer_iw);kernel/rcu/tree.c +22
-3@@ -3229,6 +3229,16 @@ static void __rcu_defer_drain(struct rcu_data *rdp) head->next =NULL ;rcu_do_enqueue (head, head->func, false); } +if (IS_ENABLED (CONFIG_DEBUG_OBJECTS_RCU_HEAD )) { +llist_for_each_safe (node, next,llist_del_all (&rdp->defer_debug_head)) { +struct rcu_defer_entry *entry; + + entry = llist_entry(node, struct rcu_defer_entry, node); + +rcu_do_enqueue (entry->head, entry->func, false); +kfree_nolock (entry); + } + }raw_spin_unlock_irqrestore (&rdp->defer_lock, flags); }@@ -3248,12 +3258,13 @@ static void rcu_defer_drain(struct irq_work *iw) }/* -* Stage @head for this CPU's irq_work to re-issue once interrupts are on. Only -* the drain side takes a lock, so this stays safe from NMI. +* Stage @head for this CPU's irq_work to re-issue once interrupts are on. +* Allocation uses nonblocking trylocks, and list insertion is lockless. */ static void call_rcu_defer (struct rcu_head *head,rcu_callback_t func) {struct rcu_data *rdp =this_cpu_ptr (&rcu_data); +struct rcu_defer_entry *entry;/* * Instrumentation on the enqueue path can re-enter here from inside the @@ -3265,6 +3276,13 @@ static void call_rcu_defer(struct rcu_head *head, rcu_callback_t func) "call_rcu() re-entered during callback drain; leaking callback\n");return ; } + entry =rcu_defer_entry_alloc (head, func); +if (entry) { +if (llist_add (&entry->node, &rdp->defer_debug_head)) +irq_work_queue (&rdp->defer_work); +return ; + } +/* Keep valid callbacks working even if debug metadata cannot be allocated. */ head->func = func;if (llist_add ((struct llist_node *)head, &rdp->defer_head))irq_work_queue (&rdp->defer_work);@@ -4345,6 +4363,7 @@ rcu_boot_init_percpu_data(int cpu) rdp->last_sched_clock = jiffies; rdp->cpu = cpu;init_llist_head (&rdp->defer_head); +init_llist_head (&rdp->defer_debug_head);raw_spin_lock_init (&rdp->defer_lock); rdp->defer_work =IRQ_WORK_INIT_HARD (rcu_defer_drain);rcu_boot_init_nocb_percpu_data (rdp);@@ -4646,7 +4665,7 @@ void rcutree_migrate_callbacks(int cpu)/* * Callbacks deferred past the point the outgoing CPU's irq_work can run -* sit on ->defer_head, which the ->cblist migration below does not +* sit on the deferred lists, which the ->cblist migration below does not * cover. Drain them here, before the early returns. */ __rcu_defer_drain (rdp);kernel/rcu/tree.h +1
-1@@ -231,6 +231,7 @@ struct rcu_data {/* Deferral of an NMI/reentrant call_rcu(); see __call_rcu_common(). */ struct llist_head defer_head; +struct llist_head defer_debug_head;struct irq_work defer_work;raw_spinlock_t defer_lock;bool defer_draining; --2.54.0