Re: [PATCH] lockdep: Add a document describing crossrelease feature

From: Boqun Feng
Date: Tue Jul 05 2016 - 20:45:53 EST


On Mon, Jul 04, 2016 at 03:42:59PM +0900, Byungchul Park wrote:
[snip]
> > > +2. A lock has dependency with all locks in the releasing context, having
> > > + been held since the lock was held.
> >
> > But you cannot tell this. The 'since the lock was held' thing fully
> > depends on timing and is not fundamentally correct.
> >
> > lock(A)
> > unlock(A)
> > lock(A)
> > wait_for(B)
> > unlock(A)
> > wake(B)
> >
> > Between the wait_for(B) and wake(B), _nothing_ has been held, yet still
> > there's the deadlock potential.
>
> Crossreleas feature can detect this situation as a deadlock. wait_for()
> is not an actual lock, but we can make it detectable by using acquring and
> releasing semantics on wait_for() and wake().
>
> > And note that if the timing was 'right', you would never get to wake(B)
> > because deadlock, so you'd never establish that there would be a
> > deadlock.
>
> If a deadlock actually happens, then we cannot establish it as you said.
> Remind that current lockdep does nothing for this situation. But at least
> crossrelease feature can detect this deadlock possibility at the time the
> dependency tree(graph) is built, which is better than doing nothing.
>

Confused, how?

Say the sequence of events is as follow:

(two tasks are initially with no lock held)

Task 1 Task 2
============= ====================
lock(A)
unlock(A)
lock(A)
wait_for(B) // acquire
wake(B) // commit + release
unlock(A)

by the time, the commit are called, the dependency tree will be built,
and we will find there is _no_ lock held before wake(B). Therefore at
the release stage, you will end up only adding dependency chain A->B in
the lockdep, right? And it looks like neither Task1 or Task2 will break
the dependency chain A->B. So how can crossrelease detect the potential
deadlock?

It will be better, that you could provide some samples that crossrelease
can detect after your confirmation.

Regards,
Boqun

Attachment: signature.asc
Description: PGP signature