Skip to contentSkip to conversation

exit: Detect and fix irq disabled state in oops

PATCH In review Nicholas Piggin 2 participants 2 messages Jan 20, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exit: Detect and fix irq disabled state in oops

If a task oopses with irqs disabled, this can cause various cascading problems in the oops path such as sleep-from-invalid warnings, and potentially worse.

Since commit 0258b5fd7c712 ("coredump: Limit coredumps to a single thread group"), the unconditional irq enable in coredump_task_exit() will "fix" the irq state to be enabled early in do_exit(), so currently this may not be triggerable, but that is coincidental and fragile.

Detect and fix the irqs_disabled() condition in the oops path before calling do_exit(), similarly to the way in_atomic() is handled.

---
Hi Peter,

Would you consider taking this through the sched tree?

Thanks,
Nick

 kernel/exit.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/exit.c +7 -0
index 15dc2ec80c46..bccfa4218356 100644
@@ -807,6 +807,8 @@ void __noreturn do_exit(long code)
 	struct task_struct *tsk = current;
 	int group_dead;
 
+	WARN_ON(irqs_disabled());
+
 	synchronize_group_exit(tsk, code);
 
 	WARN_ON(tsk->plug);
@@ -938,6 +940,11 @@ void __noreturn make_task_dead(int signr)
 	if (unlikely(!tsk->pid))
 		panic("Attempted to kill the idle task!");
 
+	if (unlikely(irqs_disabled())) {
+		pr_info("note: %s[%d] exited with irqs disabled\n",
+			current->comm, task_pid_nr(current));
+		local_irq_enable();
+	}
 	if (unlikely(in_atomic())) {
 		pr_info("note: %s[%d] exited with preempt_count %d\n",
 			current->comm, task_pid_nr(current),
Signature · 1 line
2.37.2
#1 lore raw
Quoted 12 lines · Nicholas Piggin

If a task oopses with irqs disabled, this can cause various cascading problems in the oops path such as sleep-from-invalid warnings, and potentially worse.

Since commit 0258b5fd7c712 ("coredump: Limit coredumps to a single thread group"), the unconditional irq enable in coredump_task_exit() will "fix" the irq state to be enabled early in do_exit(), so currently this may not be triggerable, but that is coincidental and fragile.

Detect and fix the irqs_disabled() condition in the oops path before calling do_exit(), similarly to the way in_atomic() is handled.

Quoted 8 lines

---
Hi Peter,

Would you consider taking this through the sched tree?

Yep, can do, let me go queue it.