Skip to contentSkip to conversation

check for stack overflow in ___might_sleep

PATCH New Eric Sandeen 2 participants 2 messages Dec 16, 2014 – Jan 14, 2015 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 check for stack overflow in ___might_sleep

Sometimes a "BUG: sleeping function called from invalid context" message is not indicative of locking problems, but is the result of a stack overflow corrupting the thread info.

Witness http://oss.sgi.com/archives/xfs/2014-02/msg00325.html
for example, which took a few go-rounds to sort out.

If we're printing the warning, things are wonky already, and it'd be informative to check for the stack end corruption at this point, too.

---

kernel/sched/core.c +3 -0
index b5797b7..4ef726c 100644
@@ -7328,6 +7328,9 @@ void ___might_sleep(const char *file, int line, int preempt_offset)
 			in_atomic(), irqs_disabled(),
 			current->pid, current->comm);
 
+	if (task_stack_end_corrupted(current))
+		printk(KERN_EMERG "Thread overran stack, or stack corrupted\n");
+
 	debug_show_held_locks(current);
 	if (irqs_disabled())
 		print_irqtrace_events(current);
#1 lore raw

[tip:sched/core] sched/debug: Check for stack overflow in ___might_sleep()

sched/debug: Check for stack overflow in ___might_sleep()
Commit-ID:  a8b686b3af4419f92e0ea5be1c76fb68363df8e6
Gitweb:     http://git.kernel.org/tip/a8b686b3af4419f92e0ea5be1c76fb68363df8e6
Author:     Eric Sandeen <[email protected]>
AuthorDate: Tue, 16 Dec 2014 16:25:28 -0600
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 14 Jan 2015 13:34:14 +0100

sched/debug: Check for stack overflow in ___might_sleep()

Sometimes a "BUG: sleeping function called from invalid context" message is not indicative of locking problems, but is the result of a stack overflow corrupting the thread info.

Witness http://oss.sgi.com/archives/xfs/2014-02/msg00325.html
for example, which took a few go-rounds to sort out.

If we're printing the warning, things are wonky already, and it'd be informative to check for the stack end corruption at this point, too.

---
 kernel/sched/core.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/core.c +3 -0
index c0accc0..56c9b79 100644
@@ -7325,6 +7325,9 @@ void ___might_sleep(const char *file, int line, int preempt_offset)
 			in_atomic(), irqs_disabled(),
 			current->pid, current->comm);
 
+	if (task_stack_end_corrupted(current))
+		printk(KERN_EMERG "Thread overran stack, or stack corrupted\n");
+
 	debug_show_held_locks(current);
 	if (irqs_disabled())
 		print_irqtrace_events(current);