History

Merge branches 'doc.2020.02.27a', 'fixes.2020.03.21a', 'kfree_rcu.2020.02.20a', 'locktorture.2020.02.20a', 'ovld.2020.02.20a', 'rcu-tasks.2020.02.20a', 'srcu.2020.02.20a' and 'torture.2020.02.20a' into HEAD

doc.2020.02.27a: Documentation updates. fixes.2020.03.21a: Miscellaneous fixes. kfree_rcu.2020.02.20a: Updates to kfree_rcu(). locktorture.2020.02.20a: Lock torture-test updates. ovld.2020.02.20a: Updates to callback-overload handling. rcu-tasks.2020.02.20a: RCU-tasks updates. srcu.2020.02.20a: SRCU updates. torture.2020.02.20a: Torture-test updates.

Paul E. McKenney committed 6 years ago

Commit aa93ec68 parents 8149b5c 127e298 6137079 28e09a2 b692dc4 90ba11b 7104260 a14493529 files · +644 −203Browse files

Unified · Split

29 files
  1. Documentation/admin-guide/kernel-parameters.txt +19 −0
  2. fs/nfs/dir.c +1 −1
  3. include/linux/rculist.h +2 −2
  4. include/linux/rcutiny.h +1 −0
  5. include/linux/rcutree.h +1 −0
  6. include/linux/timer.h +1 −1
  7. include/trace/events/rcu.h +29 −0
  8. kernel/locking/locktorture.c +8 −7
  9. kernel/locking/rtmutex.c +1 −1
  10. kernel/rcu/Makefile +4 −0
  11. kernel/rcu/rcu.h +21 −2
  12. kernel/rcu/rcu_segcblist.c +1 −3
  13. kernel/rcu/rcuperf.c +12 −2
  14. kernel/rcu/rcutorture.c +50 −17
  15. kernel/rcu/srcutree.c +10 −8
  16. kernel/rcu/tree.c +339 −113
  17. kernel/rcu/tree.h +4 −0
  18. kernel/rcu/tree_exp.h +9 −4
  19. kernel/rcu/tree_plugin.h +16 −9
  20. kernel/rcu/tree_stall.h +23 −18
  21. kernel/rcu/update.c +23 −5
  22. kernel/time/timer.c +4 −3
  23. kernel/torture.c +25 −4
  24. tools/testing/selftests/rcutorture/bin/functions.sh +1 −1
  25. tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh +2 −0
  26. tools/testing/selftests/rcutorture/bin/kvm-recheck.sh +16 −1
  27. tools/testing/selftests/rcutorture/bin/kvm.sh +1 −1
  28. tools/testing/selftests/rcutorture/configs/rcu/CFcommon +2 −0
  29. tools/testing/selftests/rcutorture/configs/rcu/TREE10 +18 −0
