From: Jerome Marchand <jmarchan@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fix a race between /proc/lock_stat and module unloading
Date: Tue, 02 Jun 2015 16:15:24 +0200 [thread overview]
Message-ID: <556DBA7C.3020909@redhat.com> (raw)
In-Reply-To: <20150602105013.GS3644@twins.programming.kicks-ass.net>
[-- Attachment #1: Type: text/plain, Size: 2782 bytes --]
On 06/02/2015 12:50 PM, Peter Zijlstra wrote:
> On Tue, Jun 02, 2015 at 11:54:13AM +0200, Jerome Marchand wrote:
>>
>> I guess I jumped to conclusion here and my explanation is wrong. However
>> there is still a bug which occurs when the kernel tries to access
>> class->name is seq_stats:
>>
>> [ 43.533732] BUG: unable to handle kernel paging request at
>> ffffffffa03181ce
>> [ 43.534006] IP: [<ffffffff8142b489>] strnlen+0x9/0x50
>
> Does something like so cure things?
Yes, I can't reproduce the issue anymore.
>
> ---
> kernel/locking/lockdep.c | 3 ++-
> kernel/locking/lockdep_proc.c | 22 +++++++++++++++++-----
> 2 files changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
> index a0831e1b99f4..50ed2685f937 100644
> --- a/kernel/locking/lockdep.c
> +++ b/kernel/locking/lockdep.c
> @@ -3900,7 +3900,8 @@ static void zap_class(struct lock_class *class)
> list_del_rcu(&class->hash_entry);
> list_del_rcu(&class->lock_entry);
>
> - class->key = NULL;
> + WRITE_ONCE(class->key, NULL);
> + WRITE_ONCE(class->name, NULL);
> }
>
> static inline int within(const void *addr, void *start, unsigned long size)
> diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
> index ef43ac4bafb5..03946779eacc 100644
> --- a/kernel/locking/lockdep_proc.c
> +++ b/kernel/locking/lockdep_proc.c
> @@ -426,10 +426,12 @@ static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
>
> static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
> {
> - char name[39];
> - struct lock_class *class;
> + struct lockdep_subclass_key *ckey;
> struct lock_class_stats *stats;
> + struct lock_class *class;
> int i, namelen;
> + char name[39];
> + char *cname;
>
> class = data->class;
> stats = &data->stats;
> @@ -440,15 +442,25 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
> if (class->subclass)
> namelen -= 2;
>
> - if (!class->name) {
> + rcu_read_lock_sched();
> + cname = rcu_dereference_sched(class->name);
> + ckey = rcu_dereference_sched(class->key);
> +
> + if (!cname && !ckey) {
> + rcu_read_unlock_sched();
> + return;
> +
> + } else if (!cname) {
> char str[KSYM_NAME_LEN];
> const char *key_name;
>
> - key_name = __get_key_name(class->key, str);
> + key_name = __get_key_name(ckey, str);
> snprintf(name, namelen, "%s", key_name);
> } else {
> - snprintf(name, namelen, "%s", class->name);
> + snprintf(name, namelen, "%s", cname);
> }
> + rcu_read_unlock_sched();
> +
> namelen = strlen(name);
> if (class->name_version > 1) {
> snprintf(name+namelen, 3, "#%d", class->name_version);
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-06-02 14:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-29 12:47 [PATCH] fix a race between /proc/lock_stat and module unloading Jerome Marchand
2015-06-02 9:30 ` Peter Zijlstra
2015-06-02 9:54 ` Jerome Marchand
2015-06-02 10:50 ` Peter Zijlstra
2015-06-02 14:15 ` Jerome Marchand [this message]
2015-06-02 15:01 ` Peter Zijlstra
2015-06-07 17:45 ` [tip:locking/urgent] lockdep: Fix a race between /proc/ lock_stat and module unload tip-bot for 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=556DBA7C.3020909@redhat.com \
--to=jmarchan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@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