kprobes: Fix to delay the kprobes jump optimization
Masami Hiramatsu
maintainerPATCH 1/1 kprobes: Fix to delay the kprobes jump optimization
Commit 36dadef23fcc ("kprobes: Init kprobes in early_initcall") moved the kprobe setup in early_initcall(), which includes kprobe jump optimization.
The kprobes jump optimizer involves synchronize_rcu_tasks() which depends on the ksoftirqd and rcu_spawn_tasks_*(). However, since those are setup in core_initcall(), kprobes jump optimizer can not run at the early_initcall().
To avoid this issue, make the kprobe optimization disabled in the early_initcall() and enables it in subsys_initcall().
Note that non-optimized kprobes is still available after early_initcall(). Only jump optimization is delayed.
--- kernel/kprobes.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)
kernel/kprobes.c +21 -10
@@ -861,7 +861,6 @@ static void try_to_optimize_kprobe(struct kprobe *p)cpus_read_unlock (); } -#ifdef CONFIG_SYSCTL static void optimize_all_kprobes (void ) {struct hlist_head *head;
@@ -887,6 +886,7 @@ static void optimize_all_kprobes(void)mutex_unlock (&kprobe_mutex); } +#ifdef CONFIG_SYSCTL static void unoptimize_all_kprobes (void ) {struct hlist_head *head;
@@ -2497,18 +2497,14 @@ static int __init init_kprobes(void) } } -#if defined(CONFIG_OPTPROBES ) -#if defined(__ARCH_WANT_KPROBES_INSN_SLOT) -/* Init kprobe_optinsn_slots */ - kprobe_optinsn_slots.insn_size =MAX_OPTINSN_SIZE ; -#endif -/* By default, kprobes can be optimized */ - kprobes_allow_optimization = true; -#endif -/* By default, kprobes are armed */ kprobes_all_disarmed = false; +#if defined(CONFIG_OPTPROBES ) && defined(__ARCH_WANT_KPROBES_INSN_SLOT) +/* Init kprobe_optinsn_slots for allocation */ + kprobe_optinsn_slots.insn_size =MAX_OPTINSN_SIZE ; +#endif + err =arch_init_kprobes ();if (!err) err =register_die_notifier (&kprobe_exceptions_nb);
@@ -2523,6 +2519,21 @@ static int __init init_kprobes(void) }early_initcall (init_kprobes); +#if defined(CONFIG_OPTPROBES ) +static int __init init_optprobes (void ) +{ +/* +* Enable kprobe optimization - this kicks the optimizer which +* depends on synchronize_rcu_tasks() and ksoftirqd, that is +* not spawned in early initcall. So delay the optimization. +*/ +optimize_all_kprobes (); + +return 0 ; +} +subsys_initcall (init_optprobes); +#endif +#ifdef CONFIG_DEBUG_FS static void report_probe (struct seq_file *pi,struct kprobe *p,const char *sym,int offset,char *modname,struct kprobe *pp)
Quoted 8 lines · Masami Hiramatsu
Commit
36dadef23fcc("kprobes: Init kprobes inearly_initcall") moved the kprobe setup inearly_initcall(), which includes kprobe jump optimization.
The kprobes jump optimizer involvessynchronize_rcu_tasks()which depends on the ksoftirqd and rcu_spawn_tasks_*(). However, since those are setup incore_initcall(), kprobes jump optimizer can not run at theearly_initcall().
Quoted 8 lines
To avoid this issue, make the kprobe optimization disabled in the
early_initcall()and enables it insubsys_initcall().Note that non-optimized kprobes is still available after
early_initcall(). Only jump optimization is delayed.Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")Reported-by Paul E. McKenney <[email protected]>
Thank you, but the original report of a problem was from Sebastian and the connection to softirq was Uladzislau. So could you please add these before (or even in place of) my Reported-by?
Other than that, looks good!
Thanx, Paul
Quoted 73 lines
Signed-off-by Masami Hiramatsu <[email protected]>--- kernel/kprobes.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)kernel/kprobes.c +21
-10@@ -861,7 +861,6 @@ static void try_to_optimize_kprobe(struct kprobe *p)cpus_read_unlock (); } -#ifdef CONFIG_SYSCTL static void optimize_all_kprobes (void ) {struct hlist_head *head;@@ -887,6 +886,7 @@ static void optimize_all_kprobes(void)mutex_unlock (&kprobe_mutex); } +#ifdef CONFIG_SYSCTL static void unoptimize_all_kprobes (void ) {struct hlist_head *head;@@ -2497,18 +2497,14 @@ static int __init init_kprobes(void) } } -#if defined(CONFIG_OPTPROBES ) -#if defined(__ARCH_WANT_KPROBES_INSN_SLOT) -/* Init kprobe_optinsn_slots */ - kprobe_optinsn_slots.insn_size =MAX_OPTINSN_SIZE ; -#endif -/* By default, kprobes can be optimized */ - kprobes_allow_optimization = true; -#endif -/* By default, kprobes are armed */ kprobes_all_disarmed = false; +#if defined(CONFIG_OPTPROBES ) && defined(__ARCH_WANT_KPROBES_INSN_SLOT) +/* Init kprobe_optinsn_slots for allocation */ + kprobe_optinsn_slots.insn_size =MAX_OPTINSN_SIZE ; +#endif + err =arch_init_kprobes ();if (!err) err =register_die_notifier (&kprobe_exceptions_nb);@@ -2523,6 +2519,21 @@ static int __init init_kprobes(void) }early_initcall (init_kprobes); +#if defined(CONFIG_OPTPROBES ) +static int __init init_optprobes (void ) +{ +/* +* Enable kprobe optimization - this kicks the optimizer which +* depends on synchronize_rcu_tasks() and ksoftirqd, that is +* not spawned in early initcall. So delay the optimization. +*/ +optimize_all_kprobes (); + +return 0 ; +} +subsys_initcall (init_optprobes); +#endif +#ifdef CONFIG_DEBUG_FS static void report_probe (struct seq_file *pi,struct kprobe *p,const char *sym,int offset,char *modname,struct kprobe *pp)
Quoted 8 lines · Paul E. McKenney
Thank you, but the original report of a problem was from Sebastian and the connection to softirq was Uladzislau. So could you please add these before (or even in place of) my Reported-by?
Reported-by Sebastian Andrzej Siewior <[email protected]>Reported-by Uladzislau Rezki <[email protected]>Other than that, looks good!
Perfect. I'm kind of lost here, nevertheless ;) Does this mean that the RCU selftest can now be delayed?
Quoted 3 lines
Acked-by Paul E. McKenney <[email protected]>Thanx, Paul
Sebastian
Uladzislau Rezki
maintainerQuoted 5 lines · Sebastian Andrzej Siewior
Quoted 4 lines · Paul E. McKenney
Thank you, but the original report of a problem was from Sebastian and the connection to softirq was Uladzislau. So could you please add these before (or even in place of) my Reported-by?
Quoted 8 lines
Quoted 4 lines
Reported-by Sebastian Andrzej Siewior <[email protected]>Reported-by Uladzislau Rezki <[email protected]>Other than that, looks good!
Perfect. I'm kind of lost here, nevertheless ;) Does this mean that the RCU selftest can now be delayed?
If above fix works, we can initialize rcu_init_tasks_generic() from the core_initcall() including selftst. It means that such initialization can be done later:
include/linux/rcupdate.h +0 -6
@@ -88,12 +88,6 @@ void rcu_sched_clock_irq(int user);void rcu_report_dead (unsigned int cpu);void rcutree_migrate_callbacks (int cpu); -#ifdef CONFIG_TASKS_RCU_GENERIC -void rcu_init_tasks_generic (void ); -#else -static inline void rcu_init_tasks_generic (void ) { } -#endif -#ifdef CONFIG_RCU_STALL_COMMON void rcu_sysrq_start (void );void rcu_sysrq_end (void );
init/main.c +0 -1
@@ -1512,7 +1512,6 @@ static noinline void __init kernel_init_freeable(void)init_mm_internals (); -rcu_init_tasks_generic ();do_pre_smp_initcalls ();lockup_detector_init ();
kernel/rcu/tasks.h +2 -6
@@ -966,11 +966,6 @@ static void rcu_tasks_trace_pregp_step(void)static void rcu_tasks_trace_pertask (struct task_struct *t,struct list_head *hop) { -// During early boot when there is only the one boot CPU, there -// is no idle task for the other CPUs. Just return. -if (unlikely (t ==NULL )) -return ; -WRITE_ONCE (t->trc_reader_special.b.need_qs, false);WRITE_ONCE (t->trc_reader_checked, false); t->trc_ipi_to_cpu =-1 ;
@@ -1300,7 +1295,7 @@ late_initcall(rcu_tasks_verify_self_tests);static void rcu_tasks_initiate_self_tests (void ) { }#endif /* #else #ifdef CONFIG_PROVE_RCU */ -void __init rcu_init_tasks_generic (void ) +static void __init rcu_init_tasks_generic (void ) {#ifdef CONFIG_TASKS_RCU rcu_spawn_tasks_kthread ();
@@ -1318,6 +1313,7 @@ void __init rcu_init_tasks_generic(void) rcu_tasks_initiate_self_tests(); } +core_initcall (rcu_init_tasks_generic);#else /* #ifdef CONFIG_TASKS_RCU_GENERIC */ static inline void rcu_tasks_bootup_oddness (void ) {}void show_rcu_tasks_gp_kthreads (void ) {}
--
Vlad Rezki
Quoted 3 lines · Uladzislau Rezki
If above fix works, we can initialize
rcu_init_tasks_generic()from thecore_initcall()including selftst. It means that such initialization can be done later:
Good. Please let me know once there is something for me to test. Do I assume correctly that the self-test, I stumbled upon, is v5.12 material?
Sebastian
Uladzislau Rezki
maintainerQuoted 9 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Uladzislau Rezki
If above fix works, we can initialize
rcu_init_tasks_generic()from thecore_initcall()including selftst. It means that such initialization can be done later:Good. Please let me know once there is something for me to test. Do I assume correctly that the self-test, I stumbled upon, is v5.12 material?
I or Paul will ask for a test once it is settled down :) Looks like it is, so we should fix for v5.12.
--
Vlad Rezki
Quoted 2 lines · Uladzislau Rezki
I or Paul will ask for a test once it is settled down :) Looks like it is, so we should fix for v5.12.
Okay. Since Paul asked for powerpc test on v5.11-rc I wanted check if parts of it are also -stable material.
Sebastian
Uladzislau Rezki
maintainerQuoted 7 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Uladzislau Rezki
I or Paul will ask for a test once it is settled down :) Looks like it is, so we should fix for v5.12.
Okay. Since Paul asked for powerpc test on v5.11-rc I wanted check if parts of it are also -stable material.
OK, i see. It will be broken starting from v5.12-rc unless we fix it.
--
Vlad Rezki
Uladzislau Rezki
maintainerQuoted 10 lines · Uladzislau Rezki
Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Uladzislau Rezki
I or Paul will ask for a test once it is settled down :) Looks like it is, so we should fix for v5.12.
Okay. Since Paul asked for powerpc test on v5.11-rc I wanted check if parts of it are also -stable material.
OK, i see. It will be broken starting from v5.12-rc unless we fix it.
Sorry it is broken since 5.11 kernel already, i messed it up.
--
Vlad Rezki
Paul E. McKenney
maintainerQuoted 8 lines · Uladzislau Rezki
Quoted 7 lines · Uladzislau Rezki
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Uladzislau Rezki
I or Paul will ask for a test once it is settled down :) Looks like it is, so we should fix for v5.12.
Okay. Since Paul asked for powerpc test on v5.11-rc I wanted check if parts of it are also -stable material.
If Masami's patch works for the PowerPC guys on v5.10-rc7, then it can be backported. The patch making RCU Tasks initialize itself early won't have any effect and can be left or reverted, as we choose. The self-test patch will need to be either adjusted or reverted.
However...
The root cause of this problem is that softirq only kind-of works during a window of time during boot. It works only if the number and duration of softirq handlers during this time is small enough, for some ill-defined notion of "small enough". If there are too many, whatever that means exactly, then we get failed attempt to awaken ksoftirqd, which (sometimes!) results in a silent hang. Which, as you pointed out earlier, is a really obnoxious error message. And any minor change could kick us into silent-hang state because of the heuristics used to hand off to ksoftirqd. The straw that broke the camel's back and all that.
One approach would be to add WARN_ON_ONCE() so that if softirq tries to awaken ksoftirqd before it is spawned, we get a nice obvious splat. Unfortunately, this gives false positives because there is code that needs a softirq handler to run eventually, but is OK with that handler being delayed until some random point in the early_initcall() sequence.
Besides which, if we are going to add a check, why not use that check just make things work by forcing handler execution to remain within the softirq back-of-interrupt context instead of awakening a not-yet-spawned ksoftirqd? We can further prevent entry into dyntick-idle state until the ksoftirqd kthreads have been spawned, which means that if softirq handlers must be deferred, they will be resumed within one jiffy by the next scheduler-clock interrupt.
Yes, this can allow softirq handlers to impose large latencies, but only during early boot, long before any latency-sensitive applications can possibly have been created. So this does not seem like a real problem.
Am I missing something here?
Thanx, Paul
Quoted 6 lines
Quoted 2 lines
OK, i see. It will be broken starting from v5.12-rc unless we fix it.
Sorry it is broken since 5.11 kernel already, i messed it up.
--
Vlad Rezki
Paul E. McKenney
maintainerQuoted 41 lines · Paul E. McKenney
Quoted 8 lines · Uladzislau Rezki
Quoted 7 lines · Uladzislau Rezki
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Uladzislau Rezki
I or Paul will ask for a test once it is settled down :) Looks like it is, so we should fix for v5.12.
Okay. Since Paul asked for powerpc test on v5.11-rc I wanted check if parts of it are also -stable material.
If Masami's patch works for the PowerPC guys on v5.10-rc7, then it can be backported. The patch making RCU Tasks initialize itself early won't have any effect and can be left or reverted, as we choose. The self-test patch will need to be either adjusted or reverted.
However...
The root cause of this problem is that softirq only kind-of works during a window of time during boot. It works only if the number and duration of softirq handlers during this time is small enough, for some ill-defined notion of "small enough". If there are too many, whatever that means exactly, then we get failed attempt to awaken ksoftirqd, which (sometimes!) results in a silent hang. Which, as you pointed out earlier, is a really obnoxious error message. And any minor change could kick us into silent-hang state because of the heuristics used to hand off to ksoftirqd. The straw that broke the camel's back and all that.
One approach would be to add
WARN_ON_ONCE()so that if softirq tries to awaken ksoftirqd before it is spawned, we get a nice obvious splat. Unfortunately, this gives false positives because there is code that needs a softirq handler to run eventually, but is OK with that handler being delayed until some random point in theearly_initcall()sequence.Besides which, if we are going to add a check, why not use that check just make things work by forcing handler execution to remain within the softirq back-of-interrupt context instead of awakening a not-yet-spawned ksoftirqd? We can further prevent entry into dyntick-idle state until the ksoftirqd kthreads have been spawned, which means that if softirq handlers must be deferred, they will be resumed within one jiffy by the next scheduler-clock interrupt.
Quoted 5 lines
Yes, this can allow softirq handlers to impose large latencies, but only during early boot, long before any latency-sensitive applications can possibly have been created. So this does not seem like a real problem.
Am I missing something here?
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
Thanx, Paul
------------------------------------------------------------------------
commit 4f659bf04fc4610523544493d6db92fc8670b086
Author: Paul E. McKenney <[email protected]> Date: Fri Feb 12 16:20:40 2021 -0800
softirq: Don't try waking ksoftirqd before it has been spawned
If there is heavy softirq activity, the softirq system will attempt to awaken ksoftirqd and will stop the traditional back-of-interrupt softirq processing. This is all well and good, but only if the ksoftirqd kthreads already exist, which is not the case during early boot, in which case the system hangs.
One reproducer is as follows:
tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make
This commit therefore adds a couple of existence checks for ksoftirqd and forces back-of-interrupt softirq processing when ksoftirqd does not yet exist. With this change, the above test passes.
kernel/softirq.c +3 -3
@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads) { +if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if
@@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) pending =local_softirq_pending ();if (pending) { -if (time_before (jiffies, end) && !need_resched () && - --max_restart) +if (!__this_cpu_read (ksoftirqd) || + (time_before (jiffies, end) && !need_resched () && --max_restart)) goto restart;wakeup_softirqd ();
Steven Rostedt
reviewerQuoted 4 lines · On Fri, 19 Feb 2021 10:18:11 -0800 "Paul E. McKenney" <[email protected]>…
We can further prevent entry into dyntick-idle state until the ksoftirqd kthreads have been spawned, which means that if softirq handlers must be deferred, they will be resumed within one jiffy by the next scheduler-clock interrupt.
Why not just prevent entry into dyntick-idle state until the system is finished booting? As you said; There should be no latency-sensitive applications running, until after we started the system.
-- Steve
Paul E. McKenney
maintainerQuoted 46 lines · Paul E. McKenney
Quoted 45 lines · Paul E. McKenney
Quoted 8 lines · Uladzislau Rezki
Quoted 7 lines · Uladzislau Rezki
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Uladzislau Rezki
I or Paul will ask for a test once it is settled down :) Looks like it is, so we should fix for v5.12.
Okay. Since Paul asked for powerpc test on v5.11-rc I wanted check if parts of it are also -stable material.
If Masami's patch works for the PowerPC guys on v5.10-rc7, then it can be backported. The patch making RCU Tasks initialize itself early won't have any effect and can be left or reverted, as we choose. The self-test patch will need to be either adjusted or reverted.
However...
The root cause of this problem is that softirq only kind-of works during a window of time during boot. It works only if the number and duration of softirq handlers during this time is small enough, for some ill-defined notion of "small enough". If there are too many, whatever that means exactly, then we get failed attempt to awaken ksoftirqd, which (sometimes!) results in a silent hang. Which, as you pointed out earlier, is a really obnoxious error message. And any minor change could kick us into silent-hang state because of the heuristics used to hand off to ksoftirqd. The straw that broke the camel's back and all that.
One approach would be to add
WARN_ON_ONCE()so that if softirq tries to awaken ksoftirqd before it is spawned, we get a nice obvious splat. Unfortunately, this gives false positives because there is code that needs a softirq handler to run eventually, but is OK with that handler being delayed until some random point in theearly_initcall()sequence.Besides which, if we are going to add a check, why not use that check just make things work by forcing handler execution to remain within the softirq back-of-interrupt context instead of awakening a not-yet-spawned ksoftirqd? We can further prevent entry into dyntick-idle state until the ksoftirqd kthreads have been spawned, which means that if softirq handlers must be deferred, they will be resumed within one jiffy by the next scheduler-clock interrupt.
Yes, this can allow softirq handlers to impose large latencies, but only during early boot, long before any latency-sensitive applications can possibly have been created. So this does not seem like a real problem.
Quoted 5 lines
Quoted 1 line
Am I missing something here?
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
And here it is.
Thanx, Paul
------------------------------------------------------------------------
kernel/rcu/tree_plugin.h +11 -0
@@ -1320,6 +1320,11 @@ static void rcu_prepare_kthreads(int cpu)*/ int rcu_needs_cpu (u64 basemono,u64 *nextevt) { +/* Through early_initcall(), need tick for softirq handlers. */ +if (!this_cpu_ksoftirqd ()) { + *nextevt =1 ; +return 1 ; + } *nextevt =KTIME_MAX ;return !rcu_segcblist_empty (&this_cpu_ptr (&rcu_data)->cblist) && !rcu_rdp_is_offloaded (this_cpu_ptr (&rcu_data));
@@ -1415,6 +1420,12 @@ int rcu_needs_cpu(u64 basemono, u64 *nextevt)lockdep_assert_irqs_disabled (); +/* Through early_initcall(), need tick for softirq handlers. */ +if (!this_cpu_ksoftirqd ()) { + *nextevt =1 ; +return 1 ; + } +/* If no non-offloaded callbacks, RCU doesn't need the CPU. */ if (rcu_segcblist_empty (&rdp->cblist) ||rcu_rdp_is_offloaded (rdp)) {
Steven Rostedt
reviewerQuoted 11 lines · On Thu, 18 Feb 2021 23:29:23 +0900 Masami Hiramatsu <[email protected]> wrote:
Commit
36dadef23fcc("kprobes: Init kprobes inearly_initcall") moved the kprobe setup inearly_initcall(), which includes kprobe jump optimization.
The kprobes jump optimizer involvessynchronize_rcu_tasks()which depends on the ksoftirqd and rcu_spawn_tasks_*(). However, since those are setup incore_initcall(), kprobes jump optimizer can not run at theearly_initcall().To avoid this issue, make the kprobe optimization disabled in the
early_initcall()and enables it insubsys_initcall().
Quoted 9 lines
Note that non-optimized kprobes is still available after
early_initcall(). Only jump optimization is delayed.Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")Reported-by Paul E. McKenney <[email protected]>Signed-off-by Masami Hiramatsu <[email protected]>---
I pulled this into my queue to be tested, and when that completes (hopefully without failure), I'll add this to my pull request for the current merge window (which I still need to send).
Thanks!
-- Steve
Paul E. McKenney
maintainerQuoted 11 lines · Steven Rostedt
Quoted 4 lines · On Fri, 19 Feb 2021 10:18:11 -0800 "Paul E. McKenney" <[email protected]>…
We can further prevent entry into dyntick-idle state until the ksoftirqd kthreads have been spawned, which means that if softirq handlers must be deferred, they will be resumed within one jiffy by the next scheduler-clock interrupt.
Why not just prevent entry into dyntick-idle state until the system is finished booting? As you said; There should be no latency-sensitive applications running, until after we started the system.
Exactly, and that is the effect of patch to rcu_needs_cpu() that I just now posted.
Ah, your point is that if the tick keeps running, there is no need to modify softirq? Good point, and I will test that, thank you!!!
Thanx, Paul
Paul E. McKenney
maintainerQuoted 23 lines · Steven Rostedt
Quoted 11 lines · On Thu, 18 Feb 2021 23:29:23 +0900 Masami Hiramatsu <[email protected]> wrote:
Commit
36dadef23fcc("kprobes: Init kprobes inearly_initcall") moved the kprobe setup inearly_initcall(), which includes kprobe jump optimization.
The kprobes jump optimizer involvessynchronize_rcu_tasks()which depends on the ksoftirqd and rcu_spawn_tasks_*(). However, since those are setup incore_initcall(), kprobes jump optimizer can not run at theearly_initcall().To avoid this issue, make the kprobe optimization disabled in the
early_initcall()and enables it insubsys_initcall().Quoted 8 lines
Note that non-optimized kprobes is still available after
early_initcall(). Only jump optimization is delayed.Fixes 36dadef23fcc ("kprobes: Init kprobes in early_initcall")Reported-by Paul E. McKenney <[email protected]>Signed-off-by Masami Hiramatsu <[email protected]>---
Quoted 3 lines
I pulled this into my queue to be tested, and when that completes (hopefully without failure), I'll add this to my pull request for the current merge window (which I still need to send).
Thank you, Steve!
Could you please add the following Reported-by tags?
Sebastian first noticed the problem, and Uladzislau figured out how softirqs were involved.
Thanx, Paul
Steven Rostedt
reviewerQuoted 7 lines · On Fri, 19 Feb 2021 11:47:44 -0800 "Paul E. McKenney" <[email protected]>…
Could you please add the following Reported-by tags?
Reported-by Sebastian Andrzej Siewior <[email protected]>Reported-by Uladzislau Rezki <[email protected]>Sebastian first noticed the problem, and Uladzislau figured out how softirqs were involved.
These were already added. They must have appeared in the thread somewhere, as my internal patchwork picked them up already.
-- Steve
Steven Rostedt
reviewerQuoted 16 lines · On Fri, 19 Feb 2021 10:33:36 -0800 "Paul E. McKenney" <[email protected]>…
commit
4f659bf04fc4610523544493d6db92fc8670b086Author: Paul E. McKenney <[email protected]> Date: Fri Feb 12 16:20:40 2021 -0800softirq: Don't try waking ksoftirqd before it has been spawned
If there is heavy softirq activity, the softirq system will attempt to awaken ksoftirqd and will stop the traditional back-of-interrupt softirq processing. This is all well and good, but only if the ksoftirqd kthreads already exist, which is not the case during early boot, in which case the system hangs.
One reproducer is as follows:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=yCONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make
Quoted 7 lines
This commit therefore adds a couple of existence checks for ksoftirqd and forces back-of-interrupt softirq processing when ksoftirqd does not yet exist. With this change, the above test passes.
Reported-by Sebastian Andrzej Siewior <[email protected]>Reported-by Uladzislau Rezki <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>
Hmm, I wonder if this is what patchwork picked up regarding the reported-by.
And I checked, it did not add the "Signed-off-by" from you to Masami's patch ;-)
The dangers of posting patches in threads of other patches :-/
-- Steve
Paul E. McKenney
maintainerQuoted 13 lines · Paul E. McKenney
Quoted 11 lines · Steven Rostedt
Quoted 4 lines · On Fri, 19 Feb 2021 10:18:11 -0800 "Paul E. McKenney" <[email protected]>…
We can further prevent entry into dyntick-idle state until the ksoftirqd kthreads have been spawned, which means that if softirq handlers must be deferred, they will be resumed within one jiffy by the next scheduler-clock interrupt.
Why not just prevent entry into dyntick-idle state until the system is finished booting? As you said; There should be no latency-sensitive applications running, until after we started the system.
Quoted 5 lines
Exactly, and that is the effect of patch to
rcu_needs_cpu()that I just now posted.Ah, your point is that if the tick keeps running, there is no need to modify softirq? Good point, and I will test that, thank you!!!
But sadly keeping the tick on without also modifying softirq still results in a hang. The problem is that when the kernel is booted with threadirqs=1, invoke_softirq() will avoid ever running the softirq handlers on the backside of an interrupt.
So is this where Sebastian tells me that some -rt transformation can result in locking-based deadlocks if softirq handlers are ever run on the backside of an interrupt? ;-)
Thanx, Paul
Paul E. McKenney
maintainerQuoted 5 lines · Steven Rostedt
Quoted 2 lines · On Fri, 19 Feb 2021 11:47:44 -0800 "Paul E. McKenney" <[email protected]>…
Could you please add the following Reported-by tags?
Quoted 8 lines
Quoted 5 lines
Reported-by Sebastian Andrzej Siewior <[email protected]>Reported-by Uladzislau Rezki <[email protected]>Sebastian first noticed the problem, and Uladzislau figured out how softirqs were involved.
These were already added. They must have appeared in the thread somewhere, as my internal patchwork picked them up already.
Even better, thank you!
Thanx, Paul
Paul E. McKenney
maintainerQuoted 27 lines · Steven Rostedt
Quoted 16 lines · On Fri, 19 Feb 2021 10:33:36 -0800 "Paul E. McKenney" <[email protected]>…
commit
4f659bf04fc4610523544493d6db92fc8670b086Author: Paul E. McKenney <[email protected]> Date: Fri Feb 12 16:20:40 2021 -0800softirq: Don't try waking ksoftirqd before it has been spawned
If there is heavy softirq activity, the softirq system will attempt to awaken ksoftirqd and will stop the traditional back-of-interrupt softirq processing. This is all well and good, but only if the ksoftirqd kthreads already exist, which is not the case during early boot, in which case the system hangs.
One reproducer is as follows:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=yCONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-makeQuoted 7 lines
This commit therefore adds a couple of existence checks for ksoftirqd and forces back-of-interrupt softirq processing when ksoftirqd does not yet exist. With this change, the above test passes.
Reported-by Sebastian Andrzej Siewior <[email protected]>Reported-by Uladzislau Rezki <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>
Quoted 7 lines
Hmm, I wonder if this is what patchwork picked up regarding the reported-by.
And I checked, it did not add the "Signed-off-by" from you to Masami's patch ;-)
The dangers of posting patches in threads of other patches :-/
Glad I asked, then! ;-)
Thanx, Paul
Quoted 5 lines · Paul E. McKenney
If Masami's patch works for the PowerPC guys on v5.10-rc7, then it can be backported. The patch making RCU Tasks initialize itself early won't have any effect and can be left or reverted, as we choose. The self-test patch will need to be either adjusted or reverted.
Quoted 7 lines
However...
The root cause of this problem is that softirq only kind-of works during a window of time during boot. It works only if the number and duration of softirq handlers during this time is small enough, for some ill-defined notion of "small enough". If there are too many, whatever that means exactly, then we get failed attempt to awaken ksoftirqd, which
The number of registered softirq handlers does not matter nor the amount times the individual softirqs that were scheduled. The only problem is that one schedules softirq and then waits for its completion. So scheduling a timer_list timer works. Waiting for its completion does not. Once ksoftirqd is up, will be processed.
Quoted 4 lines
(sometimes!) results in a silent hang. Which, as you pointed out earlier, is a really obnoxious error message. And any minor change could kick us into silent-hang state because of the heuristics used to hand off to ksoftirqd. The straw that broke the camel's back and all that.
The problem is that a softirq is raised and being waited for its completion.
Something like synchronize_rcu() would be such a thing I guess.
Quoted 6 lines
One approach would be to add
WARN_ON_ONCE()so that if softirq tries to awaken ksoftirqd before it is spawned, we get a nice obvious splat. Unfortunately, this gives false positives because there is code that needs a softirq handler to run eventually, but is OK with that handler being delayed until some random point in theearly_initcall()sequence.
Quoted 7 lines
Besides which, if we are going to add a check, why not use that check just make things work by forcing handler execution to remain within the softirq back-of-interrupt context instead of awakening a not-yet-spawned ksoftirqd? We can further prevent entry into dyntick-idle state until the ksoftirqd kthreads have been spawned, which means that if softirq handlers must be deferred, they will be resumed within one jiffy by the next scheduler-clock interrupt.
This should work.
Quoted 7 lines
Yes, this can allow softirq handlers to impose large latencies, but only during early boot, long before any latency-sensitive applications can possibly have been created. So this does not seem like a real problem.
Am I missing something here?
Thanx, Paul
Sebastian
Quoted 3 lines · Paul E. McKenney
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
…
Quoted 14 lines
kernel/softirq.c +1
-1@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads) { +if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if
kernel/softirq.c asmlinkage __visible void __softirq_entry __do_softirq(void) · line 363
Quoted 8 lines
kernel/softirq.c +2
-2@@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) pending =local_softirq_pending ();if (pending) { -if (time_before (jiffies, end) && !need_resched () && - --max_restart) +if (!__this_cpu_read (ksoftirqd) || + (time_before (jiffies, end) && !need_resched () && --max_restart)) goto restart;
This is hunk shouldn't be needed. The reason for it is probably that the following wakeup_softirqd() would avoid further invoke_softirq() performing the actual softirq work. It would leave early due to ksoftirqd_running(). Unless I'm wrong, any raise_softirq() invocation outside of an interrupt would do the same.
I would like PeterZ / tglx to comment on this one. Basically I'm not sure if it is okay to expect softirqs beeing served and waited on that early in the boot.
kernel/softirq.c asmlinkage __visible void __softirq_entry __do_softirq(void) · line 365
Quoted 1 line
kernel/softirq.c +0
-0wakeup_softirqd ();
Sebastian
Masami Hiramatsu
maintainerQuoted 9 lines · On Fri, 19 Feb 2021 12:04:42 -0800 "Paul E. McKenney" <[email protected]>…
Quoted 8 lines · Steven Rostedt
Quoted 5 lines · On Fri, 19 Feb 2021 11:47:44 -0800 "Paul E. McKenney" <[email protected]>…
Could you please add the following Reported-by tags?
Reported-by Sebastian Andrzej Siewior <[email protected]>Reported-by Uladzislau Rezki <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Sebastian first noticed the problem, and Uladzislau figured out how softirqs were involved.
These were already added. They must have appeared in the thread somewhere, as my internal patchwork picked them up already.
Even better, thank you!
Thank you for fixing and pulling it Steve and Paul! I couldn't find the original thread, so it is helpful :)
Thanks!
Signature · 1 line
Masami Hiramatsu <[email protected]>
Uladzislau Rezki
maintainerQuoted 34 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Paul E. McKenney
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
…
Quoted 14 lines
kernel/softirq.c +1
-1@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads) { +if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if kernel/softirq.c asmlinkage __visible void __softirq_entry __do_softirq(void) · line 363
Quoted 8 lines
kernel/softirq.c +2
-2@@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) pending =local_softirq_pending ();if (pending) { -if (time_before (jiffies, end) && !need_resched () && - --max_restart) +if (!__this_cpu_read (ksoftirqd) || + (time_before (jiffies, end) && !need_resched () && --max_restart)) goto restart;This is hunk shouldn't be needed. The reason for it is probably that the following
wakeup_softirqd()would avoid furtherinvoke_softirq()performing the actual softirq work. It would leave early due toksoftirqd_running(). Unless I'm wrong, anyraise_softirq()invocation outside of an interrupt would do the same.
Quoted 4 lines
I would like PeterZ / tglx to comment on this one. Basically I'm not sure if it is okay to expect softirqs beeing served and waited on that early in the boot.
The ksoftirqd threads get spawned during early_initcall() phase. Why not just spawn them one step earlier what is totally safe? I mean before do_pre_smp_initcalls() that calls early callbacks.
+ spawn_ksoftirqd();
rcu_init_tasks_generic();
do_pre_smp_initcalls();With such change the spawning will not be depended on linker/compiler i.e. when and in which order an early_initcall(spawn_ksoftirqd) callback is executed.
--
Vlad Rezki
Paul E. McKenney
maintainerQuoted 21 lines · Uladzislau Rezki
Quoted 20 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Paul E. McKenney
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
…
Quoted 15 lines
kernel/softirq.c +1
-1@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads) { +if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if @@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
kernel/softirq.c +1
-2pending =local_softirq_pending ();if (pending) { -if (time_before (jiffies, end) && !need_resched () && - --max_restart) + if (!__this_cpu_read(ksoftirqd) ||Quoted 8 lines
kernel/softirq.c asmlinkage __visible void __softirq_entry __do_softirq(void) · line 363
Quoted 2 lines
kernel/softirq.c +1
-0+ (time_before(jiffies, end) && !need_resched() && --max_restart)) goto restart;This is hunk shouldn't be needed. The reason for it is probably that the following
wakeup_softirqd()would avoid furtherinvoke_softirq()performing the actual softirq work. It would leave early due toksoftirqd_running(). Unless I'm wrong, anyraise_softirq()invocation outside of an interrupt would do the same.
And it does pass the rcutorture test without that hunk:
tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make
Quoted 3 lines
Quoted 3 lines
I would like PeterZ / tglx to comment on this one. Basically I'm not sure if it is okay to expect softirqs beeing served and waited on that early in the boot.
It would be good to get other eyes on this.
I do agree that "don't wait on softirq handlers until after completion of all early_initcall() handlers" is a nice simple rule, but debugging violations of it is not so simple. Adding warnings to ease debugging of violations of this rule is quite a bit more complex than is either of the methods of making the rule unnecessary, at least from what I can see at this point. The complexity of the warnings is exactly what Sebastian pointed out earlier, that it is currently legal to raise_softirq() but not to wait on the resulting handlers. But even waiting is OK if that waiting does not delay the boot sequence. But if the boot kthread waits on the kthread that does the waiting, it is once again not OK.
So am I missing something subtle here?
Quoted 11 lines
The ksoftirqd threads get spawned during
early_initcall()phase. Why not just spawn them one step earlier what is totally safe? I mean beforedo_pre_smp_initcalls()that calls early callbacks.+ spawn_ksoftirqd(); rcu_init_tasks_generic(); do_pre_smp_initcalls();With such change the spawning will not be depended on linker/compiler i.e. when and in which order an
early_initcall(spawn_ksoftirqd)callback is executed.
We both posted patches similar to this, so I am not opposed. One caveat, though, namely that this narrows the window quite a bit but does not entirely close it. But it does allow the early_initcall()s to wait on softirq handlers.
Thanx, Paul
Uladzislau Rezki
maintainerQuoted 36 lines · Paul E. McKenney
Quoted 21 lines · Uladzislau Rezki
Quoted 20 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Paul E. McKenney
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
…
Quoted 15 lines
kernel/softirq.c +1
-1@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads) { +if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if @@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
kernel/softirq.c +1
-2pending =local_softirq_pending ();if (pending) { -if (time_before (jiffies, end) && !need_resched () && - --max_restart) + if (!__this_cpu_read(ksoftirqd) ||Quoted 8 lines
kernel/softirq.c asmlinkage __visible void __softirq_entry __do_softirq(void) · line 363
Quoted 2 lines
kernel/softirq.c +1
-0+ (time_before(jiffies, end) && !need_resched() && --max_restart)) goto restart;This is hunk shouldn't be needed. The reason for it is probably that the following
wakeup_softirqd()would avoid furtherinvoke_softirq()performing the actual softirq work. It would leave early due toksoftirqd_running(). Unless I'm wrong, anyraise_softirq()invocation outside of an interrupt would do the same.
Quoted 4 lines
And it does pass the rcutorture test without that hunk:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=yCONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make
Yep. I have tested that patch also. It works for me as well. So technically i do not see any issues from the first glance but of course it should be reviewed by the softirq people to hear their opinion.
IRQs are enabled, so it can be handled from an IRQ tail until ksoftirqd threads are spawned.
Quoted 17 lines
Quoted 3 lines
Quoted 3 lines
I would like PeterZ / tglx to comment on this one. Basically I'm not sure if it is okay to expect softirqs beeing served and waited on that early in the boot.
It would be good to get other eyes on this.
I do agree that "don't wait on softirq handlers until after completion of all
early_initcall()handlers" is a nice simple rule, but debugging violations of it is not so simple. Adding warnings to ease debugging of violations of this rule is quite a bit more complex than is either of the methods of making the rule unnecessary, at least from what I can see at this point. The complexity of the warnings is exactly what Sebastian pointed out earlier, that it is currently legal toraise_softirq()but not to wait on the resulting handlers. But even waiting is OK if that waiting does not delay the boot sequence. But if the boot kthread waits on the kthread that does the waiting, it is once again not OK.
Quoted 2 lines
So am I missing something subtle here?
I agree here. Seems like we are on the same page in understanding :)
Quoted 8 lines
Quoted 8 lines
The ksoftirqd threads get spawned during
early_initcall()phase. Why not just spawn them one step earlier what is totally safe? I mean beforedo_pre_smp_initcalls()that calls early callbacks.+ spawn_ksoftirqd(); rcu_init_tasks_generic(); do_pre_smp_initcalls();
Quoted 9 lines
Quoted 3 lines
With such change the spawning will not be depended on linker/compiler i.e. when and in which order an
early_initcall(spawn_ksoftirqd)callback is executed.We both posted patches similar to this, so I am not opposed. One caveat, though, namely that this narrows the window quite a bit but does not entirely close it. But it does allow the early_initcall()s to wait on softirq handlers.
Yep, that was an intention. At least to provide such functionality for early callbacks. What happens before it(init/main.c) is pretty controllable.
--
Vlad Rezki
Paul E. McKenney
maintainerQuoted 41 lines · Uladzislau Rezki
Quoted 36 lines · Paul E. McKenney
Quoted 21 lines · Uladzislau Rezki
Quoted 20 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Paul E. McKenney
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
…
Quoted 15 lines
kernel/softirq.c +1
-1@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads) { +if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if @@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
kernel/softirq.c +1
-2pending =local_softirq_pending ();if (pending) { -if (time_before (jiffies, end) && !need_resched () && - --max_restart) + if (!__this_cpu_read(ksoftirqd) ||Quoted 8 lines
kernel/softirq.c asmlinkage __visible void __softirq_entry __do_softirq(void) · line 363
Quoted 2 lines
kernel/softirq.c +1
-0+ (time_before(jiffies, end) && !need_resched() && --max_restart)) goto restart;This is hunk shouldn't be needed. The reason for it is probably that the following
wakeup_softirqd()would avoid furtherinvoke_softirq()performing the actual softirq work. It would leave early due toksoftirqd_running(). Unless I'm wrong, anyraise_softirq()invocation outside of an interrupt would do the same.Quoted 4 lines
And it does pass the rcutorture test without that hunk:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=yCONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-make
Quoted 7 lines
Yep. I have tested that patch also. It works for me as well. So technically i do not see any issues from the first glance but of course it should be reviewed by the softirq people to hear their opinion.
IRQs are enabled, so it can be handled from an IRQ tail until ksoftirqd threads are spawned.
And if I add "CONFIG_NO_HZ_IDLE=y CONFIG_HZ_PERIODIC=n" it still works, even if I revert my changes to rcu_needs_cpu(). Should I rely on this working globally? ;-)
Thanx, Paul
Quoted 43 lines
Quoted 17 lines
Quoted 3 lines
Quoted 3 lines
I would like PeterZ / tglx to comment on this one. Basically I'm not sure if it is okay to expect softirqs beeing served and waited on that early in the boot.
It would be good to get other eyes on this.
I do agree that "don't wait on softirq handlers until after completion of all
early_initcall()handlers" is a nice simple rule, but debugging violations of it is not so simple. Adding warnings to ease debugging of violations of this rule is quite a bit more complex than is either of the methods of making the rule unnecessary, at least from what I can see at this point. The complexity of the warnings is exactly what Sebastian pointed out earlier, that it is currently legal toraise_softirq()but not to wait on the resulting handlers. But even waiting is OK if that waiting does not delay the boot sequence. But if the boot kthread waits on the kthread that does the waiting, it is once again not OK.Quoted 2 lines
So am I missing something subtle here?
I agree here. Seems like we are on the same page in understanding :)
Quoted 8 lines
Quoted 8 lines
The ksoftirqd threads get spawned during
early_initcall()phase. Why not just spawn them one step earlier what is totally safe? I mean beforedo_pre_smp_initcalls()that calls early callbacks.+ spawn_ksoftirqd(); rcu_init_tasks_generic(); do_pre_smp_initcalls();Quoted 9 lines
Quoted 3 lines
With such change the spawning will not be depended on linker/compiler i.e. when and in which order an
early_initcall(spawn_ksoftirqd)callback is executed.We both posted patches similar to this, so I am not opposed. One caveat, though, namely that this narrows the window quite a bit but does not entirely close it. But it does allow the early_initcall()s to wait on softirq handlers.
Yep, that was an intention. At least to provide such functionality for early callbacks. What happens before it(init/main.c) is pretty controllable.
--
Vlad Rezki
Uladzislau Rezki
maintainerQuoted 47 lines · Paul E. McKenney
Quoted 46 lines · Uladzislau Rezki
Quoted 36 lines · Paul E. McKenney
Quoted 21 lines · Uladzislau Rezki
Quoted 20 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Paul E. McKenney
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
…
Quoted 15 lines
kernel/softirq.c +1
-1@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads) { +if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if @@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
kernel/softirq.c +1
-2pending =local_softirq_pending ();if (pending) { -if (time_before (jiffies, end) && !need_resched () && - --max_restart) + if (!__this_cpu_read(ksoftirqd) ||Quoted 8 lines
kernel/softirq.c asmlinkage __visible void __softirq_entry __do_softirq(void) · line 363
Quoted 2 lines
kernel/softirq.c +1
-0+ (time_before(jiffies, end) && !need_resched() && --max_restart)) goto restart;This is hunk shouldn't be needed. The reason for it is probably that the following
wakeup_softirqd()would avoid furtherinvoke_softirq()performing the actual softirq work. It would leave early due toksoftirqd_running(). Unless I'm wrong, anyraise_softirq()invocation outside of an interrupt would do the same.Quoted 4 lines
And it does pass the rcutorture test without that hunk:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=yCONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-makeYep. I have tested that patch also. It works for me as well. So technically i do not see any issues from the first glance but of course it should be reviewed by the softirq people to hear their opinion.
Quoted 7 lines
Quoted 2 lines
IRQs are enabled, so it can be handled from an IRQ tail until ksoftirqd threads are spawned.
And if I add "
CONFIG_NO_HZ_IDLE=yCONFIG_HZ_PERIODIC=n" it still works, even if I revert my changes torcu_needs_cpu(). Should I rely on this working globally? ;-)
There might be corner cases which we are not aware of so far. From the other hand what the patch does is simulating the !threadirqs behaviour during early boot. In that case we know that handling of SW irqs from real-irq tail works :)
--
Vlad Rezki
Paul E. McKenney
maintainerQuoted 51 lines · Uladzislau Rezki
Quoted 50 lines · Paul E. McKenney
Quoted 48 lines · Uladzislau Rezki
Quoted 36 lines · Paul E. McKenney
Quoted 21 lines · Uladzislau Rezki
Quoted 20 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Paul E. McKenney
For definiteness, here is the first part of the change, posted earlier. The commit log needs to be updated. I will post the change that keeps the tick going as a reply to this email.
…
Quoted 15 lines
kernel/softirq.c +1
-1@@ -209,7 +209,7 @@ static inline void invoke_softirq(void)if (ksoftirqd_running (local_softirq_pending ()))return ; -if (!force_irqthreads) { +if (!force_irqthreads || !__this_cpu_read (ksoftirqd)) {#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK /* * We can safely execute softirq on the current stack if @@ -358,8 +358,8 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
kernel/softirq.c +1
-2pending =local_softirq_pending ();if (pending) { -if (time_before (jiffies, end) && !need_resched () && - --max_restart) + if (!__this_cpu_read(ksoftirqd) ||Quoted 8 lines
kernel/softirq.c asmlinkage __visible void __softirq_entry __do_softirq(void) · line 363
Quoted 2 lines
kernel/softirq.c +1
-0+ (time_before(jiffies, end) && !need_resched() && --max_restart)) goto restart;This is hunk shouldn't be needed. The reason for it is probably that the following
wakeup_softirqd()would avoid furtherinvoke_softirq()performing the actual softirq work. It would leave early due toksoftirqd_running(). Unless I'm wrong, anyraise_softirq()invocation outside of an interrupt would do the same.Quoted 4 lines
And it does pass the rcutorture test without that hunk:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 2 --configs "TREE03" --kconfig "CONFIG_DEBUG_LOCK_ALLOC=yCONFIG_PROVE_LOCKING=y" --bootargs "threadirqs=1" --trust-makeYep. I have tested that patch also. It works for me as well. So technically i do not see any issues from the first glance but of course it should be reviewed by the softirq people to hear their opinion.
IRQs are enabled, so it can be handled from an IRQ tail until ksoftirqd threads are spawned.
Quoted 8 lines
Quoted 4 lines
And if I add "
CONFIG_NO_HZ_IDLE=yCONFIG_HZ_PERIODIC=n" it still works, even if I revert my changes torcu_needs_cpu(). Should I rely on this working globally? ;-)There might be corner cases which we are not aware of so far. From the other hand what the patch does is simulating the !threadirqs behaviour during early boot. In that case we know that handling of SW irqs from real-irq tail works :)
Sold! I keep the rcu_needs_cpu() changes, just in case.
Thanx, Paul