All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Will Deacon <will.deacon@arm.com>
Cc: Luc Maranget <luc.maranget@inria.fr>,
	Daniel Lustig <dlustig@nvidia.com>,
	Peter Zijlstra <peterz@infradead.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Andrea Parri <parri.andrea@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Palmer Dabbelt <palmer@sifive.com>, Albert Ou <albert@sifive.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Boqun Feng <boqun.feng@gmail.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	David Howells <dhowells@redhat.com>,
	Jade Alglave <j.alglave@ucl.ac.uk>,
	Akira Yokosawa <akiyks@gmail.com>, Ingo Molnar <mingo@kernel.org>,
	linux-riscv@lists.infradead.org
Subject: Re: [RFC PATCH] riscv/locking: Strengthen spin_lock() and spin_unlock()
Date: Mon, 26 Feb 2018 09:00:43 -0800	[thread overview]
Message-ID: <CA+55aFyT=+8m0mmpeegP8LOVtkCYv3O2vyO-ZcQdLAR=s309jg@mail.gmail.com> (raw)
In-Reply-To: <20180226162426.GB17158@arm.com>

On Mon, Feb 26, 2018 at 8:24 AM, Will Deacon <will.deacon@arm.com> wrote:
>
> Strictly speaking, that's not what we've got implemented on arm64: only
> the read part of the RmW has Acquire semantics, but there is a total
> order on the lock/unlock operations for the lock.

Hmm.

I thought we had exactly that bug on some architecture with the queued
spinlocks, and people decided it was wrong.

But it's possible that I mis-remember, and that we decided it was ok after all.

> spin_lock(&lock);
> WRITE_ONCE(foo, 42);
>
> then another CPU could do:
>
> if (smp_load_acquire(&foo) == 42)
>         BUG_ON(!spin_is_locked(&lock));
>
> and that could fire. Is that relied on somewhere?

I have a distinct memory that we said the spinlock write is seen in
order, wrt the writes inside the spinlock, and the reason was
something very similar to the above, except that "spin_is_locked()"
was about our spin_unlock_wait().

Because we had something very much like the above in the exit path,
where we would look at some state and do "spin_unlock_wait()" and
expect to be guaranteed to be the last user after that.

But a few months ago we obviously got rid of spin_unlock_wait exactly
because people were worried about the semantics.

So maybe I just remember an older issue that simply became a non-issue
with that.

               Linus

WARNING: multiple messages have this Message-ID (diff)
From: torvalds@linux-foundation.org (Linus Torvalds)
To: linux-riscv@lists.infradead.org
Subject: [RFC PATCH] riscv/locking: Strengthen spin_lock() and spin_unlock()
Date: Mon, 26 Feb 2018 09:00:43 -0800	[thread overview]
Message-ID: <CA+55aFyT=+8m0mmpeegP8LOVtkCYv3O2vyO-ZcQdLAR=s309jg@mail.gmail.com> (raw)
In-Reply-To: <20180226162426.GB17158@arm.com>

On Mon, Feb 26, 2018 at 8:24 AM, Will Deacon <will.deacon@arm.com> wrote:
>
> Strictly speaking, that's not what we've got implemented on arm64: only
> the read part of the RmW has Acquire semantics, but there is a total
> order on the lock/unlock operations for the lock.

Hmm.

I thought we had exactly that bug on some architecture with the queued
spinlocks, and people decided it was wrong.

But it's possible that I mis-remember, and that we decided it was ok after all.

> spin_lock(&lock);
> WRITE_ONCE(foo, 42);
>
> then another CPU could do:
>
> if (smp_load_acquire(&foo) == 42)
>         BUG_ON(!spin_is_locked(&lock));
>
> and that could fire. Is that relied on somewhere?

I have a distinct memory that we said the spinlock write is seen in
order, wrt the writes inside the spinlock, and the reason was
something very similar to the above, except that "spin_is_locked()"
was about our spin_unlock_wait().

Because we had something very much like the above in the exit path,
where we would look at some state and do "spin_unlock_wait()" and
expect to be guaranteed to be the last user after that.

But a few months ago we obviously got rid of spin_unlock_wait exactly
because people were worried about the semantics.

So maybe I just remember an older issue that simply became a non-issue
with that.

               Linus

  reply	other threads:[~2018-02-26 17:00 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-22 12:19 [RFC PATCH] riscv/locking: Strengthen spin_lock() and spin_unlock() Andrea Parri
2018-02-22 12:19 ` Andrea Parri
2018-02-22 12:44 ` Andrea Parri
2018-02-22 12:44   ` Andrea Parri
2018-02-22 13:40 ` Peter Zijlstra
2018-02-22 13:40   ` Peter Zijlstra
2018-02-22 14:12   ` Andrea Parri
2018-02-22 14:12     ` Andrea Parri
2018-02-22 17:27     ` Daniel Lustig
2018-02-22 17:27       ` Daniel Lustig
2018-02-22 18:13       ` Paul E. McKenney
2018-02-22 18:13         ` Paul E. McKenney
2018-02-22 18:27         ` Peter Zijlstra
2018-02-22 18:27           ` Peter Zijlstra
2018-02-22 19:47           ` Daniel Lustig
2018-02-22 19:47             ` Daniel Lustig
2018-02-23 11:16             ` Andrea Parri
2018-02-23 11:16               ` Andrea Parri
2018-02-26 10:39             ` Will Deacon
2018-02-26 10:39               ` Will Deacon
2018-02-26 14:21             ` Luc Maranget
2018-02-26 14:21               ` Luc Maranget
2018-02-26 16:06               ` Linus Torvalds
2018-02-26 16:06                 ` Linus Torvalds
2018-02-26 16:24                 ` Will Deacon
2018-02-26 16:24                   ` Will Deacon
2018-02-26 17:00                   ` Linus Torvalds [this message]
2018-02-26 17:00                     ` Linus Torvalds
2018-02-26 17:10                     ` Will Deacon
2018-02-26 17:10                       ` Will Deacon
2018-03-06 13:00                     ` Peter Zijlstra
2018-03-06 13:00                       ` Peter Zijlstra
2018-02-27  5:06                   ` Boqun Feng
2018-02-27  5:06                     ` Boqun Feng
2018-02-27 10:16                     ` Boqun Feng
2018-02-27 10:16                       ` Boqun Feng
2018-03-01 15:11             ` Andrea Parri
2018-03-01 15:11               ` Andrea Parri
2018-03-01 21:54               ` Palmer Dabbelt
2018-03-01 21:54                 ` Palmer Dabbelt
2018-03-01 22:21                 ` Daniel Lustig
2018-03-01 22:21                   ` Daniel Lustig
2018-02-22 20:02           ` Paul E. McKenney
2018-02-22 20:02             ` Paul E. McKenney
2018-02-22 18:21       ` Peter Zijlstra
2018-02-22 18:21         ` Peter Zijlstra

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+55aFyT=+8m0mmpeegP8LOVtkCYv3O2vyO-ZcQdLAR=s309jg@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=akiyks@gmail.com \
    --cc=albert@sifive.com \
    --cc=boqun.feng@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dlustig@nvidia.com \
    --cc=j.alglave@ucl.ac.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=luc.maranget@inria.fr \
    --cc=mingo@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=palmer@sifive.com \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=stern@rowland.harvard.edu \
    --cc=will.deacon@arm.com \
    /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.