Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5073970imb; Thu, 7 Mar 2019 07:12:30 -0800 (PST) X-Google-Smtp-Source: APXvYqy+rYpQyiTSw1tsZSQf1OzzpA/JZhtk9GKUGT69NTiSDgXK5HCoGgp/XXMGd6Td64/+2k2+ X-Received: by 2002:aa7:8299:: with SMTP id s25mr13353469pfm.56.1551971550855; Thu, 07 Mar 2019 07:12:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551971550; cv=none; d=google.com; s=arc-20160816; b=IPH0VsXyjYv11wF9M2sAcFQfY0fUWf84qAi8FgFCHZibquNy9NptH+1hIjxG61qbuu wyPX1Q+ZBu9zBt7SOCw3k3RTJL42aleBKhkdyhYnNjMR7nAEIwXeCqdH6dFty41JW93c er4h9jGXUL4bVS/ggROiEI2C4XHY8bS7n0pmISolrWkHg3SyHoMXtxs7ZBI5XO3wdO97 cBw7NAkkTty9BRyT1D8czaQhQD78xIo/bN+pArYvi2BZKDkAlD2zUpT/azhEphsDvk77 SO7NqQ18VHf/t8fhkFWpQxlCbP4pdoGPHItTvyQO9m6YavmsK1qCU6XOrra9LqXtkHu7 WK8g== 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=kdSZyLABXvjmDygL4RnuOnEqI4iIDZt3NsvoEDPNehs=; b=OM0vVfeyITgEdc/fVekUHIbTHVO++c0kkIYhGw/nM0IQ37O1tyZubzBhIp0FsIq9FF yuqHzKZAR1Q22jewRetXkM211g1E0RCbMCBikDNpJxMwZS8m+ddXohtXHzNojUJYEd0Y fk8l5FuC2bLeFpoVG8SwaBBHgEAlZGQ1XfOdXwhwQj2amNUw09hF8xZxNVj279T3tHYX OorqnMe7lGveCLJ2oySMXaev/zMx/wT4D0pBNb583tkfUxsDQAxIlamjBpjXfZIH0JC2 ffP6+e/zNV0gfQg6mr8ZYc1YzpUjNikEudfegiPSCXVGpz/o6nVhzb3bQNsNMtXODlbE 5MbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=VxevkReC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c64si4454850pfg.36.2019.03.07.07.12.15; Thu, 07 Mar 2019 07:12:30 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=VxevkReC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726311AbfCGPKk (ORCPT + 99 others); Thu, 7 Mar 2019 10:10:40 -0500 Received: from mail.skyhub.de ([5.9.137.197]:35936 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbfCGPKk (ORCPT ); Thu, 7 Mar 2019 10:10:40 -0500 Received: from zn.tnic (unknown [IPv6:2003:ec:2f08:1c00:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 3062E1EC064E; Thu, 7 Mar 2019 16:10:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1551971438; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kdSZyLABXvjmDygL4RnuOnEqI4iIDZt3NsvoEDPNehs=; b=VxevkReCqFwOtl9CNQIPP9gjHkfkPvNXF6zSFMZRSq4+VQyXRKowRR/y94+03BL2OMZmB0 JQQG//BggqJOuKLDfIrnnXfUrkBg3eVnqigcbNhNnCeNbO6HYPrevRnsTSodztTdEEAayD MGAXCsKnyh7965zUMAu/+Ts/W3nsU8E= Date: Thu, 7 Mar 2019 16:10:36 +0100 From: Borislav Petkov To: Nadav Amit Cc: Rick Edgecombe , Andy Lutomirski , Ingo Molnar , LKML , X86 ML , "H. Peter Anvin" , 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 Subject: [PATCH] x86/cpufeature: Remove __pure attribute to _static_cpu_has() Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 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" -- 2.21.0 -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.