Re: [PATCH RFC 01/39] KVM: x86: fix Xen hypercall page msr handling

From: David Woodhouse
Date: Mon Nov 30 2020 - 06:29:00 EST


On Mon, 2020-11-30 at 12:03 +0100, Paolo Bonzini wrote:
> You can use CPUID too (search for Hv#1 in leaf 0x40000000)?

That's leaf 0x40000001. Which is also the leaf used for Xen to indicate
the Xen version. So as long as we don't pretend to be Xen version
12759.30280 I suppose that's OK.

Or we could just check leaf 0x40000000 for 'Microsoft Hv'? Or both.

How about...

#define HYPERV_CPUID_INTERFACE_MAGIC 0x31237648 /* 'Hv#1' */

static inline bool guest_cpu_has_hyperv(struct kvm_vcpu *vcpu)
{
struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
const struct kvm_cpuid_entry2 *entry;

/*
* The call to kvm_find_cpuid_entry() is a bit much to put on

* the fast path of some of the Hyper-V MSRs, so bypass it if
* the guest OS ID has already been set.
*/
if (hv->hv_guest_os_id)
return true;

entry = kvm_find_cpuid_entry(vcpu, HYPERV_CPUID_INTERFACE, 0x0);
return entry && entry->eax == HYPERV_CPUID_INTERFACE_MAGIC;
}

I wonder if this is overengineering when 'let Xen take precedence'
works well enough?

Attachment: smime.p7s
Description: S/MIME cryptographic signature