Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751505AbaJOUiM (ORCPT ); Wed, 15 Oct 2014 16:38:12 -0400 Received: from mail-qa0-f49.google.com ([209.85.216.49]:50151 "EHLO mail-qa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750792AbaJOUiL (ORCPT ); Wed, 15 Oct 2014 16:38:11 -0400 From: Patrick Palka To: linux-kernel@vger.kernel.org Cc: Patrick Palka , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Peter Zijlstra , Hans-Christian Egtvedt , "Paul E. McKenney" , Pranith Kumar Subject: [PATCH] Fix the x86 specializations of atomic_[set|clear]_mask Date: Wed, 15 Oct 2014 16:38:01 -0400 Message-Id: <1413405481-28818-1-git-send-email-patrick@parcs.ath.cx> X-Mailer: git-send-email 2.1.2.443.g670a3c1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes a number of issues with these specializations: 1. The memory operand inside the asm specification is erroneously declared read-only instead of read-write. 2. There is no reason to require the 1st operand of andl/orl to be inside a register; the 1st operand could also be an immediate operand. So change its specification from "r" to "ir". 3. Since addr is supposed to be an atomic_t *, the memory operand should be addr->counter and not *addr. 4. These specializations should be inline functions instead of macros. 5. Finally, the "memory" clobbers are unnecessary, so they should be removed. (This is in line with the other atomic functions such as atomic_add and atomic_sub, the likes of which do not have a "memory" clobber.) Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: Peter Zijlstra Cc: Hans-Christian Egtvedt Cc: "Paul E. McKenney" Cc: Pranith Kumar Signed-off-by: Patrick Palka --- arch/x86/include/asm/atomic.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h index 5e5cd12..83ae239 100644 --- a/arch/x86/include/asm/atomic.h +++ b/arch/x86/include/asm/atomic.h @@ -219,15 +219,19 @@ static inline short int atomic_inc_short(short int *v) return *v; } -/* These are x86-specific, used by some header files */ -#define atomic_clear_mask(mask, addr) \ - asm volatile(LOCK_PREFIX "andl %0,%1" \ - : : "r" (~(mask)), "m" (*(addr)) : "memory") +static inline void atomic_clear_mask(int mask, atomic_t *v) +{ + asm volatile(LOCK_PREFIX "andl %1, %0" + : "+m" (v->counter) + : "ir" (~mask)); +} -#define atomic_set_mask(mask, addr) \ - asm volatile(LOCK_PREFIX "orl %0,%1" \ - : : "r" ((unsigned)(mask)), "m" (*(addr)) \ - : "memory") +static inline void atomic_set_mask(int mask, atomic_t *v) +{ + asm volatile(LOCK_PREFIX "orl %1, %0" + : "+m" (v->counter) + : "ir" (mask)); +} #ifdef CONFIG_X86_32 # include -- 2.1.2.443.g670a3c1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/