Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5070134imu; Tue, 8 Jan 2019 10:58:17 -0800 (PST) X-Google-Smtp-Source: ALg8bN4qNt/odo4lFu2ri3H9cYcbxhUuSOyZxxDdrzDmH1+NFGe1Gjt5xTzoytogrLR5OCvZINDh X-Received: by 2002:a17:902:24e7:: with SMTP id l36mr2935979plg.61.1546973897498; Tue, 08 Jan 2019 10:58:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546973897; cv=none; d=google.com; s=arc-20160816; b=Vv5PZO4eY5yYHxDVaafUUJUiL19cbT77tS4nBl+fV/75XNyAKh0VA1+WeUbvG9IIbC hAYh1egwbi0+qVbPneziQHUdYfW3ZOEqAQaDtyb4v+GYgVOMcFfn/0r/oaPHGJxj0m36 oPTaBDK2ySQcoZQrxouWhUA5xs1xmAym+Nfi5CfhvzmFBV5DbmOKKhsUoH4vtKdzQHTg BOKT0J1VdUD8W2+KXpNXLJEw6qCuOufuF+dSYv+9Sn5JAweCajhPAQYRoxmsRnFprbar 2IfrOYOSWa2F/10H/qkz77WYtOWTimEDDfBmCBKqAG1y7v2dbv8/4WvbgWmOTPAShZEr wMnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=rwYUVliHTc7HkNXU0yAG8EFqotPKadfBdw9qfgOlpJQ=; b=lAPqx4nsODdRN4Oww5mVtq9xTI/S9rTefn3n4JYMMyq5I33WukFlgGFbwRUf0u5+5X xlsb8r/ReiMWXSKgWIm+Kut6646UGbaZdXqbxzDbH6yXUgVh5JXmeCQK+de07j6KcU8x 8hMSecVocHQ/ryuRK1IaykB376Oq4XpHfIc8RK8yyI+c/lyWoFDYdmuZi0XD2WEkhYyN JTox3u3JjaS+YErnG2zAaKwqVxHWyZNLP1xw18EVMp4s5EDYTIsCJDs/Q9Oz4ah7fvNB SOyG0CLdKzkoioLpecvVQMHgjL9bXqBK6An460BDPFWk5EdNheDJ2JBXC+yzhRMkSFzM O1gA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q20si65005588pgl.268.2019.01.08.10.58.02; Tue, 08 Jan 2019 10:58:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728794AbfAHSvD (ORCPT + 99 others); Tue, 8 Jan 2019 13:51:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42178 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727947AbfAHSvD (ORCPT ); Tue, 8 Jan 2019 13:51:03 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A6F589ACA; Tue, 8 Jan 2019 18:51:02 +0000 (UTC) Received: from redhat.com (ovpn-126-25.rdu2.redhat.com [10.10.126.25]) by smtp.corp.redhat.com (Postfix) with SMTP id 2CEA61A7D5; Tue, 8 Jan 2019 18:50:59 +0000 (UTC) Date: Tue, 8 Jan 2019 13:50:58 -0500 From: "Michael S. Tsirkin" To: Nick Desaulniers Cc: Miguel Ojeda , LKML , Jason Wang , Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , linux-arch@vger.kernel.org, netdev@vger.kernel.org, virtualization@lists.linux-foundation.org, Eli Friedman , Joe Perches , Linus Torvalds , Luc Van Oostenryck , linux-sparse@vger.kernel.org, Eric Christopher Subject: Re: [PATCH RFC 1/4] include/linux/compiler*.h: fix OPTIMIZER_HIDE_VAR Message-ID: <20190108134549-mutt-send-email-mst@kernel.org> References: <20190102205715.14054-1-mst@redhat.com> <20190102205715.14054-2-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 08 Jan 2019 18:51:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 08, 2019 at 09:44:28AM -0800, Nick Desaulniers wrote: > Thanks for the patch and sorry for the delay; was totally unplugged > for the holidays. > On Wed, Jan 2, 2019 at 12:57 PM Michael S. Tsirkin wrote: > > > > Since commit 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h > > mutually exclusive") clang no longer reuses the OPTIMIZER_HIDE_VAR macro > > from compiler-gcc - instead it gets the version in > > include/linux/compiler.h. Unfortunately that version doesn't actually > > prevent compiler from optimizing out the variable. > > Good catch. Did you find this via eyeballing the code, a test, or some > other way? eyeballing > > > > Fix up by moving the macro out from compiler-gcc.h to compiler.h. > > Compilers without incline asm support will keep working > > since it's protected by an ifdef. > > > > Also fix up comments to match reality since we are no longer overriding > > any macros. > > > > Build-tested with gcc and clang. > > > > Fixes: 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive") > > Cc: Eli Friedman > > Cc: Joe Perches > > Cc: Nick Desaulniers > > Cc: Linus Torvalds > > Signed-off-by: Michael S. Tsirkin > > Also for more context, see: > commit 7829fb09a2b4 ("lib: make memzero_explicit more robust against > dead store elimination") Interesting. That added this text: * while gcc behavior gets along with a normal * barrier(), llvm needs an explicit input variable to be assumed * clobbered. however: #define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory") So no explicit variable is clobbered. Weird isn't it? > > --- > > include/linux/compiler-clang.h | 5 ++--- > > include/linux/compiler-gcc.h | 4 ---- > > include/linux/compiler-intel.h | 4 +--- > > include/linux/compiler.h | 4 +++- > > 4 files changed, 6 insertions(+), 11 deletions(-) > > > > diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h > > index 3e7dafb3ea80..7ddaeb5182e3 100644 > > --- a/include/linux/compiler-clang.h > > +++ b/include/linux/compiler-clang.h > > @@ -3,9 +3,8 @@ > > #error "Please don't include directly, include instead." > > #endif > > > > -/* Some compiler specific definitions are overwritten here > > - * for Clang compiler > > - */ > > +/* Compiler specific definitions for Clang compiler */ > > + > > #define uninitialized_var(x) x = *(&(x)) > > > > /* same as gcc, this was present in clang-2.6 so we can assume it works > > diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h > > index 2010493e1040..72054d9f0eaa 100644 > > --- a/include/linux/compiler-gcc.h > > +++ b/include/linux/compiler-gcc.h > > @@ -58,10 +58,6 @@ > > (typeof(ptr)) (__ptr + (off)); \ > > }) > > > > -/* Make the optimizer believe the variable can be manipulated arbitrarily. */ > > -#define OPTIMIZER_HIDE_VAR(var) \ > > - __asm__ ("" : "=r" (var) : "0" (var)) > > - > > /* > > * A trick to suppress uninitialized variable warning without generating any > > * code > > diff --git a/include/linux/compiler-intel.h b/include/linux/compiler-intel.h > > index 517bd14e1222..b17f3cd18334 100644 > > --- a/include/linux/compiler-intel.h > > +++ b/include/linux/compiler-intel.h > > @@ -5,9 +5,7 @@ > > > > #ifdef __ECC > > > > -/* Some compiler specific definitions are overwritten here > > - * for Intel ECC compiler > > - */ > > +/* Compiler specific definitions for Intel ECC compiler */ > > > > #include > > > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > > index 06396c1cf127..1ad367b4cd8d 100644 > > --- a/include/linux/compiler.h > > +++ b/include/linux/compiler.h > > @@ -152,7 +152,9 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, > > #endif > > > > #ifndef OPTIMIZER_HIDE_VAR > > -#define OPTIMIZER_HIDE_VAR(var) barrier() > > +/* Make the optimizer believe the variable can be manipulated arbitrarily. */ > > +#define OPTIMIZER_HIDE_VAR(var) \ > > + __asm__ ("" : "=r" (var) : "0" (var)) > > #endif > > This should be fine, thanks for the cleanup! For now, we're not yet > confident to turn on Clang's integrated assembler for the kernel, but > I'll make sure to revisit this should we, in case Clang is then able > to optimize this out. > + Eric, who might know of a better trick for what we're trying to > accomplish with this macro. > > Reviewed-by: Nick Desaulniers > > + Miguel > Miguel, would you mind taking this into your compiler-attributes tree? > -- > Thanks, > ~Nick Desaulniers