Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2049391ybt; Mon, 15 Jun 2020 17:03:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+Q3WWlB5nqbhP2KlmmCt2NKFRT2Ntd0+Pw5l5cX6ZRaVvuJ94drsw2GXgcAOIvEzCv2rs X-Received: by 2002:a17:907:4096:: with SMTP id nm6mr304068ejb.4.1592265798498; Mon, 15 Jun 2020 17:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592265798; cv=none; d=google.com; s=arc-20160816; b=gchA7ApkLZpTWkH474+IPqB48mlMddO7fxk1Y1TKEjyQs6+hGBqMvy+9reJGCqnss5 JUNbUkRkRfk/NgZfNC+ZCPLhrH5Sq33LMoeR/zWa7zJ5aLHWfbd/trxABI+VfTX7do81 pGMMVAZ+15qJw2HmNP2BI1nFEgPbEc2uKo5jRAYYyOW02yE7xDjn3BlV1XZyAM2IaPEE VG3Y7d8qvWKB6+AbRxV5W1wYjd53y2v/O9GWQ+C//oiugVdkZrDHCEwx/xEGTNQMorQl R5NOaJbd47CIi/aZzK372FWHwSk+lsQgwusvnc06WDsjygKeF0KesO0koX5wfeKu1ido fqxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :ironport-sdr:ironport-sdr; bh=Lk3XDy6nF9M3qma+wjxEMyq0TKNdk+S4Ma+hW/yD+wI=; b=hN6VtZ++8g49NKuU8UTNvtPqKpTeURQ6uL9wEy5ke9IGx0Jfxrk4JhlIGl+aVj/4Eo xQ9XvT5QP5xnh0MS4wSeX/bP10wNDZ7Azlnx9CWg3kOA/4LyiBLyCe9DzkEBXEediXeY Eia/Z3LujwahzqA+/QFrLNA67Z5NIaItP/AYnZXCjtEhKkAdR9KdCYc5NQy+tRZb9ox+ 2ChRd8qqOoE3mRYmkGEm3l07Q6VsSUWN0FfzBSy0NxRKV0sE/S3MMPp7ZMNsntASoMFl 9nwzj8ZlfHi2mAawuuaCCfKHAG3b6jlY5RyLfIQ67IS+9gVice0cDQ1q1ViMoQ2PPHjw 9VxQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c21si9771492ejx.217.2020.06.15.17.02.55; Mon, 15 Jun 2020 17:03:18 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726765AbgFOX7B (ORCPT + 99 others); Mon, 15 Jun 2020 19:59:01 -0400 Received: from mga02.intel.com ([134.134.136.20]:16071 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725960AbgFOX7A (ORCPT ); Mon, 15 Jun 2020 19:59:00 -0400 IronPort-SDR: HESacQ+dLlDZGpShz8r/q03RCspVdbjDQnCbPvyEG+aliDB6/ATGyFkxa4sUlIOl/j7pP6tSGq 0avXI1k/krVQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2020 16:58:58 -0700 IronPort-SDR: dHTXH5faPP/KeC8Bu/ZUWkOhKD96CG8brw+X5POJU09JGloLbXkpXpTqmHhxmFEQM1ALPidmjM 1IDKLpNaL6xA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,516,1583222400"; d="scan'208";a="382697634" Received: from km-skylake-client-platform.sc.intel.com ([10.3.52.141]) by fmsmga001.fm.intel.com with ESMTP; 15 Jun 2020 16:58:58 -0700 Message-ID: Subject: Re: [RFC PATCH 1/3] Documentation/x86: Add documentation for /proc/cpuinfo feature flags From: Kyung Min Park To: Borislav Petkov Cc: x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, gregkh@linuxfoundation.org, ak@linux.intel.com, dave.hansen@intel.com, tony.luck@intel.com, ravi.v.shankar@intel.com, ricardo.neri@intel.com, Ricardo Neri Date: Mon, 15 Jun 2020 16:44:03 -0700 In-Reply-To: <20200615181527.GM14668@zn.tnic> References: <20200610200701.16757-1-kyung.min.park@intel.com> <20200610200701.16757-2-kyung.min.park@intel.com> <20200615181527.GM14668@zn.tnic> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Borislav, On Mon, 2020-06-15 at 20:15 +0200, Borislav Petkov wrote: > On Wed, Jun 10, 2020 at 01:06:59PM -0700, Kyung Min Park wrote: > > Add documentation for /proc/cpuinfo feature flags enumeration. > > Document how and when x86 feature flags are used. Also discuss what > > their presence or absence mean for the kernel, users, and > > applications. > > > > Suggested-by: Dave Hansen > > Co-developed-by: Ricardo Neri < > > ricardo.neri-calderon@linux.intel.com> > > Signed-off-by: Ricardo Neri > > Signed-off-by: Kyung Min Park > > --- > > Documentation/x86/cpuinfo.rst | 152 > > ++++++++++++++++++++++++++++++++++ > > Documentation/x86/index.rst | 1 + > > 2 files changed, 153 insertions(+) > > create mode 100644 Documentation/x86/cpuinfo.rst > > I guess, although if we ever change how all that works, we need to > update the documentation but this is the usual thing with > documentation. > Maybe it should not be documented in such a detail. :) > Sure :) > > diff --git a/Documentation/x86/cpuinfo.rst > > b/Documentation/x86/cpuinfo.rst > > new file mode 100644 > > index 000000000000..d01d2c03a4d7 > > --- /dev/null > > +++ b/Documentation/x86/cpuinfo.rst > > @@ -0,0 +1,152 @@ > > +.. SPDX-License-Identifier: GPL-2.0 > > + > > +================= > > +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, any > > application, > > +or an end user > > The kernel yes - the other two, not really. Userspace simply does > CPUID > directly. > Okay, let me remove those two (application, user) here. > > might care about a feature, it can and should have > > +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. > > This needs to say: > > It can be that the kernel doesn't support that feature and thus > hasn't > enabled it. > Sure, Let me modify. > > 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, or an old kernel is in use. In such > > cases, > > +the users need to rely on tools like > > http://www.etallen.com/cpuid.html > > +(which is not updated with kernel releases) or other custom tools > > that > > +read CPUID. > > In general, this should say something along the lines that > /proc/cpuinfo > shows features which the kernel supports. > > "For a full list of CPUID flags which the CPU supports, use > tools/arch/x86/tools/cpuid/cpuid" > > :-) Sure. > > > + > > +How are feature flags created? > > +============================== > > + > > +a: Feature flags can be derived from the contents of CPUID leaves. > > +------------------------------------------------------------------ > > +These feature definitions are organized mirroring the layout of > > CPUID > > +leaves and grouped in words with offsets as mapped in enum > > cpuid_leafs > > +in cpufeatures.h (see arch/x86/include/asm/cpufeatures.h for > > details). > > +If a feature is defined with a X86_FEATURE_ definition in > > +cpufeatures.h, and if it is detected at run time, the flags will > > be > > +displayed accordingly in /proc/cpuinfo. For example, the flag > > "avx2" > > +comes from X86_FEATURE_AVX2 in cpufeatures.h. > > + > > +b: Flags can be from scattered CPUID-based features. > > +---------------------------------------------------- > > +Hardware features enumerated in sparsely populated CPUID leaves > > get > > +software-defined values. Still, CPUID needs to be queried to > > determine > > +if a given feature is present. This is done in > > init_scattered_cpuid_features(). > > +For instance, X86_FEATURE_CQM_LLC is defined as 11*32 + 0 and its > > presence is > > +checked at runtime in the respective CPUID leaf [EAX=f, ECX=0] bit > > EDX[1]. > > + > > +The intent of scattering CPUID leaves is to not bloat struct > > +cpuinfo_x86.x86_capability[] unnecessarily. For instance, the > > CPUID leaf > > +[EAX=7, ECX=0] has 30 features and is dense, but the CPUID leaf > > [EAX=7, EAX=1] > > +has only one feature and would waste 31 bits of space in the > > x86_capability[] > > +array. > > ... and that per-CPU. Let me add more explanation regarding with per-CPU. > > > + > > +c: Flags can be created synthetically under certain conditions for > > hardware features. > > +---------------------------------------------------------------- > > --------------------- > > +Examples of conditions include whether certain features are > > present in > > +MSR_IA32_CORE_CAPS or specific CPU models are identified. If the > > needed > > +conditions are met, the features are enabled by the macro > > set_cpu_cap or > > +setup_force_cpu_cap macro. > > ... by the ... macros. > Sure, let me fix that.