All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-4.17 1/2] arm64: Remove smp_mb() from arch_spin_is_locked()
@ 2018-03-26 10:37 Andrea Parri
  2018-03-26 10:57 ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Parri @ 2018-03-26 10:37 UTC (permalink / raw)
  To: Will Deacon, Catalin Marinas, Peter Zijlstra, Ingo Molnar
  Cc: linux-kernel, Andrea Parri, Linus Torvalds

Commit 38b850a73034f ("arm64: spinlock: order spin_{is_locked,unlock_wait}
against local locks") added an smp_mb() to arch_spin_is_locked(), in order
"to ensure that the lock value is always loaded after any other locks have
been taken by the current CPU", and reported one example (the "insane case"
in ipc/sem.c) relying on such guarantee.

It is however understood (and not documented) that spin_is_locked() is not
required to ensure such an ordering guarantee, guarantee that is currently
_not_ provided by all implementations/architectures, and that callers rely-
ing on such ordering should instead insert suitable memory barriers before
acting on the result of spin_is_locked().

Following a recent auditing[1] of the callsites of {,raw_}spin_is_locked()
revealing that none of these callers are relying on the ordering guarantee
anymore, this commit removes the leading smp_mb() from this primitive thus
effectively reverting 38b850a73034f.

[1] https://marc.info/?l=linux-kernel&m=151981440005264&w=2

Signed-off-by: Andrea Parri <andrea.parri@amarulasolutions.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
---
 arch/arm64/include/asm/spinlock.h | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/arch/arm64/include/asm/spinlock.h b/arch/arm64/include/asm/spinlock.h
index ebdae15d665de..26c5bd7d88d8d 100644
--- a/arch/arm64/include/asm/spinlock.h
+++ b/arch/arm64/include/asm/spinlock.h
@@ -122,11 +122,6 @@ static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
 
 static inline int arch_spin_is_locked(arch_spinlock_t *lock)
 {
-	/*
-	 * Ensure prior spin_lock operations to other locks have completed
-	 * on this CPU before we test whether "lock" is locked.
-	 */
-	smp_mb(); /* ^^^ */
 	return !arch_spin_value_unlocked(READ_ONCE(*lock));
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.17 1/2] arm64: Remove smp_mb() from arch_spin_is_locked()
  2018-03-26 10:37 [PATCH for-4.17 1/2] arm64: Remove smp_mb() from arch_spin_is_locked() Andrea Parri
@ 2018-03-26 10:57 ` Will Deacon
  2018-03-26 14:14   ` Andrea Parri
  0 siblings, 1 reply; 4+ messages in thread
From: Will Deacon @ 2018-03-26 10:57 UTC (permalink / raw)
  To: Andrea Parri
  Cc: Catalin Marinas, Peter Zijlstra, Ingo Molnar, linux-kernel,
	Linus Torvalds

On Mon, Mar 26, 2018 at 12:37:21PM +0200, Andrea Parri wrote:
> Commit 38b850a73034f ("arm64: spinlock: order spin_{is_locked,unlock_wait}
> against local locks") added an smp_mb() to arch_spin_is_locked(), in order
> "to ensure that the lock value is always loaded after any other locks have
> been taken by the current CPU", and reported one example (the "insane case"
> in ipc/sem.c) relying on such guarantee.
> 
> It is however understood (and not documented) that spin_is_locked() is not
> required to ensure such an ordering guarantee, guarantee that is currently
> _not_ provided by all implementations/architectures, and that callers rely-
> ing on such ordering should instead insert suitable memory barriers before
> acting on the result of spin_is_locked().
> 
> Following a recent auditing[1] of the callsites of {,raw_}spin_is_locked()
> revealing that none of these callers are relying on the ordering guarantee
> anymore, this commit removes the leading smp_mb() from this primitive thus
> effectively reverting 38b850a73034f.
> 
> [1] https://marc.info/?l=linux-kernel&m=151981440005264&w=2

What is patch 2/2 in this series? I couldn't find it in the archive.

Assuming that patch doesn't do it, please can you remove the comment
about spin_is_locked from mutex_is_locked?

Also -- does this mean we can kill the #ifndef queued_spin_is_locked
guards in asm-generic/qspinlock.h?

Will

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.17 1/2] arm64: Remove smp_mb() from arch_spin_is_locked()
  2018-03-26 10:57 ` Will Deacon
@ 2018-03-26 14:14   ` Andrea Parri
  2018-03-27 16:54     ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Parri @ 2018-03-26 14:14 UTC (permalink / raw)
  To: Will Deacon
  Cc: Catalin Marinas, Peter Zijlstra, Ingo Molnar, linux-kernel,
	Linus Torvalds

