From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934801AbcHaNn2 (ORCPT ); Wed, 31 Aug 2016 09:43:28 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36286 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934597AbcHaNmo (ORCPT ); Wed, 31 Aug 2016 09:42:44 -0400 From: Manfred Spraul To: benh@kernel.crashing.org, paulmck@linux.vnet.ibm.com, Ingo Molnar , Boqun Feng , Peter Zijlstra , Andrew Morton Cc: LKML , 1vier1@web.de, Davidlohr Bueso , Manfred Spraul Subject: [PATCH 3/5] spinlock: define spinlock_store_acquire Date: Wed, 31 Aug 2016 15:42:28 +0200 Message-Id: <1472650950-3131-4-git-send-email-manfred@colorfullife.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472650950-3131-1-git-send-email-manfred@colorfullife.com> References: <1472650950-3131-1-git-send-email-manfred@colorfullife.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 (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 --- 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