Re: lockdep null-ptr-deref

From: Peter Zijlstra
Date: Wed Sep 30 2020 - 15:02:50 EST


On Wed, Sep 30, 2020 at 08:18:18PM +0800, Boqun Feng wrote:

> For one thing, I do think that LOCK_READ_USED trace is helpful for
> better reporting, because if there is a read lock in the dependency path
> which causes the deadlock, it's better to have the LOCK_READ_USED trace
> to know at least the initial READ usage. For example, if we have
>
> void f1(...)
> {
> write_lock(&A);
> spin_lock(&C);
> // A -> C
> ...
> }
>
> void g(...)
> {
> read_lock(&A);
> ...
> }
> void f2(...)
> {
> spin_lock(&B);
> g(...);
> // B -> A
> }
>
> void f3(...) {
> spin_lock(&C);
> spin_lock(&B);
> // C -> B, trigger lockdep splat
> }
>
> when lockdep reports the deadlock (at the time f3() is called), it will
> be useful if we have a trace like:
>
> INITIAL READ usage at:
> g+0x.../0x...
> f2+0x.../0x...
>
> Thoughts?

Wouldn't that also be in LOCK_ENABLED_*_READ ?

That is, with PROVE_LOCKING on, the initial usage is bound to set more
states, except for !check||trylock usage, and those aren't really all
that interesting.