public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Amerigo Wang <amwang@redhat.com>
Cc: linux-kernel@vger.kernel.org, Ben Woodard <bwoodard@llnl.gov>,
	David Howells <dhowells@redhat.com>,
	Brian Behlendorf <behlendorf1@llnl.gov>
Subject: Re: [Patch v4] rwsem: fix rwsem_is_locked() bugs
Date: Tue, 13 Oct 2009 13:34:19 -0700	[thread overview]
Message-ID: <20091013133419.3c8f5f21.akpm@linux-foundation.org> (raw)
In-Reply-To: <20091008092632.7101.62229.sendpatchset@localhost.localdomain>

On Thu, 8 Oct 2009 05:23:53 -0400
Amerigo Wang <amwang@redhat.com> wrote:

> --- a/include/linux/rwsem-spinlock.h
> +++ b/include/linux/rwsem-spinlock.h
> @@ -71,7 +71,13 @@ extern void __downgrade_write(struct rw_semaphore *sem);
>  
>  static inline int rwsem_is_locked(struct rw_semaphore *sem)
>  {
> -	return (sem->activity != 0);
> +	int ret = 1;
> +
> +	if (spin_trylock_irq(&sem->wait_lock)) {
> +		ret = (sem->activity != 0);
> +		spin_unlock_irq(&sem->wait_lock);
> +	}
> +	return ret;
>  }

a) probably to large to be inlined

b) the function will now cause bugs if called under
   local_irq_disable().  That wasn't the case before.  Fixable via
   spin_lock_irqsave().

In the present kernel there don't appear to be any irqs-off callers. 
There may of course be some out-of-tree ones which will get bitten by
this semantic change.

If we decide to leave this new rule in place then we should add a
WARN_ON(irqs_disabled()) to prevent hitting people with a nasty, subtle
bug.

Methinks that _irqsave() is better.

  parent reply	other threads:[~2009-10-13 20:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-08  9:23 [Patch v4] rwsem: fix rwsem_is_locked() bugs Amerigo Wang
2009-10-08 10:45 ` David Howells
2009-10-09  9:02   ` Amerigo Wang
2009-10-13 20:34 ` Andrew Morton [this message]
2009-10-14  9:32   ` Cong Wang

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=20091013133419.3c8f5f21.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=amwang@redhat.com \
    --cc=behlendorf1@llnl.gov \
    --cc=bwoodard@llnl.gov \
    --cc=dhowells@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox