tasklets: Replace the spin wait loops and make it RT safe
Subsystems (11)
cover tasklets: Replace the spin wait loops and make it RT safe
This is a follow up to the review comments of the series which makes softirq processing PREEMPT_RT safe:
https://lore.kernel.org/r/[email protected]
Peter suggested to replace the spin waiting in tasklet_disable() and tasklet_kill() with wait_event(). This also gets rid of the ill defined sched_yield() in tasklet_kill().
Analyzing all usage sites of tasklet_disable() and tasklet_unlock_wait() we found that most of them are safe to be converted to a sleeping wait.
Only a few instances invoke tasklet_disable() from atomic context. A few bugs which have been found in course of this analysis have been already addressed seperately.
The following series takes the following approach:
1) Provide a variant of tasklet_disable() which can be invoked from atomic contexts
2) Convert the usage sites which cannot be easily changed to a sleepable wait to use this new function
3) Replace the spin waits in tasklet_disable() and tasklet_kill() with sleepable variants.
If this is agreed on then the merging can be either done in bulk or the first 4 patches could be applied on top of rc2 and tagged for consumption in the relevant subsystem trees (networking, pci, firewire). In this case the last patch which changes the implementation of tasklet_disable() has to be post-poned until all other changes have reached mainline.
The series is also available from git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git tasklet-2021-03-09
Thanks,
tglx
PATCH 1/14 tasklets: Replace barrier() with cpu_relax() in tasklet_unlock_wait()
A barrier() in a tight loop which waits for something to happen on a remote CPU is a pointless exercise. Replace it with cpu_relax() which allows HT siblings to make progress.
--- include/linux/interrupt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/interrupt.h +2 -1
@@ -672,7 +672,8 @@ static inline void tasklet_unlock(structstatic inline void tasklet_unlock_wait (struct tasklet_struct *t) { -while (test_bit (TASKLET_STATE_RUN , &(t)->state)) {barrier (); } +while (test_bit (TASKLET_STATE_RUN , &t->state)) +cpu_relax (); }#else #define tasklet_trylock (t) 1
[tip: irq/core] tasklets: Replace barrier() with cpu_relax() in tasklet_unlock_wait()
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: d2da74d1278a1b51ef18beafa9da770f0db1c617 Gitweb: https://git.kernel.org/tip/d2da74d1278a1b51ef18beafa9da770f0db1c617 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:04 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:33:51 +01:00
tasklets: Replace barrier() with cpu_relax() in tasklet_unlock_wait()
A barrier() in a tight loop which waits for something to happen on a remote CPU is a pointless exercise. Replace it with cpu_relax() which allows HT siblings to make progress.
--- include/linux/interrupt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/interrupt.h +2 -1
@@ -672,7 +672,8 @@ static inline void tasklet_unlock(struct tasklet_struct *t)static inline void tasklet_unlock_wait (struct tasklet_struct *t) { -while (test_bit (TASKLET_STATE_RUN , &(t)->state)) {barrier (); } +while (test_bit (TASKLET_STATE_RUN , &t->state)) +cpu_relax (); }#else #define tasklet_trylock (t) 1
PATCH 2/14 tasklets: Use static inlines for stub implementations
In reply to Thomas GleixnerInlines exist for a reason.
--- include/linux/interrupt.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/interrupt.h +3 -3
@@ -676,9 +676,9 @@ static inline void tasklet_unlock_wait(s cpu_relax(); }#else -#define tasklet_trylock (t) 1 -#define tasklet_unlock_wait (t) do { } while (0) -#define tasklet_unlock (t) do { } while (0) +static inline int tasklet_trylock (struct tasklet_struct *t) {return 1 ; } +static inline void tasklet_unlock (struct tasklet_struct *t) { } +static inline void tasklet_unlock_wait (struct tasklet_struct *t) { }#endif extern void __tasklet_schedule (struct tasklet_struct *t);
[tip: irq/core] tasklets: Use static inlines for stub implementations
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 6951547a1399c8f56468ed93bea8f769b891aec3 Gitweb: https://git.kernel.org/tip/6951547a1399c8f56468ed93bea8f769b891aec3 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:05 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:33:51 +01:00
tasklets: Use static inlines for stub implementations
Inlines exist for a reason.
--- include/linux/interrupt.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/interrupt.h +3 -3
@@ -676,9 +676,9 @@ static inline void tasklet_unlock_wait(struct tasklet_struct *t) cpu_relax(); }#else -#define tasklet_trylock (t) 1 -#define tasklet_unlock_wait (t) do { } while (0) -#define tasklet_unlock (t) do { } while (0) +static inline int tasklet_trylock (struct tasklet_struct *t) {return 1 ; } +static inline void tasklet_unlock (struct tasklet_struct *t) { } +static inline void tasklet_unlock_wait (struct tasklet_struct *t) { }#endif extern void __tasklet_schedule (struct tasklet_struct *t);
PATCH 3/14 tasklets: Provide tasklet_disable_in_atomic()
In reply to Thomas GleixnerReplacing the spin wait loops in tasklet_unlock_wait() with wait_var_event() is not possible as a handful of tasklet_disable() invocations are happening in atomic context. All other invocations are in teardown paths which can sleep.
Provide tasklet_disable_in_atomic() and tasklet_unlock_spin_wait() to convert the few atomic use cases over, which allows to change tasklet_disable() and tasklet_unlock_wait() in a later step.
--- include/linux/interrupt.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
include/linux/interrupt.h +22 -0
@@ -675,10 +675,21 @@ static inline void tasklet_unlock_wait(swhile (test_bit (TASKLET_STATE_RUN , &t->state)) cpu_relax(); } + +/* +* Do not use in new code. Waiting for tasklets from atomic contexts is +* error prone and should be avoided. +*/ +static inline void tasklet_unlock_spin_wait (struct tasklet_struct *t) +{ +while (test_bit (TASKLET_STATE_RUN , &t->state)) +cpu_relax (); +}#else static inline int tasklet_trylock (struct tasklet_struct *t) {return 1 ; }static inline void tasklet_unlock (struct tasklet_struct *t) { }static inline void tasklet_unlock_wait (struct tasklet_struct *t) { } +static inline void tasklet_unlock_spin_wait (struct tasklet_struct *t) { }#endif extern void __tasklet_schedule (struct tasklet_struct *t);
@@ -703,6 +714,17 @@ static inline void tasklet_disable_nosynsmp_mb__after_atomic (); } +/* +* Do not use in new code. Disabling tasklets from atomic contexts is +* error prone and should be avoided. +*/ +static inline void tasklet_disable_in_atomic (struct tasklet_struct *t) +{ +tasklet_disable_nosync (t); +tasklet_unlock_spin_wait (t); +smp_mb (); +} +static inline void tasklet_disable (struct tasklet_struct *t) {tasklet_disable_nosync (t);
[tip: irq/core] tasklets: Provide tasklet_disable_in_atomic()
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: ca5f625118955fc544c3cb3dee7055d33ecadafb Gitweb: https://git.kernel.org/tip/ca5f625118955fc544c3cb3dee7055d33ecadafb Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:06 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:33:52 +01:00
tasklets: Provide tasklet_disable_in_atomic()
Replacing the spin wait loops in tasklet_unlock_wait() with wait_var_event() is not possible as a handful of tasklet_disable() invocations are happening in atomic context. All other invocations are in teardown paths which can sleep.
Provide tasklet_disable_in_atomic() and tasklet_unlock_spin_wait() to convert the few atomic use cases over, which allows to change tasklet_disable() and tasklet_unlock_wait() in a later step.
--- include/linux/interrupt.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
include/linux/interrupt.h +22 -0
@@ -675,10 +675,21 @@ static inline void tasklet_unlock_wait(struct tasklet_struct *t)while (test_bit (TASKLET_STATE_RUN , &t->state)) cpu_relax(); } + +/* +* Do not use in new code. Waiting for tasklets from atomic contexts is +* error prone and should be avoided. +*/ +static inline void tasklet_unlock_spin_wait (struct tasklet_struct *t) +{ +while (test_bit (TASKLET_STATE_RUN , &t->state)) +cpu_relax (); +}#else static inline int tasklet_trylock (struct tasklet_struct *t) {return 1 ; }static inline void tasklet_unlock (struct tasklet_struct *t) { }static inline void tasklet_unlock_wait (struct tasklet_struct *t) { } +static inline void tasklet_unlock_spin_wait (struct tasklet_struct *t) { }#endif extern void __tasklet_schedule (struct tasklet_struct *t);
@@ -703,6 +714,17 @@ static inline void tasklet_disable_nosync(struct tasklet_struct *t)smp_mb__after_atomic (); } +/* +* Do not use in new code. Disabling tasklets from atomic contexts is +* error prone and should be avoided. +*/ +static inline void tasklet_disable_in_atomic (struct tasklet_struct *t) +{ +tasklet_disable_nosync (t); +tasklet_unlock_spin_wait (t); +smp_mb (); +} +static inline void tasklet_disable (struct tasklet_struct *t) {tasklet_disable_nosync (t);
PATCH 4/14 tasklets: Use spin wait in tasklet_disable() temporarily
In reply to Thomas GleixnerTo ease the transition use spin waiting in tasklet_disable() until all usage sites from atomic context have been cleaned up.
--- include/linux/interrupt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/interrupt.h +2 -1
@@ -728,7 +728,8 @@ static inline void tasklet_disable_in_atstatic inline void tasklet_disable (struct tasklet_struct *t) {tasklet_disable_nosync (t); -tasklet_unlock_wait (t); +/* Spin wait until all atomic users are converted */ +tasklet_unlock_spin_wait (t);smp_mb (); }
[tip: irq/core] tasklets: Use spin wait in tasklet_disable() temporarily
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: b0cd02c2a9494dbf0a1cc7dc7a3b8b400c158d37 Gitweb: https://git.kernel.org/tip/b0cd02c2a9494dbf0a1cc7dc7a3b8b400c158d37 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:07 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:33:54 +01:00
tasklets: Use spin wait in tasklet_disable() temporarily
To ease the transition use spin waiting in tasklet_disable() until all usage sites from atomic context have been cleaned up.
--- include/linux/interrupt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/interrupt.h +2 -1
@@ -728,7 +728,8 @@ static inline void tasklet_disable_in_atomic(struct tasklet_struct *t)static inline void tasklet_disable (struct tasklet_struct *t) {tasklet_disable_nosync (t); -tasklet_unlock_wait (t); +/* Spin wait until all atomic users are converted */ +tasklet_unlock_spin_wait (t);smp_mb (); }
PATCH 5/14 tasklets: Replace spin wait in tasklet_unlock_wait()
In reply to Thomas GleixnerFrom: Peter Zijlstra <[email protected]>
tasklet_unlock_wait() spin waits for TASKLET_STATE_RUN to be cleared. This is wasting CPU cycles in a tight loop which is especially painful in a guest when the CPU running the tasklet is scheduled out.
tasklet_unlock_wait() is invoked from tasklet_kill() which is used in teardown paths and not performance critical at all. Replace the spin wait with wait_var_event().
There are no users of tasklet_unlock_wait() which are invoked from atomic contexts. The usage in tasklet_disable() has been replaced temporarily with the spin waiting variant until the atomic users are fixed up and will be converted to the sleep wait variant later.
--- include/linux/interrupt.h | 13 ++----------- kernel/softirq.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-)
include/linux/interrupt.h +2 -11
@@ -664,17 +664,8 @@ static inline int tasklet_trylock(structreturn !test_and_set_bit (TASKLET_STATE_RUN , &(t)->state); } -static inline void tasklet_unlock (struct tasklet_struct *t) -{ -smp_mb__before_atomic (); -clear_bit (TASKLET_STATE_RUN , &(t)->state); -} - -static inline void tasklet_unlock_wait (struct tasklet_struct *t) -{ -while (test_bit (TASKLET_STATE_RUN , &t->state)) -cpu_relax (); -} +void tasklet_unlock (struct tasklet_struct *t); +void tasklet_unlock_wait (struct tasklet_struct *t);/* * Do not use in new code. Waiting for tasklets from atomic contexts is
kernel/softirq.c +18 -0
@@ -25,6 +25,7 @@#include <linux/smpboot.h> #include <linux/tick.h> #include <linux/irq.h> +#include <linux/wait_bit.h> #include <asm/softirq_stack.h>
@@ -621,6 +622,23 @@ void tasklet_kill(struct tasklet_struct }EXPORT_SYMBOL (tasklet_kill); +#ifdef CONFIG_SMP +void tasklet_unlock (struct tasklet_struct *t) +{ +smp_mb__before_atomic (); +clear_bit (TASKLET_STATE_RUN , &t->state); +smp_mb__after_atomic (); +wake_up_var (&t->state); +} +EXPORT_SYMBOL_GPL (tasklet_unlock); + +void tasklet_unlock_wait (struct tasklet_struct *t) +{ +wait_var_event (&t->state, !test_bit (TASKLET_STATE_RUN , &t->state)); +} +EXPORT_SYMBOL_GPL (tasklet_unlock_wait); +#endif +void __init softirq_init (void ) {int cpu;
[tip: irq/core] tasklets: Replace spin wait in tasklet_unlock_wait()
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: da044747401fc16202e223c9da970ed4e84fd84d Gitweb: https://git.kernel.org/tip/da044747401fc16202e223c9da970ed4e84fd84d Author: Peter Zijlstra <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:08 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:33:55 +01:00
tasklets: Replace spin wait in tasklet_unlock_wait()
tasklet_unlock_wait() spin waits for TASKLET_STATE_RUN to be cleared. This is wasting CPU cycles in a tight loop which is especially painful in a guest when the CPU running the tasklet is scheduled out.
tasklet_unlock_wait() is invoked from tasklet_kill() which is used in teardown paths and not performance critical at all. Replace the spin wait with wait_var_event().
There are no users of tasklet_unlock_wait() which are invoked from atomic contexts. The usage in tasklet_disable() has been replaced temporarily with the spin waiting variant until the atomic users are fixed up and will be converted to the sleep wait variant later.
--- include/linux/interrupt.h | 13 ++----------- kernel/softirq.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-)
include/linux/interrupt.h +2 -11
@@ -664,17 +664,8 @@ static inline int tasklet_trylock(struct tasklet_struct *t)return !test_and_set_bit (TASKLET_STATE_RUN , &(t)->state); } -static inline void tasklet_unlock (struct tasklet_struct *t) -{ -smp_mb__before_atomic (); -clear_bit (TASKLET_STATE_RUN , &(t)->state); -} - -static inline void tasklet_unlock_wait (struct tasklet_struct *t) -{ -while (test_bit (TASKLET_STATE_RUN , &t->state)) -cpu_relax (); -} +void tasklet_unlock (struct tasklet_struct *t); +void tasklet_unlock_wait (struct tasklet_struct *t);/* * Do not use in new code. Waiting for tasklets from atomic contexts is
kernel/softirq.c +18 -0
@@ -25,6 +25,7 @@#include <linux/smpboot.h> #include <linux/tick.h> #include <linux/irq.h> +#include <linux/wait_bit.h> #include <asm/softirq_stack.h>
@@ -632,6 +633,23 @@ void tasklet_kill(struct tasklet_struct *t) }EXPORT_SYMBOL (tasklet_kill); +#ifdef CONFIG_SMP +void tasklet_unlock (struct tasklet_struct *t) +{ +smp_mb__before_atomic (); +clear_bit (TASKLET_STATE_RUN , &t->state); +smp_mb__after_atomic (); +wake_up_var (&t->state); +} +EXPORT_SYMBOL_GPL (tasklet_unlock); + +void tasklet_unlock_wait (struct tasklet_struct *t) +{ +wait_var_event (&t->state, !test_bit (TASKLET_STATE_RUN , &t->state)); +} +EXPORT_SYMBOL_GPL (tasklet_unlock_wait); +#endif +void __init softirq_init (void ) {int cpu;
PATCH 6/14 tasklets: Replace spin wait in tasklet_kill()
In reply to Thomas GleixnerFrom: Peter Zijlstra <[email protected]>
tasklet_kill() spin waits for TASKLET_STATE_SCHED to be cleared invoking yield() from inside the loop. yield() is an ill defined mechanism and the result might still be wasting CPU cycles in a tight loop which is especially painful in a guest when the CPU running the tasklet is scheduled out.
tasklet_kill() is used in teardown paths and not performance critical at all. Replace the spin wait with wait_var_event().
--- kernel/softirq.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
kernel/softirq.c +15 -8
@@ -532,6 +532,16 @@ void __tasklet_hi_schedule(struct taskle }EXPORT_SYMBOL (__tasklet_hi_schedule); +static inline bool tasklet_clear_sched (struct tasklet_struct *t) +{ +if (test_and_clear_bit (TASKLET_STATE_SCHED , &t->state)) { +wake_up_var (&t->state); +return true; + } + +return false; +} +static void tasklet_action_common (struct softirq_action *a,struct tasklet_head *tl_head,unsigned int softirq_nr)
@@ -551,8 +561,7 @@ static void tasklet_action_common(structif (tasklet_trylock (t)) {if (!atomic_read (&t->count)) { -if (!test_and_clear_bit (TASKLET_STATE_SCHED , - &t->state)) +if (!tasklet_clear_sched (t))BUG ();if (t->use_callback) t->callback (t);
@@ -612,13 +621,11 @@ void tasklet_kill(struct tasklet_structif (in_interrupt ())pr_notice ("Attempt to kill tasklet from interrupt\n" ); -while (test_and_set_bit (TASKLET_STATE_SCHED , &t->state)) { -do { -yield (); - }while (test_bit (TASKLET_STATE_SCHED , &t->state)); - } +while (test_and_set_bit (TASKLET_STATE_SCHED , &t->state)) +wait_var_event (&t->state, !test_bit (TASKLET_STATE_SCHED , &t->state)); +tasklet_unlock_wait (t); -clear_bit (TASKLET_STATE_SCHED , &t->state); +tasklet_clear_sched (t); }EXPORT_SYMBOL (tasklet_kill);
[tip: irq/core] tasklets: Replace spin wait in tasklet_kill()
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 697d8c63c4a2991a22a896a5e6adcdbb28fefe56 Gitweb: https://git.kernel.org/tip/697d8c63c4a2991a22a896a5e6adcdbb28fefe56 Author: Peter Zijlstra <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:09 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:33:57 +01:00
tasklets: Replace spin wait in tasklet_kill()
tasklet_kill() spin waits for TASKLET_STATE_SCHED to be cleared invoking yield() from inside the loop. yield() is an ill defined mechanism and the result might still be wasting CPU cycles in a tight loop which is especially painful in a guest when the CPU running the tasklet is scheduled out.
tasklet_kill() is used in teardown paths and not performance critical at all. Replace the spin wait with wait_var_event().
--- kernel/softirq.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
kernel/softirq.c +9 -9
@@ -532,10 +532,12 @@ void __tasklet_hi_schedule(struct tasklet_struct *t) }EXPORT_SYMBOL (__tasklet_hi_schedule); -static bool tasklet_should_run (struct tasklet_struct *t) +static bool tasklet_clear_sched (struct tasklet_struct *t) { -if (test_and_clear_bit (TASKLET_STATE_SCHED , &t->state)) +if (test_and_clear_bit (TASKLET_STATE_SCHED , &t->state)) { +wake_up_var (&t->state);return true; + } WARN_ONCE(1, "tasklet SCHED state not set: %s %pS\n", t->use_callback ? "callback" : "func",
@@ -563,7 +565,7 @@ static void tasklet_action_common(struct softirq_action *a,if (tasklet_trylock (t)) {if (!atomic_read (&t->count)) { -if (tasklet_should_run (t)) { +if (tasklet_clear_sched (t)) {if (t->use_callback) t->callback (t);else
@@ -623,13 +625,11 @@ void tasklet_kill(struct tasklet_struct *t)if (in_interrupt ())pr_notice ("Attempt to kill tasklet from interrupt\n" ); -while (test_and_set_bit (TASKLET_STATE_SCHED , &t->state)) { -do { -yield (); - }while (test_bit (TASKLET_STATE_SCHED , &t->state)); - } +while (test_and_set_bit (TASKLET_STATE_SCHED , &t->state)) +wait_var_event (&t->state, !test_bit (TASKLET_STATE_SCHED , &t->state)); +tasklet_unlock_wait (t); -clear_bit (TASKLET_STATE_SCHED , &t->state); +tasklet_clear_sched (t); }EXPORT_SYMBOL (tasklet_kill);
PATCH 7/14 tasklets: Prevent tasklet_unlock_spin_wait() deadlock on RT
In reply to Thomas Gleixnertasklet_unlock_spin_wait() spin waits for the TASKLET_STATE_SCHED bit in the tasklet state to be cleared. This works on !RT nicely because the corresponding execution can only happen on a different CPU.
On RT softirq processing is preemptible, therefore a task preempting the softirq processing thread can spin forever.
Prevent this by invoking local_bh_disable()/enable() inside the loop. In case that the softirq processing thread was preempted by the current task, current will block on the local lock which yields the CPU to the preempted softirq processing thread. If the tasklet is processed on a different CPU then the local_bh_disable()/enable() pair is just a waste of processor cycles.
--- include/linux/interrupt.h | 2 +- kernel/softirq.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-)
include/linux/interrupt.h +1 -1
@@ -658,7 +658,7 @@ enumTASKLET_STATE_RUN /* Tasklet is running (SMP only) */ }; -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP ) || defined(CONFIG_PREEMPT_RT )static inline int tasklet_trylock (struct tasklet_struct *t) {return !test_and_set_bit (TASKLET_STATE_RUN , &(t)->state);
kernel/softirq.c +27 -1
@@ -616,6 +616,32 @@ void tasklet_init(struct tasklet_struct }EXPORT_SYMBOL (tasklet_init); +#if defined(CONFIG_SMP ) || defined(CONFIG_PREEMPT_RT ) +/* +* Do not use in new code. There is no real reason to invoke this from +* atomic contexts. +*/ +void tasklet_unlock_spin_wait (struct tasklet_struct *t) +{ +while (test_bit (TASKLET_STATE_RUN , &(t)->state)) { +if (IS_ENABLED (CONFIG_PREEMPT_RT )) { +/* +* Prevent a live lock when current preempted soft +* interrupt processing or prevents ksoftirqd from +* running. If the tasklet runs on a different CPU +* then this has no effect other than doing the BH +* disable/enable dance for nothing. +*/ +local_bh_disable (); +local_bh_enable (); + }else { +cpu_relax (); + } + } +} +EXPORT_SYMBOL (tasklet_unlock_spin_wait); +#endif +void tasklet_kill (struct tasklet_struct *t) {if (in_interrupt ())
@@ -629,7 +655,7 @@ void tasklet_kill(struct tasklet_struct }EXPORT_SYMBOL (tasklet_kill); -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP ) || defined(CONFIG_PREEMPT_RT )void tasklet_unlock (struct tasklet_struct *t) {smp_mb__before_atomic ();
Re: [patch 07/14] tasklets: Prevent tasklet_unlock_spin_wait() deadlock on RT
Quoted 2 lines · Thomas Gleixner
tasklet_unlock_spin_wait()spin waits for theTASKLET_STATE_SCHEDbit in the tasklet state to be cleared. This works on !RT nicely because the
…
Could you please fold this:
include/linux/interrupt.h +0 -9
@@ -663,15 +663,6 @@ static inline int tasklet_trylock(struct tasklet_struct *t)void tasklet_unlock (struct tasklet_struct *t);void tasklet_unlock_wait (struct tasklet_struct *t); -/* -* Do not use in new code. Waiting for tasklets from atomic contexts is -* error prone and should be avoided. -*/ -static inline void tasklet_unlock_spin_wait (struct tasklet_struct *t) -{ -while (test_bit (TASKLET_STATE_RUN , &t->state)) -cpu_relax (); -}#else static inline int tasklet_trylock (struct tasklet_struct *t) {return 1 ; }static inline void tasklet_unlock (struct tasklet_struct *t) { }
kernel/softirq.c +2 -2
@@ -830,8 +830,8 @@ EXPORT_SYMBOL(tasklet_init);#if defined(CONFIG_SMP ) || defined(CONFIG_PREEMPT_RT )/* -* Do not use in new code. There is no real reason to invoke this from -* atomic contexts. +* Do not use in new code. Waiting for tasklets from atomic contexts is +* error prone and should be avoided. */ void tasklet_unlock_spin_wait (struct tasklet_struct *t) {
Signature · 1 line
2.30.1
Re: [patch 07/14] tasklets: Prevent tasklet_unlock_spin_wait() deadlock on RT
Quoted 7 lines · To Thomas Gleixner
include/linux/interrupt.h +0
-0@@ -663,15 +663,6 @@ static inline int tasklet_trylock(struct tasklet_struct *t)void tasklet_unlock (struct tasklet_struct *t);void tasklet_unlock_wait (struct tasklet_struct *t);
include/linux/interrupt.h static inline int tasklet_trylock(struct tasklet_struct *t) · line 674
Quoted 10 lines
include/linux/interrupt.h +0
-9-/* -* Do not use in new code. Waiting for tasklets from atomic contexts is -* error prone and should be avoided. -*/ -static inline void tasklet_unlock_spin_wait (struct tasklet_struct *t) -{ -while (test_bit (TASKLET_STATE_RUN , &t->state)) -cpu_relax (); -}
Look at that. The forward declaration for tasklet_unlock_spin_wait() should have remained. Sorry for that.
Sebastian
Re: [patch 07/14] tasklets: Prevent tasklet_unlock_spin_wait() deadlock on RT
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · To Thomas Gleixner
include/linux/interrupt.h +0
-0@@ -663,15 +663,6 @@ static inline int tasklet_trylock(struct tasklet_struct *t)void tasklet_unlock (struct tasklet_struct *t);void tasklet_unlock_wait (struct tasklet_struct *t);
Quoted 12 lines
include/linux/interrupt.h static inline int tasklet_trylock(struct tasklet_struct *t) · line 674
Quoted 9 lines
include/linux/interrupt.h +0
-9-/* -* Do not use in new code. Waiting for tasklets from atomic contexts is -* error prone and should be avoided. -*/ -static inline void tasklet_unlock_spin_wait (struct tasklet_struct *t) -{ -while (test_bit (TASKLET_STATE_RUN , &t->state)) -cpu_relax (); -}Look at that. The forward declaration for
tasklet_unlock_spin_wait()should have remained. Sorry for that.
No idea how I managed to mess that up and fail to notice. Brown paperbags to the rescue.
Thanks,
tglx
[tip: irq/core] tasklets: Prevent tasklet_unlock_spin_wait() deadlock on RT
In reply to Thomas GleixnerThe following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: eb2dafbba8b824ee77f166629babd470dd0b1c0a Gitweb: https://git.kernel.org/tip/eb2dafbba8b824ee77f166629babd470dd0b1c0a Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:10 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:33:57 +01:00
tasklets: Prevent tasklet_unlock_spin_wait() deadlock on RT
tasklet_unlock_spin_wait() spin waits for the TASKLET_STATE_SCHED bit in the tasklet state to be cleared. This works on !RT nicely because the corresponding execution can only happen on a different CPU.
On RT softirq processing is preemptible, therefore a task preempting the softirq processing thread can spin forever.
Prevent this by invoking local_bh_disable()/enable() inside the loop. In case that the softirq processing thread was preempted by the current task, current will block on the local lock which yields the CPU to the preempted softirq processing thread. If the tasklet is processed on a different CPU then the local_bh_disable()/enable() pair is just a waste of processor cycles.
--- include/linux/interrupt.h | 12 ++---------- kernel/softirq.c | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 11 deletions(-)
include/linux/interrupt.h +2 -10
@@ -658,7 +658,7 @@ enumTASKLET_STATE_RUN /* Tasklet is running (SMP only) */ }; -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP ) || defined(CONFIG_PREEMPT_RT )static inline int tasklet_trylock (struct tasklet_struct *t) {return !test_and_set_bit (TASKLET_STATE_RUN , &(t)->state);
@@ -666,16 +666,8 @@ static inline int tasklet_trylock(struct tasklet_struct *t)void tasklet_unlock (struct tasklet_struct *t);void tasklet_unlock_wait (struct tasklet_struct *t); +void tasklet_unlock_spin_wait (struct tasklet_struct *t); -/* -* Do not use in new code. Waiting for tasklets from atomic contexts is -* error prone and should be avoided. -*/ -static inline void tasklet_unlock_spin_wait (struct tasklet_struct *t) -{ -while (test_bit (TASKLET_STATE_RUN , &t->state)) -cpu_relax (); -}#else static inline int tasklet_trylock (struct tasklet_struct *t) {return 1 ; }static inline void tasklet_unlock (struct tasklet_struct *t) { }
kernel/softirq.c +27 -1
@@ -620,6 +620,32 @@ void tasklet_init(struct tasklet_struct *t, }EXPORT_SYMBOL (tasklet_init); +#if defined(CONFIG_SMP ) || defined(CONFIG_PREEMPT_RT ) +/* +* Do not use in new code. Waiting for tasklets from atomic contexts is +* error prone and should be avoided. +*/ +void tasklet_unlock_spin_wait (struct tasklet_struct *t) +{ +while (test_bit (TASKLET_STATE_RUN , &(t)->state)) { +if (IS_ENABLED (CONFIG_PREEMPT_RT )) { +/* +* Prevent a live lock when current preempted soft +* interrupt processing or prevents ksoftirqd from +* running. If the tasklet runs on a different CPU +* then this has no effect other than doing the BH +* disable/enable dance for nothing. +*/ +local_bh_disable (); +local_bh_enable (); + }else { +cpu_relax (); + } + } +} +EXPORT_SYMBOL (tasklet_unlock_spin_wait); +#endif +void tasklet_kill (struct tasklet_struct *t) {if (in_interrupt ())
@@ -633,7 +659,7 @@ void tasklet_kill(struct tasklet_struct *t) }EXPORT_SYMBOL (tasklet_kill); -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP ) || defined(CONFIG_PREEMPT_RT )void tasklet_unlock (struct tasklet_struct *t) {smp_mb__before_atomic ();
PATCH 8/14 net: jme: Replace link-change tasklet with work
In reply to Thomas GleixnerFrom: Sebastian Andrzej Siewior <[email protected]>
The link change tasklet disables the tasklets for tx/rx processing while upating hw parameters and then enables the tasklets again.
This update can also be pushed into a workqueue where it can be performed in preemptible context. This allows tasklet_disable() to become sleeping.
Replace the linkch_task tasklet with a work.
--- drivers/net/ethernet/jme.c | 10 +++++----- drivers/net/ethernet/jme.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/jme.c +5 -5
@@ -1265,9 +1265,9 @@ jme_stop_shutdown_timer(struct jme_adaptjwrite32f (jme,JME_APMC , apmc); } -static void jme_link_change_tasklet (struct tasklet_struct *t) +static void jme_link_change_work (struct work_struct *work) { -struct jme_adapter *jme =from_tasklet (jme, t, linkch_task); + struct jme_adapter *jme = container_of(work, struct jme_adapter, linkch_task);struct net_device *netdev = jme->dev;int rc;
@@ -1510,7 +1510,7 @@ jme_intr_msi(struct jme_adapter *jme, u3* all other events are ignored */ jwrite32 (jme,JME_IEVE , intrstat); -tasklet_schedule (&jme->linkch_task); +schedule_work (&jme->linkch_task); goto out_reenable; }
@@ -1832,7 +1832,6 @@ jme_open(struct net_device *netdev)jme_clear_pm_disable_wol (jme);JME_NAPI_ENABLE (jme); -tasklet_setup (&jme->linkch_task, jme_link_change_tasklet);tasklet_setup (&jme->txclean_task, jme_tx_clean_tasklet);tasklet_setup (&jme->rxclean_task, jme_rx_clean_tasklet);tasklet_setup (&jme->rxempty_task, jme_rx_empty_tasklet);
@@ -1920,7 +1919,7 @@ jme_close(struct net_device *netdev)JME_NAPI_DISABLE (jme); -tasklet_kill (&jme->linkch_task); +cancel_work_sync (&jme->linkch_task);tasklet_kill (&jme->txclean_task);tasklet_kill (&jme->rxclean_task);tasklet_kill (&jme->rxempty_task);
@@ -3035,6 +3034,7 @@ jme_init_one(struct pci_dev *pdev,atomic_set (&jme->rx_empty,1 );tasklet_setup (&jme->pcc_task, jme_pcc_tasklet); +INIT_WORK (&jme->linkch_task, jme_link_change_work); jme->dpi.cur =PCC_P1 ; jme->reg_ghc =0 ;
drivers/net/ethernet/jme.h +1 -1
@@ -411,7 +411,7 @@ struct jme_adapter {struct tasklet_struct rxempty_task;struct tasklet_struct rxclean_task;struct tasklet_struct txclean_task; -struct tasklet_struct linkch_task; +struct work_struct linkch_task;struct tasklet_struct pcc_task;unsigned long flags;u32 reg_txcs;
[tip: irq/core] net: jme: Replace link-change tasklet with work
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: c62c38e349c73cad90f59f00fe8070b3648b6d08 Gitweb: https://git.kernel.org/tip/c62c38e349c73cad90f59f00fe8070b3648b6d08 Author: Sebastian Andrzej Siewior <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:11 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:33:58 +01:00
net: jme: Replace link-change tasklet with work
The link change tasklet disables the tasklets for tx/rx processing while upating hw parameters and then enables the tasklets again.
This update can also be pushed into a workqueue where it can be performed in preemptible context. This allows tasklet_disable() to become sleeping.
Replace the linkch_task tasklet with a work.
--- drivers/net/ethernet/jme.c | 10 +++++----- drivers/net/ethernet/jme.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/jme.c +5 -5
@@ -1265,9 +1265,9 @@ jme_stop_shutdown_timer(struct jme_adapter *jme)jwrite32f (jme,JME_APMC , apmc); } -static void jme_link_change_tasklet (struct tasklet_struct *t) +static void jme_link_change_work (struct work_struct *work) { -struct jme_adapter *jme =from_tasklet (jme, t, linkch_task); + struct jme_adapter *jme = container_of(work, struct jme_adapter, linkch_task);struct net_device *netdev = jme->dev;int rc;
@@ -1510,7 +1510,7 @@ jme_intr_msi(struct jme_adapter *jme, u32 intrstat)* all other events are ignored */ jwrite32 (jme,JME_IEVE , intrstat); -tasklet_schedule (&jme->linkch_task); +schedule_work (&jme->linkch_task); goto out_reenable; }
@@ -1832,7 +1832,6 @@ jme_open(struct net_device *netdev)jme_clear_pm_disable_wol (jme);JME_NAPI_ENABLE (jme); -tasklet_setup (&jme->linkch_task, jme_link_change_tasklet);tasklet_setup (&jme->txclean_task, jme_tx_clean_tasklet);tasklet_setup (&jme->rxclean_task, jme_rx_clean_tasklet);tasklet_setup (&jme->rxempty_task, jme_rx_empty_tasklet);
@@ -1920,7 +1919,7 @@ jme_close(struct net_device *netdev)JME_NAPI_DISABLE (jme); -tasklet_kill (&jme->linkch_task); +cancel_work_sync (&jme->linkch_task);tasklet_kill (&jme->txclean_task);tasklet_kill (&jme->rxclean_task);tasklet_kill (&jme->rxempty_task);
@@ -3035,6 +3034,7 @@ jme_init_one(struct pci_dev *pdev,atomic_set (&jme->rx_empty,1 );tasklet_setup (&jme->pcc_task, jme_pcc_tasklet); +INIT_WORK (&jme->linkch_task, jme_link_change_work); jme->dpi.cur =PCC_P1 ; jme->reg_ghc =0 ;
drivers/net/ethernet/jme.h +1 -1
@@ -411,7 +411,7 @@ struct jme_adapter {struct tasklet_struct rxempty_task;struct tasklet_struct rxclean_task;struct tasklet_struct txclean_task; -struct tasklet_struct linkch_task; +struct work_struct linkch_task;struct tasklet_struct pcc_task;unsigned long flags;u32 reg_txcs;
PATCH 9/14 net: sundance: Use tasklet_disable_in_atomic().
In reply to Thomas GleixnerFrom: Sebastian Andrzej Siewior <[email protected]>
tasklet_disable() is used in the timer callback. This might be distangled, but without access to the hardware that's a bit risky.
Replace it with tasklet_disable_in_atomic() so tasklet_disable() can be changed to a sleep wait once all remaining atomic users are converted.
--- drivers/net/ethernet/dlink/sundance.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/dlink/sundance.c +1 -1
@@ -963,7 +963,7 @@ static void tx_timeout(struct net_deviceunsigned long flag;netif_stop_queue (dev); -tasklet_disable (&np->tx_tasklet); +tasklet_disable_in_atomic (&np->tx_tasklet);iowrite16 (0 , ioaddr + IntrEnable);printk (KERN_WARNING "%s: Transmit timed out, TxStatus %2.2x " "TxFrameId %2.2x,"
[tip: irq/core] net: sundance: Use tasklet_disable_in_atomic().
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 25cf87df1a3a85959bf1bf27df0eb2e6e04b2161 Gitweb: https://git.kernel.org/tip/25cf87df1a3a85959bf1bf27df0eb2e6e04b2161 Author: Sebastian Andrzej Siewior <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:12 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:34:00 +01:00
net: sundance: Use tasklet_disable_in_atomic().
tasklet_disable() is used in the timer callback. This might be distangled, but without access to the hardware that's a bit risky.
Replace it with tasklet_disable_in_atomic() so tasklet_disable() can be changed to a sleep wait once all remaining atomic users are converted.
--- drivers/net/ethernet/dlink/sundance.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/dlink/sundance.c +1 -1
@@ -963,7 +963,7 @@ static void tx_timeout(struct net_device *dev, unsigned int txqueue)unsigned long flag;netif_stop_queue (dev); -tasklet_disable (&np->tx_tasklet); +tasklet_disable_in_atomic (&np->tx_tasklet);iowrite16 (0 , ioaddr + IntrEnable);printk (KERN_WARNING "%s: Transmit timed out, TxStatus %2.2x " "TxFrameId %2.2x,"
PATCH 10/14 ath9k: Use tasklet_disable_in_atomic()
In reply to Thomas GleixnerFrom: Sebastian Andrzej Siewior <[email protected]>
All callers of ath9k_beacon_ensure_primary_slot() are preemptible / acquire a mutex except for this callchain:
spin_lock_bh(&sc->sc_pcu_lock);
ath_complete_reset()
-> ath9k_calculate_summary_state()
-> ath9k_beacon_ensure_primary_slot()It's unclear how that can be distangled, so use tasklet_disable_in_atomic() for now. This allows tasklet_disable() to become sleepable once the remaining atomic users are cleaned up.
--- drivers/net/wireless/ath/ath9k/beacon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/beacon.c +1 -1
@@ -251,7 +251,7 @@ void ath9k_beacon_ensure_primary_slot(stint first_slot =ATH_BCBUF ;int slot; -tasklet_disable (&sc->bcon_tasklet); +tasklet_disable_in_atomic (&sc->bcon_tasklet);/* Find first taken slot. */ for (slot =0 ; slot <ATH_BCBUF ; slot++) {
Re: [patch 10/14] ath9k: Use tasklet_disable_in_atomic()
Quoted 22 lines · Thomas Gleixner
From: Sebastian Andrzej Siewior <[email protected]>
All callers of
ath9k_beacon_ensure_primary_slot()are preemptible / acquire a mutex except for this callchain:spin_lock_bh(&sc->sc_pcu_lock); ath_complete_reset() -> ath9k_calculate_summary_state() -> ath9k_beacon_ensure_primary_slot()It's unclear how that can be distangled, so use
tasklet_disable_in_atomic()for now. This allowstasklet_disable()to become sleepable once the remaining atomic users are cleaned up.Signed-off-by Sebastian Andrzej Siewior <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>Cc Kalle Valo <[email protected]>Cc "David S. Miller" <[email protected]>Cc Jakub Kicinski <[email protected]>
Quoted 3 lines
--- drivers/net/wireless/ath/ath9k/beacon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
I assume this goes via some other tree:
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
[tip: irq/core] ath9k: Use tasklet_disable_in_atomic()
In reply to Thomas GleixnerThe following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 3250aa8a293b1859d76577714a3e1fe95732c721 Gitweb: https://git.kernel.org/tip/3250aa8a293b1859d76577714a3e1fe95732c721 Author: Sebastian Andrzej Siewior <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:13 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:34:02 +01:00
ath9k: Use tasklet_disable_in_atomic()
All callers of ath9k_beacon_ensure_primary_slot() are preemptible / acquire a mutex except for this callchain:
spin_lock_bh(&sc->sc_pcu_lock);
ath_complete_reset()
-> ath9k_calculate_summary_state()
-> ath9k_beacon_ensure_primary_slot()It's unclear how that can be distangled, so use tasklet_disable_in_atomic() for now. This allows tasklet_disable() to become sleepable once the remaining atomic users are cleaned up.
--- drivers/net/wireless/ath/ath9k/beacon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/beacon.c +1 -1
@@ -251,7 +251,7 @@ void ath9k_beacon_ensure_primary_slot(struct ath_softc *sc)int first_slot =ATH_BCBUF ;int slot; -tasklet_disable (&sc->bcon_tasklet); +tasklet_disable_in_atomic (&sc->bcon_tasklet);/* Find first taken slot. */ for (slot =0 ; slot <ATH_BCBUF ; slot++) {
PATCH 11/14 atm: eni: Use tasklet_disable_in_atomic() in the send() callback
In reply to Thomas GleixnerFrom: Sebastian Andrzej Siewior <[email protected]>
The atmdev_ops::send callback which calls tasklet_disable() is invoked with bottom halfs disabled from net_device_ops::ndo_start_xmit(). All other invocations of tasklet_disable() in this driver happen in preemptible context.
Change the send() call to use tasklet_disable_in_atomic() which allows tasklet_disable() to be made sleepable once the remaining atomic context usage sites are cleaned up.
--- drivers/atm/eni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/atm/eni.c +1 -1
@@ -2054,7 +2054,7 @@ static int eni_send(struct atm_vcc *vcc, } submitted++;ATM_SKB (skb)->vcc = vcc; -tasklet_disable (&ENI_DEV (vcc->dev)->task); +tasklet_disable_in_atomic (&ENI_DEV (vcc->dev)->task); res =do_tx (skb);tasklet_enable (&ENI_DEV (vcc->dev)->task);if (res == enq_ok)return 0 ;
[tip: irq/core] atm: eni: Use tasklet_disable_in_atomic() in the send() callback
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 405698ca359a23b1ef1a502ef2bdc4597dc6da36 Gitweb: https://git.kernel.org/tip/405698ca359a23b1ef1a502ef2bdc4597dc6da36 Author: Sebastian Andrzej Siewior <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:14 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:34:02 +01:00
atm: eni: Use tasklet_disable_in_atomic() in the send() callback
The atmdev_ops::send callback which calls tasklet_disable() is invoked with bottom halfs disabled from net_device_ops::ndo_start_xmit(). All other invocations of tasklet_disable() in this driver happen in preemptible context.
Change the send() call to use tasklet_disable_in_atomic() which allows tasklet_disable() to be made sleepable once the remaining atomic context usage sites are cleaned up.
--- drivers/atm/eni.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/atm/eni.c +1 -1
@@ -2054,7 +2054,7 @@ static int eni_send(struct atm_vcc *vcc,struct sk_buff *skb) } submitted++;ATM_SKB (skb)->vcc = vcc; -tasklet_disable (&ENI_DEV (vcc->dev)->task); +tasklet_disable_in_atomic (&ENI_DEV (vcc->dev)->task); res =do_tx (skb);tasklet_enable (&ENI_DEV (vcc->dev)->task);if (res == enq_ok)return 0 ;
PATCH 12/14 PCI: hv: Use tasklet_disable_in_atomic()
In reply to Thomas GleixnerFrom: Sebastian Andrzej Siewior <[email protected]>
The hv_compose_msi_msg() callback in irq_chip::irq_compose_msi_msg is invoked via irq_chip_compose_msi_msg(), which itself is always invoked from atomic contexts from the guts of the interrupt core code.
There is no way to change this w/o rewriting the whole driver, so use tasklet_disable_in_atomic() which allows to make tasklet_disable() sleepable once the remaining atomic users are addressed.
--- drivers/pci/controller/pci-hyperv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pci-hyperv.c +1 -1
@@ -1458,7 +1458,7 @@ static void hv_compose_msi_msg(struct ir* Prevents hv_pci_onchannelcallback() from running concurrently * in the tasklet. */ -tasklet_disable (&channel->callback_event); +tasklet_disable_in_atomic (&channel->callback_event);/* * Since this function is called with IRQ locks held, can't
Re: [patch 12/14] PCI: hv: Use tasklet_disable_in_atomic()
Quoted 10 lines · Thomas Gleixner
From: Sebastian Andrzej Siewior <[email protected]>
The
hv_compose_msi_msg()callback inirq_chip::irq_compose_msi_msgis invoked viairq_chip_compose_msi_msg(), which itself is always invoked from atomic contexts from the guts of the interrupt core code.There is no way to change this w/o rewriting the whole driver, so use
tasklet_disable_in_atomic()which allows to maketasklet_disable()sleepable once the remaining atomic users are addressed.
Quoted 11 lines
Signed-off-by Sebastian Andrzej Siewior <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>Cc "K. Y. Srinivasan" <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc Wei Liu <[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Rob Herring <[email protected]>Cc Bjorn Helgaas <[email protected]>
It'd be ideal if you could merge this as a group. Let me know if you want me to do anything else.
Quoted 16 lines
--- drivers/pci/controller/pci-hyperv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/controller/pci-hyperv.c +1
-1@@ -1458,7 +1458,7 @@ static void hv_compose_msi_msg(struct ir* Prevents hv_pci_onchannelcallback() from running concurrently * in the tasklet. */ -tasklet_disable (&channel->callback_event); +tasklet_disable_in_atomic (&channel->callback_event);/* * Since this function is called with IRQ locks held, can't
Re: [patch 12/14] PCI: hv: Use tasklet_disable_in_atomic()
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
From: Sebastian Andrzej Siewior <[email protected]>
The
hv_compose_msi_msg()callback inirq_chip::irq_compose_msi_msgis invoked viairq_chip_compose_msi_msg(), which itself is always invoked from atomic contexts from the guts of the interrupt core code.
Quoted 6 lines
There is no way to change this w/o rewriting the whole driver, so use
tasklet_disable_in_atomic()which allows to maketasklet_disable()sleepable once the remaining atomic users are addressed.Signed-off-by Sebastian Andrzej Siewior <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>
[tip: irq/core] PCI: hv: Use tasklet_disable_in_atomic()
In reply to Thomas GleixnerThe following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: be4017cea0aec6369275df7eafbb09682f810e7e Gitweb: https://git.kernel.org/tip/be4017cea0aec6369275df7eafbb09682f810e7e Author: Sebastian Andrzej Siewior <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:15 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:34:03 +01:00
PCI: hv: Use tasklet_disable_in_atomic()
The hv_compose_msi_msg() callback in irq_chip::irq_compose_msi_msg is invoked via irq_chip_compose_msi_msg(), which itself is always invoked from atomic contexts from the guts of the interrupt core code.
There is no way to change this w/o rewriting the whole driver, so use tasklet_disable_in_atomic() which allows to make tasklet_disable() sleepable once the remaining atomic users are addressed.
--- drivers/pci/controller/pci-hyperv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pci-hyperv.c +1 -1
@@ -1458,7 +1458,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)* Prevents hv_pci_onchannelcallback() from running concurrently * in the tasklet. */ -tasklet_disable (&channel->callback_event); +tasklet_disable_in_atomic (&channel->callback_event);/* * Since this function is called with IRQ locks held, can't
PATCH 13/14 firewire: ohci: Use tasklet_disable_in_atomic() where required
In reply to Thomas GleixnerFrom: Sebastian Andrzej Siewior <[email protected]>
tasklet_disable() is invoked in several places. Some of them are in atomic context which prevents a conversion of tasklet_disable() to a sleepable function.
The atomic callchains are:
ar_context_tasklet()
ohci_cancel_packet()
tasklet_disable()
...
ohci_flush_iso_completions()
tasklet_disable()
The invocation of tasklet_disable() from at_context_flush() is always in preemptible context.
Use tasklet_disable_in_atomic() for the two invocations in ohci_cancel_packet() and ohci_flush_iso_completions().
--- drivers/firewire/ohci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firewire/ohci.c +2 -2
@@ -2545,7 +2545,7 @@ static int ohci_cancel_packet(struct fw_struct driver_data *driver_data = packet->driver_data;int ret = -ENOENT ; -tasklet_disable (&ctx->tasklet); +tasklet_disable_in_atomic (&ctx->tasklet);if (packet->ack !=0 ) goto out;
@@ -3465,7 +3465,7 @@ static int ohci_flush_iso_completions(st struct iso_context *ctx = container_of(base, struct iso_context, base);int ret =0 ; -tasklet_disable (&ctx->context.tasklet); +tasklet_disable_in_atomic (&ctx->context.tasklet);if (!test_and_set_bit_lock (0 , &ctx->flushing_completions)) {context_tasklet ((unsigned long )&ctx->context);
[tip: irq/core] firewire: ohci: Use tasklet_disable_in_atomic() where required
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: f339fc16fba0167d67c4026678ef4c405bca3085 Gitweb: https://git.kernel.org/tip/f339fc16fba0167d67c4026678ef4c405bca3085 Author: Sebastian Andrzej Siewior <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:16 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:34:05 +01:00
firewire: ohci: Use tasklet_disable_in_atomic() where required
tasklet_disable() is invoked in several places. Some of them are in atomic context which prevents a conversion of tasklet_disable() to a sleepable function.
The atomic callchains are:
ar_context_tasklet()
ohci_cancel_packet()
tasklet_disable()
...
ohci_flush_iso_completions()
tasklet_disable()
The invocation of tasklet_disable() from at_context_flush() is always in preemptible context.
Use tasklet_disable_in_atomic() for the two invocations in ohci_cancel_packet() and ohci_flush_iso_completions().
--- drivers/firewire/ohci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firewire/ohci.c +2 -2
@@ -2545,7 +2545,7 @@ static int ohci_cancel_packet(struct fw_card *card, struct fw_packet *packet)struct driver_data *driver_data = packet->driver_data;int ret = -ENOENT ; -tasklet_disable (&ctx->tasklet); +tasklet_disable_in_atomic (&ctx->tasklet);if (packet->ack !=0 ) goto out;
@@ -3465,7 +3465,7 @@ static int ohci_flush_iso_completions(struct fw_iso_context *base) struct iso_context *ctx = container_of(base, struct iso_context, base);int ret =0 ; -tasklet_disable (&ctx->context.tasklet); +tasklet_disable_in_atomic (&ctx->context.tasklet);if (!test_and_set_bit_lock (0 , &ctx->flushing_completions)) {context_tasklet ((unsigned long )&ctx->context);
PATCH 14/14 tasklets: Switch tasklet_disable() to the sleep wait variant
In reply to Thomas Gleixner-- NOT FOR IMMEDIATE MERGING --
Now that all users of tasklet_disable() are invoked from sleepable context, convert it to use tasklet_unlock_wait() which might sleep.
--- include/linux/interrupt.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/interrupt.h +1 -2
@@ -716,8 +716,7 @@ static inline void tasklet_disable_in_atstatic inline void tasklet_disable (struct tasklet_struct *t) {tasklet_disable_nosync (t); -/* Spin wait until all atomic users are converted */ -tasklet_unlock_spin_wait (t); +tasklet_unlock_wait (t);smp_mb (); }
[tip: irq/core] tasklets: Switch tasklet_disable() to the sleep wait variant
The following commit has been merged into the irq/core branch of tip:
The following commit has been merged into the irq/core branch of tip:
Commit-ID: 6fd4e861250b5c89ad460a9f265caeb1bbbfc323 Gitweb: https://git.kernel.org/tip/6fd4e861250b5c89ad460a9f265caeb1bbbfc323 Author: Thomas Gleixner <[email protected]> AuthorDate: Tue, 09 Mar 2021 09:42:17 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 17 Mar 2021 16:34:07 +01:00
tasklets: Switch tasklet_disable() to the sleep wait variant
-- NOT FOR IMMEDIATE MERGING --
Now that all users of tasklet_disable() are invoked from sleepable context, convert it to use tasklet_unlock_wait() which might sleep.
--- include/linux/interrupt.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/interrupt.h +1 -2
@@ -711,8 +711,7 @@ static inline void tasklet_disable_in_atomic(struct tasklet_struct *t)static inline void tasklet_disable (struct tasklet_struct *t) {tasklet_disable_nosync (t); -/* Spin wait until all atomic users are converted */ -tasklet_unlock_spin_wait (t); +tasklet_unlock_wait (t);smp_mb (); }
Quoted 9 lines · Thomas Gleixner
This is a follow up to the review comments of the series which makes softirq processing
PREEMPT_RTsafe:https://lore.kernel.org/r/[email protected]
Peter suggested to replace the spin waiting in
tasklet_disable()andtasklet_kill()withwait_event(). This also gets rid of the ill definedsched_yield()intasklet_kill().
Quoted 6 lines
Analyzing all usage sites of
tasklet_disable()andtasklet_unlock_wait()we found that most of them are safe to be converted to a sleeping wait.Only a few instances invoke
tasklet_disable()from atomic context. A few bugs which have been found in course of this analysis have been already addressed seperately.