From patchwork Mon Jun 25 10:59: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: 139825 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3839817lji; Mon, 25 Jun 2018 04:01:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ1bAmMPFbVCgQgJEsuk8P/E3gPoOyMP2rxJ/K4+IBu7CEs93AZVFrfNJugl32PW3MgWbf1 X-Received: by 2002:a62:c16:: with SMTP id u22-v6mr12500170pfi.177.1529924507410; Mon, 25 Jun 2018 04:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529924507; cv=none; d=google.com; s=arc-20160816; b=UZeXvo+sIjtpnTeL+ChQgx3oV1O9IDrr09Y8cJiBWYCuFtrmoqY49PfAdMi2ntgV17 wBd4RHHJgwnbscmW9eVJHTz3QL7nEVqkN8sKOOHF6U7zgDdoqTCQHy016t+VA1zRNWxy qDfrNLaYRkjz8Em6pDahRU3h1GJ1TEInmb2pxhp+bPDBV4X5yoJVgtANjOZJqaM3tzd7 kdIGzyqYxsD3b+phnJ5sfo6WTmHG/2xGdX4t5HuDZeSJ8oLVuM/LvSG7jlQjStaHDGJz knletjsFGfG2HzcL1yLTjBf+twDqYGakGXQQaVk1heLy/lgCTs/f2BeFGv0lvbisIoEz JzJw== 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=Lrr94wJLxGNsjtBle/DTgwuO6ABYru+hwviQWF1TMMc=; b=ukjSqr9MAqvApqH3v4ravTrwCH+/6ZWAJ+lcHjcQ76cWRtXjFIZo2TNF6izoKHsfm8 PAK4G2Gi5r4rcGdc2RwfVMqwhvNjBY0ZPdn990VsT9TtvJSQDzQLkfzUeDTeefZ/qgtq +yyEoFaQsntRcmmvL6D9tEkvoPFkY41Z0JonCKTjpKJjFW4rXPChf7Wh0hGsKjii3j/M USGsmi6zz0PTslnsofBdYvnDoYJ3CTti2DS9fD0SdF7zm9F3aFNSZkYS5Qpw2nfL2w4x eKzYa3TSfsDJ0+brC0eoXz1V6KQJnvVuBQ4kquUnt3hhlIRDdI1lpplmRSOCV1PVBFVU JGJA== 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 n64-v6si2875003pgn.247.2018.06.25.04.01.47; Mon, 25 Jun 2018 04:01:47 -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 S933030AbeFYLBp (ORCPT + 31 others); Mon, 25 Jun 2018 07:01:45 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:54584 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932280AbeFYLAJ (ORCPT ); Mon, 25 Jun 2018 07:00:09 -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 C7F9B22C8; Mon, 25 Jun 2018 04:00:08 -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 2D0CB3F73D; Mon, 25 Jun 2018 04:00:07 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org, will.deacon@arm.com, peterz@infradead.org, boqun.feng@gmail.com Cc: Mark Rutland , Dmitry Vyukov , "H . Peter Anvin" , Ingo Molnar , Thomas Gleixner Subject: [PATCHv2 04/11] atomics/treewide: instrument xchg() Date: Mon, 25 Jun 2018 11:59:45 +0100 Message-Id: <20180625105952.3756-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180625105952.3756-1-mark.rutland@arm.com> References: <20180625105952.3756-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 atomic*() and cmpxchg(), we missed xchg(). Let's add instrumentation for xchg(), fixing up x86 to implement arch_xchg(). Signed-off-by: Mark Rutland Cc: Boqun Feng Cc: Dmitry Vyukov Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Peter Zijlstra 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); \