From: "Américo Wang" <xiyou.wangcong@gmail.com>
To: Kevin Hilman <khilman@deeprootsystems.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>,
Yinghai Lu <yinghai@kernel.org>, Rabin Vincent <rabin@rab.in>,
lkml <linux-kernel@vger.kernel.org>,
penberg@cs.helsinki.fi, cl@linux-foundation.org,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
linux-arch@vger.kernel.org, David Howells <dhowells@redhat.com>
Subject: Re: start_kernel(): bug: interrupts were enabled early
Date: Thu, 8 Apr 2010 23:55:46 +0800 [thread overview]
Message-ID: <20100408155546.GB4213@hack> (raw)
In-Reply-To: <878w8zcc6a.fsf@deeprootsystems.com>
On Wed, Apr 07, 2010 at 12:09:17PM -0700, Kevin Hilman wrote:
>Linus Torvalds <torvalds@linux-foundation.org> writes:
>
>> On Wed, 31 Mar 2010, H. Peter Anvin wrote:
>>>
>>> The obvious way to fix this would be to use
>>> spin_lock_irqsave..spin_lock_irqrestore in __down_read as well as in the
>>> other locations; I don't have a good feel for what the cost of doing so
>>> would be, though. On x86 it's fairly expensive simply because the only
>>> way to save the state is to push it on the stack, which the compiler
>>> doesn't deal well with, but this code isn't used on x86.
>>
>
>[...]
>
>> So making the slow-path do the spin_[un]lock_irq{save,restore}() versions
>> sounds like the right thing. It won't be a performance issue: it _is_ the
>> slow-path, and we're already doing the expensive part (the spinlock itself
>> and the irq thing).
>>
>> So ACK on the idea. Who wants to write the trivial patch and test it?
>
>OK, I'll bite since I was seeing boot-time hangs on ARM (TI OMAP3) due
>to this. Patch below.
>
>Kevin
>
>
>From 7baff4008353bbfd2a2e2a4da22b87bc4efa4194 Mon Sep 17 00:00:00 2001
>From: Kevin Hilman <khilman@deeprootsystems.com>
>Date: Wed, 7 Apr 2010 11:52:46 -0700
>Subject: [PATCH] rwsem generic spinlock: use IRQ save/restore spinlocks
>
>rwsems can be used with IRQs disabled, particularily in early boot
>before IRQs are enabled. Currently the spin_unlock_irq() usage in the
>slow-patch will unconditionally enable interrupts and cause problems
>since interrupts are not yet initialized or enabled.
>
>This patch uses save/restore versions of IRQ spinlocks in the slowpath
>to ensure interrupts are not unintentionally disabled.
>
>Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
This looks reasonable and fine for me.
Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com>
Thanks.
>---
> lib/rwsem-spinlock.c | 14 ++++++++------
> 1 files changed, 8 insertions(+), 6 deletions(-)
>
>diff --git a/lib/rwsem-spinlock.c b/lib/rwsem-spinlock.c
>index ccf95bf..ffc9fc7 100644
>--- a/lib/rwsem-spinlock.c
>+++ b/lib/rwsem-spinlock.c
>@@ -143,13 +143,14 @@ void __sched __down_read(struct rw_semaphore *sem)
> {
> struct rwsem_waiter waiter;
> struct task_struct *tsk;
>+ unsigned long flags;
>
>- spin_lock_irq(&sem->wait_lock);
>+ spin_lock_irqsave(&sem->wait_lock, flags);
>
> if (sem->activity >= 0 && list_empty(&sem->wait_list)) {
> /* granted */
> sem->activity++;
>- spin_unlock_irq(&sem->wait_lock);
>+ spin_unlock_irqrestore(&sem->wait_lock, flags);
> goto out;
> }
>
>@@ -164,7 +165,7 @@ void __sched __down_read(struct rw_semaphore *sem)
> list_add_tail(&waiter.list, &sem->wait_list);
>
> /* we don't need to touch the semaphore struct anymore */
>- spin_unlock_irq(&sem->wait_lock);
>+ spin_unlock_irqrestore(&sem->wait_lock, flags);
>
> /* wait to be given the lock */
> for (;;) {
>@@ -209,13 +210,14 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
> {
> struct rwsem_waiter waiter;
> struct task_struct *tsk;
>+ unsigned long flags;
>
>- spin_lock_irq(&sem->wait_lock);
>+ spin_lock_irqsave(&sem->wait_lock, flags);
>
> if (sem->activity == 0 && list_empty(&sem->wait_list)) {
> /* granted */
> sem->activity = -1;
>- spin_unlock_irq(&sem->wait_lock);
>+ spin_unlock_irqrestore(&sem->wait_lock, flags);
> goto out;
> }
>
>@@ -230,7 +232,7 @@ void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
> list_add_tail(&waiter.list, &sem->wait_list);
>
> /* we don't need to touch the semaphore struct anymore */
>- spin_unlock_irq(&sem->wait_lock);
>+ spin_unlock_irqrestore(&sem->wait_lock, flags);
>
> /* wait to be given the lock */
> for (;;) {
>--
>1.7.0.2
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at http://www.tux.org/lkml/
--
Live like a child, think like the god.
next prev parent reply other threads:[~2010-04-08 15:52 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-25 19:41 start_kernel(): bug: interrupts were enabled early Rabin Vincent
2010-03-31 20:40 ` Andrew Morton
2010-03-31 20:47 ` Yinghai Lu
2010-03-31 20:52 ` Andrew Morton
2010-03-31 21:12 ` H. Peter Anvin
2010-03-31 21:28 ` Andrew Morton
2010-03-31 22:35 ` Benjamin Herrenschmidt
2010-04-01 16:13 ` Linus Torvalds
2010-04-01 14:27 ` Andrew Morton
2010-04-01 20:12 ` Linus Torvalds
2010-04-02 14:46 ` David Howells
2010-04-02 14:54 ` Linus Torvalds
2010-04-07 19:09 ` Kevin Hilman
2010-04-08 15:55 ` Américo Wang [this message]
2010-03-31 21:01 ` Matthew Wilcox
2010-03-31 21:05 ` H. Peter Anvin
2010-03-31 21:17 ` Matthew Wilcox
2010-03-31 21:42 ` Christoph Lameter
2010-03-31 21:54 ` Russell King
2010-03-31 21:57 ` H. Peter Anvin
2010-03-31 22:30 ` Russell King
2010-03-31 22:37 ` Benjamin Herrenschmidt
2010-03-31 22:49 ` Andrew Morton
2010-04-01 1:17 ` Benjamin Herrenschmidt
2010-03-31 22:26 ` Andrew Morton
2010-04-01 6:26 ` H. Peter Anvin
2010-04-01 3:33 ` Andrew Morton
2010-04-01 6:48 ` Benjamin Herrenschmidt
2010-04-01 16:15 ` H. Peter Anvin
2010-04-01 11:06 ` David Howells
2010-04-01 15:55 ` Christoph Lameter
2010-04-01 23:00 ` Benjamin Herrenschmidt
2010-04-01 6:50 ` Benjamin Herrenschmidt
2010-03-31 22:36 ` Benjamin Herrenschmidt
2010-04-01 15:57 ` Christoph Lameter
2010-03-31 21:05 ` Russell King
2010-03-31 21:08 ` H. Peter Anvin
2010-03-31 22:31 ` Benjamin Herrenschmidt
2010-03-31 22:36 ` H. Peter Anvin
2010-03-31 22:58 ` David Howells
2010-04-01 9:41 ` Jamie Lokier
2010-04-01 11:23 ` Matthew Wilcox
2010-04-01 10:50 ` David Howells
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=20100408155546.GB4213@hack \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=cl@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=hpa@zytor.com \
--cc=khilman@deeprootsystems.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
--cc=rabin@rab.in \
--cc=torvalds@linux-foundation.org \
--cc=yinghai@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).