Skip to contentSkip to conversation

x86: Add hack to disable "Fake HT" mode

RFC PATCH In review George Dunlap 6 participants 34 messages Nov 15, 2019

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 x86: Add hack to disable "Fake HT" mode

Changeset ca2eee92df44 ("x86, hvm: Expose host core/HT topology to HVM guests") attempted to "fake up" a topology which would induce guest operating systems to not treat vcpus as sibling hyperthreads. This involved (among other things) actually reporting hyperthreading as available, but giving vcpus every other APICID. The resulting cpu featureset is invalid, but most operating systems on most hardware managed to cope with it.

Unfortunately, Windows running on modern AMD hardware -- including Ryzen 3xxx series processors, and reportedly EPYC "Rome" cpus -- gets confused by the resulting contradictory feature bits and crashes during installation. (Linux guests have so far continued to cope.)

A "proper" fix is complicated and it's too late to fix it either for 4.13, or to backport to supported branches. As a short-term fix, implement an option to disable this "Fake HT" mode. The resulting topology reported will not be canonical, but experimentally continues to work with Windows guests.

However, disabling this "Fake HT" mode has not been widely tested, and will almost certainly break migration if applied inconsistently.

To minimize impact while allowing administrators to disable "Fake HT" only on guests which are known not to work without it (i.e., Windows guests) on affected hardware, add an environment variable which can be set to disable the "Fake HT" mode on such hardware.

---
This has been compile-tested only; I'm posting it early to get feedback on the approach.

TODO: Prevent such guests from being migrated

Open questions:

- Is this the right place to put the getenv check?

- Is there any way we can make migration work, at least in some cases?

- Can we check for known-problematic models, and at least report a more useful error?

CC Andrew Cooper <[email protected]>
CC Jan Beulich <[email protected]>
CC Ian Jackson <[email protected]>
CC Anthony Perard <[email protected]>
---
 tools/libxc/xc_cpuid_x86.c | 74 +++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 29 deletions(-)
tools/libxc/xc_cpuid_x86.c +45 -29
index 312c481f1e..70c85e1467 100644
@@ -579,52 +579,68 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
+        p->basic.htt = false;
         p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-
         switch ( p->x86_vendor )
         {
         case X86_VENDOR_INTEL:
             for ( i = 0; (p->cache.subleaf[i].type &&
                           i < ARRAY_SIZE(p->cache.raw)); ++i )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
+                p->cache.subleaf[i].cores_per_package = 0;
                 p->cache.subleaf[i].threads_per_cache = 0;
             }
             break;
+        }
 
