Re: [PATCH 2/2] lockdep: Don't only check recursive read locksonce in a sequence

From: Frederic Weisbecker
Date: Thu Nov 19 2009 - 10:56:00 EST


On Wed, Nov 18, 2009 at 05:43:03PM +0800, Lai Jiangshan wrote:
> Frederic Weisbecker wrote:
> > Say we have the following locks:
> > A (rwlock, Aw: writelock, Ar: recursive read lock)
> > B (normal lock)
> >
> > and the following sequences:
> > Ar -> B -> Ar
> > Aw -> B
> >
> > This won't be detected as a lock inversion
>
> """
> read-preference <==> read-recursive ability (rwlock)
> otherwise ==> read-recursive disability (rwsem)
> """



I don't understand the idea of "read-preference". And btw I
don't understand why rwsem read locks are not considered as
recursive in lockdep.



> If "B -> Ar" is always after "Ar", it's NOT a really
> lock inversion because rwlock is read-preference, we
> can ignore all "Ar" which are after "B".



It's not a lock inversion in itself because it's legal to have:

Ar -> B -> Ar



> If sometimes "B -> Ar" is not after "Ar",
> then we have these sequences:
> B -> Ar
> Aw -> B
>
> Lockdep can detects it now(without this patch applied).
>
> Maybe I have misunderstood your patch.



Well.
In my example we have this sequence first:

Ar -> B -> Ar

And this second one:

Aw -> B

In the lockdep tree, the read lock won't even be registered,
so we'll just have Aw -> B in the tree.

If we insert these in the tree, we'll have one branch that will
look like that:

Aw
|
B
|
Ar

Like we do with any other kind of lock. We just plug the dependencies
between them. We know that B depends on Aw, but Ar also depends on B.
Although the merged sequence might never happen, there is still a risk
and the above is not legal.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/