Documentation/admin-guide/kernel-parameters.txt+19−0
@@ -3980,6 +3980,15 @@ · 3979 unmodified lines
39803980 Set threshold of queued RCU callbacks below which
39813981 batch limiting is re-enabled.
39823982
3983+ rcutree.qovld= [KNL]
3984+ Set threshold of queued RCU callbacks beyond which
3985+ RCU's force-quiescent-state scan will aggressively
3986+ enlist help from cond_resched() and sched IPIs to
3987+ help CPUs more quickly reach quiescent states.
3988+ Set to less than zero to make this be set based
3989+ on rcutree.qhimark at boot time and to zero to
3990+ disable more aggressive help enlistment.
3991+
39833992 rcutree.rcu_idle_gp_delay= [KNL]
39843993 Set wakeup interval for idle CPUs that have
39853994 RCU callbacks (RCU_FAST_NO_HZ=y).
@@ -4195,6 +4204,12 @@ · 209 unmodified lines
41954204 rcupdate.rcu_cpu_stall_suppress= [KNL]
41964205 Suppress RCU CPU stall warning messages.
41974206
4207+ rcupdate.rcu_cpu_stall_suppress_at_boot= [KNL]
4208+ Suppress RCU CPU stall warning messages and
4209+ rcutorture writer stall warnings that occur
4210+ during early boot, that is, during the time
4211+ before the init task is spawned.
4212+
41984213 rcupdate.rcu_cpu_stall_timeout= [KNL]
41994214 Set timeout for RCU CPU stall warning messages.
42004215
@@ -4867,6 +4882,10 @@ · 666 unmodified lines
48674882 topology updates sent by the hypervisor to this
48684883 LPAR.
48694884
4885+ torture.disable_onoff_at_boot= [KNL]
4886+ Prevent the CPU-hotplug component of torturing
4887+ until after init has spawned.
4888+
48704889 tp720= [HW,PS2]
48714890
48724891 tpm_suspend_pcr=[HW,TPM]
fs/nfs/dir.c+1−1
@@ -2383,7 +2383,7 @@ static int nfs_access_get_cached_rcu(struct inode *inode, const struct cred *cre · 2382 unmodified lines
23832383 rcu_read_lock();
23842384 if (nfsi->cache_validity & NFS_INO_INVALID_ACCESS)
23852385 goto out;
2386− lh = rcu_dereference(nfsi->access_cache_entry_lru.prev);
2386+ lh = rcu_dereference(list_tail_rcu(&nfsi->access_cache_entry_lru));
23872387 cache = list_entry(lh, struct nfs_access_entry, lru);
23882388 if (lh == &nfsi->access_cache_entry_lru ||
23892389 cred_fscmp(cred, cache->cred) != 0)
include/linux/rculist.h+2−2
@@ -60,9 +60,9 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list) · 59 unmodified lines
6060 #define __list_check_rcu(dummy, cond, extra...) \
6161 ({ \
6262 check_arg_count_one(extra); \
63− RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(), \
63+ RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(), \
6464 "RCU-list traversed in non-reader section!"); \
65− })
65+ })
6666 #else
6767 #define __list_check_rcu(dummy, cond, extra...) \
6868 ({ check_arg_count_one(extra); })
include/linux/rcutiny.h+1−0
@@ -83,6 +83,7 @@ void rcu_scheduler_starting(void); · 82 unmodified lines
8383 static inline void rcu_scheduler_starting(void) { }
8484 #endif /* #else #ifndef CONFIG_SRCU */
8585 static inline void rcu_end_inkernel_boot(void) { }
86+static inline bool rcu_inkernel_boot_has_ended(void) { return true; }
8687 static inline bool rcu_is_watching(void) { return true; }
8788 static inline void rcu_momentary_dyntick_idle(void) { }
8889 static inline void kfree_rcu_scheduler_running(void) { }
include/linux/rcutree.h+1−0
@@ -54,6 +54,7 @@ void exit_rcu(void); · 53 unmodified lines
5454 void rcu_scheduler_starting(void);
5555 extern int rcu_scheduler_active __read_mostly;
5656 void rcu_end_inkernel_boot(void);
57+bool rcu_inkernel_boot_has_ended(void);
5758 bool rcu_is_watching(void);
5859 #ifndef CONFIG_PREEMPTION
5960 void rcu_all_qs(void);
include/linux/timer.h+1−1
@@ -164,7 +164,7 @@ static inline void destroy_timer_on_stack(struct timer_list *timer) { } · 163 unmodified lines
164164 */
165165 static inline int timer_pending(const struct timer_list * timer)
166166 {
167− return timer->entry.pprev != NULL;
167+ return !hlist_unhashed_lockless(&timer->entry);
168168 }
169169
170170 extern void add_timer_on(struct timer_list *timer, int cpu);
include/trace/events/rcu.h+29−0
@@ -623,6 +623,34 @@ TRACE_EVENT_RCU(rcu_invoke_kfree_callback, · 622 unmodified lines
623623 __entry->rcuname, __entry->rhp, __entry->offset)
624624 );
625625
626+/*
627+ * Tracepoint for the invocation of a single RCU callback of the special
628+ * kfree_bulk() form. The first argument is the RCU flavor, the second
629+ * argument is a number of elements in array to free, the third is an
630+ * address of the array holding nr_records entries.
631+ */
632+TRACE_EVENT_RCU(rcu_invoke_kfree_bulk_callback,
633+
634+ TP_PROTO(const char *rcuname, unsigned long nr_records, void **p),
635+
636+ TP_ARGS(rcuname, nr_records, p),
637+
638+ TP_STRUCT__entry(
639+ __field(const char *, rcuname)
640+ __field(unsigned long, nr_records)
641+ __field(void **, p)
642+ ),
643+
644+ TP_fast_assign(
645+ __entry->rcuname = rcuname;
646+ __entry->nr_records = nr_records;
647+ __entry->p = p;
648+ ),
649+
650+ TP_printk("%s bulk=0x%p nr_records=%lu",
651+ __entry->rcuname, __entry->p, __entry->nr_records)
652+);
653+
626654 /*
627655 * Tracepoint for exiting rcu_do_batch after RCU callbacks have been
628656 * invoked. The first argument is the name of the RCU flavor,
@@ -712,6 +740,7 @@ TRACE_EVENT_RCU(rcu_torture_read, · 83 unmodified lines
712740 * "Begin": rcu_barrier() started.
713741 * "EarlyExit": rcu_barrier() piggybacked, thus early exit.
714742 * "Inc1": rcu_barrier() piggyback check counter incremented.
743+ * "OfflineNoCBQ": rcu_barrier() found offline no-CBs CPU with callbacks.
715744 * "OnlineQ": rcu_barrier() found online CPU with callbacks.
716745 * "OnlineNQ": rcu_barrier() found online CPU, no callbacks.
717746 * "IRQ": An rcu_barrier_callback() callback posted on remote CPU.
kernel/locking/locktorture.c+8−7
@@ -618,7 +618,7 @@ static struct lock_torture_ops percpu_rwsem_lock_ops = { · 617 unmodified lines
618618 static int lock_torture_writer(void *arg)
619619 {
620620 struct lock_stress_stats *lwsp = arg;
621− static DEFINE_TORTURE_RANDOM(rand);
621+ DEFINE_TORTURE_RANDOM(rand);
622622
623623 VERBOSE_TOROUT_STRING("lock_torture_writer task started");
624624 set_user_nice(current, MAX_NICE);
@@ -655,7 +655,7 @@ static int lock_torture_writer(void *arg) · 30 unmodified lines
655655 static int lock_torture_reader(void *arg)
656656 {
657657 struct lock_stress_stats *lrsp = arg;
658− static DEFINE_TORTURE_RANDOM(rand);
658+ DEFINE_TORTURE_RANDOM(rand);
659659
660660 VERBOSE_TOROUT_STRING("lock_torture_reader task started");
661661 set_user_nice(current, MAX_NICE);
@@ -696,15 +696,16 @@ static void __torture_print_stats(char *page, · 34 unmodified lines
696696 if (statp[i].n_lock_fail)
697697 fail = true;
698698 sum += statp[i].n_lock_acquired;
699− if (max < statp[i].n_lock_fail)
700− max = statp[i].n_lock_fail;
701− if (min > statp[i].n_lock_fail)
702− min = statp[i].n_lock_fail;
699+ if (max < statp[i].n_lock_acquired)
700+ max = statp[i].n_lock_acquired;
701+ if (min > statp[i].n_lock_acquired)
702+ min = statp[i].n_lock_acquired;
703703 }
704704 page += sprintf(page,
705705 "%s: Total: %lld Max/Min: %ld/%ld %s Fail: %d %s\n",
706706 write ? "Writes" : "Reads ",
707− sum, max, min, max / 2 > min ? "???" : "",
707+ sum, max, min,
708+ !onoff_interval && max / 2 > min ? "???" : "",
708709 fail, fail ? "!!!" : "");
709710 if (fail)
710711 atomic_inc(&cxt.n_lock_torture_errors);
kernel/locking/rtmutex.c+1−1
@@ -57,7 +57,7 @@ rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner) · 56 unmodified lines
5757 if (rt_mutex_has_waiters(lock))
5858 val |= RT_MUTEX_HAS_WAITERS;
5959
60− lock->owner = (struct task_struct *)val;
60+ WRITE_ONCE(lock->owner, (struct task_struct *)val);
6161 }
6262
6363 static inline void clear_rt_mutex_waiters(struct rt_mutex *lock)
kernel/rcu/Makefile+4−0
@@ -3,6 +3,10 @@ · 2 unmodified lines
33 # and is generally not a function of system call inputs.
44 KCOV_INSTRUMENT := n
55
6+ifeq ($(CONFIG_KCSAN),y)
7+KBUILD_CFLAGS += -g -fno-omit-frame-pointer
8+endif
9+
610 obj-y += update.o sync.o
711 obj-$(CONFIG_TREE_SRCU) += srcutree.o
812 obj-$(CONFIG_TINY_SRCU) += srcutiny.o
kernel/rcu/rcu.h+21−2
@@ -198,6 +198,13 @@ static inline void debug_rcu_head_unqueue(struct rcu_head *head) · 197 unmodified lines
198198 }
199199 #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
200200
201+extern int rcu_cpu_stall_suppress_at_boot;
202+
203+static inline bool rcu_stall_is_suppressed_at_boot(void)
204+{
205+ return rcu_cpu_stall_suppress_at_boot && !rcu_inkernel_boot_has_ended();
206+}
207+
201208 #ifdef CONFIG_RCU_STALL_COMMON
202209
203210 extern int rcu_cpu_stall_ftrace_dump;
@@ -205,6 +212,11 @@ extern int rcu_cpu_stall_suppress; · 1 unmodified line
205212 extern int rcu_cpu_stall_timeout;
206213 int rcu_jiffies_till_stall_check(void);
207214
215+static inline bool rcu_stall_is_suppressed(void)
216+{
217+ return rcu_stall_is_suppressed_at_boot() || rcu_cpu_stall_suppress;
218+}
219+
208220 #define rcu_ftrace_dump_stall_suppress() \
209221 do { \
210222 if (!rcu_cpu_stall_suppress) \
@@ -218,6 +230,11 @@ do { \ · 7 unmodified lines
218230 } while (0)
219231
220232 #else /* #endif #ifdef CONFIG_RCU_STALL_COMMON */
233+
234+static inline bool rcu_stall_is_suppressed(void)
235+{
236+ return rcu_stall_is_suppressed_at_boot();
237+}
221238 #define rcu_ftrace_dump_stall_suppress()
222239 #define rcu_ftrace_dump_stall_unsuppress()
223240 #endif /* #ifdef CONFIG_RCU_STALL_COMMON */
@@ -325,7 +342,8 @@ static inline void rcu_init_levelspread(int *levelspread, const int *levelcnt) · 101 unmodified lines
325342 * Iterate over all possible CPUs in a leaf RCU node.
326343 */
327344 #define for_each_leaf_node_possible_cpu(rnp, cpu) \
328− for ((cpu) = cpumask_next((rnp)->grplo - 1, cpu_possible_mask); \
345+ for (WARN_ON_ONCE(!rcu_is_leaf_node(rnp)), \
346+ (cpu) = cpumask_next((rnp)->grplo - 1, cpu_possible_mask); \
329347 (cpu) <= rnp->grphi; \
330348 (cpu) = cpumask_next((cpu), cpu_possible_mask))
331349
@@ -335,7 +353,8 @@ static inline void rcu_init_levelspread(int *levelspread, const int *levelcnt) · 3 unmodified lines
335353 #define rcu_find_next_bit(rnp, cpu, mask) \
336354 ((rnp)->grplo + find_next_bit(&(mask), BITS_PER_LONG, (cpu)))
337355 #define for_each_leaf_node_cpu_mask(rnp, cpu, mask) \
338− for ((cpu) = rcu_find_next_bit((rnp), 0, (mask)); \
356+ for (WARN_ON_ONCE(!rcu_is_leaf_node(rnp)), \
357+ (cpu) = rcu_find_next_bit((rnp), 0, (mask)); \
339358 (cpu) <= rnp->grphi; \
340359 (cpu) = rcu_find_next_bit((rnp), (cpu) + 1 - (rnp->grplo), (mask)))
341360
kernel/rcu/rcu_segcblist.c+1−3
@@ -182,7 +182,7 @@ void rcu_segcblist_offload(struct rcu_segcblist *rsclp) · 181 unmodified lines
182182 bool rcu_segcblist_ready_cbs(struct rcu_segcblist *rsclp)
183183 {
184184 return rcu_segcblist_is_enabled(rsclp) &&
185− &rsclp->head != rsclp->tails[RCU_DONE_TAIL];
185+ &rsclp->head != READ_ONCE(rsclp->tails[RCU_DONE_TAIL]);
186186 }
187187
188188 /*
@@ -381,8 +381,6 @@ void rcu_segcblist_insert_pend_cbs(struct rcu_segcblist *rsclp, · 192 unmodified lines
381381 return; /* Nothing to do. */
382382 WRITE_ONCE(*rsclp->tails[RCU_NEXT_TAIL], rclp->head);
383383 WRITE_ONCE(rsclp->tails[RCU_NEXT_TAIL], rclp->tail);
384− rclp->head = NULL;
385− rclp->tail = &rclp->head;
386384 }
387385
388386 /*
kernel/rcu/rcuperf.c+12−2
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include <linux/types.h>
1313 #include <linux/kernel.h>
1414 #include <linux/init.h>
15+#include <linux/mm.h>
1516 #include <linux/module.h>
1617 #include <linux/kthread.h>
1718 #include <linux/err.h>
@@ -611,6 +612,7 @@ kfree_perf_thread(void *arg) · 593 unmodified lines
611612 long me = (long)arg;
612613 struct kfree_obj *alloc_ptr;
613614 u64 start_time, end_time;
615+ long long mem_begin, mem_during = 0;
614616
615617 VERBOSE_PERFOUT_STRING("kfree_perf_thread task started");
616618 set_cpus_allowed_ptr(current, cpumask_of(me % nr_cpu_ids));
@@ -626,6 +628,12 @@ kfree_perf_thread(void *arg) · 9 unmodified lines
626628 }
627629
628630 do {
631+ if (!mem_during) {
632+ mem_during = mem_begin = si_mem_available();
633+ } else if (loop % (kfree_loops / 4) == 0) {
634+ mem_during = (mem_during + si_mem_available()) / 2;
635+ }
636+
629637 for (i = 0; i < kfree_alloc_num; i++) {
630638 alloc_ptr = kmalloc(sizeof(struct kfree_obj), GFP_KERNEL);
631639 if (!alloc_ptr)
@@ -645,9 +653,11 @@ kfree_perf_thread(void *arg) · 13 unmodified lines
645653 else
646654 b_rcu_gp_test_finished = cur_ops->get_gp_seq();
647655
648− pr_alert("Total time taken by all kfree'ers: %llu ns, loops: %d, batches: %ld\n",
656+ pr_alert("Total time taken by all kfree'ers: %llu ns, loops: %d, batches: %ld, memory footprint: %lldMB\n",
649657 (unsigned long long)(end_time - start_time), kfree_loops,
650− rcuperf_seq_diff(b_rcu_gp_test_finished, b_rcu_gp_test_started));
658+ rcuperf_seq_diff(b_rcu_gp_test_finished, b_rcu_gp_test_started),
659+ (mem_begin - mem_during) >> (20 - PAGE_SHIFT));
660+
651661 if (shutdown) {
652662 smp_mb(); /* Assign before wake. */
653663 wake_up(&shutdown_wq);
kernel/rcu/rcutorture.c+50−17
@@ -339,7 +339,7 @@ rcu_read_delay(struct torture_random_state *rrsp, struct rt_read_seg *rtrsp) · 338 unmodified lines
339339 * period, and we want a long delay occasionally to trigger
340340 * force_quiescent_state. */
341341
342− if (!rcu_fwd_cb_nodelay &&
342+ if (!READ_ONCE(rcu_fwd_cb_nodelay) &&
343343 !(torture_random(rrsp) % (nrealreaders * 2000 * longdelay_ms))) {
344344 started = cur_ops->get_gp_seq();
345345 ts = rcu_trace_clock_local();
@@ -375,11 +375,12 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp) · 29 unmodified lines
375375 {
376376 int i;
377377
378− i = rp->rtort_pipe_count;
378+ i = READ_ONCE(rp->rtort_pipe_count);
379379 if (i > RCU_TORTURE_PIPE_LEN)
380380 i = RCU_TORTURE_PIPE_LEN;
381381 atomic_inc(&rcu_torture_wcount[i]);
382− if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
382+ WRITE_ONCE(rp->rtort_pipe_count, i + 1);
383+ if (rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
383384 rp->rtort_mbtest = 0;
384385 return true;
385386 }
@@ -1015,7 +1016,8 @@ rcu_torture_writer(void *arg) · 629 unmodified lines
10151016 if (i > RCU_TORTURE_PIPE_LEN)
10161017 i = RCU_TORTURE_PIPE_LEN;
10171018 atomic_inc(&rcu_torture_wcount[i]);
1018− old_rp->rtort_pipe_count++;
1019+ WRITE_ONCE(old_rp->rtort_pipe_count,
1020+ old_rp->rtort_pipe_count + 1);
10191021 switch (synctype[torture_random(&rand) % nsynctypes]) {
10201022 case RTWS_DEF_FREE:
10211023 rcu_torture_writer_state = RTWS_DEF_FREE;
@@ -1067,7 +1069,8 @@ rcu_torture_writer(void *arg) · 45 unmodified lines
10671069 if (stutter_wait("rcu_torture_writer") &&
10681070 !READ_ONCE(rcu_fwd_cb_nodelay) &&
10691071 !cur_ops->slow_gps &&
1070− !torture_must_stop())
1072+ !torture_must_stop() &&
1073+ rcu_inkernel_boot_has_ended())
10711074 for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++)
10721075 if (list_empty(&rcu_tortures[i].rtort_free) &&
10731076 rcu_access_pointer(rcu_torture_current) !=
@@ -1290,7 +1293,7 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp) · 216 unmodified lines
12901293 atomic_inc(&n_rcu_torture_mberror);
12911294 rtrsp = rcutorture_loop_extend(&readstate, trsp, rtrsp);
12921295 preempt_disable();
1293− pipe_count = p->rtort_pipe_count;
1296+ pipe_count = READ_ONCE(p->rtort_pipe_count);
12941297 if (pipe_count > RCU_TORTURE_PIPE_LEN) {
12951298 /* Should not happen, but... */
12961299 pipe_count = RCU_TORTURE_PIPE_LEN;
@@ -1404,14 +1407,15 @@ rcu_torture_stats_print(void) · 107 unmodified lines
14041407 int i;
14051408 long pipesummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
14061409 long batchsummary[RCU_TORTURE_PIPE_LEN + 1] = { 0 };
1410+ struct rcu_torture *rtcp;
14071411 static unsigned long rtcv_snap = ULONG_MAX;
14081412 static bool splatted;
14091413 struct task_struct *wtp;
14101414
14111415 for_each_possible_cpu(cpu) {
14121416 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1413− pipesummary[i] += per_cpu(rcu_torture_count, cpu)[i];
1414− batchsummary[i] += per_cpu(rcu_torture_batch, cpu)[i];
1417+ pipesummary[i] += READ_ONCE(per_cpu(rcu_torture_count, cpu)[i]);
1418+ batchsummary[i] += READ_ONCE(per_cpu(rcu_torture_batch, cpu)[i]);
14151419 }
14161420 }
14171421 for (i = RCU_TORTURE_PIPE_LEN - 1; i >= 0; i--) {
@@ -1420,9 +1424,10 @@ rcu_torture_stats_print(void) · 2 unmodified lines
14201424 }
14211425
14221426 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1427+ rtcp = rcu_access_pointer(rcu_torture_current);
14231428 pr_cont("rtc: %p %s: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1424− rcu_torture_current,
1425− rcu_torture_current ? "ver" : "VER",
1429+ rtcp,
1430+ rtcp && !rcu_stall_is_suppressed_at_boot() ? "ver" : "VER",
14261431 rcu_torture_current_version,
14271432 list_empty(&rcu_torture_freelist),
14281433 atomic_read(&n_rcu_torture_alloc),
@@ -1478,7 +1483,8 @@ rcu_torture_stats_print(void) · 49 unmodified lines
14781483 if (cur_ops->stats)
14791484 cur_ops->stats();
14801485 if (rtcv_snap == rcu_torture_current_version &&
1481− rcu_torture_current != NULL) {
1486+ rcu_access_pointer(rcu_torture_current) &&
1487+ !rcu_stall_is_suppressed()) {
14821488 int __maybe_unused flags = 0;
14831489 unsigned long __maybe_unused gp_seq = 0;
14841490
@@ -1993,8 +1999,11 @@ static int rcu_torture_fwd_prog(void *args) · 508 unmodified lines
19931999 schedule_timeout_interruptible(fwd_progress_holdoff * HZ);
19942000 WRITE_ONCE(rcu_fwd_emergency_stop, false);
19952001 register_oom_notifier(&rcutorture_oom_nb);
1996− rcu_torture_fwd_prog_nr(rfp, &tested, &tested_tries);
1997− rcu_torture_fwd_prog_cr(rfp);
2002+ if (!IS_ENABLED(CONFIG_TINY_RCU) ||
2003+ rcu_inkernel_boot_has_ended())
2004+ rcu_torture_fwd_prog_nr(rfp, &tested, &tested_tries);
2005+ if (rcu_inkernel_boot_has_ended())
2006+ rcu_torture_fwd_prog_cr(rfp);
19982007 unregister_oom_notifier(&rcutorture_oom_nb);
19992008
20002009 /* Avoid slow periods, better to test when busy. */
@@ -2044,6 +2053,14 @@ static void rcu_torture_barrier_cbf(struct rcu_head *rcu) · 43 unmodified lines
20442053 atomic_inc(&barrier_cbs_invoked);
20452054 }
20462055
2056+/* IPI handler to get callback posted on desired CPU, if online. */
2057+static void rcu_torture_barrier1cb(void *rcu_void)
2058+{
2059+ struct rcu_head *rhp = rcu_void;
2060+
2061+ cur_ops->call(rhp, rcu_torture_barrier_cbf);
2062+}
2063+
20472064 /* kthread function to register callbacks used to test RCU barriers. */
20482065 static int rcu_torture_barrier_cbs(void *arg)
20492066 {
@@ -2067,9 +2084,11 @@ static int rcu_torture_barrier_cbs(void *arg) · 17 unmodified lines
20672084 * The above smp_load_acquire() ensures barrier_phase load
20682085 * is ordered before the following ->call().
20692086 */
2070− local_irq_disable(); /* Just to test no-irq call_rcu(). */
2071− cur_ops->call(&rcu, rcu_torture_barrier_cbf);
2072− local_irq_enable();
2087+ if (smp_call_function_single(myid, rcu_torture_barrier1cb,
2088+ &rcu, 1)) {
2089+ // IPI failed, so use direct call from current CPU.
2090+ cur_ops->call(&rcu, rcu_torture_barrier_cbf);
2091+ }
20732092 if (atomic_dec_and_test(&barrier_cbs_count))
20742093 wake_up(&barrier_wq);
20752094 } while (!torture_must_stop());
@@ -2105,7 +2124,21 @@ static int rcu_torture_barrier(void *arg) · 29 unmodified lines
21052124 pr_err("barrier_cbs_invoked = %d, n_barrier_cbs = %d\n",
21062125 atomic_read(&barrier_cbs_invoked),
21072126 n_barrier_cbs);
2108− WARN_ON_ONCE(1);
2127+ WARN_ON(1);
2128+ // Wait manually for the remaining callbacks
2129+ i = 0;
2130+ do {
2131+ if (WARN_ON(i++ > HZ))
2132+ i = INT_MIN;
2133+ schedule_timeout_interruptible(1);
2134+ cur_ops->cb_barrier();
2135+ } while (atomic_read(&barrier_cbs_invoked) !=
2136+ n_barrier_cbs &&
2137+ !torture_must_stop());
2138+ smp_mb(); // Can't trust ordering if broken.
2139+ if (!torture_must_stop())
2140+ pr_err("Recovered: barrier_cbs_invoked = %d\n",
2141+ atomic_read(&barrier_cbs_invoked));
21092142 } else {
21102143 n_barrier_successes++;
21112144 }
kernel/rcu/srcutree.c+10−8
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 * Copyright (C) IBM Corporation, 2006
66 * Copyright (C) Fujitsu, 2012
77 *
8− * Author: Paul McKenney <paulmck@linux.ibm.com>
8+ * Authors: Paul McKenney <paulmck@linux.ibm.com>
99 * Lai Jiangshan <laijs@cn.fujitsu.com>
1010 *
1111 * For detailed explanation of Read-Copy Update mechanism see -
@@ -450,7 +450,7 @@ static void srcu_gp_start(struct srcu_struct *ssp) · 438 unmodified lines
450450 spin_unlock_rcu_node(sdp); /* Interrupts remain disabled. */
451451 smp_mb(); /* Order prior store to ->srcu_gp_seq_needed vs. GP start. */
452452 rcu_seq_start(&ssp->srcu_gp_seq);
453− state = rcu_seq_state(READ_ONCE(ssp->srcu_gp_seq));
453+ state = rcu_seq_state(ssp->srcu_gp_seq);
454454 WARN_ON_ONCE(state != SRCU_STATE_SCAN1);
455455 }
456456
@@ -534,7 +534,7 @@ static void srcu_gp_end(struct srcu_struct *ssp) · 77 unmodified lines
534534 rcu_seq_end(&ssp->srcu_gp_seq);
535535 gpseq = rcu_seq_current(&ssp->srcu_gp_seq);
536536 if (ULONG_CMP_LT(ssp->srcu_gp_seq_needed_exp, gpseq))
537− ssp->srcu_gp_seq_needed_exp = gpseq;
537+ WRITE_ONCE(ssp->srcu_gp_seq_needed_exp, gpseq);
538538 spin_unlock_irq_rcu_node(ssp);
539539 mutex_unlock(&ssp->srcu_gp_mutex);
540540 /* A new grace period can start at this point. But only one. */
@@ -550,7 +550,7 @@ static void srcu_gp_end(struct srcu_struct *ssp) · 9 unmodified lines
550550 snp->srcu_have_cbs[idx] = gpseq;
551551 rcu_seq_set_state(&snp->srcu_have_cbs[idx], 1);
552552 if (ULONG_CMP_LT(snp->srcu_gp_seq_needed_exp, gpseq))
553− snp->srcu_gp_seq_needed_exp = gpseq;
553+ WRITE_ONCE(snp->srcu_gp_seq_needed_exp, gpseq);
554554 mask = snp->srcu_data_have_cbs[idx];
555555 snp->srcu_data_have_cbs[idx] = 0;
556556 spin_unlock_irq_rcu_node(snp);
@@ -614,7 +614,7 @@ static void srcu_funnel_exp_start(struct srcu_struct *ssp, struct srcu_node *snp · 57 unmodified lines
614614 }
615615 spin_lock_irqsave_rcu_node(ssp, flags);
616616 if (ULONG_CMP_LT(ssp->srcu_gp_seq_needed_exp, s))
617− ssp->srcu_gp_seq_needed_exp = s;
617+ WRITE_ONCE(ssp->srcu_gp_seq_needed_exp, s);
618618 spin_unlock_irqrestore_rcu_node(ssp, flags);
619619 }
620620
@@ -660,7 +660,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · 39 unmodified lines
660660 if (snp == sdp->mynode)
661661 snp->srcu_data_have_cbs[idx] |= sdp->grpmask;
662662 if (!do_norm && ULONG_CMP_LT(snp->srcu_gp_seq_needed_exp, s))
663− snp->srcu_gp_seq_needed_exp = s;
663+ WRITE_ONCE(snp->srcu_gp_seq_needed_exp, s);
664664 spin_unlock_irqrestore_rcu_node(snp, flags);
665665 }
666666
@@ -674,7 +674,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · 7 unmodified lines
674674 smp_store_release(&ssp->srcu_gp_seq_needed, s); /*^^^*/
675675 }
676676 if (!do_norm && ULONG_CMP_LT(ssp->srcu_gp_seq_needed_exp, s))
677− ssp->srcu_gp_seq_needed_exp = s;
677+ WRITE_ONCE(ssp->srcu_gp_seq_needed_exp, s);
678678
679679 /* If grace period not already done and none in progress, start it. */
680680 if (!rcu_seq_done(&ssp->srcu_gp_seq, s) &&
@@ -1079,7 +1079,7 @@ EXPORT_SYMBOL_GPL(srcu_barrier); · 398 unmodified lines
10791079 */
10801080 unsigned long srcu_batches_completed(struct srcu_struct *ssp)
10811081 {
1082− return ssp->srcu_idx;
1082+ return READ_ONCE(ssp->srcu_idx);
10831083 }
10841084 EXPORT_SYMBOL_GPL(srcu_batches_completed);
10851085
@@ -1130,7 +1130,9 @@ static void srcu_advance_state(struct srcu_struct *ssp) · 44 unmodified lines
11301130 return; /* readers present, retry later. */
11311131 }
11321132 srcu_flip(ssp);
1133+ spin_lock_irq_rcu_node(ssp);
11331134 rcu_seq_set_state(&ssp->srcu_gp_seq, SRCU_STATE_SCAN2);
1135+ spin_unlock_irq_rcu_node(ssp);
11341136 }
11351137
11361138 if (rcu_seq_state(READ_ONCE(ssp->srcu_gp_seq)) == SRCU_STATE_SCAN2) {
kernel/rcu/tree.c+339−113
@@ -1,12 +1,12 @@
11 // SPDX-License-Identifier: GPL-2.0+
22 /*
3− * Read-Copy Update mechanism for mutual exclusion
3+ * Read-Copy Update mechanism for mutual exclusion (tree-based version)
44 *
55 * Copyright IBM Corporation, 2008
66 *
77 * Authors: Dipankar Sarma <dipankar@in.ibm.com>
88 * Manfred Spraul <manfred@colorfullife.com>
9− * Paul E. McKenney <paulmck@linux.ibm.com> Hierarchical version
9+ * Paul E. McKenney <paulmck@linux.ibm.com>
1010 *
1111 * Based on the original work by Paul McKenney <paulmck@linux.ibm.com>
1212 * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
@@ -150,6 +150,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu) · 137 unmodified lines
150150 static void invoke_rcu_core(void);
151151 static void rcu_report_exp_rdp(struct rcu_data *rdp);
152152 static void sync_sched_exp_online_cleanup(int cpu);
153+static void check_cb_ovld_locked(struct rcu_data *rdp, struct rcu_node *rnp);
153154
154155 /* rcuc/rcub kthread realtime priority */
155156 static int kthread_prio = IS_ENABLED(CONFIG_RCU_BOOST) ? 1 : 0;
@@ -342,14 +343,17 @@ bool rcu_eqs_special_set(int cpu) · 186 unmodified lines
342343 {
343344 int old;
344345 int new;
346+ int new_old;
345347 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
346348
349+ new_old = atomic_read(&rdp->dynticks);
347350 do {
348− old = atomic_read(&rdp->dynticks);
351+ old = new_old;
349352 if (old & RCU_DYNTICK_CTRL_CTR)
350353 return false;
351354 new = old | RCU_DYNTICK_CTRL_MASK;
352− } while (atomic_cmpxchg(&rdp->dynticks, old, new) != old);
355+ new_old = atomic_cmpxchg(&rdp->dynticks, old, new);
356+ } while (new_old != old);
353357 return true;
354358 }
355359
@@ -410,10 +414,15 @@ static long blimit = DEFAULT_RCU_BLIMIT; · 54 unmodified lines
410414 static long qhimark = DEFAULT_RCU_QHIMARK;
411415 #define DEFAULT_RCU_QLOMARK 100 /* Once only this many pending, use blimit. */
412416 static long qlowmark = DEFAULT_RCU_QLOMARK;
417+#define DEFAULT_RCU_QOVLD_MULT 2
418+#define DEFAULT_RCU_QOVLD (DEFAULT_RCU_QOVLD_MULT * DEFAULT_RCU_QHIMARK)
419+static long qovld = DEFAULT_RCU_QOVLD; /* If this many pending, hammer QS. */
420+static long qovld_calc = -1; /* No pre-initialization lock acquisitions! */
413421
414422 module_param(blimit, long, 0444);
415423 module_param(qhimark, long, 0444);
416424 module_param(qlowmark, long, 0444);
425+module_param(qovld, long, 0444);
417426
418427 static ulong jiffies_till_first_fqs = ULONG_MAX;
419428 static ulong jiffies_till_next_fqs = ULONG_MAX;
@@ -818,11 +827,12 @@ static __always_inline void rcu_nmi_enter_common(bool irq) · 398 unmodified lines
818827 incby = 1;
819828 } else if (tick_nohz_full_cpu(rdp->cpu) &&
820829 rdp->dynticks_nmi_nesting == DYNTICK_IRQ_NONIDLE &&
821− READ_ONCE(rdp->rcu_urgent_qs) && !rdp->rcu_forced_tick) {
830+ READ_ONCE(rdp->rcu_urgent_qs) &&
831+ !READ_ONCE(rdp->rcu_forced_tick)) {
822832 raw_spin_lock_rcu_node(rdp->mynode);
823833 // Recheck under lock.
824834 if (rdp->rcu_urgent_qs && !rdp->rcu_forced_tick) {
825− rdp->rcu_forced_tick = true;
835+ WRITE_ONCE(rdp->rcu_forced_tick, true);
826836 tick_dep_set_cpu(rdp->cpu, TICK_DEP_BIT_RCU);
827837 }
828838 raw_spin_unlock_rcu_node(rdp->mynode);
@@ -899,7 +909,7 @@ static void rcu_disable_urgency_upon_qs(struct rcu_data *rdp) · 70 unmodified lines
899909 WRITE_ONCE(rdp->rcu_need_heavy_qs, false);
900910 if (tick_nohz_full_cpu(rdp->cpu) && rdp->rcu_forced_tick) {
901911 tick_dep_clear_cpu(rdp->cpu, TICK_DEP_BIT_RCU);
902− rdp->rcu_forced_tick = false;
912+ WRITE_ONCE(rdp->rcu_forced_tick, false);
903913 }
904914 }
905915
@@ -1072,7 +1082,8 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) · 166 unmodified lines
10721082 rnhqp = &per_cpu(rcu_data.rcu_need_heavy_qs, rdp->cpu);
10731083 if (!READ_ONCE(*rnhqp) &&
10741084 (time_after(jiffies, rcu_state.gp_start + jtsq * 2) ||
1075− time_after(jiffies, rcu_state.jiffies_resched))) {
1085+ time_after(jiffies, rcu_state.jiffies_resched) ||
1086+ rcu_state.cbovld)) {
10761087 WRITE_ONCE(*rnhqp, true);
10771088 /* Store rcu_need_heavy_qs before rcu_urgent_qs. */
10781089 smp_store_release(ruqp, true);
@@ -1089,8 +1100,8 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) · 10 unmodified lines
10891100 * So hit them over the head with the resched_cpu() hammer!
10901101 */
10911102 if (tick_nohz_full_cpu(rdp->cpu) &&
1092− time_after(jiffies,
1093− READ_ONCE(rdp->last_fqs_resched) + jtsq * 3)) {
1103+ (time_after(jiffies, READ_ONCE(rdp->last_fqs_resched) + jtsq * 3) ||
1104+ rcu_state.cbovld)) {
10941105 WRITE_ONCE(*ruqp, true);
10951106 resched_cpu(rdp->cpu);
10961107 WRITE_ONCE(rdp->last_fqs_resched, jiffies);
@@ -1126,8 +1137,9 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) · 29 unmodified lines
11261137 static void trace_rcu_this_gp(struct rcu_node *rnp, struct rcu_data *rdp,
11271138 unsigned long gp_seq_req, const char *s)
11281139 {
1129− trace_rcu_future_grace_period(rcu_state.name, rnp->gp_seq, gp_seq_req,
1130− rnp->level, rnp->grplo, rnp->grphi, s);
1140+ trace_rcu_future_grace_period(rcu_state.name, READ_ONCE(rnp->gp_seq),
1141+ gp_seq_req, rnp->level,
1142+ rnp->grplo, rnp->grphi, s);
11311143 }
11321144
11331145 /*
@@ -1174,7 +1186,7 @@ static bool rcu_start_this_gp(struct rcu_node *rnp_start, struct rcu_data *rdp, · 40 unmodified lines
11741186 TPS("Prestarted"));
11751187 goto unlock_out;
11761188 }
1177− rnp->gp_seq_needed = gp_seq_req;
1189+ WRITE_ONCE(rnp->gp_seq_needed, gp_seq_req);
11781190 if (rcu_seq_state(rcu_seq_current(&rnp->gp_seq))) {
11791191 /*
11801192 * We just marked the leaf or internal node, and a
@@ -1199,18 +1211,18 @@ static bool rcu_start_this_gp(struct rcu_node *rnp_start, struct rcu_data *rdp, · 18 unmodified lines
11991211 }
12001212 trace_rcu_this_gp(rnp, rdp, gp_seq_req, TPS("Startedroot"));
12011213 WRITE_ONCE(rcu_state.gp_flags, rcu_state.gp_flags | RCU_GP_FLAG_INIT);
1202− rcu_state.gp_req_activity = jiffies;
1203− if (!rcu_state.gp_kthread) {
1214+ WRITE_ONCE(rcu_state.gp_req_activity, jiffies);
1215+ if (!READ_ONCE(rcu_state.gp_kthread)) {
12041216 trace_rcu_this_gp(rnp, rdp, gp_seq_req, TPS("NoGPkthread"));
12051217 goto unlock_out;
12061218 }
1207− trace_rcu_grace_period(rcu_state.name, READ_ONCE(rcu_state.gp_seq), TPS("newreq"));
1219+ trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("newreq"));
12081220 ret = true; /* Caller must wake GP kthread. */
12091221 unlock_out:
12101222 /* Push furthest requested GP to leaf node and rcu_data structure. */
12111223 if (ULONG_CMP_LT(gp_seq_req, rnp->gp_seq_needed)) {
1212− rnp_start->gp_seq_needed = rnp->gp_seq_needed;
1213− rdp->gp_seq_needed = rnp->gp_seq_needed;
1224+ WRITE_ONCE(rnp_start->gp_seq_needed, rnp->gp_seq_needed);
1225+ WRITE_ONCE(rdp->gp_seq_needed, rnp->gp_seq_needed);
12141226 }
12151227 if (rnp != rnp_start)
12161228 raw_spin_unlock_rcu_node(rnp);
@@ -1235,12 +1247,13 @@ static bool rcu_future_gp_cleanup(struct rcu_node *rnp) · 18 unmodified lines
12351247 }
12361248
12371249 /*
1238− * Awaken the grace-period kthread. Don't do a self-awaken (unless in
1239− * an interrupt or softirq handler), and don't bother awakening when there
1240− * is nothing for the grace-period kthread to do (as in several CPUs raced
1241− * to awaken, and we lost), and finally don't try to awaken a kthread that
1242− * has not yet been created. If all those checks are passed, track some
1243− * debug information and awaken.
1250+ * Awaken the grace-period kthread. Don't do a self-awaken (unless in an
1251+ * interrupt or softirq handler, in which case we just might immediately
1252+ * sleep upon return, resulting in a grace-period hang), and don't bother
1253+ * awakening when there is nothing for the grace-period kthread to do
1254+ * (as in several CPUs raced to awaken, we lost), and finally don't try
1255+ * to awaken a kthread that has not yet been created. If all those checks
1256+ * are passed, track some debug information and awaken.
12441257 *
12451258 * So why do the self-wakeup when in an interrupt or softirq handler
12461259 * in the grace-period kthread's context? Because the kthread might have
@@ -1250,10 +1263,10 @@ static bool rcu_future_gp_cleanup(struct rcu_node *rnp) · 3 unmodified lines
12501263 */
12511264 static void rcu_gp_kthread_wake(void)
12521265 {
1253− if ((current == rcu_state.gp_kthread &&
1254− !in_irq() && !in_serving_softirq()) ||
1255− !READ_ONCE(rcu_state.gp_flags) ||
1256− !rcu_state.gp_kthread)
1266+ struct task_struct *t = READ_ONCE(rcu_state.gp_kthread);
1267+
1268+ if ((current == t && !in_irq() && !in_serving_softirq()) ||
1269+ !READ_ONCE(rcu_state.gp_flags) || !t)
12571270 return;
12581271 WRITE_ONCE(rcu_state.gp_wake_time, jiffies);
12591272 WRITE_ONCE(rcu_state.gp_wake_seq, READ_ONCE(rcu_state.gp_seq));
@@ -1321,7 +1334,7 @@ static void rcu_accelerate_cbs_unlocked(struct rcu_node *rnp, · 61 unmodified lines
13211334
13221335 rcu_lockdep_assert_cblist_protected(rdp);
13231336 c = rcu_seq_snap(&rcu_state.gp_seq);
1324− if (!rdp->gpwrap && ULONG_CMP_GE(rdp->gp_seq_needed, c)) {
1337+ if (!READ_ONCE(rdp->gpwrap) && ULONG_CMP_GE(rdp->gp_seq_needed, c)) {
13251338 /* Old request still live, so mark recent callbacks. */
13261339 (void)rcu_segcblist_accelerate(&rdp->cblist, c);
13271340 return;
@@ -1386,7 +1399,7 @@ static void __maybe_unused rcu_advance_cbs_nowake(struct rcu_node *rnp, · 58 unmodified lines
13861399 static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp)
13871400 {
13881401 bool ret = false;
1389− bool need_gp;
1402+ bool need_qs;
13901403 const bool offloaded = IS_ENABLED(CONFIG_RCU_NOCB_CPU) &&
13911404 rcu_segcblist_is_offloaded(&rdp->cblist);
13921405
@@ -1400,10 +1413,13 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp) · 7 unmodified lines
14001413 unlikely(READ_ONCE(rdp->gpwrap))) {
14011414 if (!offloaded)
14021415 ret = rcu_advance_cbs(rnp, rdp); /* Advance CBs. */
1416+ rdp->core_needs_qs = false;
14031417 trace_rcu_grace_period(rcu_state.name, rdp->gp_seq, TPS("cpuend"));
14041418 } else {
14051419 if (!offloaded)
14061420 ret = rcu_accelerate_cbs(rnp, rdp); /* Recent CBs. */
1421+ if (rdp->core_needs_qs)
1422+ rdp->core_needs_qs = !!(rnp->qsmask & rdp->grpmask);
14071423 }
14081424
14091425 /* Now handle the beginnings of any new-to-this-CPU grace periods. */
@@ -1415,14 +1431,14 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp) · 5 unmodified lines
14151431 * go looking for one.
14161432 */
14171433 trace_rcu_grace_period(rcu_state.name, rnp->gp_seq, TPS("cpustart"));
1418− need_gp = !!(rnp->qsmask & rdp->grpmask);
1419− rdp->cpu_no_qs.b.norm = need_gp;
1420− rdp->core_needs_qs = need_gp;
1434+ need_qs = !!(rnp->qsmask & rdp->grpmask);
1435+ rdp->cpu_no_qs.b.norm = need_qs;
1436+ rdp->core_needs_qs = need_qs;
14211437 zero_cpu_stall_ticks(rdp);
14221438 }
14231439 rdp->gp_seq = rnp->gp_seq; /* Remember new grace-period state. */
14241440 if (ULONG_CMP_LT(rdp->gp_seq_needed, rnp->gp_seq_needed) || rdp->gpwrap)
1425− rdp->gp_seq_needed = rnp->gp_seq_needed;
1441+ WRITE_ONCE(rdp->gp_seq_needed, rnp->gp_seq_needed);
14261442 WRITE_ONCE(rdp->gpwrap, false);
14271443 rcu_gpnum_ovf(rnp, rdp);
14281444 return ret;
@@ -1651,8 +1667,7 @@ static void rcu_gp_fqs_loop(void) · 222 unmodified lines
16511667 WRITE_ONCE(rcu_state.jiffies_kick_kthreads,
16521668 jiffies + (j ? 3 * j : 2));
16531669 }
1654− trace_rcu_grace_period(rcu_state.name,
1655− READ_ONCE(rcu_state.gp_seq),
1670+ trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
16561671 TPS("fqswait"));
16571672 rcu_state.gp_state = RCU_GP_WAIT_FQS;
16581673 ret = swait_event_idle_timeout_exclusive(
@@ -1666,13 +1681,11 @@ static void rcu_gp_fqs_loop(void) · 7 unmodified lines
16661681 /* If time for quiescent-state forcing, do it. */
16671682 if (ULONG_CMP_GE(jiffies, rcu_state.jiffies_force_qs) ||
16681683 (gf & RCU_GP_FLAG_FQS)) {
1669− trace_rcu_grace_period(rcu_state.name,
1670− READ_ONCE(rcu_state.gp_seq),
1684+ trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
16711685 TPS("fqsstart"));
16721686 rcu_gp_fqs(first_gp_fqs);
16731687 first_gp_fqs = false;
1674− trace_rcu_grace_period(rcu_state.name,
1675− READ_ONCE(rcu_state.gp_seq),
1688+ trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
16761689 TPS("fqsend"));
16771690 cond_resched_tasks_rcu_qs();
16781691 WRITE_ONCE(rcu_state.gp_activity, jiffies);
@@ -1683,8 +1696,7 @@ static void rcu_gp_fqs_loop(void) · 4 unmodified lines
16831696 cond_resched_tasks_rcu_qs();
16841697 WRITE_ONCE(rcu_state.gp_activity, jiffies);
16851698 WARN_ON(signal_pending(current));
1686− trace_rcu_grace_period(rcu_state.name,
1687− READ_ONCE(rcu_state.gp_seq),
1699+ trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
16881700 TPS("fqswaitsig"));
16891701 ret = 1; /* Keep old FQS timing. */
16901702 j = jiffies;
@@ -1701,8 +1713,9 @@ static void rcu_gp_fqs_loop(void) · 10 unmodified lines
17011713 */
17021714 static void rcu_gp_cleanup(void)
17031715 {
1704− unsigned long gp_duration;
1716+ int cpu;
17051717 bool needgp = false;
1718+ unsigned long gp_duration;
17061719 unsigned long new_gp_seq;
17071720 bool offloaded;
17081721 struct rcu_data *rdp;
@@ -1748,6 +1761,12 @@ static void rcu_gp_cleanup(void) · 39 unmodified lines
17481761 needgp = __note_gp_changes(rnp, rdp) || needgp;
17491762 /* smp_mb() provided by prior unlock-lock pair. */
17501763 needgp = rcu_future_gp_cleanup(rnp) || needgp;
1764+ // Reset overload indication for CPUs no longer overloaded
1765+ if (rcu_is_leaf_node(rnp))
1766+ for_each_leaf_node_cpu_mask(rnp, cpu, rnp->cbovldmask) {
1767+ rdp = per_cpu_ptr(&rcu_data, cpu);
1768+ check_cb_ovld_locked(rdp, rnp);
1769+ }
17511770 sq = rcu_nocb_gp_get(rnp);
17521771 raw_spin_unlock_irq_rcu_node(rnp);
17531772 rcu_nocb_gp_cleanup(sq);
@@ -1774,9 +1793,9 @@ static void rcu_gp_cleanup(void) · 20 unmodified lines
17741793 rcu_segcblist_is_offloaded(&rdp->cblist);
17751794 if ((offloaded || !rcu_accelerate_cbs(rnp, rdp)) && needgp) {
17761795 WRITE_ONCE(rcu_state.gp_flags, RCU_GP_FLAG_INIT);
1777− rcu_state.gp_req_activity = jiffies;
1796+ WRITE_ONCE(rcu_state.gp_req_activity, jiffies);
17781797 trace_rcu_grace_period(rcu_state.name,
1779− READ_ONCE(rcu_state.gp_seq),
1798+ rcu_state.gp_seq,
17801799 TPS("newreq"));
17811800 } else {
17821801 WRITE_ONCE(rcu_state.gp_flags,
@@ -1795,8 +1814,7 @@ static int __noreturn rcu_gp_kthread(void *unused) · 12 unmodified lines
17951814
17961815 /* Handle grace-period start. */
17971816 for (;;) {
1798− trace_rcu_grace_period(rcu_state.name,
1799− READ_ONCE(rcu_state.gp_seq),
1817+ trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
18001818 TPS("reqwait"));
18011819 rcu_state.gp_state = RCU_GP_WAIT_GPS;
18021820 swait_event_idle_exclusive(rcu_state.gp_wq,
@@ -1809,8 +1827,7 @@ static int __noreturn rcu_gp_kthread(void *unused) · 6 unmodified lines
18091827 cond_resched_tasks_rcu_qs();
18101828 WRITE_ONCE(rcu_state.gp_activity, jiffies);
18111829 WARN_ON(signal_pending(current));
1812− trace_rcu_grace_period(rcu_state.name,
1813− READ_ONCE(rcu_state.gp_seq),
1830+ trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
18141831 TPS("reqwaitsig"));
18151832 }
18161833
@@ -1881,7 +1898,7 @@ static void rcu_report_qs_rnp(unsigned long mask, struct rcu_node *rnp, · 64 unmodified lines
18811898 WARN_ON_ONCE(oldmask); /* Any child must be all zeroed! */
18821899 WARN_ON_ONCE(!rcu_is_leaf_node(rnp) &&
18831900 rcu_preempt_blocked_readers_cgp(rnp));
1884− rnp->qsmask &= ~mask;
1901+ WRITE_ONCE(rnp->qsmask, rnp->qsmask & ~mask);
18851902 trace_rcu_quiescent_state_report(rcu_state.name, rnp->gp_seq,
18861903 mask, rnp->qsmask, rnp->level,
18871904 rnp->grplo, rnp->grphi,
@@ -1904,7 +1921,7 @@ static void rcu_report_qs_rnp(unsigned long mask, struct rcu_node *rnp, · 16 unmodified lines
19041921 rnp_c = rnp;
19051922 rnp = rnp->parent;
19061923 raw_spin_lock_irqsave_rcu_node(rnp, flags);
1907− oldmask = rnp_c->qsmask;
1924+ oldmask = READ_ONCE(rnp_c->qsmask);
19081925 }
19091926
19101927 /*
@@ -1987,6 +2004,8 @@ rcu_report_qs_rdp(int cpu, struct rcu_data *rdp) · 76 unmodified lines
19872004 return;
19882005 }
19892006 mask = rdp->grpmask;
2007+ if (rdp->cpu == smp_processor_id())
2008+ rdp->core_needs_qs = false;
19902009 if ((rnp->qsmask & mask) == 0) {
19912010 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
19922011 } else {
@@ -2052,7 +2071,7 @@ int rcutree_dying_cpu(unsigned int cpu) · 59 unmodified lines
20522071 return 0;
20532072
20542073 blkd = !!(rnp->qsmask & rdp->grpmask);
2055− trace_rcu_grace_period(rcu_state.name, rnp->gp_seq,
2074+ trace_rcu_grace_period(rcu_state.name, READ_ONCE(rnp->gp_seq),
20562075 blkd ? TPS("cpuofl") : TPS("cpuofl-bgp"));
20572076 return 0;
20582077 }
@@ -2294,10 +2313,13 @@ static void force_qs_rnp(int (*f)(struct rcu_data *rdp)) · 235 unmodified lines
22942313 struct rcu_data *rdp;
22952314 struct rcu_node *rnp;
22962315
2316+ rcu_state.cbovld = rcu_state.cbovldnext;
2317+ rcu_state.cbovldnext = false;
22972318 rcu_for_each_leaf_node(rnp) {
22982319 cond_resched_tasks_rcu_qs();
22992320 mask = 0;
23002321 raw_spin_lock_irqsave_rcu_node(rnp, flags);
2322+ rcu_state.cbovldnext |= !!rnp->cbovldmask;
23012323 if (rnp->qsmask == 0) {
23022324 if (!IS_ENABLED(CONFIG_PREEMPT_RCU) ||
23032325 rcu_preempt_blocked_readers_cgp(rnp)) {
@@ -2579,11 +2601,48 @@ static void rcu_leak_callback(struct rcu_head *rhp) · 275 unmodified lines
25792601 }
25802602
25812603 /*
2582− * Helper function for call_rcu() and friends. The cpu argument will
2583− * normally be -1, indicating "currently running CPU". It may specify
2584− * a CPU only if that CPU is a no-CBs CPU. Currently, only rcu_barrier()
2585− * is expected to specify a CPU.
2604+ * Check and if necessary update the leaf rcu_node structure's
2605+ * ->cbovldmask bit corresponding to the current CPU based on that CPU's
2606+ * number of queued RCU callbacks. The caller must hold the leaf rcu_node
2607+ * structure's ->lock.
25862608 */
2609+static void check_cb_ovld_locked(struct rcu_data *rdp, struct rcu_node *rnp)
2610+{
2611+ raw_lockdep_assert_held_rcu_node(rnp);
2612+ if (qovld_calc <= 0)
2613+ return; // Early boot and wildcard value set.
2614+ if (rcu_segcblist_n_cbs(&rdp->cblist) >= qovld_calc)
2615+ WRITE_ONCE(rnp->cbovldmask, rnp->cbovldmask | rdp->grpmask);
2616+ else
2617+ WRITE_ONCE(rnp->cbovldmask, rnp->cbovldmask & ~rdp->grpmask);
2618+}
2619+
2620+/*
2621+ * Check and if necessary update the leaf rcu_node structure's
2622+ * ->cbovldmask bit corresponding to the current CPU based on that CPU's
2623+ * number of queued RCU callbacks. No locks need be held, but the
2624+ * caller must have disabled interrupts.
2625+ *
2626+ * Note that this function ignores the possibility that there are a lot
2627+ * of callbacks all of which have already seen the end of their respective
2628+ * grace periods. This omission is due to the need for no-CBs CPUs to
2629+ * be holding ->nocb_lock to do this check, which is too heavy for a
2630+ * common-case operation.
2631+ */
2632+static void check_cb_ovld(struct rcu_data *rdp)
2633+{
2634+ struct rcu_node *const rnp = rdp->mynode;
2635+
2636+ if (qovld_calc <= 0 ||
2637+ ((rcu_segcblist_n_cbs(&rdp->cblist) >= qovld_calc) ==
2638+ !!(READ_ONCE(rnp->cbovldmask) & rdp->grpmask)))
2639+ return; // Early boot wildcard value or already set correctly.
2640+ raw_spin_lock_rcu_node(rnp);
2641+ check_cb_ovld_locked(rdp, rnp);
2642+ raw_spin_unlock_rcu_node(rnp);
2643+}
2644+
2645+/* Helper function for call_rcu() and friends. */
25872646 static void
25882647 __call_rcu(struct rcu_head *head, rcu_callback_t func)
25892648 {
@@ -2621,9 +2680,10 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) · 31 unmodified lines
26212680 rcu_segcblist_init(&rdp->cblist);
26222681 }
26232682
2683+ check_cb_ovld(rdp);
26242684 if (rcu_nocb_try_bypass(rdp, head, &was_alldone, flags))
26252685 return; // Enqueued onto ->nocb_bypass, so just leave.
2626− /* If we get here, rcu_nocb_try_bypass() acquired ->nocb_lock. */
2686+ // If no-CBs CPU gets here, rcu_nocb_try_bypass() acquired ->nocb_lock.
26272687 rcu_segcblist_enqueue(&rdp->cblist, head);
26282688 if (__is_kfree_rcu_offset((unsigned long)func))
26292689 trace_rcu_kfree_callback(rcu_state.name, head,
@@ -2689,22 +2749,47 @@ EXPORT_SYMBOL_GPL(call_rcu); · 59 unmodified lines
26892749 #define KFREE_DRAIN_JIFFIES (HZ / 50)
26902750 #define KFREE_N_BATCHES 2
26912751
2752+/*
2753+ * This macro defines how many entries the "records" array
2754+ * will contain. It is based on the fact that the size of
2755+ * kfree_rcu_bulk_data structure becomes exactly one page.
2756+ */
2757+#define KFREE_BULK_MAX_ENTR ((PAGE_SIZE / sizeof(void *)) - 3)
2758+
2759+/**
2760+ * struct kfree_rcu_bulk_data - single block to store kfree_rcu() pointers
2761+ * @nr_records: Number of active pointers in the array
2762+ * @records: Array of the kfree_rcu() pointers
2763+ * @next: Next bulk object in the block chain
2764+ * @head_free_debug: For debug, when CONFIG_DEBUG_OBJECTS_RCU_HEAD is set
2765+ */
2766+struct kfree_rcu_bulk_data {
2767+ unsigned long nr_records;
2768+ void *records[KFREE_BULK_MAX_ENTR];
2769+ struct kfree_rcu_bulk_data *next;
2770+ struct rcu_head *head_free_debug;
2771+};
2772+
26922773 /**
26932774 * struct kfree_rcu_cpu_work - single batch of kfree_rcu() requests
26942775 * @rcu_work: Let queue_rcu_work() invoke workqueue handler after grace period
26952776 * @head_free: List of kfree_rcu() objects waiting for a grace period
2777+ * @bhead_free: Bulk-List of kfree_rcu() objects waiting for a grace period
26962778 * @krcp: Pointer to @kfree_rcu_cpu structure
26972779 */
26982780
26992781 struct kfree_rcu_cpu_work {
27002782 struct rcu_work rcu_work;
27012783 struct rcu_head *head_free;
2784+ struct kfree_rcu_bulk_data *bhead_free;
27022785 struct kfree_rcu_cpu *krcp;
27032786 };
27042787
27052788 /**
27062789 * struct kfree_rcu_cpu - batch up kfree_rcu() requests for RCU grace period
27072790 * @head: List of kfree_rcu() objects not yet waiting for a grace period
2791+ * @bhead: Bulk-List of kfree_rcu() objects not yet waiting for a grace period
2792+ * @bcached: Keeps at most one object for later reuse when build chain blocks
27082793 * @krw_arr: Array of batches of kfree_rcu() objects waiting for a grace period
27092794 * @lock: Synchronize access to this structure
27102795 * @monitor_work: Promote @head to @head_free after KFREE_DRAIN_JIFFIES
@@ -2718,6 +2803,8 @@ struct kfree_rcu_cpu_work { · 7 unmodified lines
27182803 */
27192804 struct kfree_rcu_cpu {
27202805 struct rcu_head *head;
2806+ struct kfree_rcu_bulk_data *bhead;
2807+ struct kfree_rcu_bulk_data *bcached;
27212808 struct kfree_rcu_cpu_work krw_arr[KFREE_N_BATCHES];
27222809 spinlock_t lock;
27232810 struct delayed_work monitor_work;
@@ -2727,14 +2814,24 @@ struct kfree_rcu_cpu { · 3 unmodified lines
27272814
27282815 static DEFINE_PER_CPU(struct kfree_rcu_cpu, krc);
27292816
2817+static __always_inline void
2818+debug_rcu_head_unqueue_bulk(struct rcu_head *head)
2819+{
2820+#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
2821+ for (; head; head = head->next)
2822+ debug_rcu_head_unqueue(head);
2823+#endif
2824+}
2825+
27302826 /*
27312827 * This function is invoked in workqueue context after a grace period.
2732− * It frees all the objects queued on ->head_free.
2828+ * It frees all the objects queued on ->bhead_free or ->head_free.
27332829 */
27342830 static void kfree_rcu_work(struct work_struct *work)
27352831 {
27362832 unsigned long flags;
27372833 struct rcu_head *head, *next;
2834+ struct kfree_rcu_bulk_data *bhead, *bnext;
27382835 struct kfree_rcu_cpu *krcp;
27392836 struct kfree_rcu_cpu_work *krwp;
27402837
@@ -2744,22 +2841,44 @@ static void kfree_rcu_work(struct work_struct *work) · 3 unmodified lines
27442841 spin_lock_irqsave(&krcp->lock, flags);
27452842 head = krwp->head_free;
27462843 krwp->head_free = NULL;
2844+ bhead = krwp->bhead_free;
2845+ krwp->bhead_free = NULL;
27472846 spin_unlock_irqrestore(&krcp->lock, flags);
27482847
2749− // List "head" is now private, so traverse locklessly.
2848+ /* "bhead" is now private, so traverse locklessly. */
2849+ for (; bhead; bhead = bnext) {
2850+ bnext = bhead->next;
2851+
2852+ debug_rcu_head_unqueue_bulk(bhead->head_free_debug);
2853+
2854+ rcu_lock_acquire(&rcu_callback_map);
2855+ trace_rcu_invoke_kfree_bulk_callback(rcu_state.name,
2856+ bhead->nr_records, bhead->records);
2857+
2858+ kfree_bulk(bhead->nr_records, bhead->records);
2859+ rcu_lock_release(&rcu_callback_map);
2860+
2861+ if (cmpxchg(&krcp->bcached, NULL, bhead))
2862+ free_page((unsigned long) bhead);
2863+
2864+ cond_resched_tasks_rcu_qs();
2865+ }
2866+
2867+ /*
2868+ * Emergency case only. It can happen under low memory
2869+ * condition when an allocation gets failed, so the "bulk"
2870+ * path can not be temporary maintained.
2871+ */
27502872 for (; head; head = next) {
27512873 unsigned long offset = (unsigned long)head->func;
27522874
27532875 next = head->next;
2754− // Potentially optimize with kfree_bulk in future.
27552876 debug_rcu_head_unqueue(head);
27562877 rcu_lock_acquire(&rcu_callback_map);
27572878 trace_rcu_invoke_kfree_callback(rcu_state.name, head, offset);
27582879
2759− if (!WARN_ON_ONCE(!__is_kfree_rcu_offset(offset))) {
2760− /* Could be optimized with kfree_bulk() in future. */
2880+ if (!WARN_ON_ONCE(!__is_kfree_rcu_offset(offset)))
27612881 kfree((void *)head - offset);
2762− }
27632882
27642883 rcu_lock_release(&rcu_callback_map);
27652884 cond_resched_tasks_rcu_qs();
@@ -2774,26 +2893,48 @@ static void kfree_rcu_work(struct work_struct *work) · 8 unmodified lines
27742893 */
27752894 static inline bool queue_kfree_rcu_work(struct kfree_rcu_cpu *krcp)
27762895 {
2896+ struct kfree_rcu_cpu_work *krwp;
2897+ bool queued = false;
27772898 int i;
2778− struct kfree_rcu_cpu_work *krwp = NULL;
27792899
27802900 lockdep_assert_held(&krcp->lock);
2781− for (i = 0; i < KFREE_N_BATCHES; i++)
2782− if (!krcp->krw_arr[i].head_free) {
2783− krwp = &(krcp->krw_arr[i]);
2784− break;
2785− }
27862901
2787− // If a previous RCU batch is in progress, we cannot immediately
2788− // queue another one, so return false to tell caller to retry.
2789− if (!krwp)
2790− return false;
2902+ for (i = 0; i < KFREE_N_BATCHES; i++) {
2903+ krwp = &(krcp->krw_arr[i]);
27912904
2792− krwp->head_free = krcp->head;
2793− krcp->head = NULL;
2794− INIT_RCU_WORK(&krwp->rcu_work, kfree_rcu_work);
2795− queue_rcu_work(system_wq, &krwp->rcu_work);
2796− return true;
2905+ /*
2906+ * Try to detach bhead or head and attach it over any
2907+ * available corresponding free channel. It can be that
2908+ * a previous RCU batch is in progress, it means that
2909+ * immediately to queue another one is not possible so
2910+ * return false to tell caller to retry.
2911+ */
2912+ if ((krcp->bhead && !krwp->bhead_free) ||
2913+ (krcp->head && !krwp->head_free)) {
2914+ /* Channel 1. */
2915+ if (!krwp->bhead_free) {
2916+ krwp->bhead_free = krcp->bhead;
2917+ krcp->bhead = NULL;
2918+ }
2919+
2920+ /* Channel 2. */
2921+ if (!krwp->head_free) {
2922+ krwp->head_free = krcp->head;
2923+ krcp->head = NULL;
2924+ }
2925+
2926+ /*
2927+ * One work is per one batch, so there are two "free channels",
2928+ * "bhead_free" and "head_free" the batch can handle. It can be
2929+ * that the work is in the pending state when two channels have
2930+ * been detached following each other, one by one.
2931+ */
2932+ queue_rcu_work(system_wq, &krwp->rcu_work);
2933+ queued = true;
2934+ }
2935+ }
2936+
2937+ return queued;
27972938 }
27982939
27992940 static inline void kfree_rcu_drain_unlock(struct kfree_rcu_cpu *krcp,
@@ -2830,19 +2971,65 @@ static void kfree_rcu_monitor(struct work_struct *work) · 30 unmodified lines
28302971 spin_unlock_irqrestore(&krcp->lock, flags);
28312972 }
28322973
2974+static inline bool
2975+kfree_call_rcu_add_ptr_to_bulk(struct kfree_rcu_cpu *krcp,
2976+ struct rcu_head *head, rcu_callback_t func)
2977+{
2978+ struct kfree_rcu_bulk_data *bnode;
2979+
2980+ if (unlikely(!krcp->initialized))
2981+ return false;
2982+
2983+ lockdep_assert_held(&krcp->lock);
2984+
2985+ /* Check if a new block is required. */
2986+ if (!krcp->bhead ||
2987+ krcp->bhead->nr_records == KFREE_BULK_MAX_ENTR) {
2988+ bnode = xchg(&krcp->bcached, NULL);
2989+ if (!bnode) {
2990+ WARN_ON_ONCE(sizeof(struct kfree_rcu_bulk_data) > PAGE_SIZE);
2991+
2992+ bnode = (struct kfree_rcu_bulk_data *)
2993+ __get_free_page(GFP_NOWAIT | __GFP_NOWARN);
2994+ }
2995+
2996+ /* Switch to emergency path. */
2997+ if (unlikely(!bnode))
2998+ return false;
2999+
3000+ /* Initialize the new block. */
3001+ bnode->nr_records = 0;
3002+ bnode->next = krcp->bhead;
3003+ bnode->head_free_debug = NULL;
3004+
3005+ /* Attach it to the head. */
3006+ krcp->bhead = bnode;
3007+ }
3008+
3009+#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
3010+ head->func = func;
3011+ head->next = krcp->bhead->head_free_debug;
3012+ krcp->bhead->head_free_debug = head;
3013+#endif
3014+
3015+ /* Finally insert. */
3016+ krcp->bhead->records[krcp->bhead->nr_records++] =
3017+ (void *) head - (unsigned long) func;
3018+
3019+ return true;
3020+}
3021+
28333022 /*
2834− * Queue a request for lazy invocation of kfree() after a grace period.
3023+ * Queue a request for lazy invocation of kfree_bulk()/kfree() after a grace
3024+ * period. Please note there are two paths are maintained, one is the main one
3025+ * that uses kfree_bulk() interface and second one is emergency one, that is
3026+ * used only when the main path can not be maintained temporary, due to memory
3027+ * pressure.
28353028 *
28363029 * Each kfree_call_rcu() request is added to a batch. The batch will be drained
2837− * every KFREE_DRAIN_JIFFIES number of jiffies. All the objects in the batch
2838− * will be kfree'd in workqueue context. This allows us to:
2839− *
2840− * 1. Batch requests together to reduce the number of grace periods during
2841− * heavy kfree_rcu() load.
2842− *
2843− * 2. It makes it possible to use kfree_bulk() on a large number of
2844− * kfree_rcu() requests thus reducing cache misses and the per-object
2845− * overhead of kfree().
3030+ * every KFREE_DRAIN_JIFFIES number of jiffies. All the objects in the batch will
3031+ * be free'd in workqueue context. This allows us to: batch requests together to
3032+ * reduce the number of grace periods during heavy kfree_rcu() load.
28463033 */
28473034 void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
28483035 {
@@ -2861,9 +3048,16 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func) · 12 unmodified lines
28613048 __func__, head);
28623049 goto unlock_return;
28633050 }
2864− head->func = func;
2865− head->next = krcp->head;
2866− krcp->head = head;
3051+
3052+ /*
3053+ * Under high memory pressure GFP_NOWAIT can fail,
3054+ * in that case the emergency path is maintained.
3055+ */
3056+ if (unlikely(!kfree_call_rcu_add_ptr_to_bulk(krcp, head, func))) {
3057+ head->func = func;
3058+ head->next = krcp->head;
3059+ krcp->head = head;
3060+ }
28673061
28683062 // Set timer to drain after KFREE_DRAIN_JIFFIES.
28693063 if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING &&
@@ -3075,24 +3269,32 @@ static void rcu_barrier_trace(const char *s, int cpu, unsigned long done) · 205 unmodified lines
30753269 /*
30763270 * RCU callback function for rcu_barrier(). If we are last, wake
30773271 * up the task executing rcu_barrier().
3272+ *
3273+ * Note that the value of rcu_state.barrier_sequence must be captured
3274+ * before the atomic_dec_and_test(). Otherwise, if this CPU is not last,
3275+ * other CPUs might count the value down to zero before this CPU gets
3276+ * around to invoking rcu_barrier_trace(), which might result in bogus
3277+ * data from the next instance of rcu_barrier().
30783278 */
30793279 static void rcu_barrier_callback(struct rcu_head *rhp)
30803280 {
3281+ unsigned long __maybe_unused s = rcu_state.barrier_sequence;
3282+
30813283 if (atomic_dec_and_test(&rcu_state.barrier_cpu_count)) {
3082− rcu_barrier_trace(TPS("LastCB"), -1,
3083− rcu_state.barrier_sequence);
3284+ rcu_barrier_trace(TPS("LastCB"), -1, s);
30843285 complete(&rcu_state.barrier_completion);
30853286 } else {
3086− rcu_barrier_trace(TPS("CB"), -1, rcu_state.barrier_sequence);
3287+ rcu_barrier_trace(TPS("CB"), -1, s);
30873288 }
30883289 }
30893290
30903291 /*
30913292 * Called with preemption disabled, and from cross-cpu IRQ context.
30923293 */
3093−static void rcu_barrier_func(void *unused)
3294+static void rcu_barrier_func(void *cpu_in)
30943295 {
3095− struct rcu_data *rdp = raw_cpu_ptr(&rcu_data);
3296+ uintptr_t cpu = (uintptr_t)cpu_in;
3297+ struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
30963298
30973299 rcu_barrier_trace(TPS("IRQ"), -1, rcu_state.barrier_sequence);
30983300 rdp->barrier_head.func = rcu_barrier_callback;
@@ -3119,7 +3321,7 @@ static void rcu_barrier_func(void *unused) · 20 unmodified lines
31193321 */
31203322 void rcu_barrier(void)
31213323 {
3122− int cpu;
3324+ uintptr_t cpu;
31233325 struct rcu_data *rdp;
31243326 unsigned long s = rcu_seq_snap(&rcu_state.barrier_sequence);
31253327
@@ -3142,13 +3344,14 @@ void rcu_barrier(void) · 16 unmodified lines
31423344 rcu_barrier_trace(TPS("Inc1"), -1, rcu_state.barrier_sequence);
31433345
31443346 /*
3145− * Initialize the count to one rather than to zero in order to
3146− * avoid a too-soon return to zero in case of a short grace period
3147− * (or preemption of this task). Exclude CPU-hotplug operations
3148− * to ensure that no offline CPU has callbacks queued.
3347+ * Initialize the count to two rather than to zero in order
3348+ * to avoid a too-soon return to zero in case of an immediate
3349+ * invocation of the just-enqueued callback (or preemption of
3350+ * this task). Exclude CPU-hotplug operations to ensure that no
3351+ * offline non-offloaded CPU has callbacks queued.
31493352 */
31503353 init_completion(&rcu_state.barrier_completion);
3151− atomic_set(&rcu_state.barrier_cpu_count, 1);
3354+ atomic_set(&rcu_state.barrier_cpu_count, 2);
31523355 get_online_cpus();
31533356
31543357 /*
@@ -3158,13 +3361,23 @@ void rcu_barrier(void) · 3 unmodified lines
31583361 */
31593362 for_each_possible_cpu(cpu) {
31603363 rdp = per_cpu_ptr(&rcu_data, cpu);
3161− if (!cpu_online(cpu) &&
3364+ if (cpu_is_offline(cpu) &&
31623365 !rcu_segcblist_is_offloaded(&rdp->cblist))
31633366 continue;
3164− if (rcu_segcblist_n_cbs(&rdp->cblist)) {
3367+ if (rcu_segcblist_n_cbs(&rdp->cblist) && cpu_online(cpu)) {
31653368 rcu_barrier_trace(TPS("OnlineQ"), cpu,
31663369 rcu_state.barrier_sequence);
3167− smp_call_function_single(cpu, rcu_barrier_func, NULL, 1);
3370+ smp_call_function_single(cpu, rcu_barrier_func, (void *)cpu, 1);
3371+ } else if (rcu_segcblist_n_cbs(&rdp->cblist) &&
3372+ cpu_is_offline(cpu)) {
3373+ rcu_barrier_trace(TPS("OfflineNoCBQ"), cpu,
3374+ rcu_state.barrier_sequence);
3375+ local_irq_disable();
3376+ rcu_barrier_func((void *)cpu);
3377+ local_irq_enable();
3378+ } else if (cpu_is_offline(cpu)) {
3379+ rcu_barrier_trace(TPS("OfflineNoCBNoQ"), cpu,
3380+ rcu_state.barrier_sequence);
31683381 } else {
31693382 rcu_barrier_trace(TPS("OnlineNQ"), cpu,
31703383 rcu_state.barrier_sequence);
@@ -3176,7 +3389,7 @@ void rcu_barrier(void) · 5 unmodified lines
31763389 * Now that we have an rcu_barrier_callback() callback on each
31773390 * CPU, and thus each counted, remove the initial count.
31783391 */
3179− if (atomic_dec_and_test(&rcu_state.barrier_cpu_count))
3392+ if (atomic_sub_and_test(2, &rcu_state.barrier_cpu_count))
31803393 complete(&rcu_state.barrier_completion);
31813394
31823395 /* Wait for all rcu_barrier_callback() callbacks to be invoked. */
@@ -3275,12 +3488,12 @@ int rcutree_prepare_cpu(unsigned int cpu) · 92 unmodified lines
32753488 rnp = rdp->mynode;
32763489 raw_spin_lock_rcu_node(rnp); /* irqs already disabled. */
32773490 rdp->beenonline = true; /* We have now been online. */
3278− rdp->gp_seq = rnp->gp_seq;
3279− rdp->gp_seq_needed = rnp->gp_seq;
3491+ rdp->gp_seq = READ_ONCE(rnp->gp_seq);
3492+ rdp->gp_seq_needed = rdp->gp_seq;
32803493 rdp->cpu_no_qs.b.norm = true;
32813494 rdp->core_needs_qs = false;
32823495 rdp->rcu_iw_pending = false;
3283− rdp->rcu_iw_gp_seq = rnp->gp_seq - 1;
3496+ rdp->rcu_iw_gp_seq = rdp->gp_seq - 1;
32843497 trace_rcu_grace_period(rcu_state.name, rdp->gp_seq, TPS("cpuonl"));
32853498 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
32863499 rcu_prepare_kthreads(cpu);
@@ -3378,7 +3591,7 @@ void rcu_cpu_starting(unsigned int cpu) · 91 unmodified lines
33783591 rnp = rdp->mynode;
33793592 mask = rdp->grpmask;
33803593 raw_spin_lock_irqsave_rcu_node(rnp, flags);
3381− rnp->qsmaskinitnext |= mask;
3594+ WRITE_ONCE(rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask);
33823595 oldmask = rnp->expmaskinitnext;
33833596 rnp->expmaskinitnext |= mask;
33843597 oldmask ^= rnp->expmaskinitnext;
@@ -3431,7 +3644,7 @@ void rcu_report_dead(unsigned int cpu) · 46 unmodified lines
34313644 rcu_report_qs_rnp(mask, rnp, rnp->gp_seq, flags);
34323645 raw_spin_lock_irqsave_rcu_node(rnp, flags);
34333646 }
3434− rnp->qsmaskinitnext &= ~mask;
3647+ WRITE_ONCE(rnp->qsmaskinitnext, rnp->qsmaskinitnext & ~mask);
34353648 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
34363649 raw_spin_unlock(&rcu_state.ofl_lock);
34373650
@@ -3545,7 +3758,10 @@ static int __init rcu_spawn_gp_kthread(void) · 107 unmodified lines
35453758 }
35463759 rnp = rcu_get_root();
35473760 raw_spin_lock_irqsave_rcu_node(rnp, flags);
3548− rcu_state.gp_kthread = t;
3761+ WRITE_ONCE(rcu_state.gp_activity, jiffies);
3762+ WRITE_ONCE(rcu_state.gp_req_activity, jiffies);
3763+ // Reset .gp_activity and .gp_req_activity before setting .gp_kthread.
3764+ smp_store_release(&rcu_state.gp_kthread, t); /* ^^^ */
35493765 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
35503766 wake_up_process(t);
35513767 rcu_spawn_nocb_kthreads();
@@ -3769,8 +3985,11 @@ static void __init kfree_rcu_batch_init(void) · 217 unmodified lines
37693985 struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu);
37703986
37713987 spin_lock_init(&krcp->lock);
3772− for (i = 0; i < KFREE_N_BATCHES; i++)
3988+ for (i = 0; i < KFREE_N_BATCHES; i++) {
3989+ INIT_RCU_WORK(&krcp->krw_arr[i].rcu_work, kfree_rcu_work);
37733990 krcp->krw_arr[i].krcp = krcp;
3991+ }
3992+
37743993 INIT_DELAYED_WORK(&krcp->monitor_work, kfree_rcu_monitor);
37753994 krcp->initialized = true;
37763995 }
@@ -3809,6 +4028,13 @@ void __init rcu_init(void) · 32 unmodified lines
38094028 rcu_par_gp_wq = alloc_workqueue("rcu_par_gp", WQ_MEM_RECLAIM, 0);
38104029 WARN_ON(!rcu_par_gp_wq);
38114030 srcu_init();
4031+
4032+ /* Fill in default value for rcutree.qovld boot parameter. */
4033+ /* -After- the rcu_node ->lock fields are initialized! */
4034+ if (qovld < 0)
4035+ qovld_calc = DEFAULT_RCU_QOVLD_MULT * qhimark;
4036+ else
4037+ qovld_calc = qovld;
38124038 }
38134039
38144040 #include "tree_stall.h"
kernel/rcu/tree.h+4−0
@@ -68,6 +68,8 @@ struct rcu_node { · 67 unmodified lines
6868 /* Online CPUs for next expedited GP. */
6969 /* Any CPU that has ever been online will */
7070 /* have its bit set. */
71+ unsigned long cbovldmask;
72+ /* CPUs experiencing callback overload. */
7173 unsigned long ffmask; /* Fully functional CPUs. */
7274 unsigned long grpmask; /* Mask to apply to parent qsmask. */
7375 /* Only one bit will be set in this mask. */
@@ -321,6 +323,8 @@ struct rcu_state { · 247 unmodified lines
321323 atomic_t expedited_need_qs; /* # CPUs left to check in. */
322324 struct swait_queue_head expedited_wq; /* Wait for check-ins. */
323325 int ncpus_snap; /* # CPUs seen last time. */
326+ u8 cbovld; /* Callback overload now? */
327+ u8 cbovldnext; /* ^ ^ next time? */
324328
325329 unsigned long jiffies_force_qs; /* Time at which to invoke */
326330 /* force_quiescent_state(). */
kernel/rcu/tree_exp.h+9−4
@@ -314,7 +314,7 @@ static bool exp_funnel_lock(unsigned long s) · 313 unmodified lines
314314 sync_exp_work_done(s));
315315 return true;
316316 }
317− rnp->exp_seq_rq = s; /* Followers can wait on us. */
317+ WRITE_ONCE(rnp->exp_seq_rq, s); /* Followers can wait on us. */
318318 spin_unlock(&rnp->exp_lock);
319319 trace_rcu_exp_funnel_lock(rcu_state.name, rnp->level,
320320 rnp->grplo, rnp->grphi, TPS("nxtlvl"));
@@ -485,6 +485,7 @@ static bool synchronize_rcu_expedited_wait_once(long tlimit) · 164 unmodified lines
485485 static void synchronize_rcu_expedited_wait(void)
486486 {
487487 int cpu;
488+ unsigned long j;
488489 unsigned long jiffies_stall;
489490 unsigned long jiffies_start;
490491 unsigned long mask;
@@ -496,7 +497,7 @@ static void synchronize_rcu_expedited_wait(void) · 5 unmodified lines
496497 trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("startwait"));
497498 jiffies_stall = rcu_jiffies_till_stall_check();
498499 jiffies_start = jiffies;
499− if (IS_ENABLED(CONFIG_NO_HZ_FULL)) {
500+ if (tick_nohz_full_enabled() && rcu_inkernel_boot_has_ended()) {
500501 if (synchronize_rcu_expedited_wait_once(1))
501502 return;
502503 rcu_for_each_leaf_node(rnp) {
@@ -508,12 +509,16 @@ static void synchronize_rcu_expedited_wait(void) · 5 unmodified lines
508509 tick_dep_set_cpu(cpu, TICK_DEP_BIT_RCU_EXP);
509510 }
510511 }
512+ j = READ_ONCE(jiffies_till_first_fqs);
513+ if (synchronize_rcu_expedited_wait_once(j + HZ))
514+ return;
515+ WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT));
511516 }
512517
513518 for (;;) {
514519 if (synchronize_rcu_expedited_wait_once(jiffies_stall))
515520 return;
516− if (rcu_cpu_stall_suppress)
521+ if (rcu_stall_is_suppressed())
517522 continue;
518523 panic_on_rcu_stall();
519524 pr_err("INFO: %s detected expedited stalls on CPUs/tasks: {",
@@ -589,7 +594,7 @@ static void rcu_exp_wait_wake(unsigned long s) · 69 unmodified lines
589594 spin_lock(&rnp->exp_lock);
590595 /* Recheck, avoid hang in case someone just arrived. */
591596 if (ULONG_CMP_LT(rnp->exp_seq_rq, s))
592− rnp->exp_seq_rq = s;
597+ WRITE_ONCE(rnp->exp_seq_rq, s);
593598 spin_unlock(&rnp->exp_lock);
594599 }
595600 smp_mb(); /* All above changes before wakeup. */
kernel/rcu/tree_plugin.h+16−9
@@ -56,6 +56,8 @@ static void __init rcu_bootup_announce_oddness(void) · 55 unmodified lines
5656 pr_info("\tBoot-time adjustment of callback high-water mark to %ld.\n", qhimark);
5757 if (qlowmark != DEFAULT_RCU_QLOMARK)
5858 pr_info("\tBoot-time adjustment of callback low-water mark to %ld.\n", qlowmark);
59+ if (qovld != DEFAULT_RCU_QOVLD)
60+ pr_info("\tBoot-time adjustment of callback overload level to %ld.\n", qovld);
5961 if (jiffies_till_first_fqs != ULONG_MAX)
6062 pr_info("\tBoot-time adjustment of first FQS scan delay to %ld jiffies.\n", jiffies_till_first_fqs);
6163 if (jiffies_till_next_fqs != ULONG_MAX)
@@ -753,7 +755,7 @@ dump_blkd_tasks(struct rcu_node *rnp, int ncheck) · 691 unmodified lines
753755 raw_lockdep_assert_held_rcu_node(rnp);
754756 pr_info("%s: grp: %d-%d level: %d ->gp_seq %ld ->completedqs %ld\n",
755757 __func__, rnp->grplo, rnp->grphi, rnp->level,
756− (long)rnp->gp_seq, (long)rnp->completedqs);
758+ (long)READ_ONCE(rnp->gp_seq), (long)rnp->completedqs);
757759 for (rnp1 = rnp; rnp1; rnp1 = rnp1->parent)
758760 pr_info("%s: %d:%d ->qsmask %#lx ->qsmaskinit %#lx ->qsmaskinitnext %#lx\n",
759761 __func__, rnp1->grplo, rnp1->grphi, rnp1->qsmask, rnp1->qsmaskinit, rnp1->qsmaskinitnext);
@@ -1032,18 +1034,18 @@ static int rcu_boost_kthread(void *arg) · 272 unmodified lines
10321034
10331035 trace_rcu_utilization(TPS("Start boost kthread@init"));
10341036 for (;;) {
1035− rnp->boost_kthread_status = RCU_KTHREAD_WAITING;
1037+ WRITE_ONCE(rnp->boost_kthread_status, RCU_KTHREAD_WAITING);
10361038 trace_rcu_utilization(TPS("End boost kthread@rcu_wait"));
10371039 rcu_wait(rnp->boost_tasks || rnp->exp_tasks);
10381040 trace_rcu_utilization(TPS("Start boost kthread@rcu_wait"));
1039− rnp->boost_kthread_status = RCU_KTHREAD_RUNNING;
1041+ WRITE_ONCE(rnp->boost_kthread_status, RCU_KTHREAD_RUNNING);
10401042 more2boost = rcu_boost(rnp);
10411043 if (more2boost)
10421044 spincnt++;
10431045 else
10441046 spincnt = 0;
10451047 if (spincnt > 10) {
1046− rnp->boost_kthread_status = RCU_KTHREAD_YIELDING;
1048+ WRITE_ONCE(rnp->boost_kthread_status, RCU_KTHREAD_YIELDING);
10471049 trace_rcu_utilization(TPS("End boost kthread@rcu_yield"));
10481050 schedule_timeout_interruptible(2);
10491051 trace_rcu_utilization(TPS("Start boost kthread@rcu_yield"));
@@ -1077,12 +1079,12 @@ static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags) · 27 unmodified lines
10771079 (rnp->gp_tasks != NULL &&
10781080 rnp->boost_tasks == NULL &&
10791081 rnp->qsmask == 0 &&
1080− ULONG_CMP_GE(jiffies, rnp->boost_time))) {
1082+ (ULONG_CMP_GE(jiffies, rnp->boost_time) || rcu_state.cbovld))) {
10811083 if (rnp->exp_tasks == NULL)
10821084 rnp->boost_tasks = rnp->gp_tasks;
10831085 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
10841086 rcu_wake_cond(rnp->boost_kthread_task,
1085− rnp->boost_kthread_status);
1087+ READ_ONCE(rnp->boost_kthread_status));
10861088 } else {
10871089 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
10881090 }
@@ -1486,6 +1488,7 @@ module_param(nocb_nobypass_lim_per_jiffy, int, 0); · 397 unmodified lines
14861488 * flag the contention.
14871489 */
14881490 static void rcu_nocb_bypass_lock(struct rcu_data *rdp)
1491+ __acquires(&rdp->nocb_bypass_lock)
14891492 {
14901493 lockdep_assert_irqs_disabled();
14911494 if (raw_spin_trylock(&rdp->nocb_bypass_lock))
@@ -1529,6 +1532,7 @@ static bool rcu_nocb_bypass_trylock(struct rcu_data *rdp) · 37 unmodified lines
15291532 * Release the specified rcu_data structure's ->nocb_bypass_lock.
15301533 */
15311534 static void rcu_nocb_bypass_unlock(struct rcu_data *rdp)
1535+ __releases(&rdp->nocb_bypass_lock)
15321536 {
15331537 lockdep_assert_irqs_disabled();
15341538 raw_spin_unlock(&rdp->nocb_bypass_lock);
@@ -1577,8 +1581,7 @@ static void rcu_nocb_unlock_irqrestore(struct rcu_data *rdp, · 42 unmodified lines
15771581 static void rcu_lockdep_assert_cblist_protected(struct rcu_data *rdp)
15781582 {
15791583 lockdep_assert_irqs_disabled();
1580− if (rcu_segcblist_is_offloaded(&rdp->cblist) &&
1581− cpu_online(rdp->cpu))
1584+ if (rcu_segcblist_is_offloaded(&rdp->cblist))
15821585 lockdep_assert_held(&rdp->nocb_lock);
15831586 }
15841587
@@ -1930,6 +1933,7 @@ static void nocb_gp_wait(struct rcu_data *my_rdp) · 345 unmodified lines
19301933 struct rcu_data *rdp;
19311934 struct rcu_node *rnp;
19321935 unsigned long wait_gp_seq = 0; // Suppress "use uninitialized" warning.
1936+ bool wasempty = false;
19331937
19341938 /*
19351939 * Each pass through the following loop checks for CBs and for the
@@ -1969,10 +1973,13 @@ static void nocb_gp_wait(struct rcu_data *my_rdp) · 33 unmodified lines
19691973 rcu_seq_done(&rnp->gp_seq, cur_gp_seq))) {
19701974 raw_spin_lock_rcu_node(rnp); /* irqs disabled. */
19711975 needwake_gp = rcu_advance_cbs(rnp, rdp);
1976+ wasempty = rcu_segcblist_restempty(&rdp->cblist,
1977+ RCU_NEXT_READY_TAIL);
19721978 raw_spin_unlock_rcu_node(rnp); /* irqs disabled. */
19731979 }
19741980 // Need to wait on some grace period?
1975− WARN_ON_ONCE(!rcu_segcblist_restempty(&rdp->cblist,
1981+ WARN_ON_ONCE(wasempty &&
1982+ !rcu_segcblist_restempty(&rdp->cblist,
19761983 RCU_NEXT_READY_TAIL));
19771984 if (rcu_segcblist_nextgp(&rdp->cblist, &cur_gp_seq)) {
19781985 if (!needwait_gp ||
kernel/rcu/tree_stall.h+23−18
@@ -102,7 +102,7 @@ static void record_gp_stall_check_time(void) · 101 unmodified lines
102102 unsigned long j = jiffies;
103103 unsigned long j1;
104104
105− rcu_state.gp_start = j;
105+ WRITE_ONCE(rcu_state.gp_start, j);
106106 j1 = rcu_jiffies_till_stall_check();
107107 /* Record ->gp_start before ->jiffies_stall. */
108108 smp_store_release(&rcu_state.jiffies_stall, j + j1); /* ^^^ */
@@ -383,7 +383,7 @@ static void print_other_cpu_stall(unsigned long gp_seq) · 274 unmodified lines
383383
384384 /* Kick and suppress, if so configured. */
385385 rcu_stall_kick_kthreads();
386− if (rcu_cpu_stall_suppress)
386+ if (rcu_stall_is_suppressed())
387387 return;
388388
389389 /*
@@ -452,7 +452,7 @@ static void print_cpu_stall(void) · 62 unmodified lines
452452
453453 /* Kick and suppress, if so configured. */
454454 rcu_stall_kick_kthreads();
455− if (rcu_cpu_stall_suppress)
455+ if (rcu_stall_is_suppressed())
456456 return;
457457
458458 /*
@@ -504,7 +504,7 @@ static void check_cpu_stall(struct rcu_data *rdp) · 45 unmodified lines
504504 unsigned long js;
505505 struct rcu_node *rnp;
506506
507− if ((rcu_cpu_stall_suppress && !rcu_kick_kthreads) ||
507+ if ((rcu_stall_is_suppressed() && !rcu_kick_kthreads) ||
508508 !rcu_gp_in_progress())
509509 return;
510510 rcu_stall_kick_kthreads();
@@ -578,6 +578,7 @@ void show_rcu_gp_kthreads(void) · 67 unmodified lines
578578 unsigned long jw;
579579 struct rcu_data *rdp;
580580 struct rcu_node *rnp;
581+ struct task_struct *t = READ_ONCE(rcu_state.gp_kthread);
581582
582583 j = jiffies;
583584 ja = j - READ_ONCE(rcu_state.gp_activity);
@@ -585,28 +586,28 @@ void show_rcu_gp_kthreads(void) · 1 unmodified line
585586 jw = j - READ_ONCE(rcu_state.gp_wake_time);
586587 pr_info("%s: wait state: %s(%d) ->state: %#lx delta ->gp_activity %lu ->gp_req_activity %lu ->gp_wake_time %lu ->gp_wake_seq %ld ->gp_seq %ld ->gp_seq_needed %ld ->gp_flags %#x\n",
587588 rcu_state.name, gp_state_getname(rcu_state.gp_state),
588− rcu_state.gp_state,
589− rcu_state.gp_kthread ? rcu_state.gp_kthread->state : 0x1ffffL,
589+ rcu_state.gp_state, t ? t->state : 0x1ffffL,
590590 ja, jr, jw, (long)READ_ONCE(rcu_state.gp_wake_seq),
591591 (long)READ_ONCE(rcu_state.gp_seq),
592592 (long)READ_ONCE(rcu_get_root()->gp_seq_needed),
593593 READ_ONCE(rcu_state.gp_flags));
594594 rcu_for_each_node_breadth_first(rnp) {
595− if (ULONG_CMP_GE(rcu_state.gp_seq, rnp->gp_seq_needed))
595+ if (ULONG_CMP_GE(READ_ONCE(rcu_state.gp_seq),
596+ READ_ONCE(rnp->gp_seq_needed)))
596597 continue;
597598 pr_info("\trcu_node %d:%d ->gp_seq %ld ->gp_seq_needed %ld\n",
598− rnp->grplo, rnp->grphi, (long)rnp->gp_seq,
599− (long)rnp->gp_seq_needed);
599+ rnp->grplo, rnp->grphi, (long)READ_ONCE(rnp->gp_seq),
600+ (long)READ_ONCE(rnp->gp_seq_needed));
600601 if (!rcu_is_leaf_node(rnp))
601602 continue;
602603 for_each_leaf_node_possible_cpu(rnp, cpu) {
603604 rdp = per_cpu_ptr(&rcu_data, cpu);
604− if (rdp->gpwrap ||
605− ULONG_CMP_GE(rcu_state.gp_seq,
606− rdp->gp_seq_needed))
605+ if (READ_ONCE(rdp->gpwrap) ||
606+ ULONG_CMP_GE(READ_ONCE(rcu_state.gp_seq),
607+ READ_ONCE(rdp->gp_seq_needed)))
607608 continue;
608609 pr_info("\tcpu %d ->gp_seq_needed %ld\n",
609− cpu, (long)rdp->gp_seq_needed);
610+ cpu, (long)READ_ONCE(rdp->gp_seq_needed));
610611 }
611612 }
612613 for_each_possible_cpu(cpu) {
@@ -631,7 +632,9 @@ static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp, · 18 unmodified lines
631632 static atomic_t warned = ATOMIC_INIT(0);
632633
633634 if (!IS_ENABLED(CONFIG_PROVE_RCU) || rcu_gp_in_progress() ||
634− ULONG_CMP_GE(rnp_root->gp_seq, rnp_root->gp_seq_needed))
635+ ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
636+ READ_ONCE(rnp_root->gp_seq_needed)) ||
637+ !smp_load_acquire(&rcu_state.gp_kthread)) // Get stable kthread.
635638 return;
636639 j = jiffies; /* Expensive access, and in common case don't get here. */
637640 if (time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
@@ -642,7 +645,8 @@ static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp, · 4 unmodified lines
642645 raw_spin_lock_irqsave_rcu_node(rnp, flags);
643646 j = jiffies;
644647 if (rcu_gp_in_progress() ||
645− ULONG_CMP_GE(rnp_root->gp_seq, rnp_root->gp_seq_needed) ||
648+ ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
649+ READ_ONCE(rnp_root->gp_seq_needed)) ||
646650 time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
647651 time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
648652 atomic_read(&warned)) {
@@ -655,9 +659,10 @@ static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp, · 6 unmodified lines
655659 raw_spin_lock_rcu_node(rnp_root); /* irqs already disabled. */
656660 j = jiffies;
657661 if (rcu_gp_in_progress() ||
658− ULONG_CMP_GE(rnp_root->gp_seq, rnp_root->gp_seq_needed) ||
659− time_before(j, rcu_state.gp_req_activity + gpssdelay) ||
660− time_before(j, rcu_state.gp_activity + gpssdelay) ||
662+ ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
663+ READ_ONCE(rnp_root->gp_seq_needed)) ||
664+ time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
665+ time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
661666 atomic_xchg(&warned, 1)) {
662667 if (rnp_root != rnp)
663668 /* irqs remain disabled. */
kernel/rcu/update.c+23−5
@@ -183,6 +183,8 @@ void rcu_unexpedite_gp(void) · 182 unmodified lines
183183 }
184184 EXPORT_SYMBOL_GPL(rcu_unexpedite_gp);
185185
186+static bool rcu_boot_ended __read_mostly;
187+
186188 /*
187189 * Inform RCU of the end of the in-kernel boot sequence.
188190 */
@@ -191,8 +193,18 @@ void rcu_end_inkernel_boot(void) · 2 unmodified lines
191193 rcu_unexpedite_gp();
192194 if (rcu_normal_after_boot)
193195 WRITE_ONCE(rcu_normal, 1);
196+ rcu_boot_ended = 1;
194197 }
195198
199+/*
200+ * Let rcutorture know when it is OK to turn it up to eleven.
201+ */
202+bool rcu_inkernel_boot_has_ended(void)
203+{
204+ return rcu_boot_ended;
205+}
206+EXPORT_SYMBOL_GPL(rcu_inkernel_boot_has_ended);
207+
196208 #endif /* #ifndef CONFIG_TINY_RCU */
197209
198210 /*
@@ -464,13 +476,19 @@ EXPORT_SYMBOL_GPL(rcutorture_sched_setaffinity); · 265 unmodified lines
464476 #ifdef CONFIG_RCU_STALL_COMMON
465477 int rcu_cpu_stall_ftrace_dump __read_mostly;
466478 module_param(rcu_cpu_stall_ftrace_dump, int, 0644);
467−int rcu_cpu_stall_suppress __read_mostly; /* 1 = suppress stall warnings. */
479+int rcu_cpu_stall_suppress __read_mostly; // !0 = suppress stall warnings.
468480 EXPORT_SYMBOL_GPL(rcu_cpu_stall_suppress);
469481 module_param(rcu_cpu_stall_suppress, int, 0644);
470482 int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT;
471483 module_param(rcu_cpu_stall_timeout, int, 0644);
472484 #endif /* #ifdef CONFIG_RCU_STALL_COMMON */
473485
486+// Suppress boot-time RCU CPU stall warnings and rcutorture writer stall
487+// warnings. Also used by rcutorture even if stall warnings are excluded.
488+int rcu_cpu_stall_suppress_at_boot __read_mostly; // !0 = suppress boot stalls.
489+EXPORT_SYMBOL_GPL(rcu_cpu_stall_suppress_at_boot);
490+module_param(rcu_cpu_stall_suppress_at_boot, int, 0444);
491+
474492 #ifdef CONFIG_TASKS_RCU
475493
476494 /*
@@ -528,7 +546,7 @@ void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func) · 51 unmodified lines
528546 rhp->func = func;
529547 raw_spin_lock_irqsave(&rcu_tasks_cbs_lock, flags);
530548 needwake = !rcu_tasks_cbs_head;
531− *rcu_tasks_cbs_tail = rhp;
549+ WRITE_ONCE(*rcu_tasks_cbs_tail, rhp);
532550 rcu_tasks_cbs_tail = &rhp->next;
533551 raw_spin_unlock_irqrestore(&rcu_tasks_cbs_lock, flags);
534552 /* We can't create the thread unless interrupts are enabled. */
@@ -658,7 +676,7 @@ static int __noreturn rcu_tasks_kthread(void *arg) · 123 unmodified lines
658676 /* If there were none, wait a bit and start over. */
659677 if (!list) {
660678 wait_event_interruptible(rcu_tasks_cbs_wq,
661− rcu_tasks_cbs_head);
679+ READ_ONCE(rcu_tasks_cbs_head));
662680 if (!rcu_tasks_cbs_head) {
663681 WARN_ON(signal_pending(current));
664682 schedule_timeout_interruptible(HZ/10);
@@ -801,7 +819,7 @@ static int __init rcu_spawn_tasks_kthread(void) · 136 unmodified lines
801819 core_initcall(rcu_spawn_tasks_kthread);
802820
803821 /* Do the srcu_read_lock() for the above synchronize_srcu(). */
804−void exit_tasks_rcu_start(void)
822+void exit_tasks_rcu_start(void) __acquires(&tasks_rcu_exit_srcu)
805823 {
806824 preempt_disable();
807825 current->rcu_tasks_idx = __srcu_read_lock(&tasks_rcu_exit_srcu);
@@ -809,7 +827,7 @@ void exit_tasks_rcu_start(void) · 1 unmodified line
809827 }
810828
811829 /* Do the srcu_read_unlock() for the above synchronize_srcu(). */
812−void exit_tasks_rcu_finish(void)
830+void exit_tasks_rcu_finish(void) __releases(&tasks_rcu_exit_srcu)
813831 {
814832 preempt_disable();
815833 __srcu_read_unlock(&tasks_rcu_exit_srcu, current->rcu_tasks_idx);
kernel/time/timer.c+4−3
@@ -944,6 +944,7 @@ static struct timer_base *lock_timer_base(struct timer_list *timer, · 943 unmodified lines
944944
945945 #define MOD_TIMER_PENDING_ONLY 0x01
946946 #define MOD_TIMER_REDUCE 0x02
947+#define MOD_TIMER_NOTPENDING 0x04
947948
948949 static inline int
949950 __mod_timer(struct timer_list *timer, unsigned long expires, unsigned int options)
@@ -960,7 +961,7 @@ __mod_timer(struct timer_list *timer, unsigned long expires, unsigned int option · 10 unmodified lines
960961 * the timer is re-modified to have the same timeout or ends up in the
961962 * same array bucket then just return:
962963 */
963− if (timer_pending(timer)) {
964+ if (!(options & MOD_TIMER_NOTPENDING) && timer_pending(timer)) {
964965 /*
965966 * The downside of this optimization is that it can result in
966967 * larger granularity than you would get from adding a new
@@ -1133,7 +1134,7 @@ EXPORT_SYMBOL(timer_reduce); · 166 unmodified lines
11331134 void add_timer(struct timer_list *timer)
11341135 {
11351136 BUG_ON(timer_pending(timer));
1136− mod_timer(timer, timer->expires);
1137+ __mod_timer(timer, timer->expires, MOD_TIMER_NOTPENDING);
11371138 }
11381139 EXPORT_SYMBOL(add_timer);
11391140
@@ -1891,7 +1892,7 @@ signed long __sched schedule_timeout(signed long timeout) · 751 unmodified lines
18911892
18921893 timer.task = current;
18931894 timer_setup_on_stack(&timer.timer, process_timeout, 0);
1894− __mod_timer(&timer.timer, expire, 0);
1895+ __mod_timer(&timer.timer, expire, MOD_TIMER_NOTPENDING);
18951896 schedule();
18961897 del_singleshot_timer_sync(&timer.timer);
18971898
kernel/torture.c+25−4
@@ -42,6 +42,9 @@ · 41 unmodified lines
4242 MODULE_LICENSE("GPL");
4343 MODULE_AUTHOR("Paul E. McKenney <paulmck@linux.ibm.com>");
4444
45+static bool disable_onoff_at_boot;
46+module_param(disable_onoff_at_boot, bool, 0444);
47+
4548 static char *torture_type;
4649 static int verbose;
4750
@@ -84,6 +87,7 @@ bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes, · 36 unmodified lines
8487 {
8588 unsigned long delta;
8689 int ret;
90+ char *s;
8791 unsigned long starttime;
8892
8993 if (!cpu_online(cpu) || !cpu_is_hotpluggable(cpu))
@@ -99,10 +103,16 @@ bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes, · 9 unmodified lines
99103 (*n_offl_attempts)++;
100104 ret = cpu_down(cpu);
101105 if (ret) {
106+ s = "";
107+ if (!rcu_inkernel_boot_has_ended() && ret == -EBUSY) {
108+ // PCI probe frequently disables hotplug during boot.
109+ (*n_offl_attempts)--;
110+ s = " (-EBUSY forgiven during boot)";
111+ }
102112 if (verbose)
103113 pr_alert("%s" TORTURE_FLAG
104− "torture_onoff task: offline %d failed: errno %d\n",
105− torture_type, cpu, ret);
114+ "torture_onoff task: offline %d failed%s: errno %d\n",
115+ torture_type, cpu, s, ret);
106116 } else {
107117 if (verbose > 1)
108118 pr_alert("%s" TORTURE_FLAG
@@ -137,6 +147,7 @@ bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes, · 28 unmodified lines
137147 {
138148 unsigned long delta;
139149 int ret;
150+ char *s;
140151 unsigned long starttime;
141152
142153 if (cpu_online(cpu) || !cpu_is_hotpluggable(cpu))
@@ -150,10 +161,16 @@ bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes, · 7 unmodified lines
150161 (*n_onl_attempts)++;
151162 ret = cpu_up(cpu);
152163 if (ret) {
164+ s = "";
165+ if (!rcu_inkernel_boot_has_ended() && ret == -EBUSY) {
166+ // PCI probe frequently disables hotplug during boot.
167+ (*n_onl_attempts)--;
168+ s = " (-EBUSY forgiven during boot)";
169+ }
153170 if (verbose)
154171 pr_alert("%s" TORTURE_FLAG
155− "torture_onoff task: online %d failed: errno %d\n",
156− torture_type, cpu, ret);
172+ "torture_onoff task: online %d failed%s: errno %d\n",
173+ torture_type, cpu, s, ret);
157174 } else {
158175 if (verbose > 1)
159176 pr_alert("%s" TORTURE_FLAG
@@ -215,6 +232,10 @@ torture_onoff(void *arg) · 55 unmodified lines
215232 VERBOSE_TOROUT_STRING("torture_onoff end holdoff");
216233 }
217234 while (!torture_must_stop()) {
235+ if (disable_onoff_at_boot && !rcu_inkernel_boot_has_ended()) {
236+ schedule_timeout_interruptible(HZ / 10);
237+ continue;
238+ }
218239 cpu = (torture_random(&rand) >> 4) % (maxcpu + 1);
219240 if (!torture_offline(cpu,
220241 &n_offline_attempts, &n_offline_successes,
tools/testing/selftests/rcutorture/bin/functions.sh+1−1
@@ -12,7 +12,7 @@ · 11 unmodified lines
1212 # Returns 1 if the specified boot-parameter string tells rcutorture to
1313 # test CPU-hotplug operations.
1414 bootparam_hotplug_cpu () {
15− echo "$1" | grep -q "rcutorture\.onoff_"
15+ echo "$1" | grep -q "torture\.onoff_"
1616 }
1717
1818 # checkarg --argname argtype $# arg mustmatch cannotmatch
tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh+2−0
@@ -20,7 +20,9 @@ · 19 unmodified lines
2020 rundir="${1}"
2121 if test -z "$rundir" -o ! -d "$rundir"
2222 then
23+ echo Directory "$rundir" not found.
2324 echo Usage: $0 directory
25+ exit 1
2426 fi
2527 editor=${EDITOR-vi}
2628
tools/testing/selftests/rcutorture/bin/kvm-recheck.sh+16−1
@@ -13,6 +13,9 @@ · 12 unmodified lines
1313 #
1414 # Authors: Paul E. McKenney <paulmck@linux.ibm.com>
1515
16+T=/tmp/kvm-recheck.sh.$$
17+trap 'rm -f $T' 0 2
18+
1619 PATH=`pwd`/tools/testing/selftests/rcutorture/bin:$PATH; export PATH
1720 . functions.sh
1821 for rd in "$@"
@@ -68,4 +71,16 @@ do · 49 unmodified lines
6871 fi
6972 done
7073 done
71−EDITOR=echo kvm-find-errors.sh "${@: -1}" > /dev/null 2>&1
74+EDITOR=echo kvm-find-errors.sh "${@: -1}" > $T 2>&1
75+ret=$?
76+builderrors="`tr ' ' '\012' < $T | grep -c '/Make.out.diags'`"
77+if test "$builderrors" -gt 0
78+then
79+ echo $builderrors runs with build errors.
80+fi
81+runerrors="`tr ' ' '\012' < $T | grep -c '/console.log.diags'`"
82+if test "$runerrors" -gt 0
83+then
84+ echo $runerrors runs with runtime errors.
85+fi
86+exit $ret
tools/testing/selftests/rcutorture/bin/kvm.sh+1−1
@@ -39,7 +39,7 @@ TORTURE_TRUST_MAKE="" · 38 unmodified lines
3939 resdir=""
4040 configs=""
4141 cpus=0
42−ds=`date +%Y.%m.%d-%H:%M:%S`
42+ds=`date +%Y.%m.%d-%H.%M.%S`
4343 jitter="-1"
4444
4545 usage () {
tools/testing/selftests/rcutorture/configs/rcu/CFcommon+2−0
@@ -3,3 +3,5 @@ CONFIG_PRINTK_TIME=y · 2 unmodified lines
33 CONFIG_HYPERVISOR_GUEST=y
44 CONFIG_PARAVIRT=y
55 CONFIG_KVM_GUEST=y
6+CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n
7+CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=n
tools/testing/selftests/rcutorture/configs/rcu/TREE10+18−0
@@ -0,0 +1,18 @@
1+CONFIG_SMP=y
2+CONFIG_NR_CPUS=100
3+CONFIG_PREEMPT_NONE=y
4+CONFIG_PREEMPT_VOLUNTARY=n
5+CONFIG_PREEMPT=n
6+#CHECK#CONFIG_TREE_RCU=y
7+CONFIG_HZ_PERIODIC=n
8+CONFIG_NO_HZ_IDLE=y
9+CONFIG_NO_HZ_FULL=n
10+CONFIG_RCU_FAST_NO_HZ=n
11+CONFIG_RCU_TRACE=n
12+CONFIG_RCU_NOCB_CPU=n
13+CONFIG_DEBUG_LOCK_ALLOC=n
14+CONFIG_PROVE_LOCKING=n
15+#CHECK#CONFIG_PROVE_RCU=n
16+CONFIG_DEBUG_OBJECTS=n
17+CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
18+CONFIG_RCU_EXPERT=n