Re: [PATCH] proc: Disable /proc/$pid/wchan
From: Josh Poimboeuf
Date: Wed Sep 29 2021 - 17:10:36 EST
On Wed, Sep 29, 2021 at 09:40:26PM +0200, Peter Zijlstra wrote:
> On Wed, Sep 29, 2021 at 11:54:55AM -0700, Kees Cook wrote:
>
> > > > > > > It's supposed to show where a blocked task is blocked; the "wait
> > > > > > > channel".
>
> > Since I think we're considering get_wchan() to be slow-path, can we just
> > lock the runqueue and use arch_stack_walk_reliable()?
>
> Funny thing, when a task is blocked it isn't on the runqueue :-)
>
> So if all we want to do is capture a blocked task and fail otherwise we
> don't need the rq->lock at all.
>
> Something like:
>
> unsigned long ip = 0;
>
> raw_spin_lock_irq(&p->pi_lock);
> state = READ_ONCE(p->__state);
> smp_rmb(); /* see try_to_wake_up() */
> if (state == TASK_RUNNING || state == TASK_WAKING || p->on_rq)
> goto unlock;
>
> ip = /* do actual stack walk on a blocked task */
> unlock:
> raw_spin_unlock_irq(&p->pi_lock);
>
> return ip;
Ah, cool :-)
I'd also add that I don't see any reason to use the "reliable" unwinding
variant. AFAIK, just basic stack_trace_save_tsk() should be sufficient.
--
Josh