-        case X86_VENDOR_AMD:
-        case X86_VENDOR_HYGON:
+        if ( !getenv("XEN_LIBXC_DISABLE_FAKEHT") ) {
             /*
-             * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
-             * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
-             * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
-             * - overflow,
-             * - going out of sync with leaf 1 EBX[23:16],
-             * - incrementing ApicIdCoreSize when it's zero (which changes the
-             *   meaning of bits 7:0).
+             * Topology for HVM guests is entirely controlled by Xen.  For now, we
+             * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
              */
-            if ( p->extd.nc < 0x7f )
+            p->basic.htt = true;
+
+            /*
+             * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
+             * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
+             * overflow.
+             */
+            if ( !(p->basic.lppp & 0x80) )
+                p->basic.lppp *= 2;
+
+            switch ( p->x86_vendor )
             {
-                if ( p->extd.apic_id_size != 0 && p->extd.apic_id_size != 0xf )
-                    p->extd.apic_id_size++;
+            case X86_VENDOR_INTEL:
+                for ( i = 0; (p->cache.subleaf[i].type &&
+                              i < ARRAY_SIZE(p->cache.raw)); ++i )
+                {
+                    p->cache.subleaf[i].cores_per_package =
+                        (p->cache.subleaf[i].cores_per_package << 1) | 1;
+                    p->cache.subleaf[i].threads_per_cache = 0;
+                }
+
+            case X86_VENDOR_AMD:
+            case X86_VENDOR_HYGON:
+                /*
+                 * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
+                 * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
+                 * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
+                 * - overflow,
+                 * - going out of sync with leaf 1 EBX[23:16],
+                 * - incrementing ApicIdCoreSize when it's zero (which changes the
+                 *   meaning of bits 7:0).
+                 */
+                if ( p->extd.nc < 0x7f )
+                {
+                    if ( p->extd.apic_id_size != 0 && p->extd.apic_id_size != 0xf )
+                        p->extd.apic_id_size++;
+
+                    p->extd.nc = (p->extd.nc << 1) | 1;
+                }
+                break;
 
-                p->extd.nc = (p->extd.nc << 1) | 1;
             }
-            break;
         }
 
         /*
Signature · 7 lines
2.24.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 8 lines · George Dunlap

Open questions:

- Is this the right place to put the getenv check?

- Is there any way we can make migration work, at least in some cases?

- Can we check for known-problematic models, and at least report a more useful error?

Checking for specific models should be straightforward, but I wonder how sensible it is to compile a likely ever growing list into here.

As to the reporting of an error - you saying "more useful" suggests there is some error already being reported. But I don't see any here, nor does any come to mind.

Quoted 12 lines
tools/libxc/xc_cpuid_x86.c +1 -5
@@ -579,52 +579,68 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
+        p->basic.htt = false;

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 596

Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +0 -8
         p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-

I appreciate you wanting to put all adjustments in a central place, but at least it makes patch review more difficult. How about you latch !getenv("XEN_LIBXC_DISABLE_FAKEHT") into a local boolean at the top of the function and then the above would become

        if ( !(p->basic.lppp & 0x80) )
            p->basic.lppp <<= fakeht;

and e.g. ...

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 604

Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +0 -2
         switch ( p->x86_vendor )
         {
         case X86_VENDOR_INTEL:
             for ( i = 0; (p->cache.subleaf[i].type &&
                           i < ARRAY_SIZE(p->cache.raw)); ++i )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;

... this

                p->cache.subleaf[i].cores_per_package =
                    (p->cache.subleaf[i].cores_per_package << fakeht) | fakeht;

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 591

Quoted 1 line
tools/libxc/xc_cpuid_x86.c +1 -0
+                p->cache.subleaf[i].cores_per_package = 0;

This doesn't look correct - you need to leave alone the field if the adjustment moved down is supposed to have any effect. This is an example of why the bigger code movement you do is risky.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 5 lines · Jan Beulich
Quoted 4 lines · George Dunlap

Open questions:

- Is this the right place to put the getenv check?

Quoted 7 lines
Quoted 4 lines

- Is there any way we can make migration work, at least in some cases?

- Can we check for known-problematic models, and at least report a more useful error?

Checking for specific models should be straightforward, but I wonder how sensible it is to compile a likely ever growing list into here.

The hope is that this would be a short-term fix, replaced by something more robust in 4.14.

Quoted 4 lines

As to the reporting of an error - you saying "more useful" suggests there is some error already being reported. But I don't see any here, nor does any come to mind.

At the moment, if someone buys a Ryzen 3xxx box, installs Xen, and tries to boot a Windows guest, Windows will simply crash (as I understand it).
(That is, the issue is "reported" by a BSoD.) That person will then
google around, and hopefully run across the various threads here, and see that she should add "export XEN_LIBXC_DISABLE_FAKEHT=1" when starting their Windows guests.

Suppose instead that after buying a Ryzen 3xxx box, and installing Xen, when starting a guest, they got the following error message:

"WARNING: This system may be affected by Xen bug $FOO. Please see $DOCUMENTATION and set XEN_LIBXC_DISABLE_FAKEHT appropriately."

It would mean annoying people not running Windows unnecessarily; but it seems like a better experience than having a guest crash and searching for a solution.

(And to be clear, the reason it's RFC is to ask what people think of this idea, rather than to argue that this is what we should do.)

Quoted 43 lines
Quoted 13 lines
tools/libxc/xc_cpuid_x86.c +1 -5
@@ -579,52 +579,68 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
+        p->basic.htt = false;

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 596

Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +0 -8
         p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-

I appreciate you wanting to put all adjustments in a central place, but at least it makes patch review more difficult. How about you latch !getenv("XEN_LIBXC_DISABLE_FAKEHT") into a local boolean at the top of the function and then the above would become

        if ( !(p->basic.lppp & 0x80) )
            p->basic.lppp <<= fakeht;

and e.g. ...

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 604

Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +0 -2
         switch ( p->x86_vendor )
         {
         case X86_VENDOR_INTEL:
             for ( i = 0; (p->cache.subleaf[i].type &&
                           i < ARRAY_SIZE(p->cache.raw)); ++i )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
Quoted 4 lines

... this

                p->cache.subleaf[i].cores_per_package =
                    (p->cache.subleaf[i].cores_per_package << fakeht) | fakeht;

I'm afraid I think the code itself would then become more difficult to read; and it seems a bit strange to be architecting our code based on limitations of the diff algorithm and/or diff viewer used.

I could break the patch down into two if you think that would make it easier to review. You might also try a diff viewer which shows both before and after; I use 'meld'.

Quoted 5 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 591

Quoted 1 line
tools/libxc/xc_cpuid_x86.c +1 -0
+                p->cache.subleaf[i].cores_per_package = 0;

This doesn't look correct - you need to leave alone the field if the adjustment moved down is supposed to have any effect. This is an example of why the bigger code movement you do is risky.

Ah yes, I didn't notice the calculation was self-referential. Let me take a look.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 44 lines · George Dunlap
Quoted 43 lines · Jan Beulich
Quoted 12 lines · George Dunlap
tools/libxc/xc_cpuid_x86.c +1 -5
@@ -579,52 +579,68 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
+        p->basic.htt = false;

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 596

Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +0 -8
         p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-

I appreciate you wanting to put all adjustments in a central place, but at least it makes patch review more difficult. How about you latch !getenv("XEN_LIBXC_DISABLE_FAKEHT") into a local boolean at the top of the function and then the above would become

        if ( !(p->basic.lppp & 0x80) )
            p->basic.lppp <<= fakeht;

and e.g. ...

Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +0 -2
         switch ( p->x86_vendor )
         {
         case X86_VENDOR_INTEL:
             for ( i = 0; (p->cache.subleaf[i].type &&
                           i < ARRAY_SIZE(p->cache.raw)); ++i )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
Quoted 7 lines
Quoted 4 lines

... this

                p->cache.subleaf[i].cores_per_package =
                    (p->cache.subleaf[i].cores_per_package << fakeht) | fakeht;

I'm afraid I think the code itself would then become more difficult to read;

Slightly, but yes.

Quoted 2 lines

and it seems a bit strange to be architecting our code based on limitations of the diff algorithm and/or diff viewer used.

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 53 lines · Jan Beulich
Quoted 42 lines · George Dunlap
Quoted 41 lines · Jan Beulich
Quoted 12 lines · George Dunlap
tools/libxc/xc_cpuid_x86.c +1 -5
@@ -579,52 +579,68 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
+        p->basic.htt = false;

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 596

Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +0 -8
         p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-

I appreciate you wanting to put all adjustments in a central place, but at least it makes patch review more difficult. How about you latch !getenv("XEN_LIBXC_DISABLE_FAKEHT") into a local boolean at the top of the function and then the above would become

        if ( !(p->basic.lppp & 0x80) )
            p->basic.lppp <<= fakeht;

and e.g. ...

Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +0 -2
         switch ( p->x86_vendor )
         {
         case X86_VENDOR_INTEL:
             for ( i = 0; (p->cache.subleaf[i].type &&
                           i < ARRAY_SIZE(p->cache.raw)); ++i )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
Quoted 6 lines
Quoted 4 lines

... this

                p->cache.subleaf[i].cores_per_package =
                    (p->cache.subleaf[i].cores_per_package << fakeht) | fakeht;

I'm afraid I think the code itself would then become more difficult to read;

Slightly, but yes.

Quoted 2 lines

and it seems a bit strange to be architecting our code based on limitations of the diff algorithm and/or diff viewer used.

Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The only thing which is an open question (IMO) is if/how to trigger this quirk mode.  There are no good options.  We just need to agree on the least bad one.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 64 lines · Andrew Cooper
Quoted 53 lines · Jan Beulich
Quoted 42 lines · George Dunlap
Quoted 41 lines · Jan Beulich
Quoted 12 lines · George Dunlap
tools/libxc/xc_cpuid_x86.c +1 -5
@@ -579,52 +579,68 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
+        p->basic.htt = false;

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 596

Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +0 -8
         p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-

I appreciate you wanting to put all adjustments in a central place, but at least it makes patch review more difficult. How about you latch !getenv("XEN_LIBXC_DISABLE_FAKEHT") into a local boolean at the top of the function and then the above would become

        if ( !(p->basic.lppp & 0x80) )
            p->basic.lppp <<= fakeht;

and e.g. ...

Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +0 -2
         switch ( p->x86_vendor )
         {
         case X86_VENDOR_INTEL:
             for ( i = 0; (p->cache.subleaf[i].type &&
                           i < ARRAY_SIZE(p->cache.raw)); ++i )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
Quoted 6 lines
Quoted 4 lines

... this

                p->cache.subleaf[i].cores_per_package =
                    (p->cache.subleaf[i].cores_per_package << fakeht) | fakeht;

I'm afraid I think the code itself would then become more difficult to read;

Slightly, but yes.

Quoted 2 lines

and it seems a bit strange to be architecting our code based on limitations of the diff algorithm and/or diff viewer used.

Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

-George

From f26c03ebc1b8ad91a61ce07fd5632ea63f158120 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 14 Nov 2019 16:58:34 +0000
Subject: [PATCH] x86: Add hack to disable "Fake HT" mode

Changeset ca2eee92df44 ("x86, hvm: Expose host core/HT topology to HVM guests") attempted to "fake up" a topology which would induce guest operating systems to not treat vcpus as sibling hyperthreads. This involved (among other things) actually reporting hyperthreading as available, but giving vcpus every other APICID. The resulting cpu featureset is invalid, but most operating systems on most hardware managed to cope with it.

Unfortunately, Windows running on modern AMD hardware -- including Ryzen 3xxx series processors, and reportedly EPYC "Rome" cpus -- gets confused by the resulting contradictory feature bits and crashes during installation. (Linux guests have so far continued to cope.)

A "proper" fix is complicated and it's too late to fix it either for 4.13, or to backport to supported branches. As a short-term fix, implement an option to disable this "Fake HT" mode. The resulting topology reported will not be canonical, but experimentally continues to work with Windows guests.

However, disabling this "Fake HT" mode has not been widely tested, and will almost certainly break migration if applied inconsistently.

To minimize impact while allowing administrators to disable "Fake HT" only on guests which are known not to work without it (i.e., Windows guests) on affected hardware, add an environment variable which can be set to disable the "Fake HT" mode on such hardware.

---
This has been compile-tested only; I'm posting it early to get feedback on the approach.

TODO: Prevent such guests from being migrated

Open questions:

- Is this the right place to put the getenv check?

- Is there any way we can make migration work, at least in some cases?

- Can we check for known-problematic models, and at least report a more useful error?

CC Andrew Cooper <[email protected]>
CC Jan Beulich <[email protected]>
CC Ian Jackson <[email protected]>
CC Anthony Perard <[email protected]>
---
 tools/libxc/xc_cpuid_x86.c | 97 +++++++++++++++++++++++---------------
 1 file changed, 58 insertions(+), 39 deletions(-)
tools/libxc/xc_cpuid_x86.c +58 -39
index 312c481f1e..bc088e45f0 100644
@@ -579,52 +579,71 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
-        p->extd.cmp_legacy = false;
+        if ( !getenv("XEN_LIBXC_DISABLE_FAKEHT") ) {
+            /*
+             * Topology for HVM guests is entirely controlled by Xen.  For now, we
+             * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
+             */
+            p->basic.htt = true;
+            p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
+            /*
+             * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
+             * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
+             * overflow.
+             */
+            if ( !(p->basic.lppp & 0x80) )
+                p->basic.lppp *= 2;
 
-        switch ( p->x86_vendor )
-        {
-        case X86_VENDOR_INTEL:
-            for ( i = 0; (p->cache.subleaf[i].type &&
-                          i < ARRAY_SIZE(p->cache.raw)); ++i )
+            switch ( p->x86_vendor )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
-                p->cache.subleaf[i].threads_per_cache = 0;
+            case X86_VENDOR_INTEL:
+                for ( i = 0; (p->cache.subleaf[i].type &&
+                              i < ARRAY_SIZE(p->cache.raw)); ++i )
+                {
+                    p->cache.subleaf[i].cores_per_package =
+                        (p->cache.subleaf[i].cores_per_package << 1) | 1;
+                    p->cache.subleaf[i].threads_per_cache = 0;
+                }
+
+            case X86_VENDOR_AMD:
+            case X86_VENDOR_HYGON:
+                /*
+                 * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
+                 * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
+                 * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
+                 * - overflow,
+                 * - going out of sync with leaf 1 EBX[23:16],
+                 * - incrementing ApicIdCoreSize when it's zero (which changes the
+                 *   meaning of bits 7:0).
+                 */
+                if ( p->extd.nc < 0x7f )
+                {
+                    if ( p->extd.apic_id_size != 0 && p->extd.apic_id_size != 0xf )
+                        p->extd.apic_id_size++;
+
+                    p->extd.nc = (p->extd.nc << 1) | 1;
+                }
+                break;
+
             }
