linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: David Howells <dhowells@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>,
	milosz@adfin.com,
	"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Is spin_is_locked() safe to use with BUG_ON()/WARN_ON()?
Date: Thu, 23 May 2013 07:59:38 -0700	[thread overview]
Message-ID: <CA+55aFww-UYfLA4cN6MSkeXzmAnAruShddAPegCpn+5yd1HGmQ@mail.gmail.com> (raw)
In-Reply-To: <6402.1369320636@warthog.procyon.org.uk>

On Thu, May 23, 2013 at 7:50 AM, David Howells <dhowells@redhat.com> wrote:
>
> We are using spin_is_locked() in a few places to give a warning or an oops if
> either a spinlock is not held or if it is held.  I'm not sure all of these are
> safe.

No, they're not. On SMP, you can get spurious "it's locked" (because
somebody *else* took the lock on another CPU) and on UP you'll always
get "it's unlocked".

So it's never safe to check the state, at least not without checking
for SMP or UP (and realizing that in the SMP case you can only assert
that it's held).

I guess we could change the UP case to always return "it's locked".
But since you'd better know what you're doing with "spin_is_locked()",
I don't think it's worth it making it easier to use.

> Take uas_try_complete() in drivers/usb/storage/uas.c which does:
>
>         WARN_ON(!spin_is_locked(&devinfo->lock));

Pure garbage. That's a debug thing that should not exist.

> or fscache_start_operations() which does:
>
>         ASSERT(spin_is_locked(&object->lock));

Same thing.

We do *not* want to add some crazy "spin_is_nt_locked". We just want
to get rid of these idiotic debug tests.

Note that even on SMP, spin_is_locked() can end up being bad. If this
whole memory transaction thing takes off, testing the lock is possibly
going to abort the transaction.

So I'd suggest removing it entirely. Drivers have absolutely no place
doing crap like this. We could add some particular
"assert_spin_lock_held()" that only ends up existing if spinlock
debugging is enabled or something, and make it clear that it is purely
a debug feature (and it verifies that *this* process holds the lock,
using the debug fields), not a "test if something is locked" or not.

             Linus

  reply	other threads:[~2013-05-23 14:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-23 14:50 Is spin_is_locked() safe to use with BUG_ON()/WARN_ON()? David Howells
2013-05-23 14:59 ` Linus Torvalds [this message]
2013-05-23 15:12 ` David Howells
2013-05-24  1:29   ` Ryan Mallon
2013-05-24  1:29     ` Ryan Mallon
2013-05-28  8:07     ` Ingo Molnar

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=CA+55aFww-UYfLA4cN6MSkeXzmAnAruShddAPegCpn+5yd1HGmQ@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=milosz@adfin.com \
    --cc=mingo@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).