Skip to contentSkip to conversation

x86/hvm: Fix hvm_cr4_guest_valid_bits() for PVH dom0

PATCH In review Andrew Cooper 3 participants 7 messages Jan 28, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: Fix hvm_cr4_guest_valid_bits() for PVH dom0

Before the cpuid_policy logic came along, %cr4 auditing on migrate-in was complicated, because at that point no CPUID information had been set for the guest. Auditing against the host CPUID was better than nothing, but not ideal.

Order of information in the migration stream is still an issue (hence we still need to keep the restore parameter to cope with a nested virt corner case), but since Xen 4.9, the domain starts with the applicable max policy, which is a more appropriate upper bound than the host cpuid policy.

This also makes the fix from c/s 9d2efbafb8 obsolete, as not even dom0 starts without a policy.

Finally, reposition the UMIP logic as it is the only row out of order.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>

I suspect this isn't an issue in practice because there is no way to get X86_CR4_SMXE set with the logic in this state, but it is a latent bug.

This ideally wants backporting to Xen 4.9 and later. I don't think there is anything we can reasonably do for 4.8 and earlier.

I should also note that the nested virt corner case probably isn't useful. Noone ever bothered wiring the VMXON/VMCS pointer registers into the migration stream, so migrating a VM will cause it to lose all configured state.

---
 xen/arch/x86/hvm/hvm.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/hvm.c +2 -7
index 401c4a9..1966fd4 100644
@@ -928,14 +928,9 @@ const char *hvm_efer_valid(const struct vcpu *v, uint64_t value,
 /* These bits in CR4 can be set by the guest. */
 unsigned long hvm_cr4_guest_valid_bits(const struct domain *d, bool restore)
 {
-    const struct cpuid_policy *p;
+    const struct cpuid_policy *p = d->arch.cpuid;
     bool mce, vmxe;
 
-    if ( !restore && !is_hardware_domain(d) )
-        p = d->arch.cpuid;
-    else
-        p = &host_cpuid_policy;
-
     /* Logic broken out simply to aid readability below. */
     mce  = p->basic.mce || p->basic.mca;
     vmxe = p->basic.vmx && (restore || nestedhvm_enabled(d));
@@ -950,13 +945,13 @@ unsigned long hvm_cr4_guest_valid_bits(const struct domain *d, bool restore)
                                 X86_CR4_PCE                    |
             (p->basic.fxsr    ? X86_CR4_OSFXSR            : 0) |
             (p->basic.sse     ? X86_CR4_OSXMMEXCPT        : 0) |
+            (p->feat.umip     ? X86_CR4_UMIP              : 0) |
             (vmxe             ? X86_CR4_VMXE              : 0) |
             (p->feat.fsgsbase ? X86_CR4_FSGSBASE          : 0) |
             (p->basic.pcid    ? X86_CR4_PCIDE             : 0) |
             (p->basic.xsave   ? X86_CR4_OSXSAVE           : 0) |
             (p->feat.smep     ? X86_CR4_SMEP              : 0) |
             (p->feat.smap     ? X86_CR4_SMAP              : 0) |
-            (p->feat.umip     ? X86_CR4_UMIP              : 0) |
             (p->feat.pku      ? X86_CR4_PKE               : 0));
 }
 
Signature · 7 lines
2.1.4


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

Before the cpuid_policy logic came along, %cr4 auditing on migrate-in was complicated, because at that point no CPUID information had been set for the guest. Auditing against the host CPUID was better than nothing, but not ideal.

Order of information in the migration stream is still an issue (hence we still need to keep the restore parameter to cope with a nested virt corner case), but since Xen 4.9, the domain starts with the applicable max policy, which is a more appropriate upper bound than the host cpuid policy.

Quoted 6 lines

This also makes the fix from c/s 9d2efbafb8 obsolete, as not even dom0 starts without a policy.

Finally, reposition the UMIP logic as it is the only row out of order.

It is indeed the case that all x86 domains will get a cpuid policy, auditing against that makes more sense. But what about code in hvm_efer_valid? Why didn't you make it work with arch.cpuid?

Wei.

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

#2 lore raw
Quoted 14 lines · Wei Liu
Quoted 13 lines · Andrew Cooper

Before the cpuid_policy logic came along, %cr4 auditing on migrate-in was complicated, because at that point no CPUID information had been set for the guest. Auditing against the host CPUID was better than nothing, but not ideal.

Order of information in the migration stream is still an issue (hence we still need to keep the restore parameter to cope with a nested virt corner case), but since Xen 4.9, the domain starts with the applicable max policy, which is a more appropriate upper bound than the host cpuid policy.

This also makes the fix from c/s 9d2efbafb8 obsolete, as not even dom0 starts without a policy.

Quoted 6 lines
Quoted 3 lines

Finally, reposition the UMIP logic as it is the only row out of order.

It is indeed the case that all x86 domains will get a cpuid policy, auditing against that makes more sense. But what about code in hvm_efer_valid? Why didn't you make it work with arch.cpuid?

Frankly, because I hadn't spotted it.

hvm_efer_valid() is rather harder to reason about with the cr0_pg parameter, as it doubles as a restore boolean.

~Andrew

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

#3 lore raw
In reply to Andrew Cooper
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 28.01.19 at 14:56, <[email protected]> wrote:

