2020-05-05 14:26:18

by Thomas Gleixner

[permalink] [raw]
Subject: [patch V4 part 1 06/36] compiler: Simple READ/WRITE_ONCE() implementations

READ/WRITE_ONCE_NOCHECK() is required for atomics in code which cannot be
instrumented like the x86 int3 text poke code. As READ/WRITE_ONCE() is
undergoing a rewrite, provide __{READ,WRITE}_ONCE_SCALAR().

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
---
include/linux/compiler.h | 8 ++++++++
1 file changed, 8 insertions(+)

--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -313,6 +313,14 @@ unsigned long read_word_at_a_time(const
__u.__val; \
})

+#define __READ_ONCE_SCALAR(x) \
+ (*(const volatile typeof(x) *)&(x))
+
+#define __WRITE_ONCE_SCALAR(x, val) \
+do { \
+ *(volatile typeof(x) *)&(x) = val; \
+} while (0)
+
/**
* data_race - mark an expression as containing intentional data races
*


2020-05-06 13:16:00

by Alexandre Chartre

[permalink] [raw]
Subject: Re: [patch V4 part 1 06/36] compiler: Simple READ/WRITE_ONCE() implementations



On 5/5/20 3:16 PM, Thomas Gleixner wrote:
> READ/WRITE_ONCE_NOCHECK() is required for atomics in code which cannot be
> instrumented like the x86 int3 text poke code. As READ/WRITE_ONCE() is
> undergoing a rewrite, provide __{READ,WRITE}_ONCE_SCALAR().
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> Signed-off-by: Thomas Gleixner <[email protected]>
> ---
> include/linux/compiler.h | 8 ++++++++
> 1 file changed, 8 insertions(+)

Reviewed-by: Alexandre Chartre <[email protected]>

alex.

> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -313,6 +313,14 @@ unsigned long read_word_at_a_time(const
> __u.__val; \
> })
>
> +#define __READ_ONCE_SCALAR(x) \
> + (*(const volatile typeof(x) *)&(x))
> +
> +#define __WRITE_ONCE_SCALAR(x, val) \
> +do { \
> + *(volatile typeof(x) *)&(x) = val; \
> +} while (0)
> +
> /**
> * data_race - mark an expression as containing intentional data races
> *
>

2020-05-06 13:36:39

by Will Deacon

[permalink] [raw]
Subject: Re: [patch V4 part 1 06/36] compiler: Simple READ/WRITE_ONCE() implementations

On Tue, May 05, 2020 at 03:16:08PM +0200, Thomas Gleixner wrote:
> READ/WRITE_ONCE_NOCHECK() is required for atomics in code which cannot be
> instrumented like the x86 int3 text poke code. As READ/WRITE_ONCE() is
> undergoing a rewrite, provide __{READ,WRITE}_ONCE_SCALAR().
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> Signed-off-by: Thomas Gleixner <[email protected]>
> ---
> include/linux/compiler.h | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -313,6 +313,14 @@ unsigned long read_word_at_a_time(const
> __u.__val; \
> })
>
> +#define __READ_ONCE_SCALAR(x) \
> + (*(const volatile typeof(x) *)&(x))
> +
> +#define __WRITE_ONCE_SCALAR(x, val) \
> +do { \
> + *(volatile typeof(x) *)&(x) = val; \
> +} while (0)

FWIW, these end up being called __READ_ONCE() and __WRITE_ONCE() after
the rewrite; the *_SCALAR() variants will call into kcsan_check_atomic_*().

If you go with that naming now, then any later conflict should fall out in
the wash.

Will

2020-05-06 16:37:31

by Borislav Petkov

[permalink] [raw]
Subject: Re: [patch V4 part 1 06/36] compiler: Simple READ/WRITE_ONCE() implementations

On Tue, May 05, 2020 at 03:16:08PM +0200, Thomas Gleixner wrote:
> READ/WRITE_ONCE_NOCHECK() is required for atomics in code which cannot be
> instrumented like the x86 int3 text poke code. As READ/WRITE_ONCE() is
> undergoing a rewrite, provide __{READ,WRITE}_ONCE_SCALAR().
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> Signed-off-by: Thomas Gleixner <[email protected]>

Subject needs a verb and patch needs From: Peter, judging by the SOB
chain.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

2020-05-06 23:14:56

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [patch V4 part 1 06/36] compiler: Simple READ/WRITE_ONCE() implementations

On Wed, May 06, 2020 at 02:33:33PM +0100, Will Deacon wrote:
> On Tue, May 05, 2020 at 03:16:08PM +0200, Thomas Gleixner wrote:
> > READ/WRITE_ONCE_NOCHECK() is required for atomics in code which cannot be
> > instrumented like the x86 int3 text poke code. As READ/WRITE_ONCE() is
> > undergoing a rewrite, provide __{READ,WRITE}_ONCE_SCALAR().
> >
> > Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> > Signed-off-by: Thomas Gleixner <[email protected]>
> > ---
> > include/linux/compiler.h | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > --- a/include/linux/compiler.h
> > +++ b/include/linux/compiler.h
> > @@ -313,6 +313,14 @@ unsigned long read_word_at_a_time(const
> > __u.__val; \
> > })
> >
> > +#define __READ_ONCE_SCALAR(x) \
> > + (*(const volatile typeof(x) *)&(x))
> > +
> > +#define __WRITE_ONCE_SCALAR(x, val) \
> > +do { \
> > + *(volatile typeof(x) *)&(x) = val; \
> > +} while (0)
>
> FWIW, these end up being called __READ_ONCE() and __WRITE_ONCE() after
> the rewrite; the *_SCALAR() variants will call into kcsan_check_atomic_*().
>
> If you go with that naming now, then any later conflict should fall out in
> the wash.

Ah excellent, clearly we had slightly different resoltions vs kcsan.
Thanks!