Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5147095imb; Thu, 7 Mar 2019 08:45:32 -0800 (PST) X-Google-Smtp-Source: APXvYqzE6VFiLDBQ+JhlQ23hpjL+1t3x8j+GN3VlWcIteuDA2Ho3F09q4vvMXAt66SAfoBpIdJIN X-Received: by 2002:a17:902:930b:: with SMTP id bc11mr14042492plb.101.1551977132284; Thu, 07 Mar 2019 08:45:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551977132; cv=none; d=google.com; s=arc-20160816; b=rW0WLuzqAt3Klx+AxaGWPPSG8PhTwD9fLhof3p3OG0mE+5wWneY3I849qe85Gb4prA tmJ2sUnji0WVKSLSn+I77MNEEl2gkPXJIIRpsx75i1yCUWVLXgExOzhZglQPvtUQmJ0d yFBDB18qThyHZvENxbYvNQ5TDDfSYQjlJfiznWmbK9pOOhzexnksr3pNk8iiJd3BycIr yQxIui0Pr4sWlj9mH6CjzBSfupWDgJAonf+dbGRux1ht7YgBJO0gviTbhSMAxX8OkJih gV28FxsjBFR6+/c1V5Z5OZIQ3CpwfG8N5NE2dkOVrM53KfDr3xxcpU+taeyXqT2O2pm9 WNIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:from:cc:to:subject :content-transfer-encoding:mime-version:references:in-reply-to :user-agent:date; bh=w/e2RTQ5o/JxR76ClVgXTAs5scRf9RG/GonpiwjhH2c=; b=enzCPkm6roH9liz1j5bq/oxAQJ0BTAHe1EnfI1SXwzUOY5NZRtK35bivoxMS4ZmEdg JLBVHeSc/EgiSQ00DS76CqaSPqrYFdCIBCyMZU5hM9jQ2y8BSiWq8ny0TidDbbk1oarE XWC+JdykrqTPwyMNeFmLhQtCYUTBIqaqU2/8AXTw6Q0Yx6tg6v3uT4XnkbFU/CEOrWR9 pGGFXI+aA742z/6RU/+Fbsfg6kgzWEAMIbFgY9va/gnVcn5c2djTt1PVqrSZxTBkO7Ua wRhCuR1Xv5HFtDH41qFZ5/punZjfKDpv9ofRZru3/iZ4EQRHDKsd9+0hrt+EpUgM6fbL aaMQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k30si4345568pgi.146.2019.03.07.08.45.16; Thu, 07 Mar 2019 08:45:32 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726346AbfCGQou convert rfc822-to-8bit (ORCPT + 99 others); Thu, 7 Mar 2019 11:44:50 -0500 Received: from terminus.zytor.com ([198.137.202.136]:59551 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbfCGQou (ORCPT ); Thu, 7 Mar 2019 11:44:50 -0500 Received: from [IPv6:2607:fb90:363c:d311:852d:262d:594c:4506] ([IPv6:2607:fb90:363c:d311:852d:262d:594c:4506]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id x27Ghstd2258097 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 7 Mar 2019 08:43:55 -0800 Date: Thu, 07 Mar 2019 08:43:50 -0800 User-Agent: K-9 Mail for Android In-Reply-To: <20190307151036.GD26566@zn.tnic> References: <20190129003422.9328-1-rick.p.edgecombe@intel.com> <20190129003422.9328-11-rick.p.edgecombe@intel.com> <20190211182956.GN19618@zn.tnic> <1533F2BB-2284-499B-9912-6D74D0B87BC1@gmail.com> <20190211190108.GP19618@zn.tnic> <20190211191059.GR19618@zn.tnic> <3996E3F9-92D2-4561-84E9-68B43AC60F43@gmail.com> <20190211194251.GS19618@zn.tnic> <20190307151036.GD26566@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Subject: Re: [PATCH] x86/cpufeature: Remove __pure attribute to _static_cpu_has() To: Borislav Petkov , Nadav Amit CC: Rick Edgecombe , Andy Lutomirski , Ingo Molnar , LKML , X86 ML , Thomas Gleixner , Dave Hansen , Peter Zijlstra , Damian Tometzki , linux-integrity , LSM List , Andrew Morton , Kernel Hardening , Linux-MM , Will Deacon , Ard Biesheuvel , Kristen Carlson Accardi , "Dock, Deneen T" , Kees Cook , Dave Hansen , Masami Hiramatsu From: hpa@zytor.com Message-ID: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On March 7, 2019 7:10:36 AM PST, Borislav Petkov wrote: >On Mon, Feb 11, 2019 at 12:32:41PM -0800, Nadav Amit wrote: >> BTW: the “__pure” attribute is useless when “__always_inline” is >used. >> Unless it is intended to be some sort of comment, of course. > >--- >From: Borislav Petkov >Date: Thu, 7 Mar 2019 15:54:51 +0100 > >__pure is used to make gcc do Common Subexpression Elimination (CSE) >and thus save subsequent invocations of a function which does a complex >computation (without side effects). As a simple example: > > bool a = _static_cpu_has(x); > bool b = _static_cpu_has(x); > >gets turned into > > bool a = _static_cpu_has(x); > bool b = a; > >However, gcc doesn't do CSE with asm()s when those get inlined - like >it >is done with _static_cpu_has() - because, for example, the t_yes/t_no >labels are different for each inlined function body and thus cannot be >detected as equivalent anymore for the CSE heuristic to hit. > >However, this all is beside the point because best it should be avoided >to have more than one call to _static_cpu_has(X) in the same function >due to the fact that each such call is an alternatives patch site and >it >is simply pointless. > >Therefore, drop the __pure attribute as it is not doing anything. > >Reported-by: Nadav Amit >Signed-off-by: Borislav Petkov >Cc: Peter Zijlstra >Cc: x86@kernel.org >--- > arch/x86/include/asm/cpufeature.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/arch/x86/include/asm/cpufeature.h >b/arch/x86/include/asm/cpufeature.h >index e25d11ad7a88..6d6d5cc4302b 100644 >--- a/arch/x86/include/asm/cpufeature.h >+++ b/arch/x86/include/asm/cpufeature.h >@@ -162,7 +162,7 @@ extern void clear_cpu_cap(struct cpuinfo_x86 *c, >unsigned int bit); >* majority of cases and you should stick to using it as it is generally > * only two instructions: a RIP-relative MOV and a TEST. > */ >-static __always_inline __pure bool _static_cpu_has(u16 bit) >+static __always_inline bool _static_cpu_has(u16 bit) > { > asm_volatile_goto("1: jmp 6f\n" > "2:\n" Uhm... (a) it is correct, even if the compiler doesn't use it now, it allows the compiler to CSE it in the future; (b) it is documentation; (c) there is an actual bug here: the "volatile" implies a side effect, which in reality is not present, inhibiting CSE. So the correct fix is to remove "volatile", not remove "__pure". -- Sent from my Android device with K-9 Mail. Please excuse my brevity.