public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Cong Wang <amwang@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
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: Wed, 14 Oct 2009 17:32:51 +0800	[thread overview]
Message-ID: <4AD59AC3.9020807@redhat.com> (raw)
In-Reply-To: <20091013133419.3c8f5f21.akpm@linux-foundation.org>

Andrew Morton wrote:
> 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


Yeah, maybe, I forgot spin_trylock_irq() and spin_unlock_irq
are macros.

> 
> 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.


My bad, I misunderstood spin_lock_irqsave(), thus used spin_lock_irq().
:( Will update the patch now.

Thanks!

      reply	other threads:[~2009-10-14  9:30 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
2009-10-14  9:32   ` Cong Wang [this message]

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=4AD59AC3.9020807@redhat.com \
    --to=amwang@redhat.com \
    --cc=akpm@linux-foundation.org \
    --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