x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic_read()
Subsystems (3)
PATCH 1/1 x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic_read()
Two problems was reported with READ_ONCE_NOCHECK in arch_atomic_read:
1. Andrey Ryabinin reported significant binary size increase (+400K of text). READ_ONCE_NOCHECK is intentionally compiled to non-inlined function call, and I counted 640 copies of it in my vmlinux.
2. Arnd Bergmann reported a new splat of too large frame sizes.
A single inlined KASAN check is very cheap, a non-inlined function call with KASAN/KCOV instrumentation can easily be more expensive.
Switch to READ_ONCE() in arch_atomic_read().
--- arch/x86/include/asm/atomic.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
arch/x86/include/asm/atomic.h +6 -9
@@ -24,10 +24,13 @@ static __always_inline int arch_atomic_read(const atomic_t *v) {/* -* We use READ_ONCE_NOCHECK() because atomic_read() contains KASAN -* instrumentation. Double instrumentation is unnecessary. +* Note: READ_ONCE() here leads to double instrumentation as +* both READ_ONCE() and atomic_read() contain instrumentation. +* This is deliberate choice. READ_ONCE_NOCHECK() is compiled to a +* non-inlined function call that considerably increases binary size +* and stack usage under KASAN. */ -return READ_ONCE_NOCHECK ((v)->counter); +return READ_ONCE ((v)->counter); }/**
@@ -39,12 +42,6 @@ static __always_inline int arch_atomic_read(const atomic_t *v)*/ static __always_inline void arch_atomic_set(atomic_t *v, int i) { -/* -* We could use WRITE_ONCE_NOCHECK() if it exists, similar to -* READ_ONCE_NOCHECK() in arch_atomic_read(). But there is no such -* thing at the moment, and introducing it for this case does not -* worth it. -*/ WRITE_ONCE (v->counter, i); }
Signature · 7 lines
2.12.1.500.gab5fba24ee-goog -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 36 lines · Dmitry Vyukov
Two problems was reported with
READ_ONCE_NOCHECKinarch_atomic_read:
1. Andrey Ryabinin reported significant binary size increase (+400K of text).READ_ONCE_NOCHECKis intentionally compiled to non-inlined function call, and I counted 640 copies of it in my vmlinux.
2. Arnd Bergmann reported a new splat of too large frame sizes.A single inlined KASAN check is very cheap, a non-inlined function call with KASAN/KCOV instrumentation can easily be more expensive.
Switch to
READ_ONCE()inarch_atomic_read().Signed-off-by Dmitry Vyukov <[email protected]>Reported-by Arnd Bergmann <[email protected]>Reported-by Andrey Ryabinin <[email protected]>Cc Mark Rutland <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Will Deacon <[email protected]>Cc Andrey Ryabinin <[email protected]>Cc Andrew Morton <[email protected]>--- arch/x86/include/asm/atomic.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)arch/x86/include/asm/atomic.h +0
-1@@ -24,10 +24,13 @@ static __always_inline int arch_atomic_read(const atomic_t *v) {/* -* We use READ_ONCE_NOCHECK() because atomic_read() contains KASAN
arch/x86/include/asm/atomic.h line 34
Quoted 10 lines
arch/x86/include/asm/atomic.h +6
-2-* instrumentation. Double instrumentation is unnecessary. +* Note: READ_ONCE() here leads to double instrumentation as +* both READ_ONCE() and atomic_read() contain instrumentation. +* This is deliberate choice. READ_ONCE_NOCHECK() is compiled to a +* non-inlined function call that considerably increases binary size +* and stack usage under KASAN. */ -return READ_ONCE_NOCHECK ((v)->counter); +return READ_ONCE ((v)->counter); }
The change looks good, but the same one is needed in atomic64.h
Arnd
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 41 lines · Arnd Bergmann
Quoted 40 lines · Dmitry Vyukov
Two problems was reported with
READ_ONCE_NOCHECKinarch_atomic_read:
1. Andrey Ryabinin reported significant binary size increase (+400K of text).READ_ONCE_NOCHECKis intentionally compiled to non-inlined function call, and I counted 640 copies of it in my vmlinux.
2. Arnd Bergmann reported a new splat of too large frame sizes.A single inlined KASAN check is very cheap, a non-inlined function call with KASAN/KCOV instrumentation can easily be more expensive.
Switch to
READ_ONCE()inarch_atomic_read().Signed-off-by Dmitry Vyukov <[email protected]>Reported-by Arnd Bergmann <[email protected]>Reported-by Andrey Ryabinin <[email protected]>Cc Mark Rutland <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Will Deacon <[email protected]>Cc Andrey Ryabinin <[email protected]>Cc Andrew Morton <[email protected]>--- arch/x86/include/asm/atomic.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)arch/x86/include/asm/atomic.h +3
-2@@ -24,10 +24,13 @@ static __always_inline int arch_atomic_read(const atomic_t *v) {/* -* We use READ_ONCE_NOCHECK() because atomic_read() contains KASAN -* instrumentation. Double instrumentation is unnecessary. +* Note: READ_ONCE() here leads to double instrumentation as +* both READ_ONCE() and atomic_read() contain instrumentation. +* This is deliberate choice. READ_ONCE_NOCHECK() is compiled to a
Quoted 8 lines
arch/x86/include/asm/atomic.h line 34
Quoted 6 lines
arch/x86/include/asm/atomic.h +3
-1+* non-inlined function call that considerably increases binary size +* and stack usage under KASAN. */ -return READ_ONCE_NOCHECK ((v)->counter); +return READ_ONCE ((v)->counter); }The change looks good, but the same one is needed in
atomic64.h
Right. Mailed v2.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>