On Mon, Mar 26, 2018 at 11:57:05AM +0100, Will Deacon wrote:
> On Mon, Mar 26, 2018 at 12:37:21PM +0200, Andrea Parri wrote:
> > Commit 38b850a73034f ("arm64: spinlock: order spin_{is_locked,unlock_wait}
> > against local locks") added an smp_mb() to arch_spin_is_locked(), in order
> > "to ensure that the lock value is always loaded after any other locks have
> > been taken by the current CPU", and reported one example (the "insane case"
> > in ipc/sem.c) relying on such guarantee.
> > 
> > It is however understood (and not documented) that spin_is_locked() is not
> > required to ensure such an ordering guarantee, guarantee that is currently
> > _not_ provided by all implementations/architectures, and that callers rely-
> > ing on such ordering should instead insert suitable memory barriers before
> > acting on the result of spin_is_locked().
> > 
> > Following a recent auditing[1] of the callsites of {,raw_}spin_is_locked()
> > revealing that none of these callers are relying on the ordering guarantee
> > anymore, this commit removes the leading smp_mb() from this primitive thus
> > effectively reverting 38b850a73034f.
> > 
> > [1] https://marc.info/?l=linux-kernel&m=151981440005264&w=2
> 
> What is patch 2/2 in this series? I couldn't find it in the archive.

2/2 is this change for powerpc:

  https://marc.info/?l=linux-kernel&m=152206068707522&w=2

> 
> Assuming that patch doesn't do it, please can you remove the comment
> about spin_is_locked from mutex_is_locked?

I ended up with the patch below but I suspect that it's not what you had
in mind; please let me know if you'd like me to add it into this series.


> 
> Also -- does this mean we can kill the #ifndef queued_spin_is_locked
> guards in asm-generic/qspinlock.h?

I don't see why arch may want to override that definition (maybe lack of
imagination?); please let me know if you'd like to see the #ifndef gone.

  Andrea

---
>From 1b77a9a70823620f1c98e43453edf5707d02074e Mon Sep 17 00:00:00 2001
From: Andrea Parri <andrea.parri@amarulasolutions.com>
Date: Mon, 26 Mar 2018 15:03:58 +0200
Subject: [PATCH] mutex: Remove the comment about spin_is_locked() from
 mutex_is_locked()

Still true/valid, but not particularly useful [IMO].

Suggested-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Andrea Parri <andrea.parri@amarulasolutions.com>
---
 include/linux/mutex.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index cb3bbed4e6339..9921822c51585 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -147,9 +147,6 @@ extern void __mutex_init(struct mutex *lock, const char *name,
  */
 static inline bool mutex_is_locked(struct mutex *lock)
 {
-	/*
-	 * XXX think about spin_is_locked
-	 */
 	return __mutex_owner(lock) != NULL;
 }
 
-- 
2.7.4


> 
> Will

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.17 1/2] arm64: Remove smp_mb() from arch_spin_is_locked()
  2018-03-26 14:14   ` Andrea Parri
@ 2018-03-27 16:54     ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2018-03-27 16:54 UTC (permalink / raw)
  To: Andrea Parri
  Cc: Catalin Marinas, Peter Zijlstra, Ingo Molnar, linux-kernel,
	Linus Torvalds

Hi Andrea,

On Mon, Mar 26, 2018 at 04:14:36PM +0200, Andrea Parri wrote:
> On Mon, Mar 26, 2018 at 11:57:05AM +0100, Will Deacon wrote:
> > On Mon, Mar 26, 2018 at 12:37:21PM +0200, Andrea Parri wrote:
> > > Commit 38b850a73034f ("arm64: spinlock: order spin_{is_locked,unlock_wait}
> > > against local locks") added an smp_mb() to arch_spin_is_locked(), in order
> > > "to ensure that the lock value is always loaded after any other locks have
> > > been taken by the current CPU", and reported one example (the "insane case"
> > > in ipc/sem.c) relying on such guarantee.
> > > 
> > > It is however understood (and not documented) that spin_is_locked() is not
> > > required to ensure such an ordering guarantee, guarantee that is currently
> > > _not_ provided by all implementations/architectures, and that callers rely-
> > > ing on such ordering should instead insert suitable memory barriers before
> > > acting on the result of spin_is_locked().
> > > 
> > > Following a recent auditing[1] of the callsites of {,raw_}spin_is_locked()
> > > revealing that none of these callers are relying on the ordering guarantee
> > > anymore, this commit removes the leading smp_mb() from this primitive thus
> > > effectively reverting 38b850a73034f.
> > > 
> > > [1] https://marc.info/?l=linux-kernel&m=151981440005264&w=2
> > 
> > What is patch 2/2 in this series? I couldn't find it in the archive.
> 
> 2/2 is this change for powerpc:
> 
>   https://marc.info/?l=linux-kernel&m=152206068707522&w=2
> 
> > 
> > Assuming that patch doesn't do it, please can you remove the comment
> > about spin_is_locked from mutex_is_locked?
> 
> I ended up with the patch below but I suspect that it's not what you had
> in mind; please let me know if you'd like me to add it into this series.

That's exactly what I meant! I think you can remove the #ifndef
queued_spin_is_locked in the same patch. If you do that:

Acked-by: Will Deacon <will.deacon@arm.com>

for the arm64 patch and the mythical core patch we've been discussing.

Will

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-27 16:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-26 10:37 [PATCH for-4.17 1/2] arm64: Remove smp_mb() from arch_spin_is_locked() Andrea Parri
2018-03-26 10:57 ` Will Deacon
2018-03-26 14:14   ` Andrea Parri
2018-03-27 16:54     ` Will Deacon

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.