Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1275373ybk; Thu, 14 May 2020 05:05:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqgZ00aql7v7YODBw/mayIzM4UyUck3hKKpBzD99C+hzV3lqNJQGsi/XKtvAXed6wvQdcv X-Received: by 2002:a17:906:abce:: with SMTP id kq14mr3325628ejb.187.1589457951248; Thu, 14 May 2020 05:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589457951; cv=none; d=google.com; s=arc-20160816; b=Y/Nut9GamyXkkeiuJvfw+0+svZvHqkked04bkUcvyhDHZ7uqyjNNCMxdrSjG218z3R 0j/XbWbcXZauvCG99UlCR+zuN110Ujl1IHSL8j3ZlFzK4GT6S3PWfcDM2VU5qmmFlvWr ZKV4yL4n/WVirBnapgpYg7vPRvPyi6jgKcNir3Iu0Q3YNEV1xcNMA3A2aSyq1SanF/rR Sgy87DrBlmCU8ptK2lww52trTgJphDbbbx9Aaxn/O7SA0nmhoCsXmHt3J+v3sBlt4hMh dSn1/5lbf2IsXiD7yrpjpUKlrviKu7BB4EP1nIOAR+TVHSFES/lNlVY1D1LkKK5CPDHf m0yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nmk6vvjr5QH1T9fCUw/iewIkU6DAwKp6b6Kzy6BD130=; b=dUr8KcBxO5baFSeb+uB4b2KFq3QgGKW7qVkPP4T6Nat73KS0G6LWgjFwN/x2+AjdC0 xDB3eCqRjnt1o1kbigMP8egBvnPwUAEt5JDbU7JEtGZI/uRFRDjye5v2nHFnHEu05Fwz YRF2N5ohYWzDudZ2ZESK96X44ZUMjteyYaJ1waAr3NKx2jZUmQ3XfpAY+K3aGira5tES DekG28kvkQgDxL1N6xSjT+ASikforbanhwB0k2FHfEfiwnoxxLwVG+u1RnwXe2r9Qcjn NwO+mbhhO4Mp2jKoGqA+qGrfrz9loa2I9hGlB8/XxXdZqx7at2O8QhUG6X4UIIJ7kRBJ Aj/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f8ckis++; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si1749835eja.138.2020.05.14.05.05.28; Thu, 14 May 2020 05:05:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f8ckis++; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726240AbgENMBK (ORCPT + 99 others); Thu, 14 May 2020 08:01:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:45192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgENMBJ (ORCPT ); Thu, 14 May 2020 08:01:09 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 203902065D; Thu, 14 May 2020 12:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589457669; bh=1R0oD1rKhcYN+Ed55aTvuPeewcTVpQPAYBSDRIGjIV4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=f8ckis++g/UCCCD8zU/9atNzfBa4/gzp+fCSUbSHEC2YQKx1+PwiDi07W3Z1ScOH8 nEzRCM9nY5lEOIg2No0tz9Tvnu6fMsZiHmZnMFteJ0r6JKQu5SBtZABcohnio91jkz chdf0eUnHWBwSxZS2b0lN02Z3edXoDJ5Baa4CJGg= Date: Thu, 14 May 2020 13:01:04 +0100 From: Will Deacon To: Peter Zijlstra Cc: Marco Elver , LKML , Thomas Gleixner , "Paul E. McKenney" , Ingo Molnar , Dmitry Vyukov Subject: Re: [PATCH v5 00/18] Rework READ_ONCE() to improve codegen Message-ID: <20200514120104.GD4280@willie-the-truck> References: <20200512190755.GL2957@hirez.programming.kicks-ass.net> <20200513111057.GN2957@hirez.programming.kicks-ass.net> <20200513123243.GO2957@hirez.programming.kicks-ass.net> <20200513124021.GB20278@willie-the-truck> <20200513132440.GN2978@hirez.programming.kicks-ass.net> <20200514112142.GV2978@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200514112142.GV2978@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 14, 2020 at 01:21:42PM +0200, Peter Zijlstra wrote: > On Wed, May 13, 2020 at 03:58:30PM +0200, Marco Elver wrote: > > On Wed, 13 May 2020 at 15:24, Peter Zijlstra wrote: > > > > > > On Wed, May 13, 2020 at 03:15:55PM +0200, Marco Elver wrote: > > > > So far so good, except: both __no_sanitize_or_inline and > > > > __no_kcsan_or_inline *do* avoid KCSAN instrumenting plain accesses, it > > > > just doesn't avoid explicit kcsan_check calls, like those in > > > > READ/WRITE_ONCE if KCSAN is enabled for the compilation unit. That's > > > > just because macros won't be redefined just for __no_sanitize > > > > functions. Similarly, READ_ONCE_NOCHECK does work as expected, and its > > > > access is unchecked. > > > > > > > > This will have the expected result: > > > > __no_sanitize_or_inline void foo(void) { x++; } // no data races reported > > > > > > > > This will not work as expected: > > > > __no_sanitize_or_inline void foo(void) { READ_ONCE(x); } // data > > > > races are reported > > > > > > > > All this could be fixed if GCC devs would finally take my patch to > > > > make -fsanitize=thread distinguish volatile [1], but then we have to > > > > wait ~years for the new compilers to reach us. So please don't hold > > > > your breath for this one any time soon. > > > > [1] https://gcc.gnu.org/pipermail/gcc-patches/2020-April/544452.html > > > > > > Right, but that does not address the much larger issue of the attribute > > > vs inline tranwreck :/ > > > > Could you check if Clang is equally broken for you? I think GCC and > > Clang have differing behaviour on this. No idea what it takes to fix > > GCC though. > > So I have some good and some maybe not so good news. > > Given the patch below (on top of tglx's entry-v5-the-rest tag); I did > find that I could actually build alternative.o for gcc-{8,9,10} and > indeed clang-10. Any earlier gcc (I tried, 5,6,7) does not build: > > ../arch/x86/include/asm/ptrace.h:126:28: error: inlining failed in call to always_inline ‘user_mode’: function attribute mismatch > > I dumped the poke_int3_handler output using objdump, find the attached > files. > > It looks like clang-10 doesn't want to turn UBSAN off :/ The GCC files > look OK, no funny calls in those. > > (the config has KASAN/UBSAN on, it looks like KCSAN and KASAN are > mutually exclusive) > > --- > > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c > index 77c83833d91e..06d8db612efc 100644 > --- a/arch/x86/kernel/alternative.c > +++ b/arch/x86/kernel/alternative.c > @@ -990,7 +990,7 @@ static __always_inline int patch_cmp(const void *key, const void *elt) > return 0; > } > > -int noinstr poke_int3_handler(struct pt_regs *regs) > +int noinstr __no_kcsan __no_sanitize_address __no_sanitize_undefined poke_int3_handler(struct pt_regs *regs) > { > struct bp_patching_desc *desc; > struct text_poke_loc *tp; > diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h > index 2cb42d8bdedc..5e83aada6553 100644 > --- a/include/linux/compiler-clang.h > +++ b/include/linux/compiler-clang.h > @@ -15,6 +15,13 @@ > /* all clang versions usable with the kernel support KASAN ABI version 5 */ > #define KASAN_ABI_VERSION 5 > > +#if __has_feature(undefined_sanitizer) Hmm, this might want to be __has_feature(undefined_behavior_sanitizer) (and damn is that hard for a Brit to type out!) Will