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

Re: [PATCH 2/2] x86/cpuid: support LFENCE always serializing CPUID bit


  • To: Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 14 Apr 2021 14:25:56 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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-SenderADCheck; bh=CD3uwGRZGixIgUbWmlGZxvHhKFX92PHkE4UIamvxsK0=; b=SNiiW+1/W1MLdHJ0pICOycBbiFTYAzR6k6SExW+6B5S4+v6p21BrJJsM6V8yLtxuHQD+A4nTz7YApI9ogXekoFtHuW3GKJ4/efHk7osdyaMUq9iwSE/jwbPu5uxyCxx9S0kvflHdfv+2+0dtdPx0dRQPUCMNdCh71pKeYpJ5QWAcIRYZPRWl7F11QB5JfCOn7w6iaAz5spkgDdLSJ600AuDcSNcGIHpqutMIl7XbaTU5zcVWKsgdeXsvYoH5HYLhc29qTtcR8Y0F6+6nyD4X8TzHRwSXPgBATX5KKPxSO48UMuQxLIUZZr6awfBUoNV3NNtDK/xaM66u9xZ+nUQDAg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O+HJL/DVBwVkRjoV+rTNMef/XdKPf08E5rd/vkOTE0HtBrK3DJOX7HJp+g82ittMosltPQCDj1UZEBYTT+1QrwQFxGzQw1bXHD7+O0Z7jurmvjB7q3TPpbIQBRiM2BXBqNrpJMbDaLKmwK4v0v9R11ZV/zLhHooTGkIztX/XmIcYvYrMpH04agCHAC3tW8zgGl9d1rq68nm8dPTCRHCt7uceQ97y1Fn67uRLDMFxAJm5dLeuGk6D1yh/Qo26Gi09M7RqlwdPDrJg1PoCRrssUKLjFZLyazeubJ6HUyJxv/6YynDbj17XwFjEXYfXZ5Fl/k0jetWg9VzcKGZSiHPurw==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Wei Liu <wl@xxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 14 Apr 2021 13:26:21 +0000
  • Ironport-hdrordr: A9a23:mgbOB6wItJeeN7UMAdULKrPxge4kLtp033Aq2lEZdDV8Sebdv9 yynfgdyB//gCsQXnZlotybJKycWxrnmqJdybI6eZOvRhPvtmftFoFt6oP+3ybtcheTysd07o 0lSaR3DbTLYGRSpdrm4QW+DtYryMSG9qftvuvF03JxV2hRCp1IxS0RMHf9LmRdQg5aCZ0lUL +V4cRarzStEE5nEfiTLH8DQuTFupn3j5rgexELHFoK7wOJgDOu5tfBYmSl9z0ZVC5CxqpnzH jdn2XCl9iemtyY6juZ7W/c6JxKhMDso+EsOOWggtUYQw+c8jqAS59mX9S5zVUIicGprG0nid zd5yonVv4DkU/5WkGQjV/T1xL70DAogkWSumOwpXf4u8T2SHYbJqN69PtkWyDU4UYho91wuZ gjtwny1+s1fGb9tR/w6NTSWxZhmlDcmwtFrccpg2FCSoxbUbdNrOUkjTNoOa0dFyH34p1PKp gNMOjg4p9tADenRkzCsnIq6NKhWWlbJGb8fmEy/uaR0zRQgUljyVoZyME1jh47heMAYqgByO LePqtykrZSCucQcKJmHe8EBfC6E2rXXHv3QS2vCGWiMJtCF2PGqpbx7rlwzOa2eKYQxJ93vJ jaSltXuUM7ZkqGM7zB4LR7tjT2BEmtVzXkzc9To7JjvKfnebbtOSqfDHgzjsqJuZwkc47mcs f2HKgTL+7oLGPoF4oM9Rb5QYNuJX4XV9BQksonWmiJvtnAJuTRx6zmWceWAICoPScvW2v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dc7e/XYLRqmLPeINlZkDVxbjhJqdHinRcGQS9xLzE fOsKK99ykRaYLYrhqwEXX+Bi44A7jfX5l6BRFZBKG35112D9wchVzrIcy4sTewP5RufWAQgbz9 OrlKpnVbAr7PmJ0SlRuxMxAURPhG7Dc04jv04S87v/On5RCNT6px0epsdZWr+sekCIy5df/HHO Nq8=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 14/04/2021 14:05, Andrew Cooper wrote:
> On 14/04/2021 13:57, Jan Beulich wrote:
>> On 14.04.2021 13:04, Roger Pau Monne wrote:
>>> @@ -264,6 +265,38 @@ struct cpuid_policy
>>>              };
>>>              uint32_t nc:8, :4, apic_id_size:4, :16;
>>>              uint32_t /* d */:32;
>>> +
>>> +            uint64_t :64, :64; /* Leaf 0x80000009. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000000a - SVM rev and features. 
>>> */
>>> +            uint64_t :64, :64; /* Leaf 0x8000000b. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000000c. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000000d. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000000e. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000000f. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000010. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000011. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000012. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000013. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000014. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000015. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000016. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000017. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000018. */
>>> +            uint64_t :64, :64; /* Leaf 0x80000019 - TLB 1GB Identifiers. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000001a - Performance related 
>>> info. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000001b - IBS feature 
>>> information. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000001c. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000001d - Cache properties. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000001e - Extd APIC/Core/Node 
>>> IDs. */
>>> +            uint64_t :64, :64; /* Leaf 0x8000001f - AMD Secure Encryption. 
>>> */
>>> +            uint64_t :64, :64; /* Leaf 0x80000020 - Platform QoS. */
>>> +
>>> +            /* Leaf 0x80000021 - Extended Feature 2 */
>>> +            union {
>>> +                uint32_t e21a;
>>> +                struct { DECL_BITFIELD(e21a); };
>>> +            };
>>> +            uint32_t /* b */:32, /* c */:32, /* d */:32;
>>>          };
>>>      } extd;
>> Due to the effect of this on what guests get to see, I think this
>> wants to take my "x86/CPUID: shrink max_{,sub}leaf fields according
>> to actual leaf contents" as a prereq, which in turn may better
>> remain on top of "x86/CPUID: adjust extended leaves out of range
>> clearing" (both are neighbors in that over 4 months old series,
>> fair parts of which could imo go in irrespective of the unsettled
>> dispute on xvmalloc() - unfortunately I had made that patch 2 of
>> the series, not expecting it to be blocked for so long, and then
>> presumably signaling to others that the rest of the series is also
>> blocked).
> There is no shrinking to be done in this case.  The bit is set across
> the board on AMD/Hygon hardware, even on older parts.
>
> What does need changing however is the logic to trim max_extd_leaf down
> to what hardware supports, so the bit is visible on Rome/older
> hardware.  I.e. after this change, all VMs should get 0x80000021 by
> default on AMD hardware.
>
> (A curious observation of Milan hardware is that it actually advertises
> 0x80000023 as max_extd_leaf, and has two leaves of zeros at the end. 
> I've got an open query about this.)

Something like this:

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 050cd5713e..d9eb2878c5 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -311,6 +311,7 @@ static void __init calculate_raw_policy(void)
 static void __init calculate_host_policy(void)
 {
     struct cpuid_policy *p = &host_cpuid_policy;
+    unsigned int max_extd_leaf;
 
     *p = raw_cpuid_policy;
 
@@ -318,7 +319,18 @@ static void __init calculate_host_policy(void)
         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);
-    p->extd.max_leaf = 0x80000000 | min_t(uint32_t, p->extd.max_leaf &
0xffff,
+
+    max_extd_leaf = p->extd.max_leaf;
+
+    /*
+     * For AMD/Hygon hardware before Zen3, we modify LFENCE to be dispatch
+     * serialsing.  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);
 
     cpuid_featureset_to_policy(boot_cpu_data.x86_capability, p);



Only compile tested.  Needs checking on Zen2 or older.  The Raw policy
should have the real max_extd_leaf, while host and derived should have
0x80000021.

~Andrew



 


Rackspace

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