Before the cpuid_policy logic came along, %cr4 auditing on migrate-in was complicated, because at that point no CPUID information had been set for the guest. Auditing against the host CPUID was better than nothing, but not ideal.

Quoted 7 lines

Order of information in the migration stream is still an issue (hence we still need to keep the restore parameter to cope with a nested virt corner case), but since Xen 4.9, the domain starts with the applicable max policy, which is a more appropriate upper bound than the host cpuid policy.

This also makes the fix from c/s 9d2efbafb8 obsolete, as not even dom0 starts without a policy.

While I agree with the change itself, I'm struggling to make a connection from this description to what was actually wrong for PVH Dom0. You mostly talk about migration, which is not relevant do Dom0 as an object (and I don't see a connection to domains being migrated by PVH Dom0).

Quoted 2 lines

This ideally wants backporting to Xen 4.9 and later. I don't think there is anything we can reasonably do for 4.8 and earlier.

As (per its title) it affects PVH Dom0 only, is this really something worth backporting? (But perhaps this clarifies itself once I better understand the relation between title and description.

Jan

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

#4 lore raw
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 28.01.19 at 14:56, <[email protected]> wrote:

Before the cpuid_policy logic came along, %cr4 auditing on migrate-in was complicated, because at that point no CPUID information had been set for the guest. Auditing against the host CPUID was better than nothing, but not ideal.

Order of information in the migration stream is still an issue (hence we still need to keep the restore parameter to cope with a nested virt corner case), but since Xen 4.9, the domain starts with the applicable max policy, which is a more appropriate upper bound than the host cpuid policy.

Quoted 6 lines
Quoted 2 lines

This also makes the fix from c/s 9d2efbafb8 obsolete, as not even dom0 starts without a policy.

While I agree with the change itself, I'm struggling to make a connection from this description to what was actually wrong for PVH Dom0. You mostly talk about migration, which is not relevant do Dom0 as an object (and I don't see a connection to domains being migrated by PVH Dom0).

The PVH Dom0 angle is simply that it is wrong to audit against the host policy.

The logic from c/s 9d2efbafb8 is a vestigial remnant of PVHv1, because HVM domains never had the "pass through host CPUID values" logic which PV guests used to have.  Now that all domains have a cpuid policy, this logic is no longer necessary.

Quoted 6 lines
Quoted 3 lines

This ideally wants backporting to Xen 4.9 and later. I don't think there is anything we can reasonably do for 4.8 and earlier.

As (per its title) it affects PVH Dom0 only, is this really something worth backporting? (But perhaps this clarifies itself once I better understand the relation between title and description.

Hmm - perhaps not.  As I said, I'm not aware of any differences between the host max policy and the hvm max policy when it comes to the subset of bits selected by this logic.

~Andrew

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

Reviewed-by
#5 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 28.01.19 at 16:36, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 28.01.19 at 14:56, <[email protected]> wrote:

Before the cpuid_policy logic came along, %cr4 auditing on migrate-in was complicated, because at that point no CPUID information had been set for the guest. Auditing against the host CPUID was better than nothing, but not ideal.

Order of information in the migration stream is still an issue (hence we

still

Quoted 2 lines
Quoted 2 lines

need to keep the restore parameter to cope with a nested virt corner case), but since Xen 4.9, the domain starts with the applicable max policy, which

is

Quoted 3 lines
Quoted 3 lines

a more appropriate upper bound than the host cpuid policy.

This also makes the fix from c/s 9d2efbafb8 obsolete, as not even dom0

starts

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

without a policy.

While I agree with the change itself, I'm struggling to make a connection from this description to what was actually wrong for PVH Dom0. You mostly talk about migration, which is not relevant do Dom0 as an object (and I don't see a connection to domains being migrated by PVH Dom0).

The PVH Dom0 angle is simply that it is wrong to audit against the host policy.

So I'd appreciate if you could make the connection a little more explicit. In any event

Jan

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

#6 lore raw
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 28.01.19 at 16:36, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 28.01.19 at 14:56, <[email protected]> wrote:

Before the cpuid_policy logic came along, %cr4 auditing on migrate-in was complicated, because at that point no CPUID information had been set for the guest. Auditing against the host CPUID was better than nothing, but not ideal.

Order of information in the migration stream is still an issue (hence we

still

Quoted 2 lines
Quoted 2 lines

need to keep the restore parameter to cope with a nested virt corner case), but since Xen 4.9, the domain starts with the applicable max policy, which

is

Quoted 3 lines
Quoted 3 lines

a more appropriate upper bound than the host cpuid policy.

This also makes the fix from c/s 9d2efbafb8 obsolete, as not even dom0

starts

Quoted 5 lines
Quoted 1 line

without a policy.

While I agree with the change itself, I'm struggling to make a connection from this description to what was actually wrong for PVH Dom0. You mostly talk about migration, which is not relevant do Dom0 as an object (and I don't see a connection to domains being migrated by PVH Dom0).

Quoted 5 lines
Quoted 2 lines

The PVH Dom0 angle is simply that it is wrong to audit against the host policy.

So I'd appreciate if you could make the connection a little more explicit. In any event

As noticed by Wei, hvm_efer_valid() suffers from the same issue, but is in a more problematic state.  I'll do a combined v2 patch and see about describing things more clearly.

~Andrew

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