From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: mingo@kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] lockdep: Check if nested lock is actually held
Date: Thu, 13 Sep 2012 11:59:53 +0200 [thread overview]
Message-ID: <1347530393.15764.115.camel@twins> (raw)
In-Reply-To: <5051A9E7.5040501@canonical.com>
On Thu, 2012-09-13 at 11:39 +0200, Maarten Lankhorst wrote:
> It is considered good form to lock the lock you claim to be nested in.
Uhm yeah.. cute. You actually found a site where this triggered?
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
> ---
> diff --git a/kernel/lockdep.c b/kernel/lockdep.c
> index ea9ee45..7175447 100644
> --- a/kernel/lockdep.c
> +++ b/kernel/lockdep.c
> @@ -2998,6 +2998,43 @@ EXPORT_SYMBOL_GPL(lockdep_init_map);
>
> struct lock_class_key __lockdep_no_validate__;
>
> +static int
> +print_lock_nested_lock_not_held(struct task_struct *curr,
> + struct held_lock *lock,
> + struct lockdep_map *nest,
> + unsigned long ip)
> +{
> + if (!debug_locks_off())
> + return 0;
> + if (debug_locks_silent)
> + return 0;
> +
> + printk("\n");
> + printk("==================================\n");
> + printk("[ BUG: Nested lock was not taken ]\n");
> + print_kernel_ident();
> + printk("----------------------------------\n");
> +
> + printk("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr));
> + print_lock(lock);
> +
> + printk("\nbut this task is not holding:\n");
> + printk("%s\n", nest->name);
> +
> + printk("\nstack backtrace:\n");
> + dump_stack();
> +
> + printk("\nother info that might help us debug this:\n");
> + lockdep_print_held_locks(curr);
> +
> + printk("\nstack backtrace:\n");
> + dump_stack();
> +
> + return 0;
> +}
> +
> +static int __lock_is_held(struct lockdep_map *lock);
> +
> /*
> * This gets called for every mutex_lock*()/spin_lock*() operation.
> * We maintain the dependency maps and validate the locking attempt:
> @@ -3139,6 +3176,10 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
> }
> chain_key = iterate_chain_key(chain_key, id);
>
> + if (nest_lock && !__lock_is_held(nest_lock))
> + return print_lock_nested_lock_not_held(curr, hlock,
> + nest_lock, ip);
At this time we've already set hlock->nest_lock, so I've shortened the
argument list here a little.
> if (!validate_chain(curr, lock, hlock, chain_head, chain_key))
> return 0;
>
>
next prev parent reply other threads:[~2012-09-13 10:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-13 9:39 [PATCH] lockdep: Check if nested lock is actually held Maarten Lankhorst
2012-09-13 9:59 ` Peter Zijlstra [this message]
2012-09-13 10:10 ` Maarten Lankhorst
2012-09-13 10:16 ` Peter Zijlstra
2012-09-14 6:18 ` [tip:core/locking] " tip-bot for Maarten Lankhorst
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=1347530393.15764.115.camel@twins \
--to=a.p.zijlstra@chello.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@canonical.com \
--cc=mingo@kernel.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).