Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2168549ybk; Mon, 11 May 2020 13:45:06 -0700 (PDT) X-Google-Smtp-Source: APiQypJW+/uRUMUFScmtZP3RZtSVCAbtA78hoXsyTmyqGIGJffkkDd7yRfVpzI0ceoxP6clFHvjr X-Received: by 2002:a05:6402:1adc:: with SMTP id ba28mr15569164edb.336.1589229906243; Mon, 11 May 2020 13:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589229906; cv=none; d=google.com; s=arc-20160816; b=OP2OK41JEzoTXOt7ME9kGKmlZrpKp3/pVjFzJW2wUJuQFLUT94pqj5BucL5JbdC5KO w4I5Yw38qv+cMrLDwc02/XmNTPi1qjeaDeFf3b6y7KqyDhQH2gvwTTVBB/x9B71QLnEd RfRp0Ic2XZjM+gQzO3/u3iGuyGpFwk8mumhQfpZV55NAFKzmPRX3RP+h36vG4I/ju1IX +WHCLBeL00xjM7eaEexODh1ZsSF1kUPocBrfuCo3wzqjwKzMHuhm4O56Glr8KvcKrq3s DTpVSHQCtGuK97/qqYotp2czI1IOpP7RQHD+4d0rerZMGZsWIr3yI9YIhpLNpC4a5wph V5oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fkRfUsikxJ3kIGnDHQy9C+Ws1D413PGO+plEikYz4Ug=; b=N7wGqFh1E3I2RBV9EUf7r/TTXfh1YIIyX5zlZZqM3AuUNj/WiKGgK1a1px7RC05o31 kPO6ZSMRO/geYW6mjUCOVKNscVGQSuqKVD8jCQYgpFTqQ+GvFJu/ER5HH/JDfuj+vKOU YyT/pXKlyRAomXOuxSU0n+PvTIw6wF06R9jyUKFSucln1QEbiI5ivO0AoCPh1Hhu9Oui G5eVb0XvYSF8Li8zWYaEVXTJM4Akr6Nolwgs82KWZO78eAotE98PpIZ/rqgzScp8QnN4 Jwgq/xZvd4LrjqYWOQScI5smv6zl6NC/CqUpPhRztNr2tQDkcvFRSkPJ97h2VxPfbloA 069A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AN4J+Xnj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v21si7048563edq.326.2020.05.11.13.44.43; Mon, 11 May 2020 13:45:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AN4J+Xnj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731915AbgEKUnD (ORCPT + 99 others); Mon, 11 May 2020 16:43:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:54890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731907AbgEKUnC (ORCPT ); Mon, 11 May 2020 16:43:02 -0400 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 112C6206A3; Mon, 11 May 2020 20:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589229781; bh=Pq18jh+dBO+5MVurPUTV7sJ+HQII+LY1UCZPrtlXpZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AN4J+XnjVOiqN8cznGqBaIotz/EsEqUyAFo5x++BzfcdufV0sFA3OnvEr8/NBs+me LfUclYiWqck+lHWnVkv24s9TNi4taqz//M4oOADwasOcaUEpuFYIIGMU4w/foYrz2p uUZJanhtAAvxlS91EoBBWS1x5WgTtRI0thRR1nEI= From: Will Deacon To: linux-kernel@vger.kernel.org Cc: elver@google.com, tglx@linutronix.de, paulmck@kernel.org, mingo@kernel.org, peterz@infradead.org, will@kernel.org Subject: [PATCH v5 17/18] READ_ONCE: Use data_race() to avoid KCSAN instrumentation Date: Mon, 11 May 2020 21:41:49 +0100 Message-Id: <20200511204150.27858-18-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200511204150.27858-1-will@kernel.org> References: <20200511204150.27858-1-will@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rather then open-code the disabling/enabling of KCSAN across the guts of {READ,WRITE}_ONCE(), defer to the data_race() macro instead. Cc: Marco Elver Signed-off-by: Will Deacon --- include/linux/compiler.h | 53 ++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index f2a64195ee8e..d21a823e73c6 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -199,6 +199,26 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, #include #include +/** + * data_race - mark an expression as containing intentional data races + * + * This data_race() macro is useful for situations in which data races + * should be forgiven. One example is diagnostic code that accesses + * shared variables but is not a part of the core synchronization design. + * + * This macro *does not* affect normal code generation, but is a hint + * to tooling that data races here are to be ignored. + */ +#define data_race(expr) \ +({ \ + __kcsan_disable_current(); \ + ({ \ + __unqual_scalar_typeof(({ expr; })) __v = ({ expr; }); \ + __kcsan_enable_current(); \ + __v; \ + }); \ +}) + /* * Use __READ_ONCE() instead of READ_ONCE() if you do not require any * atomicity or dependency ordering guarantees. Note that this may result @@ -209,14 +229,10 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, #define __READ_ONCE_SCALAR(x) \ ({ \ typeof(x) *__xp = &(x); \ + __unqual_scalar_typeof(x) __x = data_race(__READ_ONCE(*__xp)); \ kcsan_check_atomic_read(__xp, sizeof(*__xp)); \ - __kcsan_disable_current(); \ - ({ \ - __unqual_scalar_typeof(x) __x = __READ_ONCE(*__xp); \ - __kcsan_enable_current(); \ - smp_read_barrier_depends(); \ - (typeof(x))__x; \ - }); \ + smp_read_barrier_depends(); \ + (typeof(x))__x; \ }) #define READ_ONCE(x) \ @@ -234,9 +250,7 @@ do { \ do { \ typeof(x) *__xp = &(x); \ kcsan_check_atomic_write(__xp, sizeof(*__xp)); \ - __kcsan_disable_current(); \ - __WRITE_ONCE(*__xp, val); \ - __kcsan_enable_current(); \ + data_race(({ __WRITE_ONCE(*__xp, val); 0; })); \ } while (0) #define WRITE_ONCE(x, val) \ @@ -304,25 +318,6 @@ unsigned long read_word_at_a_time(const void *addr) return *(unsigned long *)addr; } -/** - * data_race - mark an expression as containing intentional data races - * - * This data_race() macro is useful for situations in which data races - * should be forgiven. One example is diagnostic code that accesses - * shared variables but is not a part of the core synchronization design. - * - * This macro *does not* affect normal code generation, but is a hint - * to tooling that data races here are to be ignored. - */ -#define data_race(expr) \ -({ \ - __kcsan_disable_current(); \ - ({ \ - __unqual_scalar_typeof(({ expr; })) __v = ({ expr; }); \ - __kcsan_enable_current(); \ - __v; \ - }); \ -}) #else #endif /* __KERNEL__ */ -- 2.26.2.645.ge9eca65c58-goog