-            break;
+        }
+        else
+        {
+            p->basic.htt = false;
+            p->extd.cmp_legacy = false;
 
-        case X86_VENDOR_AMD:
-        case X86_VENDOR_HYGON:
-            /*
-             * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
-             * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
-             * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
-             * - overflow,
-             * - going out of sync with leaf 1 EBX[23:16],
-             * - incrementing ApicIdCoreSize when it's zero (which changes the
-             *   meaning of bits 7:0).
-             */
-            if ( p->extd.nc < 0x7f )
+            switch ( p->x86_vendor )
             {
-                if ( p->extd.apic_id_size != 0 && p->extd.apic_id_size != 0xf )
-                    p->extd.apic_id_size++;
-
-                p->extd.nc = (p->extd.nc << 1) | 1;
+            case X86_VENDOR_INTEL:
+                for ( i = 0; (p->cache.subleaf[i].type &&
+                              i < ARRAY_SIZE(p->cache.raw)); ++i )
+                {
+                    p->cache.subleaf[i].cores_per_package = 0;
+                    p->cache.subleaf[i].threads_per_cache = 0;
+                }
+                break;
             }
-            break;
         }
 
         /*
Signature · 1 line
2.24.0

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 65 lines · George Dunlap
Quoted 64 lines · Andrew Cooper
Quoted 62 lines · Jan Beulich
Quoted 42 lines · George Dunlap
Quoted 41 lines · Jan Beulich
Quoted 12 lines · George Dunlap
tools/libxc/xc_cpuid_x86.c +1 -5
@@ -579,52 +579,68 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  For now, we
-         * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
-         */
-        p->basic.htt = true;
+        p->basic.htt = false;

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 596

Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +0 -8
         p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package.
-         * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-

I appreciate you wanting to put all adjustments in a central place, but at least it makes patch review more difficult. How about you latch !getenv("XEN_LIBXC_DISABLE_FAKEHT") into a local boolean at the top of the function and then the above would become

        if ( !(p->basic.lppp & 0x80) )
            p->basic.lppp <<= fakeht;

and e.g. ...

Quoted 8 lines
tools/libxc/xc_cpuid_x86.c +0 -2
         switch ( p->x86_vendor )
         {
         case X86_VENDOR_INTEL:
             for ( i = 0; (p->cache.subleaf[i].type &&
                           i < ARRAY_SIZE(p->cache.raw)); ++i )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
Quoted 6 lines
Quoted 4 lines

... this

                p->cache.subleaf[i].cores_per_package =
                    (p->cache.subleaf[i].cores_per_package << fakeht) | fakeht;

I'm afraid I think the code itself would then become more difficult to read;

Slightly, but yes.

Quoted 2 lines

and it seems a bit strange to be architecting our code based on limitations of the diff algorithm and/or diff viewer used.

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 5 lines
Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

I mean, if we *really* wanted to optimize for diff readability, we could use gotos instead, but I thought that would be going a bit too far.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
In reply to George Dunlap
Quoted 9 lines · George Dunlap
Quoted 9 lines
Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 4 lines
Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

What I meant was:

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 579

Quoted 6 lines
tools/libxc/xc_cpuid_x86.c +0 -0
index 312c481f1e..bc088e45f0 100644
@@ -579,52 +579,71 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }

else if ( getenv() )
{
    ...
}

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 581

Quoted 2 lines
tools/libxc/xc_cpuid_x86.c +0 -0
     else
     {

With no delta to this block at all.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw
Quoted 29 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 9 lines
Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 4 lines
Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

What I meant was:

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 579

Quoted 6 lines
tools/libxc/xc_cpuid_x86.c +0 -0
index 312c481f1e..bc088e45f0 100644
@@ -579,52 +579,71 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }

else if ( getenv() )
{
    ...
}

Quoted 4 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 581

