From: Rohan McLure <rmclure@linux.ibm.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: "chris@zankel.net" <chris@zankel.net>,
"elver@google.com" <elver@google.com>,
"linux-xtensa@linux.xtensa.org" <linux-xtensa@linux.xtensa.org>,
"npiggin@gmail.com" <npiggin@gmail.com>,
"jcmvbkbc@gmail.com" <jcmvbkbc@gmail.com>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH v4 1/7] kcsan: Add atomic builtin stubs for 32-bit systems
Date: Thu, 9 Feb 2023 10:14:41 +1100 [thread overview]
Message-ID: <E2FD06BA-F229-425B-B143-01152496C01D@linux.ibm.com> (raw)
In-Reply-To: <fab33693-3a11-2649-0556-e4501faec418@csgroup.eu>
> On 8 Feb 2023, at 11:23 pm, Christophe Leroy <christophe.leroy@csgroup.eu> wrote:
>
>
>
> Le 08/02/2023 à 04:21, Rohan McLure a écrit :
>> KCSAN instruments calls to atomic builtins, and will in turn call these
>> builtins itself. As such, architectures supporting KCSAN must have
>> compiler support for these atomic primitives.
>>
>> Since 32-bit systems are unlikely to have 64-bit compiler builtins,
>> provide a stub for each missing builtin, and use BUG() to assert
>> unreachability.
>>
>> In commit 725aea873261 ("xtensa: enable KCSAN"), xtensa implements these
>> locally, but does not advertise the fact with preprocessor macros. To
>> avoid production of duplicate symbols, do not build the stubs on xtensa.
>> A future patch will remove the xtensa implementation of these stubs.
>>
>> Signed-off-by: Rohan McLure <rmclure@linux.ibm.com>
>> ---
>> v4: New patch
>> ---
>> kernel/kcsan/Makefile | 3 ++
>> kernel/kcsan/stubs.c | 78 +++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 81 insertions(+)
>> create mode 100644 kernel/kcsan/stubs.c
>
> I think it would be better to merge patch 1 and patch 2, that way we
> would keep the history and see that stubs.c almost comes from xtensa.
>
> The summary would then be:
>
> arch/xtensa/lib/Makefile | 1 -
> kernel/kcsan/Makefile | 2 +-
> arch/xtensa/lib/kcsan-stubs.c => kernel/kcsan/stubs.c | 26
> +++++++++++++++++++++++++-
> 3 files changed, 26 insertions(+), 3 deletions(-)
>
>
>>
>> diff --git a/kernel/kcsan/Makefile b/kernel/kcsan/Makefile
>> index 8cf70f068d92..5dfc5825aae9 100644
>> --- a/kernel/kcsan/Makefile
>> +++ b/kernel/kcsan/Makefile
>> @@ -12,6 +12,9 @@ CFLAGS_core.o := $(call cc-option,-fno-conserve-stack) \
>> -fno-stack-protector -DDISABLE_BRANCH_PROFILING
>>
>> obj-y := core.o debugfs.o report.o
>> +ifndef XTENSA
>> + obj-y += stubs.o
>
> obj-$(CONFIG_32BIT) += stubs.o
>
> That would avoid the #if CONFIG_32BIT in stubs.c
Thanks. Yes happy to do this.
>
>> +endif
>>
>> KCSAN_INSTRUMENT_BARRIERS_selftest.o := y
>> obj-$(CONFIG_KCSAN_SELFTEST) += selftest.o
>> diff --git a/kernel/kcsan/stubs.c b/kernel/kcsan/stubs.c
>> new file mode 100644
>> index 000000000000..ec5cd99be422
>> --- /dev/null
>> +++ b/kernel/kcsan/stubs.c
>> @@ -0,0 +1,78 @@
>> +// SPDX-License Identifier: GPL-2.0
>
> Missing - between License and Identifier ?
>
>> +
>> +#include <linux/bug.h>
>> +#include <linux/types.h>
>> +
>> +#ifdef CONFIG_32BIT
>
> Should be handled in Makefile
>
>> +
>> +#if !__has_builtin(__atomic_store_8)
>
> Does any 32 bit ARCH support that ? Is that #if required ?
>
> If yes, do we really need the #if for each and every function, can't we
> just check for one and assume that if we don't have __atomic_store_8 we
> don't have any of the functions ?
Turns out that testing with gcc provides 8-byte atomic builtins on x86
and arm on 32-bit. However I believe it should just suffice to check for
__atomic_store_8 or any other such builtin i.e. if an arch implements one it
likely implements them all from what I’ve seen.
>
>
>> +void __atomic_store_8(volatile void *p, u64 v, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_load_8)
>> +u64 __atomic_load_8(const volatile void *p, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_exchange_8)
>> +u64 __atomic_exchange_8(volatile void *p, u64 v, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_compare_exchange_8)
>> +bool __atomic_compare_exchange_8(volatile void *p1, void *p2, u64 v, bool b, int i1, int i2)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_fetch_add_8)
>> +u64 __atomic_fetch_add_8(volatile void *p, u64 v, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_fetch_sub_8)
>> +u64 __atomic_fetch_sub_8(volatile void *p, u64 v, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_fetch_and_8)
>> +u64 __atomic_fetch_and_8(volatile void *p, u64 v, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_fetch_or_8)
>> +u64 __atomic_fetch_or_8(volatile void *p, u64 v, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_fetch_xor_8)
>> +u64 __atomic_fetch_xor_8(volatile void *p, u64 v, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#if !__has_builtin(__atomic_fetch_nand_8)
>> +u64 __atomic_fetch_nand_8(volatile void *p, u64 v, int i)
>> +{
>> + BUG();
>> +}
>> +#endif
>> +
>> +#endif /* CONFIG_32BIT */
next prev parent reply other threads:[~2023-02-08 23:16 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 3:21 [PATCH v4 0/7] powerpc: Add KCSAN Support Rohan McLure
2023-02-08 3:21 ` [PATCH v4 1/7] kcsan: Add atomic builtin stubs for 32-bit systems Rohan McLure
2023-02-08 4:23 ` Max Filippov
2023-02-08 12:23 ` Christophe Leroy
2023-02-08 23:14 ` Rohan McLure [this message]
2023-02-09 23:36 ` Rohan McLure
2023-02-08 3:21 ` [PATCH v4 2/7] xtensa: kcsan: Remove kcsan stubs for atomic builtins Rohan McLure
2023-02-08 4:24 ` Max Filippov
2023-02-08 3:21 ` [PATCH v4 3/7] powerpc: kcsan: Add exclusions from instrumentation Rohan McLure
2023-02-08 3:21 ` [PATCH v4 4/7] powerpc: kcsan: Exclude udelay to prevent recursive instrumentation Rohan McLure
2023-02-08 3:22 ` [PATCH v4 5/7] powerpc: kcsan: Memory barriers semantics Rohan McLure
2023-02-08 3:22 ` [PATCH v4 6/7] powerpc: kcsan: Prevent recursive instrumentation with IRQ save/restores Rohan McLure
2023-02-08 3:22 ` [PATCH v4 7/7] powerpc: kcsan: Add KCSAN Support Rohan McLure
2023-02-08 10:10 ` Marco Elver
2023-02-08 12:25 ` Christophe Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E2FD06BA-F229-425B-B143-01152496C01D@linux.ibm.com \
--to=rmclure@linux.ibm.com \
--cc=chris@zankel.net \
--cc=christophe.leroy@csgroup.eu \
--cc=elver@google.com \
--cc=jcmvbkbc@gmail.com \
--cc=linux-xtensa@linux.xtensa.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).