Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3747582imm; Mon, 25 Jun 2018 04:04:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLi3s9lzZV+2i8mIUzn7Nz2M6DqXYu+UaiM1/PgY2k5MwhNOkRqWHryELXUNGDa0/biLIMF X-Received: by 2002:a17:902:5488:: with SMTP id e8-v6mr11806831pli.137.1529924656825; Mon, 25 Jun 2018 04:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529924656; cv=none; d=google.com; s=arc-20160816; b=Yd7zmfC9CjSP73bT7xm/kDnn6Z+v5kyc5uIzVPOYNhg4tTjc3umRXIptB1Ie5/9AZt u5dG0qhGkaGBoo2MUbdWz7Q/dFvD9ZU1NKfZ2mDuXARLjH85COZL+cHmgNonDwEOY6/S zONSYC5E0fwf2hAEZFaBx0kFdS+C6yGo2SLmchzdM1tfpzGokQEDCVT5Z4gUXrDIwip5 BJF2v7kpEQdMr6Bqsll1sU9KB4Aj6jhaS5lYDYbH/eNdWUa0aqn+N0WzcYoZaxJhez1M /wJw0tXP6jRvXxU9z8pkHo7vD0tbUTZyWLaUA280rA6fHkypQVwdEQQY3J5R9I3ARYjv +G6w== 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 e188-v6si7644821pfc.110.2018.06.25.04.04.02; Mon, 25 Jun 2018 04:04:16 -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 S932981AbeFYLBp (ORCPT + 99 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(-) 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); \ -- 2.11.0