Quoted 2 lines
tools/libxc/xc_cpuid_x86.c +0 -0
     else
     {

With no delta to this block at all.

Then we have to duplicate this code in both blocks:

/*
* These settings are necessary to cause earlier
HVM_PARAM_NESTEDHVM /

         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;

I won't object if that's what you guys really want.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw
Quoted 44 lines · George Dunlap
Quoted 27 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 9 lines
Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 4 lines
Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

What I meant was:

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 579

Quoted 6 lines
tools/libxc/xc_cpuid_x86.c +0 -0
index 312c481f1e..bc088e45f0 100644
@@ -579,52 +579,71 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }

else if ( getenv() )
{
    ...
}

Quoted 3 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 581

Quoted 2 lines
tools/libxc/xc_cpuid_x86.c +0 -0
     else
     {

With no delta to this block at all.

Then we have to duplicate this code in both blocks:

/*
* These settings are necessary to cause earlier
HVM_PARAM_NESTEDHVM /

         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
Quoted 1 line

I won't object if that's what you guys really want.

I'd also be happy with a single "goto hvm_common;".  These tweaks are already at the end of the block, so suitably positioned.

None of this code is going to survive for long.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw
In reply to George Dunlap
Quoted 48 lines · George Dunlap
Quoted 29 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 9 lines
Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 4 lines
Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

What I meant was:

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 579

Quoted 6 lines
tools/libxc/xc_cpuid_x86.c +0 -0
index 312c481f1e..bc088e45f0 100644
@@ -579,52 +579,71 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }

else if ( getenv() )
{
    ...
}

Quoted 4 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 581

Quoted 2 lines
tools/libxc/xc_cpuid_x86.c +0 -0
     else
     {

With no delta to this block at all.

Then we have to duplicate this code in both blocks:

/*
* These settings are necessary to cause earlier
HVM_PARAM_NESTEDHVM /

         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
Quoted 1 line

I won't object if that's what you guys really want.

Personally I think the duplication is less bad than the far heavier original code churn, but to be honest, especially with this intended to go away again soon anyway, I'd not be opposed at all to

    ...
    else if ( getenv() )
        goto no_fake_ht;
    else
    {
    ...
 no_fake_ht:
        /*
         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
    }

(despite my general dislike of goto).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#11 lore raw
Quoted 51 lines · Jan Beulich
Quoted 48 lines · George Dunlap
Quoted 29 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 9 lines
Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 4 lines
Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

What I meant was:

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 579

Quoted 6 lines
tools/libxc/xc_cpuid_x86.c +0 -0
index 312c481f1e..bc088e45f0 100644
@@ -579,52 +579,71 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }

else if ( getenv() )
{
    ...
}

Quoted 4 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 581

Quoted 2 lines
tools/libxc/xc_cpuid_x86.c +0 -0
     else
     {

With no delta to this block at all.

Then we have to duplicate this code in both blocks:

/*
* These settings are necessary to cause earlier
HVM_PARAM_NESTEDHVM /

         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
Quoted 1 line

I won't object if that's what you guys really want.

Quoted 8 lines

Personally I think the duplication is less bad than the far heavier original code churn, but to be honest, especially with this intended to go away again soon anyway, I'd not be opposed at all to

    ...
    else if ( getenv() )
        goto no_fake_ht;

This isn't correct, because you do need to clear htt and cmp_legacy, as well as zeroing out cores_per_package and threads_per_cache on Intel. (At least, that's what XenServer's patch does, and it's the best tested.)

Quoted 15 lines
    else
    {
    ...
 no_fake_ht:
        /*
         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
    }
Quoted 1 line

(despite my general dislike of goto).

Well I think gotos into other blocks is even worse. :-)

I think the result is a lot nicer to review for sure.

-George

From b83b7b6db04b0705878798cded2f4c6904cf6fb5 Mon Sep 17 00:00:00 2001
From: George Dunlap <[email protected]>
Date: Thu, 14 Nov 2019 16:58:34 +0000
Subject: [PATCH] x86: Add hack to disable "Fake HT" mode

Changeset ca2eee92df44 ("x86, hvm: Expose host core/HT topology to HVM guests") attempted to "fake up" a topology which would induce guest operating systems to not treat vcpus as sibling hyperthreads. This involved (among other things) actually reporting hyperthreading as available, but giving vcpus every other APICID. The resulting cpu featureset is invalid, but most operating systems on most hardware managed to cope with it.

Unfortunately, Windows running on modern AMD hardware -- including Ryzen 3xxx series processors, and reportedly EPYC "Rome" cpus -- gets confused by the resulting contradictory feature bits and crashes during installation. (Linux guests have so far continued to cope.)

A "proper" fix is complicated and it's too late to fix it either for 4.13, or to backport to supported branches. As a short-term fix, implement an option to disable this "Fake HT" mode. The resulting topology reported will not be canonical, but experimentally continues to work with Windows guests.

However, disabling this "Fake HT" mode has not been widely tested, and will almost certainly break migration if applied inconsistently.

To minimize impact while allowing administrators to disable "Fake HT" only on guests which are known not to work without it (i.e., Windows guests) on affected hardware, add an environment variable which can be set to disable the "Fake HT" mode on such hardware.

---
This has been compile-tested only; I'm posting it early to get feedback on the approach.

TODO: Prevent such guests from being migrated

Open questions:

- Is this the right place to put the getenv check?

- Is there any way we can make migration work, at least in some cases?

- Can we check for known-problematic models, and at least report a more useful error?

CC Andrew Cooper <[email protected]>
CC Jan Beulich <[email protected]>
CC Ian Jackson <[email protected]>
CC Anthony Perard <[email protected]>
---
 tools/libxc/xc_cpuid_x86.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
tools/libxc/xc_cpuid_x86.c +21 -0
index 312c481f1e..029a1f1938 100644
@@ -579,6 +579,26 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }
     else
     {
+        if ( getenv("XEN_LIBXC_DISABLE_FAKEHT") ) {
+            p->basic.htt = false;
+            p->extd.cmp_legacy = false;
+
+            switch ( p->x86_vendor )
+            {
+            case X86_VENDOR_INTEL:
+                for ( i = 0; (p->cache.subleaf[i].type &&
+                              i < ARRAY_SIZE(p->cache.raw)); ++i )
+                {
+                    p->cache.subleaf[i].cores_per_package = 0;
+                    p->cache.subleaf[i].threads_per_cache = 0;
+                }
+                break;
+            }
+
+            goto hvm_common;
+        }
+
+
         /*
          * Topology for HVM guests is entirely controlled by Xen.  For now, we
          * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT.
@@ -627,6 +647,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
             break;
         }
 
+    hvm_common:
         /*
          * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
          * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
Signature · 1 line
2.24.0

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#12 lore raw
Quoted 80 lines · George Dunlap
Quoted 51 lines · Jan Beulich
Quoted 48 lines · George Dunlap
Quoted 29 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 9 lines
Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 4 lines
Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

What I meant was:

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 579

Quoted 6 lines
tools/libxc/xc_cpuid_x86.c +0 -0
index 312c481f1e..bc088e45f0 100644
@@ -579,52 +579,71 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }

else if ( getenv() )
{
    ...
}

Quoted 4 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 581

Quoted 2 lines
tools/libxc/xc_cpuid_x86.c +0 -0
     else
     {

With no delta to this block at all.

Then we have to duplicate this code in both blocks:

/*
* These settings are necessary to cause earlier
HVM_PARAM_NESTEDHVM /

         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
Quoted 1 line

I won't object if that's what you guys really want.

Quoted 8 lines

Personally I think the duplication is less bad than the far heavier original code churn, but to be honest, especially with this intended to go away again soon anyway, I'd not be opposed at all to

    ...
    else if ( getenv() )
        goto no_fake_ht;

This isn't correct, because you do need to clear htt and cmp_legacy, as well as zeroing out cores_per_package and threads_per_cache on Intel. (At least, that's what XenServer's patch does, and it's the best tested.)

Quoted 15 lines
    else
    {
    ...
 no_fake_ht:
        /*
         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
    }
Quoted 5 lines
Quoted 1 line

(despite my general dislike of goto).

Well I think gotos into other blocks is even worse. :-)

I think the result is a lot nicer to review for sure.

Trying to comment despite this having been an attachment:

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 582

Quoted 7 lines
tools/libxc/xc_cpuid_x86.c +1 -0
@@ -579,6 +579,26 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
    }
    else
    {
+        if ( getenv("XEN_LIBXC_DISABLE_FAKEHT") ) {

The brace wants to move onto its own line.

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 583

Quoted 1 line
tools/libxc/xc_cpuid_x86.c +1 -0
+            p->basic.htt = false;

I think everything below here indeed simply undoes what said old commit did, but I can't match up this one. And together with the question of whether instead leaving it alone, cmp_legacy then would have the same question raised.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw
Quoted 89 lines · Jan Beulich
Quoted 80 lines · George Dunlap
Quoted 51 lines · Jan Beulich
Quoted 48 lines · George Dunlap
Quoted 29 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 9 lines
Quoted 9 lines

It's not entirely uncommon to (also) consider how the resulting diff would look like when putting together a change. And besides the review aspect, there's also the archeology one - "git blame" yields much more helpful results when code doesn't get moved around more than necessary. But yes, there's no very clear "this is the better option" here. I've taken another look at the code before your change though - everything is already nicely in one place with Andrew's most recent code reorg. So I'm now having an even harder time seeing why you want to move things around again.

Quoted 4 lines
Quoted 3 lines

We don't.  I've recommend twice now to have a single "else if" hunk which is nearly empty, and much more obviously a gross "make it work for 4.13" bodge.

The results are a tiny bit better, but not much really (see attached).

What I meant was:

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 579

Quoted 6 lines
tools/libxc/xc_cpuid_x86.c +0 -0
index 312c481f1e..bc088e45f0 100644
@@ -579,52 +579,71 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
     }

else if ( getenv() )
{
    ...
}

Quoted 4 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 581

Quoted 2 lines
tools/libxc/xc_cpuid_x86.c +0 -0
     else
     {

With no delta to this block at all.

Then we have to duplicate this code in both blocks:

/*
* These settings are necessary to cause earlier
HVM_PARAM_NESTEDHVM /

         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
Quoted 1 line

I won't object if that's what you guys really want.

Quoted 8 lines

Personally I think the duplication is less bad than the far heavier original code churn, but to be honest, especially with this intended to go away again soon anyway, I'd not be opposed at all to

    ...
    else if ( getenv() )
        goto no_fake_ht;

This isn't correct, because you do need to clear htt and cmp_legacy, as well as zeroing out cores_per_package and threads_per_cache on Intel. (At least, that's what XenServer's patch does, and it's the best tested.)

Quoted 15 lines
    else
    {
    ...
 no_fake_ht:
        /*
         * These settings are necessary to cause earlier HVM_PARAM_NESTEDHVM /
         * XEN_DOMCTL_disable_migrate settings to be reflected correctly in
         * CPUID.  Xen will discard these bits if configuration hasn't been
         * set for the domain.
         */
        p->extd.itsc = true;
        p->basic.vmx = true;
        p->extd.svm = true;
    }
Quoted 5 lines
Quoted 1 line

(despite my general dislike of goto).

Well I think gotos into other blocks is even worse. :-)

I think the result is a lot nicer to review for sure.

Trying to comment despite this having been an attachment:

Quoted 9 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 582

