[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200401083818.GA16446@willie-the-truck>
Date: Wed, 1 Apr 2020 09:38:19 +0100
From: Will Deacon <will@...nel.org>
To: Marco Elver <elver@...gle.com>
Cc: paulmck@...nel.org, dvyukov@...gle.com, glider@...gle.com,
andreyknvl@...gle.com, cai@....pw, kasan-dev@...glegroups.com,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] kcsan: Change data_race() to no longer require
marking racing accesses
On Tue, Mar 31, 2020 at 09:32:33PM +0200, Marco Elver wrote:
> Thus far, accesses marked with data_race() would still require the
> racing access to be marked in some way (be it with READ_ONCE(),
> WRITE_ONCE(), or data_race() itself), as otherwise KCSAN would still
> report a data race. This requirement, however, seems to be unintuitive,
> and some valid use-cases demand *not* marking other accesses, as it
> might hide more serious bugs (e.g. diagnostic reads).
>
> Therefore, this commit changes data_race() to no longer require marking
> racing accesses (although it's still recommended if possible).
>
> The alternative would have been introducing another variant of
> data_race(), however, since usage of data_race() already needs to be
> carefully reasoned about, distinguishing between these cases likely adds
> more complexity in the wrong place.
Just a thought, but perhaps worth extending scripts/checkpatch.pl to
check for use of data_race() without a comment? We already have that for
memory barriers, so should be easy enough to extend with any luck.
> Link: https://lkml.kernel.org/r/20200331131002.GA30975@willie-the-truck
> Signed-off-by: Marco Elver <elver@...gle.com>
> Cc: Paul E. McKenney <paulmck@...nel.org>
> Cc: Will Deacon <will@...nel.org>
> Cc: Qian Cai <cai@....pw>
> ---
> include/linux/compiler.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index f504edebd5d7..1729bd17e9b7 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -326,9 +326,9 @@ unsigned long read_word_at_a_time(const void *addr)
> #define data_race(expr) \
> ({ \
> typeof(({ expr; })) __val; \
> - kcsan_nestable_atomic_begin(); \
> + kcsan_disable_current(); \
> __val = ({ expr; }); \
> - kcsan_nestable_atomic_end(); \
> + kcsan_enable_current(); \
> __val; \
> })
> #else
Acked-by: Will Deacon <will@...nel.org>
Will
Powered by blists - more mailing lists