From: Gautham R Shenoy <ego@in.ibm.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
Hugh Dickins <hugh@veritas.com>
Subject: Re: [PATCH 1/2] lockdep: fix recursive read lock validation
Date: Thu, 13 Mar 2008 01:56:58 +0530 [thread overview]
Message-ID: <20080312202658.GA7856@in.ibm.com> (raw)
In-Reply-To: <20080312121323.697634000@chello.nl>
On Wed, Mar 12, 2008 at 01:09:21PM +0100, Peter Zijlstra wrote:
> __lock_acquire( .read = 2 )
> hlock->read = read; /* [1] */
> validate_chain()
> ret = check_deadlock(); /* returns 2 when recursive */
>
> if (ret == 2)
> hlock->read = 2; /* but it was already 2 from [1] */
>
> check_prevs_add()
> if (hlock->read != 2)
> /* add to dependency chain */
>
> So it will never add a recursive read lock to the dependency chain. Fix this
> by setting hlock->read to 1 when its the first recursive lock instance.
>
> This means that the following sequence is now invalid, whereas previously
> it was considered valid:
>
> rlock(a); rlock(b); runlock(b); runlock(a)
> rlock(b); rlock(a);
>
> It really is invalid when considered against write locks.
>
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> CC: Gautham R Shenoy <ego@in.ibm.com>
Tested-by: Gautham R Shenoy <ego@in.ibm.com>
> ---
> kernel/lockdep.c | 9 ++++-----
> lib/locking-selftest.c | 12 ++++++------
> 2 files changed, 10 insertions(+), 11 deletions(-)
>
> Index: linux-2.6-2/kernel/lockdep.c
> ===================================================================
> --- linux-2.6-2.orig/kernel/lockdep.c
> +++ linux-2.6-2/kernel/lockdep.c
> @@ -1557,12 +1557,11 @@ static int validate_chain(struct task_st
> if (!ret)
> return 0;
> /*
> - * Mark recursive read, as we jump over it when
> - * building dependencies (just like we jump over
> - * trylock entries):
> + * If we are the first recursive read, don't jump over our
> + * dependency.
> */
> - if (ret == 2)
> - hlock->read = 2;
> + if (hlock->read == 2 && ret != 2)
> + hlock->read = 1;
> /*
> * Add dependency only if this lock is not the head
> * of the chain, and if it's not a secondary read-lock:
> Index: linux-2.6-2/lib/locking-selftest.c
> ===================================================================
> --- linux-2.6-2.orig/lib/locking-selftest.c
> +++ linux-2.6-2/lib/locking-selftest.c
> @@ -1135,12 +1135,12 @@ void locking_selftest(void)
> debug_locks_silent = !debug_locks_verbose;
>
> DO_TESTCASE_6R("A-A deadlock", AA);
> - DO_TESTCASE_6R("A-B-B-A deadlock", ABBA);
> - DO_TESTCASE_6R("A-B-B-C-C-A deadlock", ABBCCA);
> - DO_TESTCASE_6R("A-B-C-A-B-C deadlock", ABCABC);
> - DO_TESTCASE_6R("A-B-B-C-C-D-D-A deadlock", ABBCCDDA);
> - DO_TESTCASE_6R("A-B-C-D-B-D-D-A deadlock", ABCDBDDA);
> - DO_TESTCASE_6R("A-B-C-D-B-C-D-A deadlock", ABCDBCDA);
> + DO_TESTCASE_6("A-B-B-A deadlock", ABBA);
> + DO_TESTCASE_6("A-B-B-C-C-A deadlock", ABBCCA);
> + DO_TESTCASE_6("A-B-C-A-B-C deadlock", ABCABC);
> + DO_TESTCASE_6("A-B-B-C-C-D-D-A deadlock", ABBCCDDA);
> + DO_TESTCASE_6("A-B-C-D-B-D-D-A deadlock", ABCDBDDA);
> + DO_TESTCASE_6("A-B-C-D-B-C-D-A deadlock", ABCDBCDA);
> DO_TESTCASE_6("double unlock", double_unlock);
> DO_TESTCASE_6("initialize held", init_held);
> DO_TESTCASE_6_SUCCESS("bad unlock order", bad_unlock_order);
>
> --
--
Thanks and Regards
gautham
next prev parent reply other threads:[~2008-03-12 20:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-12 12:09 [PATCH 0/2] lockdep vs recursive read locks Peter Zijlstra
2008-03-12 12:09 ` [PATCH 1/2] lockdep: fix recursive read lock validation Peter Zijlstra
2008-03-12 20:26 ` Gautham R Shenoy [this message]
2008-03-12 12:09 ` [PATCH 2/2] lockdep: fix fib_hash softirq inversion Peter Zijlstra
2008-03-13 3:50 ` [PATCH] net/lockdep: Make nl_table_lock read acquire softirq safe Gautham R Shenoy
2008-03-13 6:08 ` [PATCH 2/2] lockdep: fix fib_hash softirq inversion David Miller
2008-03-13 9:40 ` Arjan van de Ven
2008-03-13 11:25 ` [PATCH 0/2] lockdep vs recursive read locks Hugh Dickins
2008-03-14 7:35 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080312202658.GA7856@in.ibm.com \
--to=ego@in.ibm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox