From patchwork Thu Jul 5 16:40:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141214 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2154668ljj; Thu, 5 Jul 2018 09:41:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe/BVIfsAQx/UwJ9l2tJik5fcCfRzKjXGPkXLcS6umdL6KOQOSswF+kYWFaUvod2MF/mSq7 X-Received: by 2002:a63:8c5:: with SMTP id 188-v6mr6203272pgi.97.1530808895183; Thu, 05 Jul 2018 09:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530808895; cv=none; d=google.com; s=arc-20160816; b=NuVYdVMaTAEPnBR6FmKXjf3FIxzofjaeC2SwwOelhwL7oTWF1siJsSyh03sco8JST8 QRoKZZLyQY6LSKM9zCx3aXldV+ZTVdvkjTREqJm2Lq3Som+P0jFkM35J8y4jgF3a7524 9GR1kQADODyfrrepV3xoFCPKNU3GwzEaeUe/5YbLw+EDJDOz4suSFqJgmPG/ULIF0px0 /3HGohsPk/XI3GagFJUl14pIAy48XpBs59se95jZwMOt4hOnhaWbg1KLpxuMBmB+zCsT QacweY8zLhPXPxioy4hs6lzdLo2R4OpVlJ3ymj6idguRpMzuJ/CkvmszXvMy7xHXFhSZ bifw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=O9u4T9MxVYxaxKRFpAu9c2wf0w6geSGfrYIc28LWjr4=; b=VLc3jNngyDQssGv4yQ6B+KNkGQQ7PV0qwEsca95ndHYHCezKsu8rrwIliU7Azt50ZH YQ5qvY++LrOb6LdltOX8xY/uLCdlSb1SgUGApp6juuqeHaKkaVHvzVpPk3c6GBOBiVAb O8ppUC6jkrw7NZvZ+AhB2sBtCULg6AoP13oQQ6M5f8swaQ8GHfi5xKEt+G129z/YAvCr n3I/do4xnNo7Ng/krtq1joFmvV1+lw6ITs8OjTxamPg0+gtvrHwPoqmptDxHU3V51mI1 BjJbwxzpDmD4v0q7GdElWnSi2Fh9Eog2otNGBx9lvKVHSxZNneuju2Aw9Qsk1zM3hUUJ S3PQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5-v6si6633672plc.203.2018.07.05.09.41.34; Thu, 05 Jul 2018 09:41:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754150AbeGEQlc (ORCPT + 31 others); Thu, 5 Jul 2018 12:41:32 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53416 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753459AbeGEQl3 (ORCPT ); Thu, 5 Jul 2018 12:41:29 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 52D017A9; Thu, 5 Jul 2018 09:41:29 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 22D053F5BA; Thu, 5 Jul 2018 09:41:25 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, peterz@infradead.org, will.deacon@arm.com Cc: andy.shevchenko@gmail.com, arnd@arndb.de, aryabinin@virtuozzo.com, boqun.feng@gmail.com, catalin.marinas@arm.com, dvyukov@google.com, glider@google.com, hpa@zytor.com, linuxdrivers@attotech.com, mark.rutland@arm.com, mingo@kernel.org, mingo@redhat.com, parri.andrea@gmail.com, peter@hurleysoftware.com, tglx@linutronix.de Subject: [PATCHv3 04/12] atomics/treewide: instrument xchg() Date: Thu, 5 Jul 2018 17:40:45 +0100 Message-Id: <20180705164053.10073-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180705164053.10073-1-mark.rutland@arm.com> References: <20180705164053.10073-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While we instrument all of the (non-relaxed) atomic_*() functions and cmpxchg(), we missed xchg(). Let's add instrumentation for xchg(), fixing up x86 to implement arch_xchg(). Signed-off-by: Mark Rutland Acked-by: Peter Zijlstra (Intel) Cc: Boqun Feng Cc: Dmitry Vyukov Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Will Deacon --- arch/x86/include/asm/atomic.h | 2 +- arch/x86/include/asm/atomic64_64.h | 2 +- arch/x86/include/asm/cmpxchg.h | 2 +- include/asm-generic/atomic-instrumented.h | 7 +++++++ 4 files changed, 10 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h index 823fd2f320cf..b143717b92b3 100644 --- a/arch/x86/include/asm/atomic.h +++ b/arch/x86/include/asm/atomic.h @@ -202,7 +202,7 @@ static __always_inline bool arch_atomic_try_cmpxchg(atomic_t *v, int *old, int n static inline int arch_atomic_xchg(atomic_t *v, int new) { - return xchg(&v->counter, new); + return arch_xchg(&v->counter, new); } static inline void arch_atomic_and(int i, atomic_t *v) diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h index 849f1c566a11..4343d9b4f30e 100644 --- a/arch/x86/include/asm/atomic64_64.h +++ b/arch/x86/include/asm/atomic64_64.h @@ -188,7 +188,7 @@ static __always_inline bool arch_atomic64_try_cmpxchg(atomic64_t *v, s64 *old, l static inline long arch_atomic64_xchg(atomic64_t *v, long new) { - return xchg(&v->counter, new); + return arch_xchg(&v->counter, new); } static inline void arch_atomic64_and(long i, atomic64_t *v) diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h index e3efd8a06066..a55d79b233d3 100644 --- a/arch/x86/include/asm/cmpxchg.h +++ b/arch/x86/include/asm/cmpxchg.h @@ -75,7 +75,7 @@ extern void __add_wrong_size(void) * use "asm volatile" and "memory" clobbers to prevent gcc from moving * information around. */ -#define xchg(ptr, v) __xchg_op((ptr), (v), xchg, "") +#define arch_xchg(ptr, v) __xchg_op((ptr), (v), xchg, "") /* * Atomic compare and exchange. Compare OLD with MEM, if identical, diff --git a/include/asm-generic/atomic-instrumented.h b/include/asm-generic/atomic-instrumented.h index c7c3e4cdd942..53481b6eacdf 100644 --- a/include/asm-generic/atomic-instrumented.h +++ b/include/asm-generic/atomic-instrumented.h @@ -408,6 +408,13 @@ static __always_inline bool atomic64_add_negative(s64 i, atomic64_t *v) } #endif +#define xchg(ptr, new) \ +({ \ + typeof(ptr) __ai_ptr = (ptr); \ + kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + arch_xchg(__ai_ptr, (new)); \ +}) + #define cmpxchg(ptr, old, new) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \