Skip to contentSkip to conversation

x86/cpu-policy: Fix migration from Ice Lake to Cascade Lake

PATCH Superseded Andrew Cooper 3 participants 9 messages May 7, 2024 – May 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/cpu-policy: Fix migration from Ice Lake to Cascade Lake

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Extend the host policy's feat.max_subleaf to the hightest number Xen knows about, similarly to how we extend extd.max_leaf for LFENCE_DISPATCH. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Eventually we'll manage to teach the toolstack how to avoid creating such VMs in the first place, but there's still more work to do there.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/cpu-policy.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/cpu-policy.c +7 -2
index 4b6d96276399..a216fc8b886f 100644
@@ -373,8 +373,13 @@ static void __init calculate_host_policy(void)
 
     p->basic.max_leaf =
         min_t(uint32_t, p->basic.max_leaf,   ARRAY_SIZE(p->basic.raw) - 1);
-    p->feat.max_subleaf =
-        min_t(uint32_t, p->feat.max_subleaf, ARRAY_SIZE(p->feat.raw) - 1);
+
+    /*
+     * p->feat is "just" featureset information.  We know about more than may
+     * be present in this hardware.  Also, VMs may have a higher max_subleaf
+     * than strictly necessary, and we can accept those too.
+     */
+    p->feat.max_subleaf = ARRAY_SIZE(p->feat.raw) - 1;
 
     max_extd_leaf = p->extd.max_leaf;
 

base-commit: ebab808eb1bb8f24c7d0dd41b956e48cb1824b81

Signature · 1 line
2.30.2
#1 lore raw
Quoted 7 lines · Andrew Cooper

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

Quoted 8 lines

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Extend the host policy's feat.max_subleaf to the hightest number Xen knows about, similarly to how we extend extd.max_leaf for LFENCE_DISPATCH. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Seeing what we do for max_extd_leaf, shouldn't we switch to doing what you propose for feat.max_subleaf to max_extd_leaf also?

To allow migration between hosts that have 0x80000021.eax and hosts that don't have such extended leaf.

cpu_has_lfence_dispatch kind of does that, but if lfence cannot be made serializing then the max extended leaf is not expanded. And we should also likely account for more feature leafs possibly appearing after 0x80000021?

Thanks, Roger.

#2 lore raw
Quoted 19 lines · Roger Pau Monné
Quoted 7 lines · Andrew Cooper

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

Quoted 8 lines

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Extend the host policy's feat.max_subleaf to the hightest number Xen knows about, similarly to how we extend extd.max_leaf for LFENCE_DISPATCH. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Seeing what we do for max_extd_leaf, shouldn't we switch to doing what you propose for feat.max_subleaf to max_extd_leaf also?

Quoted 7 lines

To allow migration between hosts that have 0x80000021.eax and hosts that don't have such extended leaf.

cpu_has_lfence_dispatch kind of does that, but if lfence cannot be made serializing then the max extended leaf is not expanded. And we should also likely account for more feature leafs possibly appearing after 0x80000021?

On second thoughts, this adjustment ought to be in the max policies only.

It's slightly different to LFENCE_DISPATCH, in that we don't actually have any set bits in those leaves.

I'll do a different patch.

~Andrew

#3 lore raw

PATCH v2 1/1 x86/cpu-policy: Fix migration from Ice Lake to Cascade Lake

In reply to Andrew Cooper

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Extend the max policies feat.max_subleaf to the hightest number Xen knows about, but leave the default policies matching the host. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Eventually we'll manage to teach the toolstack how to avoid creating such VMs in the first place, but there's still more work to do there.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

v2:
* Adjust max policies rather than the host policy.

---
 xen/arch/x86/cpu-policy.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
xen/arch/x86/cpu-policy.c +22 -0
index 4b6d96276399..f7e2910c01b5 100644
@@ -590,6 +590,13 @@ static void __init calculate_pv_max_policy(void)
     unsigned int i;
 
     *p = host_cpu_policy;
+
+    /*
+     * Some VMs may have a larger-than-necessary feat max_leaf.  Allow them to
+     * migrate in.
+     */
+    p->feat.max_subleaf = ARRAY_SIZE(p->feat.raw) - 1;
+
     x86_cpu_policy_to_featureset(p, fs);
 
     for ( i = 0; i < ARRAY_SIZE(fs); ++i )
@@ -630,6 +637,10 @@ static void __init calculate_pv_def_policy(void)
     unsigned int i;
 
     *p = pv_max_cpu_policy;
+
+    /* Default to the same max_subleaf as the host. */
+    p->feat.max_subleaf = host_cpu_policy.feat.max_subleaf;
+
     x86_cpu_policy_to_featureset(p, fs);
 
     for ( i = 0; i < ARRAY_SIZE(fs); ++i )
@@ -666,6 +677,13 @@ static void __init calculate_hvm_max_policy(void)
     const uint32_t *mask;
 
     *p = host_cpu_policy;
+
+    /*
+     * Some VMs may have a larger-than-necessary feat max_leaf.  Allow them to
+     * migrate in.
+     */
+    p->feat.max_subleaf = ARRAY_SIZE(p->feat.raw) - 1;
+
     x86_cpu_policy_to_featureset(p, fs);
 
     mask = hvm_hap_supported() ?
@@ -783,6 +801,10 @@ static void __init calculate_hvm_def_policy(void)
     const uint32_t *mask;
 
     *p = hvm_max_cpu_policy;
+
+    /* Default to the same max_subleaf as the host. */
+    p->feat.max_subleaf = host_cpu_policy.feat.max_subleaf;
+
     x86_cpu_policy_to_featureset(p, fs);
 
     mask = hvm_hap_supported() ?

base-commit: ebab808eb1bb8f24c7d0dd41b956e48cb1824b81

Signature · 1 line
2.30.2
Acked-by on v2 1/1
#4 lore raw
Quoted 11 lines · Andrew Cooper

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Quoted 8 lines

Extend the max policies feat.max_subleaf to the hightest number Xen knows about, but leave the default policies matching the host. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Eventually we'll manage to teach the toolstack how to avoid creating such VMs in the first place, but there's still more work to do there.

Even if we have just found one glitch with PSFD and Ice Lake vs Cascade Lack, wouldn't it be safer to always extend the max policies max leafs and subleafs to match the known array sizes?

Thanks, Roger.

#5 lore raw
Quoted 16 lines · Roger Pau Monné
Quoted 15 lines · Andrew Cooper

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Extend the max policies feat.max_subleaf to the hightest number Xen knows about, but leave the default policies matching the host. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Quoted 5 lines
Quoted 4 lines

Eventually we'll manage to teach the toolstack how to avoid creating such VMs in the first place, but there's still more work to do there.

Thanks.

Quoted 4 lines

Even if we have just found one glitch with PSFD and Ice Lake vs Cascade Lack, wouldn't it be safer to always extend the max policies max leafs and subleafs to match the known array sizes?

This is the final max leaf (containing feature information) to gain custom handling, I think?

~Andrew

#6 lore raw
Quoted 26 lines · Andrew Cooper
Quoted 16 lines · Roger Pau Monné
Quoted 15 lines · Andrew Cooper

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Extend the max policies feat.max_subleaf to the hightest number Xen knows about, but leave the default policies matching the host. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Quoted 5 lines
Quoted 4 lines

Eventually we'll manage to teach the toolstack how to avoid creating such VMs in the first place, but there's still more work to do there.

Thanks.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

Even if we have just found one glitch with PSFD and Ice Lake vs Cascade Lack, wouldn't it be safer to always extend the max policies max leafs and subleafs to match the known array sizes?

This is the final max leaf (containing feature information) to gain custom handling, I think?

Couldn't the same happen with extended leaves? Some of the extended leaves contain features, and hence for policy leveling toolstack might decide to zero them, yet extd.max_leaf won't be adjusted.

Thanks, Roger.

#7 lore raw
Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Andrew Cooper
Quoted 16 lines · Roger Pau Monné
Quoted 15 lines · Andrew Cooper

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Extend the max policies feat.max_subleaf to the hightest number Xen knows about, but leave the default policies matching the host. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Quoted 5 lines
Quoted 4 lines

Eventually we'll manage to teach the toolstack how to avoid creating such VMs in the first place, but there's still more work to do there.

Thanks.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Even if we have just found one glitch with PSFD and Ice Lake vs Cascade Lack, wouldn't it be safer to always extend the max policies max leafs and subleafs to match the known array sizes?

This is the final max leaf (containing feature information) to gain custom handling, I think?

Couldn't the same happen with extended leaves? Some of the extended leaves contain features, and hence for policy leveling toolstack might decide to zero them, yet extd.max_leaf won't be adjusted.

Hmm.  Right now, extd max leaf is also the one with the bit that we unconditionally advertise, and it's inherited all the way from the host policy.

So yes, in principle, but anything that bumps this limit is going to have other implications too, and I'd prefer not to second-guess them at this point.

I hope we can get the toolstack side fixes before this becomes a real problem...

~Andrew

#8 lore raw
In reply to Andrew Cooper
Quoted 11 lines · Andrew Cooper

Ever since Xen 4.14, there has been a latent bug with migration.

While some toolstacks can level the features properly, they don't shink feat.max_subleaf when all features have been dropped. This is because we *still* have not completed the toolstack side work for full CPU Policy objects.

As a consequence, even when properly feature levelled, VMs can't migrate "backwards" across hardware which reduces feat.max_subleaf. One such example is Ice Lake (max_subleaf=2 for INTEL_PSFD) to Cascade Lake (max_subleaf=0).

Quoted 6 lines

Extend the max policies feat.max_subleaf to the hightest number Xen knows about, but leave the default policies matching the host. This will allow VMs with a higher feat.max_subleaf than strictly necessary to migrate in.

Eventually we'll manage to teach the toolstack how to avoid creating such VMs in the first place, but there's still more work to do there.

Can you explain to me in how far "x86/CPUID: shrink max_{,sub}leaf fields according to actual leaf contents" would not already have taken care of this (and not just for sub-leaves of leaf 7), if only it (at least its more recent versions) was ever seriously looked at? I realize there was one todo item left there (addressing of which I could probably have used some help with), but that shouldn't have entirely prevented any progress. (If I'm not mistaken an earlier version had once gone in, but then needed to be reverted.)

Jan