Skip to contentSkip to conversation

x86/hvm: Clamp Viridian features to known set

PATCH In review Ross Lagerwall 3 participants 6 messages Sep 24 – Sep 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: Clamp Viridian features to known set

Instead of returning EINVAL on an unknown feature bit, clamp to the known feature set. This simplifies upgrades since when the hypervisor and toolstack are updated without an immediate reboot, the toolstack may set unknown feature bits and the existing behaviour leaves the VM without any Virdian features enabled.

---
 xen/arch/x86/hvm/hvm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +3 -1
index 192309c2fccc..67afa00a0f13 100644
@@ -4234,8 +4234,10 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value)
     case HVM_PARAM_VIRIDIAN:
         if ( !IS_ENABLED(CONFIG_VIRIDIAN) )
             rc = -ENODEV;
-        else if ( (value & ~HVMPV_feature_mask) || !(value & HVMPV_base_freq) )
+        else if ( !(value & HVMPV_base_freq) )
             rc = -EINVAL;
+
+        value &= HVMPV_feature_mask;
         break;
     case HVM_PARAM_IDENT_PT:
         /*
Signature · 1 line
2.55.0
#1 lore raw
Quoted 2 lines · Ross Lagerwall

Instead of returning EINVAL on an unknown feature bit, clamp to the known feature set.

Sorry, but no.

This is equivalent to saying "I've got a VM using AVX512" and Xen saying "ok, I'll ignore that safety check and let you run on non-AVX512 capable hardware".

Requesting a feature that Xen doesn't know about is a hard error. Truncating features out like this will cause a guest using those features to malfunction.

It is a bug that this was expressed as an HVM Param in the first place. It should be part of CPU Policy, and it's on a TODO list.

~Andrew

#2 lore raw
Quoted 10 lines · Andrew Cooper
Quoted 2 lines · Ross Lagerwall

Instead of returning EINVAL on an unknown feature bit, clamp to the known feature set.

Sorry, but no.

This is equivalent to saying "I've got a VM using AVX512" and Xen saying "ok, I'll ignore that safety check and let you run on non-AVX512 capable hardware".

Quoted 6 lines

Requesting a feature that Xen doesn't know about is a hard error. Truncating features out like this will cause a guest using those features to malfunction.

It is a bug that this was expressed as an HVM Param in the first place. It should be part of CPU Policy, and it's on a TODO list.

But isn't this the same thing the CPU Policy code does? In recalculate_cpuid_policy(), it silently clamps the toolstack's choices to the max featureset.

Ross

#3 lore raw
Quoted 15 lines · Ross Lagerwall
Quoted 14 lines · Andrew Cooper
Quoted 2 lines · Ross Lagerwall

Instead of returning EINVAL on an unknown feature bit, clamp to the known feature set.

Sorry, but no.

This is equivalent to saying "I've got a VM using AVX512" and Xen saying "ok, I'll ignore that safety check and let you run on non-AVX512 capable hardware".

Requesting a feature that Xen doesn't know about is a hard error. Truncating features out like this will cause a guest using those features to malfunction.

Quoted 6 lines
Quoted 2 lines

It is a bug that this was expressed as an HVM Param in the first place. It should be part of CPU Policy, and it's on a TODO list.

But isn't this the same thing the CPU Policy code does? In recalculate_cpuid_policy(), it silently clamps the toolstack's choices to the max featureset.

Which is behavior that, if I'm not mistaken, is supposed to go away. Such requests are intended to instead fail, down the road.

Jan

#4 lore raw
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Ross Lagerwall
Quoted 16 lines · Andrew Cooper
Quoted 2 lines · Ross Lagerwall

Instead of returning EINVAL on an unknown feature bit, clamp to the known feature set.

Sorry, but no.

This is equivalent to saying "I've got a VM using AVX512" and Xen saying "ok, I'll ignore that safety check and let you run on non-AVX512 capable hardware".

Requesting a feature that Xen doesn't know about is a hard error. Truncating features out like this will cause a guest using those features to malfunction.

It is a bug that this was expressed as an HVM Param in the first place. It should be part of CPU Policy, and it's on a TODO list.

Quoted 6 lines
Quoted 3 lines

But isn't this the same thing the CPU Policy code does? In recalculate_cpuid_policy(), it silently clamps the toolstack's choices to the max featureset.

Which is behavior that, if I'm not mistaken, is supposed to go away. Such requests are intended to instead fail, down the road.

OK, if that is undesirable behaviour and going to change in future I'll retract this patch.

Ross

#5 lore raw
In reply to Jan Beulich
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Ross Lagerwall
Quoted 13 lines · Andrew Cooper
Quoted 2 lines · Ross Lagerwall

Instead of returning EINVAL on an unknown feature bit, clamp to the known feature set.

Sorry, but no.

This is equivalent to saying "I've got a VM using AVX512" and Xen saying "ok, I'll ignore that safety check and let you run on non-AVX512 capable hardware".

Requesting a feature that Xen doesn't know about is a hard error. Truncating features out like this will cause a guest using those features to malfunction.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

It is a bug that this was expressed as an HVM Param in the first place. It should be part of CPU Policy, and it's on a TODO list.

But isn't this the same thing the CPU Policy code does? In recalculate_cpuid_policy(), it silently clamps the toolstack's choices to the max featureset.

Which is behavior that, if I'm not mistaken, is supposed to go away. Such requests are intended to instead fail, down the road.

Correct.

Right now, both libxc and Xen run the feature dependency calculation, so the toolstack ends up passing something which Xen will say yes to. We're fairly close to being able to alter Xen to reject a policy update rather than edit it behind the scenes.

Viridian should be part of the CPU Policy but isn't (yet).  As such there's no statement of Xen's capability for the toolstack to choose from, nor is there any dependency tracking to reject nonsense combinations.

~Andrew