Skip to content

Commit ee96f47

Browse files
Peter Zijlstragregkh
authored andcommitted
task_work: Fix NMI race condition
[ Upstream commit ef1ea98 ] __schedule() // disable irqs <NMI> task_work_add(current, work, TWA_NMI_CURRENT); </NMI> // current = next; // enable irqs <IRQ> task_work_set_notify_irq() test_and_set_tsk_thread_flag(current, TIF_NOTIFY_RESUME); // wrong task! </IRQ> // original task skips task work on its next return to user (or exit!) Fixes: 466e4d8 ("task_work: Add TWA_NMI_CURRENT as an additional notify mode.") Reported-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org> Link: https://patch.msgid.link/20250924080118.425949403@infradead.org Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 329f832 commit ee96f47

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/task_work.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ static struct callback_head work_exited; /* all we need is ->next == NULL */
99
#ifdef CONFIG_IRQ_WORK
1010
static void task_work_set_notify_irq(struct irq_work *entry)
1111
{
12-
test_and_set_tsk_thread_flag(current, TIF_NOTIFY_RESUME);
12+
/*
13+
* no-op IPI
14+
*
15+
* TWA_NMI_CURRENT will already have set the TIF flag, all
16+
* this interrupt does it tickle the return-to-user path.
17+
*/
1318
}
1419
static DEFINE_PER_CPU(struct irq_work, irq_work_NMI_resume) =
1520
IRQ_WORK_INIT_HARD(task_work_set_notify_irq);
@@ -98,6 +103,7 @@ int task_work_add(struct task_struct *task, struct callback_head *work,
98103
break;
99104
#ifdef CONFIG_IRQ_WORK
100105
case TWA_NMI_CURRENT:
106+
set_tsk_thread_flag(current, TIF_NOTIFY_RESUME);
101107
irq_work_queue(this_cpu_ptr(&irq_work_NMI_resume));
102108
break;
103109
#endif

0 commit comments

Comments
 (0)