Re: [PATCH] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic_read()

From: Dmitry Vyukov
Date: Wed Mar 22 2017 - 09:06:14 EST


On Wed, Mar 22, 2017 at 1:51 PM, Arnd Bergmann <arnd@xxxxxxxx> wrote:
> On Wed, Mar 22, 2017 at 1:24 PM, Dmitry Vyukov <dvyukov@xxxxxxxxxx> wrote:
>> 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().
>>
>> Signed-off-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
>> Reported-by: Arnd Bergmann <arnd@xxxxxxxx>
>> Reported-by: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx>
>> Cc: Mark Rutland <mark.rutland@xxxxxxx>
>> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>> Cc: Will Deacon <will.deacon@xxxxxxx>
>> Cc: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx>
>> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
>> Cc: linux-mm@xxxxxxxxx
>> Cc: x86@xxxxxxxxxx
>> Cc: linux-kernel@xxxxxxxxxxxxxxx
>> Cc: kasan-dev@xxxxxxxxxxxxxxxx
>> ---
>> arch/x86/include/asm/atomic.h | 15 ++++++---------
>> 1 file changed, 6 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
>> index 0cde164f058a..46e53bbf7ce3 100644
>> --- a/arch/x86/include/asm/atomic.h
>> +++ b/arch/x86/include/asm/atomic.h
>> @@ -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);
>> }
>
> The change looks good, but the same one is needed in atomic64.h

Right. Mailed v2.