Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4779507rdh; Wed, 29 Nov 2023 10:20:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFM0up/plgz2y965mAPisBeQHMCJdwQQZYdlgRDmndczZMJWPzPOWSByyjkd3otpvoHK/da X-Received: by 2002:a17:90b:4b88:b0:285:c1e1:66b with SMTP id lr8-20020a17090b4b8800b00285c1e1066bmr11222264pjb.37.1701282057742; Wed, 29 Nov 2023 10:20:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701282057; cv=none; d=google.com; s=arc-20160816; b=CS8iCmVHzytz678uaBJMn8/uJrGO9o5K2Lps4T5MALF2C6FJecP52Xe7bqJs18mjpu M3yrEls9sRTnvxz2We/bv6DdmqapJNP2Ay1znpoxCXN4Pxf8KTxJB9gnaBQjto+B8wFz eowBDCg71Kr5ATVdSsyUx1hMOfbPWig08QTslb+eeTzYrWA0IX8d37kVlXCUFZtSmqR9 R7hc+AdX+MxAqwtXGBI2G1QcaaRMNIFUk/t5olJtx9Bs5uUbjhLfI+szHZ3XPdMN82lQ V3hBQyw5wEEDmHsDSl2hEeCWtmblZjToIqebShingtlxFLosKAcTbJvACxMnPxsd3Cne HjnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=7y7QjGZy+zv5cePq+dZ1/iTeg6EzqP7A0PvQEtDfsHc=; fh=6LYrjt2C8+n8oZJqh4UfKQQIbZx/uXWb++PjYthlam8=; b=xhtC+AvbnjhPNZvCnGNItA2SC34/FN6vl+kTEUayYXAhMsqi4XkNYGcqXxPTLMZ69f dJ9za8s7rN5z8yY93/s4zBk5ugTKnq3/hCCIV24KXHiEoBz2OB8R7ubrHFMgfpIa/IGj /cw93gxOa4T1+ygSDe6k40D9OwQbxLZeb3681WyKElpudzH8lH7NzmviTi/CnLjx0UaL V5kWnxj3PGH0uKIMXHJiI2YjV8vhA1ngaYsZYkQmkmvG3KfbsWtm8aXHObHkZZpRsqeo 0VPQpTDj+hQ+3sUO7t++70MEg03mh8u4+PTHevrOmBlCrcsen6zNmZ1iYA/DOmG1EkWc WtRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RCcDDE4d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id p18-20020a170902e75200b001cfd2b08900si7209087plf.365.2023.11.29.10.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 10:20:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RCcDDE4d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E0D22807E00C; Wed, 29 Nov 2023 10:20:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231428AbjK2SUe (ORCPT + 99 others); Wed, 29 Nov 2023 13:20:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjK2SUc (ORCPT ); Wed, 29 Nov 2023 13:20:32 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2FBEB6 for ; Wed, 29 Nov 2023 10:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701282039; x=1732818039; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=sTyMsbuQ29XuFRsmsh7TyABKr/lHGBDM3cuS7bGFH/w=; b=RCcDDE4dbYVlvKgENGc+qaNCTqkL8HySCpZIX9veo7XHJ8XgH9Eqn+6x LKsV+GJBcDb2xA0zi0kyCgoLsF2HsUssxjbOACDJamneWVeelY2Bpr7SP dLRNft+QV6hRcsw3ZAZdgV5UrjEBldUUXLoJMJ4OBuiruLdYJLN/wSW60 G2R3WUSKNYuazQkj5qF14JQ+Jv8RFgnI2xBfUxOtsvP9uwHbQihb/YriZ 1d7SXNTPaeLdkFVgkN5Jqa9ok1qvOfpknCZzaO9ZoKATw6ggfWfGOE5XD i+lmD3O1AMy9kaMzJXwmFmlIOFmrTJO5YpVbAdm3NHNt9pj3pEcfyw06c Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="189978" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="189978" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 10:20:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="772769076" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="772769076" Received: from npandey-mobl.amr.corp.intel.com (HELO [10.212.143.94]) ([10.212.143.94]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 10:20:31 -0800 Message-ID: <4afd33ba-6b7c-415f-b9ef-964a2fc840d8@intel.com> Date: Wed, 29 Nov 2023 10:20:31 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Documentation/x86: Document what /proc/cpuinfo is for Content-Language: en-US To: Borislav Petkov , X86 ML Cc: LKML References: <20231129101700.28482-1-bp@alien8.de> From: Dave Hansen Autocrypt: addr=dave.hansen@intel.com; keydata= xsFNBE6HMP0BEADIMA3XYkQfF3dwHlj58Yjsc4E5y5G67cfbt8dvaUq2fx1lR0K9h1bOI6fC oAiUXvGAOxPDsB/P6UEOISPpLl5IuYsSwAeZGkdQ5g6m1xq7AlDJQZddhr/1DC/nMVa/2BoY 2UnKuZuSBu7lgOE193+7Uks3416N2hTkyKUSNkduyoZ9F5twiBhxPJwPtn/wnch6n5RsoXsb ygOEDxLEsSk/7eyFycjE+btUtAWZtx+HseyaGfqkZK0Z9bT1lsaHecmB203xShwCPT49Blxz VOab8668QpaEOdLGhtvrVYVK7x4skyT3nGWcgDCl5/Vp3TWA4K+IofwvXzX2ON/Mj7aQwf5W iC+3nWC7q0uxKwwsddJ0Nu+dpA/UORQWa1NiAftEoSpk5+nUUi0WE+5DRm0H+TXKBWMGNCFn c6+EKg5zQaa8KqymHcOrSXNPmzJuXvDQ8uj2J8XuzCZfK4uy1+YdIr0yyEMI7mdh4KX50LO1 pmowEqDh7dLShTOif/7UtQYrzYq9cPnjU2ZW4qd5Qz2joSGTG9eCXLz5PRe5SqHxv6ljk8mb ApNuY7bOXO/A7T2j5RwXIlcmssqIjBcxsRRoIbpCwWWGjkYjzYCjgsNFL6rt4OL11OUF37wL QcTl7fbCGv53KfKPdYD5hcbguLKi/aCccJK18ZwNjFhqr4MliQARAQABzUVEYXZpZCBDaHJp c3RvcGhlciBIYW5zZW4gKEludGVsIFdvcmsgQWRkcmVzcykgPGRhdmUuaGFuc2VuQGludGVs LmNvbT7CwXgEEwECACI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C7TF vUaNOTjKedrqHkaOcqB185ahG2had0xnFsDPlx5y In-Reply-To: <20231129101700.28482-1-bp@alien8.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 29 Nov 2023 10:20:53 -0800 (PST) On 11/29/23 02:17, Borislav Petkov wrote: > From: "Borislav Petkov (AMD)" > > This has been long overdue. Write down what x86's version of > /proc/cpuinfo is and should be used for. > > Signed-off-by: Borislav Petkov (AMD) > --- > Documentation/arch/x86/cpuinfo.rst | 79 ++++++++++++++++++++++-------- > 1 file changed, 58 insertions(+), 21 deletions(-) > > diff --git a/Documentation/arch/x86/cpuinfo.rst b/Documentation/arch/x86/cpuinfo.rst > index 08246e8ac835..cede6aad27c0 100644 > --- a/Documentation/arch/x86/cpuinfo.rst > +++ b/Documentation/arch/x86/cpuinfo.rst > @@ -7,27 +7,64 @@ x86 Feature Flags > Introduction > ============ > > -On x86, flags appearing in /proc/cpuinfo have an X86_FEATURE definition > -in arch/x86/include/asm/cpufeatures.h. If the kernel cares about a feature > -or KVM want to expose the feature to a KVM guest, it can and should have > -an X86_FEATURE_* defined. These flags represent hardware features as > -well as software features. > - > -If users want to know if a feature is available on a given system, they > -try to find the flag in /proc/cpuinfo. If a given flag is present, it > -means that the kernel supports it and is currently making it available. > -If such flag represents a hardware feature, it also means that the > -hardware supports it. > - > -If the expected flag does not appear in /proc/cpuinfo, things are murkier. > -Users need to find out the reason why the flag is missing and find the way > -how to enable it, which is not always easy. There are several factors that > -can explain missing flags: the expected feature failed to enable, the feature > -is missing in hardware, platform firmware did not enable it, the feature is > -disabled at build or run time, an old kernel is in use, or the kernel does > -not support the feature and thus has not enabled it. In general, /proc/cpuinfo > -shows features which the kernel supports. For a full list of CPUID flags > -which the CPU supports, use tools/arch/x86/kcpuid. > +The list of feature flags in /proc/cpuinfo is not complete and > +represents an ill-fated attempt from long time ago to put feature flags > +in an easy to find place for userspace. > + > +However, the amount of feature flags is growing by the CPU generation, > +leading to unparseable and unwieldy /proc/cpuinfo. > + > +What is more, those feature flags do not even need to be in that file > +because userspace doesn't care about them - glibc et al already use > +CPUID to find out what the target machine supports and what not. > + > +And even if it doesn't show a particular feature flag - although the CPU > +still does have support for the respective hardware functionality and > +said CPU supports CPUID faulting - userspace can simply probe for the > +feature and figure out if it is supported or not, regardless of whether > +it is being advertized somewhere. ^ advertised > +Furthermore, those flag strings become an ABI the moment they appear > +there and maintaining them forever when nothing even uses them is a lot > +of wasted effort. > + > +So, the current use of /proc/cpuinfo is to show features which the > +kernel has *enabled* and supports. As in: the CPUID feature flag is > +there, there's an additional setup which the kernel has done while > +booting and the functionality is there and ready to use. A perfect > +example for that is "user_shstk" where additional code enablement is > +present in the kernel to support shadow stack for user programs. > + > +So, if users want to know if a feature is available on a given system, > +they try to find the flag in /proc/cpuinfo. If a given flag is present, > +it means Just rephrasing the meanings, I think I'd say that it means: all of the following: * The kernel knows about the feature enough to have an X86_FEATURE_ bit * The kernel supports it and is currently making it available either to userspace or some other part of the kernel * If the flag represents a hardware feature the hardware supports it > +If the expected flag does not appear in /proc/cpuinfo, things are > +murkier. Users need to find out the reason why the flag is missing and > +find the way how to enable it, which is not always easy. > + > +There are several factors that can explain missing flags: the expected > +feature failed to enable, the feature is missing in hardware, platform > +firmware did not enable it, the feature is disabled at build or run > +time, an old kernel is in use, or the kernel does not support the > +feature and thus has not enabled it. In general, /proc/cpuinfo shows > +features which the kernel supports. For a full list of CPUID flags which > +the CPU supports, use tools/arch/x86/kcpuid. Could we trim this down a bit? Maybe concentrate on one example and then just jump to the takeaway: The absence of a flag in /proc/cpuinfo by itself means almost nothing to an end user. A feature like "vaes" might be fully available to user applications on an kernel that has not defined X86_FEATURE_VAES and thus there is no "vaes" in /proc/cpuinfo. On the other hand, a new kernel running on non-VAES hardware would also have no "vaes" in /proc/cpuinfo. There's no way for an application or user to tell the difference. The end result is that the flags field in /proc/cpuinfo is marginally useful for kernel debugging, but not really for anything else. Applications should instead use things like the glibc facilities for querying CPU support. Users should rely on tools like tools/arch/x86/kcpuid and cpuid(1).