Quoted 7 lines
tools/libxc/xc_cpuid_x86.c +1 -0
@@ -579,6 +579,26 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
    }
    else
    {
+        if ( getenv("XEN_LIBXC_DISABLE_FAKEHT") ) {

The brace wants to move onto its own line.

Ack

Quoted 7 lines

tools/libxc/xc_cpuid_x86.c int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, · line 583

Quoted 2 lines
tools/libxc/xc_cpuid_x86.c +1 -0
+            p->basic.htt = false;

I think everything below here indeed simply undoes what said old commit did, but I can't match up this one. And together with the question of whether instead leaving it alone, cmp_legacy then would have the same question raised.

This is based on a XenServer patch which reverts the entire commit, and has been maintained in the patchqueue since the commit made it upstream, AFAICT. So I'll let someone from that team comment on the wherefores; but as I said, it's by far the best tested option we're going to get.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw
Quoted 9 lines · George Dunlap
Quoted 5 lines
Quoted 1 line

+ p->basic.htt = false;

I think everything below here indeed simply undoes what said old commit did, but I can't match up this one. And together with the question of whether instead leaving it alone, cmp_legacy then would have the same question raised.

This is based on a XenServer patch which reverts the entire commit, and has been maintained in the patchqueue since the commit made it upstream, AFAICT. So I'll let someone from that team comment on the wherefores; but as I said, it's by far the best tested option we're going to get.

Yes.  It is a revert of c/s ca2eee92df44 (Xen 3.4, and maintained forwards until now) because it broke migration across that changeset.

It is also this exact version of the revert which has been tested and confirmed to fix the Ryzen 3xxx fixes.

A separate experiment tried playing with only the flags, via cpuid="host:htt=0,cmp_legacy=1" and this did not resolve the crashes.

Given that both the before and after logic here is broken in the eyes of the APM, I'm not overly fussed about working about exactly how.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 5 lines
Quoted 1 line

+ p->basic.htt = false;

I think everything below here indeed simply undoes what said old commit did, but I can't match up this one. And together with the question of whether instead leaving it alone, cmp_legacy then would have the same question raised.

This is based on a XenServer patch which reverts the entire commit, and has been maintained in the patchqueue since the commit made it upstream, AFAICT. So I'll let someone from that team comment on the wherefores; but as I said, it's by far the best tested option we're going to get.

Quoted 8 lines

Yes.  It is a revert of c/s ca2eee92df44 (Xen 3.4, and maintained forwards until now) because it broke migration across that changeset.

It is also this exact version of the revert which has been tested and confirmed to fix the Ryzen 3xxx fixes.

A separate experiment tried playing with only the flags, via cpuid="host:htt=0,cmp_legacy=1" and this did not resolve the crashes.

Is that because the "revert" still clears cmp_legacy, rather than setting it to 1?

I think what Jan was getting at was that ca2eee92df44 *sets* htt and *clears* cmp_legacy, but previous to that commit, htt and cmp_legacy weren't changed, they were simply left alone. When reverting this patch, why do we not simply leave it alone, as was done before, rather than actively clearing them?

I think it's a good question to ask, but unless there is a known issue with what the patch does, I think it's far less risky just to take the version which has been tested.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw
Quoted 21 lines · George Dunlap
Quoted 11 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 5 lines
Quoted 1 line

+ p->basic.htt = false;

I think everything below here indeed simply undoes what said old commit did, but I can't match up this one. And together with the question of whether instead leaving it alone, cmp_legacy then would have the same question raised.

This is based on a XenServer patch which reverts the entire commit, and has been maintained in the patchqueue since the commit made it upstream, AFAICT. So I'll let someone from that team comment on the wherefores; but as I said, it's by far the best tested option we're going to get.

Quoted 8 lines

Yes.  It is a revert of c/s ca2eee92df44 (Xen 3.4, and maintained forwards until now) because it broke migration across that changeset.

It is also this exact version of the revert which has been tested and confirmed to fix the Ryzen 3xxx fixes.

A separate experiment tried playing with only the flags, via cpuid="host:htt=0,cmp_legacy=1" and this did not resolve the crashes.

Quoted 8 lines

Is that because the "revert" still clears cmp_legacy, rather than setting it to 1?

I think what Jan was getting at was that ca2eee92df44 *sets* htt and *clears* cmp_legacy, but previous to that commit, htt and cmp_legacy weren't changed, they were simply left alone. When reverting this patch, why do we not simply leave it alone, as was done before, rather than actively clearing them?

Actually no, I wasn't looking properly - HTT used to be cleared as much as CMP_LEGACY before that change. Somehow I didn't spot the former when putting together my earlier reply (maybe I looked for HTT when its only HT there). So I'm sorry for the extra noise.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw
In reply to George Dunlap
Quoted 19 lines · George Dunlap
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · George Dunlap
Quoted 5 lines
Quoted 1 line

+ p->basic.htt = false;

I think everything below here indeed simply undoes what said old commit did, but I can't match up this one. And together with the question of whether instead leaving it alone, cmp_legacy then would have the same question raised.

This is based on a XenServer patch which reverts the entire commit, and has been maintained in the patchqueue since the commit made it upstream, AFAICT. So I'll let someone from that team comment on the wherefores; but as I said, it's by far the best tested option we're going to get.

Quoted 8 lines

Yes.  It is a revert of c/s ca2eee92df44 (Xen 3.4, and maintained forwards until now) because it broke migration across that changeset.

It is also this exact version of the revert which has been tested and confirmed to fix the Ryzen 3xxx fixes.

A separate experiment tried playing with only the flags, via cpuid="host:htt=0,cmp_legacy=1" and this did not resolve the crashes.

Quoted 8 lines

Is that because the "revert" still clears cmp_legacy, rather than setting it to 1?

I think what Jan was getting at was that ca2eee92df44 *sets* htt and *clears* cmp_legacy, but previous to that commit, htt and cmp_legacy weren't changed, they were simply left alone. When reverting this patch, why do we not simply leave it alone, as was done before, rather than actively clearing them?

You also need to account for the accumulated bugfixes of the code since ca2eee92df44.

Quoted 3 lines

I think it's a good question to ask, but unless there is a known issue with what the patch does, I think it's far less risky just to take the version which has been tested.

In short, yes I believe the behaviour is deliberate, although I don't have the bug tickets to hand to remember exactly what went wrong.

The only other possibility (and perhaps is better, now that it is possible) is to foward those two bits from the host policy.  They are set in the guest policy due to (still) not having a split between default and max (another issue in the queue to be fixed).

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#18 lore raw
In reply to George Dunlap
Quoted 8 lines · George Dunlap

Changeset ca2eee92df44 ("x86, hvm: Expose host core/HT topology to HVM guests") attempted to "fake up" a topology which would induce guest operating systems to not treat vcpus as sibling hyperthreads. This involved (among other things) actually reporting hyperthreading as available, but giving vcpus every other APICID. The resulting cpu featureset is invalid, but most operating systems on most hardware managed to cope with it.

Quoted 4 lines

Unfortunately, Windows running on modern AMD hardware -- including Ryzen 3xxx series processors, and reportedly EPYC "Rome" cpus -- gets confused by the resulting contradictory feature bits and crashes during installation. (Linux guests have so far continued to cope.)

I do not understand a central point: No matter why and/or how a fake topology is presented by Xen, why did the older generation Ryzen 2xxx work and Ryzen 3xxx doesn't? What is the change in AMD(!) not Xen that causes the one to work and the other to fail?

Regards Andreas

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#19 lore raw
Quoted 14 lines · Andreas Kinzler
Quoted 8 lines · George Dunlap

Changeset ca2eee92df44 ("x86, hvm: Expose host core/HT topology to HVM guests") attempted to "fake up" a topology which would induce guest operating systems to not treat vcpus as sibling hyperthreads.  This involved (among other things) actually reporting hyperthreading as available, but giving vcpus every other APICID.  The resulting cpu featureset is invalid, but most operating systems on most hardware managed to cope with it.

Quoted 4 lines

Unfortunately, Windows running on modern AMD hardware -- including Ryzen 3xxx series processors, and reportedly EPYC "Rome" cpus -- gets confused by the resulting contradictory feature bits and crashes during installation.  (Linux guests have so far continued to cope.)

Quoted 4 lines

I do not understand a central point: No matter why and/or how a fake topology is presented by Xen, why did the older generation Ryzen 2xxx work and Ryzen 3xxx doesn't? What is the change in AMD(!) not Xen that causes the one to work and the other to fail?

The CPU features that the guest sees are a mix of the real underlying features and changes made by Xen.  Xen and/or the hardware will behave exactly the same in both cases; the only difference is what the guest operating system does.  The guest operating system code which is trying to determine the topology sees an impossible franken-monster mix of bits which its authors never anticipated, and so did not test; and it goes off the rails somewhere and crashes. Without seeing the code I cannot tell you how or exactly why it fails on Ryzen 3xxx but not on Ryzen 2xxx.  It could be something as simple as a missed case in a switch statement somewhere which never happens on real hardware.

Ideally of course such code should never crash, and should probably be designed such that it muddles on somehow no matter what it gets.  But I doubt we're going to get a huge amount of sympathy from MS if we request a patch to allow it to deal with incoherent topology; and in any case there are already lots of images out there already with the old code.

(Caveat: This is all from my understanding of Andy's description, not from personal experience.)

 -George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#20 lore raw
Quoted 7 lines · George Dunlap
Quoted 4 lines · Andreas Kinzler

I do not understand a central point: No matter why and/or how a fake topology is presented by Xen, why did the older generation Ryzen 2xxx work and Ryzen 3xxx doesn't? What is the change in AMD(!) not Xen that causes the one to work and the other to fail?

The CPU features that the guest sees are a mix of the real underlying features and changes made by Xen.  Xen and/or the hardware will behave

Why not analyze the bits in detail? I already posted the complete CPUID for 3700X (https://lists.xenproject.org/archives/html/xen-devel/2019-09/msg02189.html).

@Steven:

Quoted 3 lines

If this is helpful, I can probably provide the same from:
* Ryzen 2700x
* Ryzen 3900x

Can you post for 2700X?

Then someone with detailed knowledge could compare the two?

Regards Andreas

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#21 lore raw
Quoted 14 lines · Andreas Kinzler
Quoted 7 lines · George Dunlap
Quoted 4 lines · Andreas Kinzler

I do not understand a central point: No matter why and/or how a fake topology is presented by Xen, why did the older generation Ryzen 2xxx work and Ryzen 3xxx doesn't? What is the change in AMD(!) not Xen that causes the one to work and the other to fail?

The CPU features that the guest sees are a mix of the real underlying features and changes made by Xen.  Xen and/or the hardware will behave

Why not analyze the bits in detail? I already posted the complete CPUID for 3700X
(https://lists.xenproject.org/archives/html/xen-devel/2019-09/msg02189.html).

Quoted 7 lines

@Steven:

Quoted 3 lines

If this is helpful, I can probably provide the same from:
    * Ryzen 2700x
    * Ryzen 3900x

Can you post for 2700X?

Then someone with detailed knowledge could compare the two?

What would be the purpose?

The code is going to look like this --

https://gitlab.com/xen-project/xen/blob/staging/xen/arch/x86/cpu/common.c

-- an impenetrable maze of "switch" and "if" statements based on individual bits or features or models. *Somewhere* in Window's version of that code, there's a path which is triggered by Ryzen-3xxx-Xen-with-Fake-HT but not triggered by Ryzen-2xxx-with-Xen-Fake-HT, or Ryzen-3xxx-Xen-without-Fake-HT.

And suppose we found exactly the bits which triggered it, what then? We could flip just that bit; but that would make the resulting CPUID even *more* weird, and likely to trigger something else in the future.

The solution this patch proposes doesn't make the CPUID topology "normal", but it certainly makes it a lot less weird, which is a better place to be.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#22 lore raw
Quoted 13 lines · George Dunlap
Quoted 6 lines · Andreas Kinzler
Quoted 5 lines · George Dunlap
Quoted 4 lines · Andreas Kinzler

I do not understand a central point: No matter why and/or how a fake topology is presented by Xen, why did the older generation Ryzen 2xxx work and Ryzen 3xxx doesn't? What is the change in AMD(!) not Xen that causes the one to work and the other to fail?

Quoted 6 lines
Quoted 2 lines

The CPU features that the guest sees are a mix of the real underlying features and changes made by Xen.  Xen and/or the hardware will behave

Why not analyze the bits in detail? I already posted the complete CPUID for 3700X
(https://lists.xenproject.org/archives/html/xen-devel/2019-09/msg02189.html).
Then someone with detailed knowledge could compare the two?

Quoted 5 lines

What would be the purpose?
The code is going to look like this --
an impenetrable maze of "switch" and "if" statements based on individual bits or features or models. *Somewhere* in Window's versionof that code, there's a path which is triggered by

As of this moment all of this is just an assumption - you might very well be right, but it could also be something totally different. What if the CPUID is nearly identical? This would lead to the conclusion that the problem has completely different root causes.

Regards Andreas

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#23 lore raw
Quoted 22 lines · Andreas Kinzler
Quoted 14 lines · George Dunlap
Quoted 13 lines · Andreas Kinzler
Quoted 8 lines · George Dunlap
Quoted 5 lines · Andreas Kinzler

I do not understand a central point: No matter why and/or how a fake topology is presented by Xen, why did the older generation Ryzen 2xxx work and Ryzen 3xxx doesn't? What is the change in AMD(!) not Xen that
causes the one to work and the other to fail?

The CPU features that the guest sees are a mix of the real underlying features and changes made by Xen.  Xen and/or the hardware will behave

Why not analyze the bits in detail? I already posted the complete CPUID for 3700X
(https://lists.xenproject.org/archives/html/xen-devel/2019-09/msg02189.html).

Quoted 6 lines
Quoted 1 line

Then someone with detailed knowledge could compare the two?

What would be the purpose?
The code is going to look like this --
an impenetrable maze of "switch" and "if" statements based on individual bits or features or models.  *Somewhere* in Window's versionof that code, there's a path which is triggered by

Quoted 4 lines

As of this moment all of this is just an assumption - you might very well be right, but it could also be something totally different. What if the CPUID is nearly identical? This would lead to the conclusion that the problem has completely different root causes.

The problem is that Xen's "messing around with topology" is, and has always been, incorrect.  It does not match the rules given in the SDM/APM.

None of this code is going to survive the rewrite making the presented topology actually follow the architectural rules.

However, for 4.13, we are trying to find the least invasive hack possible to cause windows not to explode.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#24 lore raw
In reply to George Dunlap
Quoted 19 lines · George Dunlap

Changeset ca2eee92df44 ("x86, hvm: Expose host core/HT topology to HVM guests") attempted to "fake up" a topology which would induce guest operating systems to not treat vcpus as sibling hyperthreads. This involved (among other things) actually reporting hyperthreading as available, but giving vcpus every other APICID. The resulting cpu featureset is invalid, but most operating systems on most hardware managed to cope with it.

Unfortunately, Windows running on modern AMD hardware -- including Ryzen 3xxx series processors, and reportedly EPYC "Rome" cpus -- gets confused by the resulting contradictory feature bits and crashes during installation. (Linux guests have so far continued to cope.)

A "proper" fix is complicated and it's too late to fix it either for 4.13, or to backport to supported branches. As a short-term fix, implement an option to disable this "Fake HT" mode. The resulting topology reported will not be canonical, but experimentally continues to work with Windows guests.

Quoted 7 lines

However, disabling this "Fake HT" mode has not been widely tested, and will almost certainly break migration if applied inconsistently.

To minimize impact while allowing administrators to disable "Fake HT" only on guests which are known not to work without it (i.e., Windows guests) on affected hardware, add an environment variable which can be set to disable the "Fake HT" mode on such hardware.

Hmm, how is this going to work with libvirt? AFAIK libvirtd running as a single process is creating all guests. So with this approach you'd either not be able to use libvirtd, or you'd have to disable "Fake HT" for all guests, probably by modifying the libvirtd service definition.

Quoted 9 lines

---
This has been compile-tested only; I'm posting it early to get feedback on the approach.

TODO: Prevent such guests from being migrated

Quoted 8 lines

Open questions:

- Is this the right place to put the getenv check?

- Is there any way we can make migration work, at least in some cases?

- Can we check for known-problematic models, and at least report a more useful error?

Can't we just disable "Fake HT" automatically on those models? This would automagically make migration work, too.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#25 lore raw
Quoted 28 lines · Jürgen Groß
Quoted 19 lines · George Dunlap

Changeset ca2eee92df44 ("x86, hvm: Expose host core/HT topology to HVM guests") attempted to "fake up" a topology which would induce guest operating systems to not treat vcpus as sibling hyperthreads.  This involved (among other things) actually reporting hyperthreading as available, but giving vcpus every other APICID.  The resulting cpu featureset is invalid, but most operating systems on most hardware managed to cope with it.

Unfortunately, Windows running on modern AMD hardware -- including Ryzen 3xxx series processors, and reportedly EPYC "Rome" cpus -- gets confused by the resulting contradictory feature bits and crashes during installation.  (Linux guests have so far continued to cope.)

A "proper" fix is complicated and it's too late to fix it either for 4.13, or to backport to supported branches.  As a short-term fix, implement an option to disable this "Fake HT" mode.  The resulting topology reported will not be canonical, but experimentally continues to work with Windows guests.

Quoted 7 lines

However, disabling this "Fake HT" mode has not been widely tested, and will almost certainly break migration if applied inconsistently.

To minimize impact while allowing administrators to disable "Fake HT" only on guests which are known not to work without it (i.e., Windows guests) on affected hardware, add an environment variable which can be set to disable the "Fake HT" mode on such hardware.

Quoted 4 lines

Hmm, how is this going to work with libvirt? AFAIK libvirtd running as a single process is creating all guests. So with this approach you'd either not be able to use libvirtd, or you'd have to disable "Fake HT" for all guests, probably by modifying the libvirtd service definition.

If we went the current route, yes, that's what would need to be done. Anything else would require changing the interface, which would require changes to libvirt anyway.

Quoted 13 lines
Quoted 13 lines

---
This has been compile-tested only; I'm posting it early to get feedback on the approach.

TODO: Prevent such guests from being migrated

Open questions:

- Is this the right place to put the getenv check?

Quoted 7 lines
Quoted 4 lines

- Is there any way we can make migration work, at least in some cases?

- Can we check for known-problematic models, and at least report a more useful error?

Can't we just disable "Fake HT" automatically on those models? This would automagically make migration work, too.

What if someone is using only Linux guests on a Ryzen 3xxx box with 4.12.1? If they naively update to 4.13 without going through a version that has this backport, they'll get the wrong CPUid on the receiving side and migration will fail.

There was also concern about disabling the "Fake HT" across the board on the affected CPUs -- it hasn't been well-tested on Linux, and so it's not clear whether there will be issues or not. (If this was checked in back in June it would be a different matter.)

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#26 lore raw
In reply to George Dunlap

Just regarding the use of a system environment variable to turn this feature / bugfix / hack on and off - this would probably break starting the VM via the xendomains script.

If the VM definition is in /etc/xen/auto/, then there would be nothing to set the environment variable before the VM is launched - hence it would not be applied and a guest crash would occur...

Depending on the VM's settings, this would either continue to start & crash - or just stop again until it could be started with the ENV variable. Steven Haigh

📧 [email protected] 💻 https://www.crc.id.au
📞 +613 9001 6090 📱 +614 1293 5897

Quoted 176 lines · George Dunlap

Changeset ca2eee92df44 ("x86, hvm: Expose host core/HT topology to HVM guests") attempted to "fake up" a topology which would induce guest operating systems to not treat vcpus as sibling hyperthreads. This involved (among other things) actually reporting hyperthreading as available, but giving vcpus every other APICID. The resulting cpu featureset is invalid, but most operating systems on most hardware managed to cope with it.

Unfortunately, Windows running on modern AMD hardware -- including Ryzen 3xxx series processors, and reportedly EPYC "Rome" cpus -- gets confused by the resulting contradictory feature bits and crashes during installation. (Linux guests have so far continued to cope.)

A "proper" fix is complicated and it's too late to fix it either for 4.13, or to backport to supported branches. As a short-term fix, implement an option to disable this "Fake HT" mode. The resulting topology reported will not be canonical, but experimentally continues to work with Windows guests.

However, disabling this "Fake HT" mode has not been widely tested, and will almost certainly break migration if applied inconsistently.

To minimize impact while allowing administrators to disable "Fake HT" only on guests which are known not to work without it (i.e., Windows guests) on affected hardware, add an environment variable which can be set to disable the "Fake HT" mode on such hardware.

---
This has been compile-tested only; I'm posting it early to get feedback on the approach.

TODO: Prevent such guests from being migrated

Open questions:

- Is this the right place to put the getenv check?

- Is there any way we can make migration work, at least in some cases?

- Can we check for known-problematic models, and at least report a more useful error?

CC Andrew Cooper <[email protected]>
CC Jan Beulich <[email protected]>
CC Ian Jackson <[email protected]>
CC Anthony Perard <[email protected]>
---
 tools/libxc/xc_cpuid_x86.c | 74 
+++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 29 deletions(-)
tools/libxc/xc_cpuid_x86.c +0 -2
index 312c481f1e..70c85e1467 100644
@@ -579,52 +579,68 @@ int xc_cpuid_apply_policy(xc_interface *xch, 
 uint32_t domid,
     }
     else
     {
-        /*
-         * Topology for HVM guests is entirely controlled by Xen.  

For now, we
- * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no
SMT.

tools/libxc/xc_cpuid_x86.c +1 -4
-         */
-        p->basic.htt = true;
+        p->basic.htt = false;
         p->extd.cmp_legacy = false;
 
-        /*
-         * Leaf 1 EBX[23:16] is Maximum Logical Processors Per 

Package.
- * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure
to avoid

tools/libxc/xc_cpuid_x86.c +3 -15
-         * overflow.
-         */
-        if ( !(p->basic.lppp & 0x80) )
-            p->basic.lppp *= 2;
-
         switch ( p->x86_vendor )
         {
         case X86_VENDOR_INTEL:
             for ( i = 0; (p->cache.subleaf[i].type &&
                           i < ARRAY_SIZE(p->cache.raw)); ++i )
             {
-                p->cache.subleaf[i].cores_per_package =
-                    (p->cache.subleaf[i].cores_per_package << 1) | 1;
+                p->cache.subleaf[i].cores_per_package = 0;
                 p->cache.subleaf[i].threads_per_cache = 0;
             }
             break;
+        }
 
-        case X86_VENDOR_AMD:
-        case X86_VENDOR_HYGON:
+        if ( !getenv("XEN_LIBXC_DISABLE_FAKEHT") ) {
             /*
-             * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
-             * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one).
-             * Update to reflect vLAPIC_ID = vCPU_ID * 2.  But avoid
-             * - overflow,
-             * - going out of sync with leaf 1 EBX[23:16],
-             * - incrementing ApicIdCoreSize when it's zero (which 

changes the

tools/libxc/xc_cpuid_x86.c +1 -1
-             *   meaning of bits 7:0).
+             * Topology for HVM guests is entirely controlled by 

Xen. For now, we
+ * hardcode APIC_ID = vcpu_id * 2 to give the illusion
of no SMT.

              */
tools/libxc/xc_cpuid_x86.c +4 -1
-            if ( p->extd.nc < 0x7f )
+            p->basic.htt = true;
+
+            /*
+             * Leaf 1 EBX[23:16] is Maximum Logical Processors Per 

Package.
+ * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make
sure to avoid

tools/libxc/xc_cpuid_x86.c +6 -1
+             * overflow.
+             */
+            if ( !(p->basic.lppp & 0x80) )
+                p->basic.lppp *= 2;
+
+            switch ( p->x86_vendor )
             {
-                if ( p->extd.apic_id_size != 0 && 

p->extd.apic_id_size != 0xf )

tools/libxc/xc_cpuid_x86.c +6 -1
-                    p->extd.apic_id_size++;
+            case X86_VENDOR_INTEL:
+                for ( i = 0; (p->cache.subleaf[i].type &&
+                              i < ARRAY_SIZE(p->cache.raw)); ++i )
+                {
+                    p->cache.subleaf[i].cores_per_package =
+                        (p->cache.subleaf[i].cores_per_package << 1) 

| 1;

tools/libxc/xc_cpuid_x86.c +8 -0
+                    p->cache.subleaf[i].threads_per_cache = 0;
+                }
+
+            case X86_VENDOR_AMD:
+            case X86_VENDOR_HYGON:
+                /*
+                 * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize.
+                 * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus 

one).
+ * Update to reflect vLAPIC_ID = vCPU_ID * 2. But
avoid

tools/libxc/xc_cpuid_x86.c +3 -0
+                 * - overflow,
+                 * - going out of sync with leaf 1 EBX[23:16],
+                 * - incrementing ApicIdCoreSize when it's zero 

(which changes the

tools/libxc/xc_cpuid_x86.c +5 -0
+                 *   meaning of bits 7:0).
+                 */
+                if ( p->extd.nc < 0x7f )
+                {
+                    if ( p->extd.apic_id_size != 0 && 

p->extd.apic_id_size != 0xf )

tools/libxc/xc_cpuid_x86.c +5 -3
+                        p->extd.apic_id_size++;
+
+                    p->extd.nc = (p->extd.nc << 1) | 1;
+                }
+                break;
 
-                p->extd.nc = (p->extd.nc << 1) | 1;
             }
-            break;
         }
 
         /*
--

2.24.0

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#27 lore raw

FTR, please avoid top-posting. :-)

Quoted 10 lines · Steven Haigh

Just regarding the use of a system environment variable to turn this feature / bugfix / hack on and off - this would probably break starting the VM via the xendomains script.

If the VM definition is in /etc/xen/auto/, then there would be nothing to set the environment variable before the VM is launched - hence it would not be applied and a guest crash would occur...

Depending on the VM's settings, this would either continue to start & crash - or just stop again until it could be started with the ENV variable.

Right. So a couple of options:

1. Users of xendomains could set the environment variable in their xendomains script

2. We could add a xl.cfg option. Unknown xl.cfg entries are ignored (for better or for worse); in the future, when the "fake ht" thing is replaced, we can either continue ignoring it, or give a useful error message saying how it should be changed.

2a. We could have the config option *replace* the environment variable; in which case we'd leave libvirt users high and dry

2b. We could have the config option cause xl to *set* the environment variable, which should continue to allow other toolstacks (even those not using libxl) to potentially work around the issue.

Right now I'm leaning towards 2b, and having it be in a separate patch.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#28 lore raw
Quoted 24 lines · George Dunlap

FTR, please avoid top-posting. :-)

Quoted 10 lines · Steven Haigh

Just regarding the use of a system environment variable to turn this feature / bugfix / hack on and off - this would probably break starting the VM via the xendomains script.

If the VM definition is in /etc/xen/auto/, then there would be nothing to set the environment variable before the VM is launched - hence it would not be applied and a guest crash would occur...

Depending on the VM's settings, this would either continue to start & crash - or just stop again until it could be started with the ENV variable.

Right. So a couple of options:

1. Users of xendomains could set the environment variable in their xendomains script

2. We could add a xl.cfg option. Unknown xl.cfg entries are ignored (for better or for worse); in the future, when the "fake ht" thing is replaced, we can either continue ignoring it, or give a useful error message saying how it should be changed.

Quoted 8 lines

2a. We could have the config option *replace* the environment variable; in which case we'd leave libvirt users high and dry

2b. We could have the config option cause xl to *set* the environment variable, which should continue to allow other toolstacks (even those not using libxl) to potentially work around the issue.

Right now I'm leaning towards 2b, and having it be in a separate patch.

In which case we should consider having a way to set arbitrary environment variables from the config file in order to avoid this kind of discussion in future similar cases.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#29 lore raw
Quoted 33 lines · Jürgen Groß
Quoted 32 lines · George Dunlap

FTR, please avoid top-posting. :-)

Quoted 11 lines · Steven Haigh

Just regarding the use of a system environment variable to turn this feature / bugfix / hack on and off - this would probably break starting the VM via the xendomains script.

If the VM definition is in /etc/xen/auto/, then there would be nothing to set the environment variable before the VM is launched - hence it would not be applied and a guest crash would occur...

Depending on the VM's settings, this would either continue to start & crash - or just stop again until it could be started with the ENV variable.

Right.  So a couple of options:

1. Users of xendomains could set the environment variable in their xendomains script

2. We could add a xl.cfg option.  Unknown xl.cfg entries are ignored (for better or for worse); in the future, when the "fake ht" thing is replaced, we can either continue ignoring it, or give a useful error message saying how it should be changed.

2a.  We could have the config option *replace* the environment variable; in which case we'd leave libvirt users high and dry

2b. We could have the config option cause xl to *set* the environment variable, which should continue to allow other toolstacks (even those not using libxl) to potentially work around the issue.

Quoted 5 lines
Quoted 1 line

Right now I'm leaning towards 2b, and having it be in a separate patch.

In which case we should consider having a way to set arbitrary environment variables from the config file in order to avoid this kind of discussion in future similar cases.

Right, I was thinking about a good / useful interface; e.g.:

workarounds = [
AMD_RYZEN_TOPOLOGY_FIX=ignore
]

And then have 'ignore' mean, "Ignore this if you haven't heard of it, or if the option has gone away; 'auto' mean, "Do the most reasonable thing", 'strict' to mean, "Fail domain build if this workaround is obsolete", or something like that. Then users can dial their own "just make it work" vs "tell me it's gone" as they like.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#30 lore raw
In reply to George Dunlap
Quoted 24 lines · George Dunlap

FTR, please avoid top-posting. :-)

Quoted 10 lines · Steven Haigh

Just regarding the use of a system environment variable to turn this feature / bugfix / hack on and off - this would probably break starting the VM via the xendomains script.

If the VM definition is in /etc/xen/auto/, then there would be nothing to set the environment variable before the VM is launched - hence it would not be applied and a guest crash would occur...

Depending on the VM's settings, this would either continue to start & crash - or just stop again until it could be started with the ENV variable.

Right. So a couple of options:

1. Users of xendomains could set the environment variable in their xendomains script

2. We could add a xl.cfg option. Unknown xl.cfg entries are ignored (for better or for worse); in the future, when the "fake ht" thing is replaced, we can either continue ignoring it, or give a useful error message saying how it should be changed.

Quoted 6 lines

2a. We could have the config option *replace* the environment variable; in which case we'd leave libvirt users high and dry

2b. We could have the config option cause xl to *set* the environment variable, which should continue to allow other toolstacks (even those not using libxl) to potentially work around the issue.

And how would any of these allow to deal with heterogeneous sets of guests?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#31 lore raw
Quoted 28 lines · Jan Beulich
Quoted 27 lines · George Dunlap

FTR, please avoid top-posting. :-)

Quoted 10 lines · Steven Haigh

Just regarding the use of a system environment variable to turn this feature / bugfix / hack on and off - this would probably break starting the VM via the xendomains script.

If the VM definition is in /etc/xen/auto/, then there would be nothing to set the environment variable before the VM is launched - hence it would not be applied and a guest crash would occur...

Depending on the VM's settings, this would either continue to start & crash - or just stop again until it could be started with the ENV variable.

Right. So a couple of options:

1. Users of xendomains could set the environment variable in their xendomains script

2. We could add a xl.cfg option. Unknown xl.cfg entries are ignored (for better or for worse); in the future, when the "fake ht" thing is replaced, we can either continue ignoring it, or give a useful error message saying how it should be changed.

2a. We could have the config option *replace* the environment variable; in which case we'd leave libvirt users high and dry

Quoted 6 lines
Quoted 3 lines

2b. We could have the config option cause xl to *set* the environment variable, which should continue to allow other toolstacks (even those not using libxl) to potentially work around the issue.

And how would any of these allow to deal with heterogeneous sets of guests?

Are you perhaps confusing 'xl.cfg' (which is the per-domain configuration file) with 'xl.conf' (which is the system-wide configuration file)?

#1 would obviously require arranging for *all* xendomain-enabled guests to be started with the config enabled. #2 would allow heterogeneous guests if the admin went through and added the workaround to the guests she wanted.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#32 lore raw
Quoted 33 lines · George Dunlap
Quoted 32 lines · Jan Beulich
Quoted 30 lines · George Dunlap

FTR, please avoid top-posting. :-)

Quoted 10 lines · Steven Haigh

Just regarding the use of a system environment variable to turn this feature / bugfix / hack on and off - this would probably break starting the VM via the xendomains script.

If the VM definition is in /etc/xen/auto/, then there would be nothing to set the environment variable before the VM is launched - hence it would not be applied and a guest crash would occur...

Depending on the VM's settings, this would either continue to start & crash - or just stop again until it could be started with the ENV variable.

Right. So a couple of options:

1. Users of xendomains could set the environment variable in their xendomains script

2. We could add a xl.cfg option. Unknown xl.cfg entries are ignored (for better or for worse); in the future, when the "fake ht" thing is replaced, we can either continue ignoring it, or give a useful error message saying how it should be changed.

2a. We could have the config option *replace* the environment variable; in which case we'd leave libvirt users high and dry

2b. We could have the config option cause xl to *set* the environment variable, which should continue to allow other toolstacks (even those not using libxl) to potentially work around the issue.

Quoted 6 lines
Quoted 2 lines

And how would any of these allow to deal with heterogeneous sets of guests?

Are you perhaps confusing 'xl.cfg' (which is the per-domain configuration file) with 'xl.conf' (which is the system-wide configuration file)?

Oh, indeed I was. I'm not used to any suffixes on domain config files. I'm sorry.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#33 lore raw
Quoted 37 lines · Jan Beulich
Quoted 36 lines · George Dunlap
Quoted 34 lines · Jan Beulich
Quoted 24 lines · George Dunlap

FTR, please avoid top-posting. :-)

Quoted 10 lines · Steven Haigh

Just regarding the use of a system environment variable to turn this feature / bugfix / hack on and off - this would probably break starting the VM via the xendomains script.

If the VM definition is in /etc/xen/auto/, then there would be nothing to set the environment variable before the VM is launched - hence it would not be applied and a guest crash would occur...

Depending on the VM's settings, this would either continue to start & crash - or just stop again until it could be started with the ENV variable.

Right. So a couple of options:

1. Users of xendomains could set the environment variable in their xendomains script

2. We could add a xl.cfg option. Unknown xl.cfg entries are ignored (for better or for worse); in the future, when the "fake ht" thing is replaced, we can either continue ignoring it, or give a useful error message saying how it should be changed.

Quoted 6 lines

2a. We could have the config option *replace* the environment variable; in which case we'd leave libvirt users high and dry

2b. We could have the config option cause xl to *set* the environment variable, which should continue to allow other toolstacks (even those not using libxl) to potentially work around the issue.

And how would any of these allow to deal with heterogeneous sets of guests?

Quoted 6 lines
Quoted 3 lines

Are you perhaps confusing 'xl.cfg' (which is the per-domain configuration file) with 'xl.conf' (which is the system-wide configuration file)?

Oh, indeed I was. I'm not used to any suffixes on domain config files. I'm sorry.

FYI I'm using the names of the respective man pages: man xl.cfg gives you the man page for the per-domain config, man xl.conf gives you the global config.

It's far from obvious, but at least it's something. :-)

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel