linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* SMP: BUG() on cat /proc/$PID/stack
@ 2011-01-13 18:54 Rabin Vincent
  2011-01-13 23:11 ` Russell King - ARM Linux
  0 siblings, 1 reply; 4+ messages in thread
From: Rabin Vincent @ 2011-01-13 18:54 UTC (permalink / raw)
  To: linux-arm-kernel

On SMP, this BUG() in save_stack_trace_tsk() can be easily triggered
from user space by reading /proc/$PID/stack, where $PID is any pid but
the current process:

        if (tsk != current) {
#ifdef CONFIG_SMP
                /*
                 * What guarantees do we have here that 'tsk'
                 * is not running on another CPU?
                 */
                BUG();
#else

x86 appears to go ahead in this case, but has its stack walking code
check at every step that the stack pointer it's reading from is valid --
is this what is needed in the ARM unwind code to get rid of this BUG()?

Also, get_wchan() does similar stack walking but there it just checks
for task->state != TASK_RUNNING before.  Is that a sufficient check
there?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* SMP: BUG() on cat /proc/$PID/stack
  2011-01-13 18:54 SMP: BUG() on cat /proc/$PID/stack Rabin Vincent
@ 2011-01-13 23:11 ` Russell King - ARM Linux
  2011-01-15  4:56   ` Rabin Vincent
  2011-01-19 17:04   ` Rabin Vincent
  0 siblings, 2 replies; 4+ messages in thread
From: Russell King - ARM Linux @ 2011-01-13 23:11 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 14, 2011 at 12:24:19AM +0530, Rabin Vincent wrote:
> On SMP, this BUG() in save_stack_trace_tsk() can be easily triggered
> from user space by reading /proc/$PID/stack, where $PID is any pid but
> the current process:
> 
>         if (tsk != current) {
> #ifdef CONFIG_SMP
>                 /*
>                  * What guarantees do we have here that 'tsk'
>                  * is not running on another CPU?
>                  */
>                 BUG();
> #else
> 
> x86 appears to go ahead in this case, but has its stack walking code
> check at every step that the stack pointer it's reading from is valid --
> is this what is needed in the ARM unwind code to get rid of this BUG()?

x86 stack walking is very different from ARM unwinding.  I'd rather not
expose the unwinder to a volatile stack - that's probably a recipe for
it "sometimes" working and other times going oops because the stack
changed beneath it.

I suspect this may be one of the reasons x86 merged a dwarf unwinder
and then threw it out as it was too unreliable.

So, rather than going BUG(), lets instead return a terminated trace -
something like this.  Could you test and report back please?

Thanks.

diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c
index c2e112e..381d23a 100644
--- a/arch/arm/kernel/stacktrace.c
+++ b/arch/arm/kernel/stacktrace.c
@@ -94,10 +94,13 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
 	if (tsk != current) {
 #ifdef CONFIG_SMP
 		/*
-		 * What guarantees do we have here that 'tsk'
-		 * is not running on another CPU?
+		 * What guarantees do we have here that 'tsk' is not
+		 * running on another CPU?  For now, ignore it as we
+		 * can't guarantee we won't explode.
 		 */
-		BUG();
+		if (trace->nr_entries < trace->max_entries)
+			trace->entries[trace->nr_entries++] = ULONG_MAX;
+		return;
 #else
 		data.no_sched_functions = 1;
 		frame.fp = thread_saved_fp(tsk);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* SMP: BUG() on cat /proc/$PID/stack
  2011-01-13 23:11 ` Russell King - ARM Linux
@ 2011-01-15  4:56   ` Rabin Vincent
  2011-01-19 17:04   ` Rabin Vincent
  1 sibling, 0 replies; 4+ messages in thread
From: Rabin Vincent @ 2011-01-15  4:56 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jan 14, 2011 at 04:41, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:
> So, rather than going BUG(), lets instead return a terminated trace -
> something like this. ?Could you test and report back please?

Tested-by: Rabin Vincent <rabin@rab.in>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* SMP: BUG() on cat /proc/$PID/stack
  2011-01-13 23:11 ` Russell King - ARM Linux
  2011-01-15  4:56   ` Rabin Vincent
@ 2011-01-19 17:04   ` Rabin Vincent
  1 sibling, 0 replies; 4+ messages in thread
From: Rabin Vincent @ 2011-01-19 17:04 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Jan 13, 2011 at 11:11:36PM +0000, Russell King - ARM Linux wrote:
> x86 stack walking is very different from ARM unwinding.  I'd rather not
> expose the unwinder to a volatile stack - that's probably a recipe for
> it "sometimes" working and other times going oops because the stack
> changed beneath it.

Even on UP, with preemption enabled, isn't there no guarantee that the
target stack won't change beneath us, since the task we're examining can
preempt us?

Don't we need something like the below?

8<------

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-19 17:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-13 18:54 SMP: BUG() on cat /proc/$PID/stack Rabin Vincent
2011-01-13 23:11 ` Russell King - ARM Linux
2011-01-15  4:56   ` Rabin Vincent
2011-01-19 17:04   ` Rabin Vincent

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).