From: peterz@infradead.org (Peter Zijlstra)
To: linux-arm-kernel@lists.infradead.org
Subject: BUG: spinlock recursion (sys_chdir, user_path_at, do_path_lookup ...)
Date: Thu, 13 Jan 2011 12:37:57 +0100 [thread overview]
Message-ID: <1294918677.19601.102.camel@laptop> (raw)
In-Reply-To: <alpine.LFD.2.00.1101131220240.2678@localhost6.localdomain6>
On Thu, 2011-01-13 at 12:21 +0100, Thomas Gleixner wrote:
> On Thu, 13 Jan 2011, Peter Zijlstra wrote:
>
> >
> > > On Wed, 2011-01-12 at 23:52 +0100, Thomas Gleixner wrote:
> >
> > > > @peterz: Why does lockdep ignore the lock recursion in that
> > > > spin_lock_nested() call?
> >
> > So after some hints on IRC on where to look:
> >
> > <tglx> spin_lock(&parent->d_lock);
> > <tglx> spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
> > <tglx> if parent == dentry
> >
> > That won't yell because you explicitly tell lockdep its ok, I know what
> > I'm doing.
> >
> > Several lockdep annotations (including this one) allow you to annotate
> > real bugs away, hence you really need to be sure about things when you
> > make them.
>
> Yeah, I suspected that, but checking whether the pointers are same
> would be nice as it would tell us right away where we fcked up :)
>
Something like the below would indeed do that, but it makes the
lock_acquire path more expensive, since it will now have to iterate the
held lock stack every time.
(not actually tested)
---
kernel/lockdep.c | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 42ba65d..d053d9a 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -2740,11 +2740,12 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
{
struct task_struct *curr = current;
struct lock_class *class = NULL;
- struct held_lock *hlock;
+ struct held_lock *hlock, *rhlock;
unsigned int depth, id;
int chain_head = 0;
int class_idx;
u64 chain_key;
+ int i;
if (!prove_locking)
check = 1;
@@ -2817,6 +2818,21 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
hlock->holdtime_stamp = lockstat_clock();
#endif
+ for (i = depth-1; i >= 0; i--) {
+ rhlock = curr->held_locks + i;
+ if (rhlock->instance == lock) {
+ if (debug_locks_off() || debug_locks_silent)
+ return 0;
+ printk("Lock recursion, trying to acquire:\n");
+ print_lock(hlock);
+ printk("while already holding:\n");
+ print_lock(rhlock);
+ printk("which is the same lock instance!\n");
+ dump_stack();
+ return 0;
+ }
+ }
+
if (check == 2 && !mark_irqflags(curr, hlock))
return 0;
next prev parent reply other threads:[~2011-01-13 11:37 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-12 20:59 BUG: spinlock recursion (sys_chdir, user_path_at, do_path_lookup ...) Ramirez Luna, Omar
2011-01-12 21:02 ` Uwe Kleine-König
2011-01-12 21:16 ` Ramirez Luna, Omar
2011-01-12 22:52 ` Thomas Gleixner
2011-01-13 8:09 ` Uwe Kleine-König
2011-01-13 11:01 ` Peter Zijlstra
2011-01-13 11:17 ` Peter Zijlstra
2011-01-13 11:21 ` Thomas Gleixner
2011-01-13 11:37 ` Peter Zijlstra [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-01-11 11:05 Uwe Kleine-König
2011-01-12 7:52 ` Uwe Kleine-König
2011-01-12 10:57 ` Thomas Gleixner
2011-01-12 12:03 ` Uwe Kleine-König
2011-01-12 12:35 ` Russell King - ARM Linux
2011-01-12 12:48 ` Russell King - ARM Linux
2011-01-12 12:56 ` Thomas Gleixner
2011-01-18 16:59 ` Maciej Rutecki
2011-01-18 22:19 ` Nick Piggin
2011-01-19 7:43 ` Uwe Kleine-König
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=1294918677.19601.102.camel@laptop \
--to=peterz@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).