mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: benh@kernel.crashing.org, paulmck@linux.vnet.ibm.com,
	Ingo Molnar <mingo@elte.hu>, Boqun Feng <boqun.feng@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	1vier1@web.de, Davidlohr Bueso <dave@stgolabs.net>,
	Manfred Spraul <manfred@colorfullife.com>
Subject: [PATCH 3/5] spinlock: define spinlock_store_acquire
Date: Wed, 31 Aug 2016 15:42:28 +0200	[thread overview]
Message-ID: <1472650950-3131-4-git-send-email-manfred@colorfullife.com> (raw)
In-Reply-To: <1472650950-3131-1-git-send-email-manfred@colorfullife.com>

A spinlock is an ACQUIRE regarding reading the lock state.
The store of the lock may be postponed past the first operations
within the protected area, e.g. see commit 51d7d5205d33
("powerpc: Add smp_mb() to arch_spin_is_locked()".

The patch defines a new spinlock_store_acquire primitive:
It guarantees that the store is ordered relative to the following
load/store operations. Adding the barrier into spin_is_locked()
does help as not everyone uses spin_is_locked() or
spin_unlock_wait().

The patch:
- adds a definition into <linux/spinlock.h> (as smp_mb(), which is
  safe for all architectures)
- converts ipc/sem.c to the new define.

For overriding, the same approach as for smp_mb__before_spin_lock()
is used: If smp_mb__after_spin_lock is already defined, then it is
not changed.

The default is smp_mb(), to ensure that no architecture gets broken.

Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
---
 include/linux/spinlock.h | 12 ++++++++++++
 ipc/sem.c                |  8 +-------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index 47dd0ce..496f288 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -130,6 +130,18 @@ do {								\
 #define smp_mb__before_spinlock()	smp_wmb()
 #endif
 
+#ifndef spinlock_store_acquire
+/**
+ * spinlock_store_acuqire() - Provide acquire() after store part
+ *
+ * spin_lock() provides ACQUIRE semantics regarding reading the lock.
+ * There are no guarantees that the lock write is visible before any read
+ * read or write operation within the protected area is performed.
+ * If the lock write must happen first, this function is required.
+ */
+#define spinlock_store_acquire()	smp_mb()
+#endif
+
 /**
  * raw_spin_unlock_wait - wait until the spinlock gets unlocked
  * @lock: the spinlock in question.
diff --git a/ipc/sem.c b/ipc/sem.c
index 6586e0a..49d0ae3 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -355,13 +355,7 @@ static inline int sem_lock(struct sem_array *sma, struct sembuf *sops,
 		 */
 		spin_lock(&sem->lock);
 
-		/*
-		 * See 51d7d5205d33
-		 * ("powerpc: Add smp_mb() to arch_spin_is_locked()"):
-		 * A full barrier is required: the write of sem->lock
-		 * must be visible before the read is executed
-		 */
-		smp_mb();
+		spinlock_store_acquire();
 
 		if (!smp_load_acquire(&sma->complex_mode)) {
 			/* fast path successful! */
-- 
2.7.4

  parent reply	other threads:[~2016-08-31 13:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-31 13:42 [PATCH 0/5 V5] Clarify/standardize memory barriers for lock/unlock Manfred Spraul
2016-08-31 13:42 ` [PATCH 1/5] ipc/sem.c: Remove smp_rmb() from complexmode_enter() Manfred Spraul
2016-08-31 13:42 ` [PATCH 2/5] spinlock: Document memory barrier rules for spin_lock and spin_unlock() Manfred Spraul
2016-08-31 13:42 ` Manfred Spraul [this message]
2016-08-31 13:42 ` [PATCH 4/5] spinlock.h: Move smp_mb__after_unlock_lock to spinlock.h Manfred Spraul
2016-08-31 13:42 ` [PATCH 5/5] net/netfilter/nf_conntrack_core: update memory barriers Manfred Spraul
2016-08-31 14:15   ` Eric Dumazet

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=1472650950-3131-4-git-send-email-manfred@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=1vier1@web.de \
    --cc=akpm@linux-foundation.org \
    --cc=benh@kernel.crashing.org \
    --cc=boqun.feng@gmail.com \
    --cc=dave@stgolabs.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.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

all inboxes | Powered by JetHome®