From patchwork Mon Jul 16 11:30:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 142000 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2305768ljj; Mon, 16 Jul 2018 04:30:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdnoY9TKOwyt9/ssaPuryHeqrA1nowKYkK0D64mKpuUR+rs/1V/eFAhYWEwHiDVGdqIejtt X-Received: by 2002:a63:5c52:: with SMTP id n18-v6mr14987233pgm.360.1531740652178; Mon, 16 Jul 2018 04:30:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531740652; cv=none; d=google.com; s=arc-20160816; b=bAXfsk69nE9+rkEFsQQWC5dqLP0W5+vDZExowMgbtS4KvD4VnyHhHd9axioHlpbjob zzdgAGwFJW3fsekO8u+YYvVihmNqRosw9v0kYtsdSfQnpCbKCpKWyytbHCVx16uttvoj ea8a2kvtFJtjAs7BA0naA9okAT7q/QnL32BPREQWQ73vgy34Na4KkaYu0nrrtjSwkyms boJGuU3hsD6Uyq/zLUyvI4GeV3HCz3PA14XabeAAJUugNS28lzLu4COicgQoWEz03PQd 3+rmQcZRnKJmoj4rJlsJfuZ4Uf1Y4LmLkN7V/i0Uvp/W0IraU1Jk44wCCv510gnhYPdD cxtQ== 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=SPhKtdFBSG56KdznPlkzfpBKJrtXtv38IdrkuDBoH/Q=; b=dxpv9tqqMys8LWplk9c7M2yw5yU2u2LIs+bAXzG9TMJdfTWDp4kNth0qEJUvzlIBP2 ek+QsXyvs8PfPv+IwsqijFsUY0g4l099Ooh/EU22V2yJQN3WLX8xb9zBq8CjxY2IbNur q6pIH+Ju+wxNBzQWLHU0dbxc3vRacau6Vd09Bbu2qB/Lqqm9sFJc2Mda1Etzg54QEjTg OgG22Iti6YTVSlS939Y2bedF8qfl4n68JDLE2C6Q3uHc+PqO5Y1cKDY7aJ8tXhn8QvZT gDmJouOR3XUj4hxUsufoN3wxTEc7wr+1twoUu4H1exHd4QtiPMYQkqhYUN7bKGToWc6W Q5fw== 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 ca2-v6si1063962plb.305.2018.07.16.04.30.51; Mon, 16 Jul 2018 04:30:52 -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 S1731250AbeGPL5t (ORCPT + 31 others); Mon, 16 Jul 2018 07:57:49 -0400 Received: from foss.arm.com ([217.140.101.70]:57654 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728643AbeGPL5s (ORCPT ); Mon, 16 Jul 2018 07:57:48 -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 62C6B18A; Mon, 16 Jul 2018 04:30:49 -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 727DC3F589; Mon, 16 Jul 2018 04:30:46 -0700 (PDT) From: Mark Rutland To: mingo@kernel.org, mingo@redhat.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, linux-kernel@vger.kernel.org, mark.rutland@arm.com, parri.andrea@gmail.com, peter@hurleysoftware.com, peterz@infradead.org, tglx@linutronix.de, will.deacon@arm.com, linux-arm-kernel@lists.infradead.org Subject: [PATCHv4 04/12] atomics/treewide: instrument xchg() Date: Mon, 16 Jul 2018 12:30:09 +0100 Message-Id: <20180716113017.3909-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180716113017.3909-1-mark.rutland@arm.com> References: <20180716113017.3909-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) Acked-by: Will Deacon Cc: Boqun Feng Cc: Dmitry Vyukov Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Thomas Gleixner --- 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); \