* [RESEND v2] irq: Refactor irq_wait_for_interrupt info to simplify the code
@ 2020-01-06 15:44 chengkaitao
2020-01-15 13:43 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: chengkaitao @ 2020-01-06 15:44 UTC (permalink / raw)
To: tglx; +Cc: linux-kernel, smuchun, Kaitao Cheng
From: Kaitao Cheng <pilgrimtao@gmail.com>
Cleanup extra if(test_and_clear_bit), and put the other one in front.
Signed-off-by: Kaitao Cheng <pilgrimtao@gmail.com>
---
kernel/irq/manage.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 1753486b440c..7266d0d30fa9 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -863,21 +863,15 @@ static int irq_wait_for_interrupt(struct irqaction *action)
for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
- if (kthread_should_stop()) {
- /* may need to run one last time */
- if (test_and_clear_bit(IRQTF_RUNTHREAD,
- &action->thread_flags)) {
- __set_current_state(TASK_RUNNING);
- return 0;
- }
+ if (test_and_clear_bit(IRQTF_RUNTHREAD,
+ &action->thread_flags)) {
__set_current_state(TASK_RUNNING);
- return -1;
+ return 0;
}
- if (test_and_clear_bit(IRQTF_RUNTHREAD,
- &action->thread_flags)) {
+ if (kthread_should_stop()) {
__set_current_state(TASK_RUNNING);
- return 0;
+ return -1;
}
schedule();
}
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RESEND v2] irq: Refactor irq_wait_for_interrupt info to simplify the code
2020-01-06 15:44 [RESEND v2] irq: Refactor irq_wait_for_interrupt info to simplify the code chengkaitao
@ 2020-01-15 13:43 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2020-01-15 13:43 UTC (permalink / raw)
To: chengkaitao; +Cc: linux-kernel, smuchun, Kaitao Cheng
chengkaitao <pilgrimtao@gmail.com> writes:
> From: Kaitao Cheng <pilgrimtao@gmail.com>
>
> Cleanup extra if(test_and_clear_bit), and put the other one in front.
That simplifies the code but opens a race window:
CPU 0 CPU 1
irq_wait_for_interrupt()
has not yet reached schedule()
free_irq()
remove_action();
synchronize_irq();
#ifdef CONFIG_DEBUG_SHIRQ
action->handler() if (test_and_clear_bit())
---> bit is not set yet
--> SET thread running
#endif
kthread_stop() if (kthread_stop())
---> Leave with bit set and thread active count != 0
That's just the most obvious example...
Thanks,
tglx
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-01-15 13:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-06 15:44 [RESEND v2] irq: Refactor irq_wait_for_interrupt info to simplify the code chengkaitao
2020-01-15 13:43 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).