Skip to content

Commit d28139c

Browse files
committed
rcu: Apply RCU-bh QSes to RCU-sched and RCU-preempt when safe
One necessary step towards consolidating the three flavors of RCU is to make sure that the resulting consolidated "one flavor to rule them all" correctly handles networking denial-of-service attacks. One thing that allows RCU-bh to do so is that __do_softirq() invokes rcu_bh_qs() every so often, and so something similar has to happen for consolidated RCU. This must be done carefully. For example, if a preemption-disabled region of code takes an interrupt which does softirq processing before returning, consolidated RCU must ignore the resulting rcu_bh_qs() invocations -- preemption is still disabled, and that means an RCU reader for the consolidated flavor. This commit therefore creates a new rcu_softirq_qs() that is called only from the ksoftirqd task, thus avoiding the interrupted-a-preempted-region problem. This new rcu_softirq_qs() function invokes rcu_sched_qs(), rcu_preempt_qs(), and rcu_preempt_deferred_qs(). The latter call handles any deferred quiescent states. Note that __do_softirq() still invokes rcu_bh_qs(). It will continue to do so until a later stage of cleanup when the RCU-bh flavor is removed. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> [ paulmck: Fix !SMP issue located by kbuild test robot. ]
1 parent e11ec65 commit d28139c

6 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎include/linux/rcutiny.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ static inline void kfree_call_rcu(struct rcu_head *head,
9090
call_rcu(head, func);
9191
}
9292

93+
static inline void rcu_softirq_qs(void)
94+
{
95+
rcu_sched_qs();
96+
}
97+
9398
#define rcu_note_context_switch(preempt) \
9499
do { \
95100
rcu_sched_qs(); \

‎include/linux/rcutree.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#ifndef __LINUX_RCUTREE_H
3131
#define __LINUX_RCUTREE_H
3232

33+
void rcu_softirq_qs(void);
3334
void rcu_note_context_switch(bool preempt);
3435
int rcu_needs_cpu(u64 basem, u64 *nextevt);
3536
void rcu_cpu_stall_reset(void);

‎kernel/rcu/tree.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ void rcu_bh_qs(void)
255255
}
256256
}
257257

258+
void rcu_softirq_qs(void)
259+
{
260+
rcu_sched_qs();
261+
rcu_preempt_qs();
262+
rcu_preempt_deferred_qs(current);
263+
}
264+
258265
/*
259266
* Steal a bit from the bottom of ->dynticks for idle entry/exit
260267
* control. Initially this is for TLB flushing.

‎kernel/rcu/tree.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ DECLARE_PER_CPU(char, rcu_cpu_has_work);
433433

434434
/* Forward declarations for rcutree_plugin.h */
435435
static void rcu_bootup_announce(void);
436+
static void rcu_preempt_qs(void);
436437
static void rcu_preempt_note_context_switch(bool preempt);
437438
static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp);
438439
#ifdef CONFIG_HOTPLUG_CPU

‎kernel/rcu/tree_plugin.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,11 @@ static void __init rcu_bootup_announce(void)
974974
rcu_bootup_announce_oddness();
975975
}
976976

977+
/* Because preemptible RCU does not exist, we can ignore its QSes. */
978+
static void rcu_preempt_qs(void)
979+
{
980+
}
981+
977982
/*
978983
* Because preemptible RCU does not exist, we never have to check for
979984
* CPUs being in quiescent states.

‎kernel/softirq.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
302302
}
303303

304304
rcu_bh_qs();
305+
if (__this_cpu_read(ksoftirqd) == current)
306+
rcu_softirq_qs();
305307
local_irq_disable();
306308

307309
pending = local_softirq_pending();

0 commit comments

Comments
 (0)