mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Arnd Bergmann <arnd@arndb.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Kay Sievers <kay.sievers@vrfy.org>,
	Brandon Philips <brandon@ifup.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [BUG 2.6.36-rc6] list corruption in module_bug_finalize
Date: Tue, 5 Oct 2010 00:43:38 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.00.1010050026170.2556@localhost6.localdomain6> (raw)
In-Reply-To: <201010041300.15234.arnd@arndb.de>

On Mon, 4 Oct 2010, Arnd Bergmann wrote:

> On Sunday 03 October 2010, Thomas Gleixner wrote:
> > Current mainline triggers a list corruption bug in
> > module_bug_finalize(). dmesg excerpt below.
> > 
> > The corresponding code says:
> > 
> >         /*
> >          * Strictly speaking this should have a spinlock to protect against
> >          * traversals, but since we only traverse on BUG()s, a spinlock
> >          * could potentially lead to deadlock and thus be counter-productive.
> >          */
> >         list_add(&mod->bug_list, &module_bug_list);
> > 
> > I can see the traversal problem vs. BUG(), but what's protecting the
> > list_add() ? BKL probably did, but is that true anymore ?
> 
> BKL hasn't been in this code path since before git.

Fair enough. I have to admit that I did not even look. :)
 
> I think this relatively recent change caused module_finalize to be
> called without module_mutex held:

Yeah.

> commit 75676500f8298f0ee89db12db97294883c4b768e
> Author: Rusty Russell <rusty@rustcorp.com.au>
> Date:   Sat Jun 5 11:17:36 2010 -0600
> 
>     module: make locking more fine-grained.
>     
>     Kay Sievers <kay.sievers@vrfy.org> reports that we still have some
>     contention over module loading which is slowing boot.
>     
>     Linus also disliked a previous "drop lock and regrab" patch to fix the
>     bne2 "gave up waiting for init of module libcrc32c" message.
>     
>     This is more ambitious: we only grab the lock where we need it.
>     
>     Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
>     Cc: Brandon Philips <brandon@ifup.org>
>     Cc: Kay Sievers <kay.sievers@vrfy.org>
>     Cc: Linus Torvalds <torvalds@linux-foundation.org>
> 
> 	Arnd

The patch below cures it.

Thanks,

	tglx

---->
diff --git a/lib/bug.c b/lib/bug.c
index 7cdfad8..40f32d8 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -92,18 +92,21 @@ int module_bug_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
 	}
 
 	/*
-	 * Strictly speaking this should have a spinlock to protect against
-	 * traversals, but since we only traverse on BUG()s, a spinlock
-	 * could potentially lead to deadlock and thus be counter-productive.
+	 * We need to take module_mutex here to protect the list add, though
+	 * it won't protect against a concurrent BUG().
 	 */
+	mutex_lock(&module_mutex);
 	list_add(&mod->bug_list, &module_bug_list);
+	mutex_unlock(&module_mutex);
 
 	return 0;
 }
 
 void module_bug_cleanup(struct module *mod)
 {
+	mutex_lock(&module_mutex);
 	list_del(&mod->bug_list);
+	mutex_unlock(&module_mutex);
 }
 
 #else

  reply	other threads:[~2010-10-04 22:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-03 19:51 Thomas Gleixner
2010-10-04 11:00 ` Arnd Bergmann
2010-10-04 22:43   ` Thomas Gleixner [this message]
2010-10-04 23:55     ` Linus Torvalds
2010-10-05  1:11       ` Linus Torvalds
2010-10-05  5:14     ` Rusty Russell
2010-10-05  7:30       ` Thomas Gleixner
2010-10-05 15:34         ` Linus Torvalds
2010-10-05 16:40           ` Thomas Gleixner
2010-10-05 17:17             ` Linus Torvalds
2010-10-05 17:43               ` Thomas Gleixner
2010-10-06  9:10                 ` Rusty Russell
2010-10-05  4:18 ` Rusty Russell
2010-10-05 11:08   ` Adrian Bunk

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=alpine.LFD.2.00.1010050026170.2556@localhost6.localdomain6 \
    --to=tglx@linutronix.de \
    --cc=arnd@arndb.de \
    --cc=brandon@ifup.org \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®