[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH RFC] x86/CPUID: bump max leaf values for guest exposure


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 17 Aug 2023 08:22:19 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=v3cb4RIltlvvY2OAjg0FJ2Llo2WDe3AF8xhOKh12nWo=; b=SpH1Y/HNLpnSJl+oGiKyE5hukMSzoKYwg874QRDvkv5UQfp1OuIUtQ2KAJmFCRgA8u8JCPPA/EgCMdA2MRPWzE/yoiwC9IbEBN2vWuHBHexoxTrqdepy87a8dvXFioNo28DfVOa9noRZjiC9DebK1ackJa7xPCq6ZuVzLa/iVnXCFPUs84TAuWCgc5quQbyTBzFMufgCVLCkJ1c7DcQv/H4SrJqPWsqhTOWugYyi0HStlwN5PIXkFqWD8ndiWzu5QlUolHJfwPYmndN0fJTpNOKjnMabQjVu24v5EcS2ygmmpHWkt9H+PqEo3R7GEf/b6FuLG/LMmmvD99djE7sx5w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L3rxA/EFEWDkaB87ubKT8P4dc40AXwkhQmh+8KnnqqeCUtRTYVQDiYAatUU+fwSJh7+TSKm0+Etl//Kt8EAq0IlQccTOyua0gMIsh/F6CijlSMg0BBH0ze88Wp8UuFZMPkHSfDhiBFeRk17awzdJrE8tUl/rOnCZuIaTxsJsaskEkWI26IG581yXM96I5y5Odotmn51dmBVzRTrC2/fm+NLjjN9seFAq1rAOc4aG8oRIqjKVtDkjx2AlerspacGG/60xpWz3XGbvK3JsxtRbPqHqM3mu2EdAc7KJEbGk2BC60GrsI7ICdzrpiLYRnGvOI+J7zaurLCPEe2ZjCoeCUw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 17 Aug 2023 06:22:40 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Generalize what was done for LFENCE_DISPATCH: To make certain features
that we artificially enable recognizable by guests, respective maximum
leaf values may need to be bumped as well.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
RFC: The call to the function from recalculate_cpuid_policy() is
     somewhat problematic: It's not clear whether a tool stack request
     with a low maximum leaf value should be honored despite our desire
     to expose certain features.

This omits checking basic/extended leaf 1 features, some of which we
also force. I think requests to run guests with max basic/extended leaf
set to zero are sufficiently insane.

Among the large set of changes I don't think I can identify the commit
to validly name in a possible Fixes: tag here.

The cpu-policy.c change would imo look quite a bit better on top of
"x86/CPUID: move bounding of max_{,sub}leaf fields to library code",
which has been pending for a long time.

--- a/xen/arch/x86/cpu-policy.c
+++ b/xen/arch/x86/cpu-policy.c
@@ -360,7 +360,6 @@ void calculate_raw_cpu_policy(void)
 static void __init calculate_host_policy(void)
 {
     struct cpu_policy *p = &host_cpu_policy;
-    unsigned int max_extd_leaf;
 
     *p = raw_cpu_policy;
 
@@ -368,20 +367,8 @@ static void __init calculate_host_policy
         min_t(uint32_t, p->basic.max_leaf,   ARRAY_SIZE(p->basic.raw) - 1);
     p->feat.max_subleaf =
         min_t(uint32_t, p->feat.max_subleaf, ARRAY_SIZE(p->feat.raw) - 1);
-
-    max_extd_leaf = p->extd.max_leaf;
-
-    /*
-     * For AMD/Hygon hardware before Zen3, we unilaterally modify LFENCE to be
-     * dispatch serialising for Spectre mitigations.  Extend max_extd_leaf
-     * beyond what hardware supports, to include the feature leaf containing
-     * this information.
-     */
-    if ( cpu_has_lfence_dispatch )
-        max_extd_leaf = max(max_extd_leaf, 0x80000021);
-
-    p->extd.max_leaf = 0x80000000 | min_t(uint32_t, max_extd_leaf & 0xffff,
-                                          ARRAY_SIZE(p->extd.raw) - 1);
+    p->extd.max_leaf = 0x80000000 | min(p->extd.max_leaf & 0xffffUL,
+                                        ARRAY_SIZE(p->extd.raw) - 1);
 
     x86_cpu_featureset_to_policy(boot_cpu_data.x86_capability, p);
     recalculate_xstate(p);
--- a/xen/lib/x86/cpuid.c
+++ b/xen/lib/x86/cpuid.c
@@ -104,6 +104,22 @@ void x86_cpu_featureset_to_policy(
     p->feat._7d1             = fs[FEATURESET_7d1];
     p->arch_caps.lo          = fs[FEATURESET_m10Al];
     p->arch_caps.hi          = fs[FEATURESET_m10Ah];
+
+    /*
+     * We may force-enable certain features, which then needs reflecting in
+     * respective max leaf / subleaf values.
+     *
+     * ARCH_CAPS lives in 7d0.
+     */
+    if ( p->feat._7d0 && p->basic.max_leaf < 7 )
+        p->basic.max_leaf = 7;
+
+    /*
+     * AMD's speculation related features (e.g. LFENCE_DISPATCH) live in
+     * leaf e21a.
+     */
+    if ( p->extd.e21a && p->extd.max_leaf < 0x80000021 )
+        p->extd.max_leaf = 0x80000021;
 }
 
 void x86_cpu_policy_recalc_synth(struct cpu_policy *p)



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.