From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934668AbdCVNeC (ORCPT ); Wed, 22 Mar 2017 09:34:02 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36500 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751333AbdCVNdj (ORCPT ); Wed, 22 Mar 2017 09:33:39 -0400 From: Dmitry Vyukov To: akpm@linux-foundation.org, arnd@arndb.de, aryabinin@virtuozzo.com Cc: Dmitry Vyukov , Mark Rutland , Peter Zijlstra , Will Deacon , linux-mm@kvack.org, x86@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: [PATCH] x86: s/READ_ONCE_NOCHECK/READ_ONCE/ in arch_atomic_read() Date: Wed, 22 Mar 2017 13:24:49 +0100 Message-Id: <20170322122449.54505-1-dvyukov@google.com> X-Mailer: git-send-email 2.12.1.500.gab5fba24ee-goog Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reported-by: Arnd Bergmann Reported-by: Andrey Ryabinin Cc: Mark Rutland Cc: Peter Zijlstra Cc: Will Deacon Cc: Andrey Ryabinin Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org Cc: kasan-dev@googlegroups.com --- 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); } /** @@ -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); } -- 2.12.1.500.gab5fba24ee-goog