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 2/5] spinlock: Document memory barrier rules for spin_lock and spin_unlock().
Date: Wed, 31 Aug 2016 15:42:27 +0200	[thread overview]
Message-ID: <1472650950-3131-3-git-send-email-manfred@colorfullife.com> (raw)
In-Reply-To: <1472650950-3131-1-git-send-email-manfred@colorfullife.com>

In theory, the memory ordering rules for spinlock() and spin_unlock()
are simple: spin_lock is ACQUIRE, spin_unlock is RELEASE.

What is missing is a clear documentation for the corner cases:
- What is covered by the ACQUIRE during spin_lock: only the lock load
  or also the lock store?
- spin_unlock_wait() is an ACQUIRE.
- No memory ordering is enforced by spin_is_locked().

The patch adds this into Documentation/locking/spinlock.txt.

Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
---
 Documentation/locking/spinlocks.txt | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Documentation/locking/spinlocks.txt b/Documentation/locking/spinlocks.txt
index ff35e40..0696d68 100644
--- a/Documentation/locking/spinlocks.txt
+++ b/Documentation/locking/spinlocks.txt
@@ -40,6 +40,15 @@ example, internal driver data structures that nobody else ever touches).
    touches a shared variable has to agree about the spinlock they want
    to use.
 
+   NOTE! Code that needs stricter memory barriers than ACQUIRE during
+   LOCK and RELEASE during UNLOCK must use appropriate memory barriers
+   such as smp_mb__before_spinlock(). Especially, the ACQUIRE during
+   LOCK applies to reading the lock state. Operations within the
+   guarded area can happen before the lock store.
+   spin_unlock_wait() has ACQUIRE semantics.
+   spin_is_locked() is not a memory barrier, callers that use it for
+   locking must add appropriate barriers.
+
 ----
 
 Lesson 2: reader-writer spinlocks.
-- 
2.7.4

  parent reply	other threads:[~2016-08-31 13:42 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 ` Manfred Spraul [this message]
2016-08-31 13:42 ` [PATCH 3/5] spinlock: define spinlock_store_acquire Manfred Spraul
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-3-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®