All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Dennis Chen <kernel.org.gnu@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] <down,down_interruptible...>, kernel <3.2.9>
Date: Fri, 2 Mar 2012 15:22:09 +0000	[thread overview]
Message-ID: <201203021522.10518.arnd@arndb.de> (raw)
In-Reply-To: <CA+U0gVhRUv_dWkO2yntsLvG_L727c=0zrVRkN_ceiPUwoAGbBg@mail.gmail.com>

On Friday 02 March 2012, Dennis Chen wrote:
> Current down family functions use mismatch spin_lock pairs, this will
> incur some interrupt state chaos, for example,
> down_interruptible --
>      spin_lock_irqsave(&sem->lock, flags);              P1
>            __down_common--
>                  spin_unlock_irq(&sem->lock);              P2
>                 timeout = schedule_timeout(timeout);
>                 spin_lock_irq(&sem->lock);                  P3
> 
>      spin_unlock_irqrestore(&sem->lock, flags);       P4
> 
> Suppose 2 kernel thread A and B in an UP system call
> down_interruptible to get the semaphore, if the irq is OFF before A
> calls, in the section between P2 and P3,  the irq will be turned _ON_,
> then B begins to call down_interruptible, it will save a flag
> indicating irq is _ON_. So after A finish the path of
> down_interruptible, the irq is still _OFF_, but when B wakes up and
> finish the path, the irq will be _ON_. Actually, irq should be in on
> state before any down_interruptible calling, so
> spin_lock_irqsave/irqrestore is not necessary. Given it will make
> confusion for the reason of unmatched spin_lock pairs between
> down_interruptible and __down_common, so it's reason for the patch.
> Any comments?

You are right that the spin_lock_irqsave is unnecessary because
down() can only be called in non-atomic state with interrupts enabled.
Your patch will be tiny performance improvement on architectures where
saving the interrupt state does not come for free.

However, there is nothing in the code where we can end up with an
unexpected state, because both threads have their own copy of the
'flags' variable, which always contains the enabled state that gets
restored upon leaving the functions.

	Arnd

  reply	other threads:[~2012-03-02 15:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-02 14:20 [PATCH] <down,down_interruptible...>, kernel <3.2.9> Dennis Chen
2012-03-02 15:22 ` Arnd Bergmann [this message]
2012-03-03 10:44   ` Dennis Chen

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=201203021522.10518.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=kernel.org.gnu@gmail.com \
    --cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.