Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1606444 > unrolled thread

[PATCH v2] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic[64]_read()

Started byDmitry Vyukov <dvyukov@google.com>
First post2017-03-22 14:00 +0100
Last post2017-03-27 08:30 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic[64]_read() Dmitry Vyukov <dvyukov@google.com> - 2017-03-22 14:00 +0100
    Re: [PATCH v2] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic[64]_read() Arnd Bergmann <arnd@arndb.de> - 2017-03-22 15:20 +0100
    Re: [PATCH v2] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in  arch_atomic[64]_read() Ingo Molnar <mingo@kernel.org> - 2017-03-27 08:30 +0200

#1606444 — [PATCH v2] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic[64]_read()

FromDmitry Vyukov <dvyukov@google.com>
Date2017-03-22 14:00 +0100
Subject[PATCH v2] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic[64]_read()
Message-ID<tnO1Q-2wP-29@gated-at.bofh.it>
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[64]_read().

Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Reported-by: Arnd Bergmann <arnd@arndb.de>
Reported-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: kasan-dev@googlegroups.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>

---

Changes since v1:
 - also change arch_atomic64_read()
---
 arch/x86/include/asm/atomic.h      | 15 ++++++---------
 arch/x86/include/asm/atomic64_64.h |  2 +-
 2 files changed, 7 insertions(+), 10 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);
 }
 
 /**
@@ -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);
 }
 
diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
index de9555d35cb0..d47e880e346b 100644
--- a/arch/x86/include/asm/atomic64_64.h
+++ b/arch/x86/include/asm/atomic64_64.h
@@ -18,7 +18,7 @@
  */
 static inline long arch_atomic64_read(const atomic64_t *v)
 {
-	return READ_ONCE_NOCHECK((v)->counter);
+	return READ_ONCE((v)->counter);
 }
 
 /**
-- 
2.12.1.500.gab5fba24ee-goog

[toc] | [next] | [standalone]


#1606532

FromArnd Bergmann <arnd@arndb.de>
Date2017-03-22 15:20 +0100
Message-ID<tnPhf-3Fu-11@gated-at.bofh.it>
In reply to#1606444
On Wed, Mar 22, 2017 at 1:57 PM, Dmitry Vyukov <dvyukov@google.com> 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[64]_read().
>
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Reported-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-mm@kvack.org
> Cc: x86@kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: kasan-dev@googlegroups.com
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
>

Acked-by: Arnd Bergmann <arnd@arndb.de>

[toc] | [prev] | [next] | [standalone]


#1609486 — Re: [PATCH v2] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic[64]_read()

FromIngo Molnar <mingo@kernel.org>
Date2017-03-27 08:30 +0200
SubjectRe: [PATCH v2] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic[64]_read()
Message-ID<tpwk9-3HQ-1@gated-at.bofh.it>
In reply to#1606444
* Dmitry Vyukov <dvyukov@google.com> 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[64]_read().
> 
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Reported-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-mm@kvack.org
> Cc: x86@kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: kasan-dev@googlegroups.com
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> 
> ---
> 
> Changes since v1:
>  - also change arch_atomic64_read()
> ---
>  arch/x86/include/asm/atomic.h      | 15 ++++++---------
>  arch/x86/include/asm/atomic64_64.h |  2 +-
>  2 files changed, 7 insertions(+), 10 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.

s/this is deliberate choice
 /this is a deliberate choice

Also, the patch does not apply to the latest locking tree cleanly, due to 
interacting changes.

Thanks,

	Ingo

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web