From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932436AbbJMOQh (ORCPT ); Tue, 13 Oct 2015 10:16:37 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:36414 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932190AbbJMOQf (ORCPT ); Tue, 13 Oct 2015 10:16:35 -0400 Date: Tue, 13 Oct 2015 16:16:04 +0200 From: Ingo Molnar To: Andrey Ryabinin Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , "H. Peter Anvin" , x86@kernel.org, Andrew Morton , Andy Lutomirski , Andrey Konovalov , Kostya Serebryany , Alexander Potapenko , kasan-dev , Borislav Petkov , Denys Vlasenko , Andi Kleen , Dmitry Vyukov , Sasha Levin , Wolfram Gloger Subject: Re: [PATCH v2 1/2] Provide READ_ONCE_NOCHECK() Message-ID: <20151013141604.GA9601@gmail.com> References: <1444739750-29241-1-git-send-email-aryabinin@virtuozzo.com> <1444739750-29241-2-git-send-email-aryabinin@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1444739750-29241-2-git-send-email-aryabinin@virtuozzo.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Andrey Ryabinin wrote: > +#define __READ_ONCE_SIZE \ > +({ \ > + switch (size) { \ > + case 1: *(__u8 *)res = *(volatile __u8 *)p; break; \ > + case 2: *(__u16 *)res = *(volatile __u16 *)p; break; \ > + case 4: *(__u32 *)res = *(volatile __u32 *)p; break; \ > + case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \ > + default: \ > + barrier(); \ > + __builtin_memcpy((void *)res, (const void *)p, size); \ > + barrier(); \ > + } \ > +}) > + > +static __always_inline > +void __read_once_size_check(const volatile void *p, void *res, int size) > { > + __READ_ONCE_SIZE; > } > +#ifdef CONFIG_KASAN > +static __no_sanitize_address __maybe_unused > +void __read_once_size_nocheck(const volatile void *p, void *res, int size) > +{ > + __READ_ONCE_SIZE; > +} > +#else > +static __always_inline __alias(__read_once_size_check) > +void __read_once_size_nocheck(const volatile void *p, void *res, int size); > +#endif > +#define __READ_ONCE(x, check) \ > +({ \ > + union { typeof(x) __val; char __c[1]; } __u; \ > + __read_once_size##check(&(x), __u.__c, sizeof(x)); \ > + __u.__val; \ > +}) > +#define READ_ONCE(x) __READ_ONCE(x, _check) > +#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, _nocheck) So all this code is quite convoluted, and as the changelog explains it's done to work around a GCC inlining + no-kasan bug. But please explain this in the code as well, in a comment, so future generations are not kept wondering why these relatively simple wrappers are coded in such an ugly and roundabout fashion. Thanks, Ingo