On Wed, Mar 4, 2020 at 3:58 PM Vitaly Kuznetsov <vkuznets@xxxxxxxxxx> wrote: > > Jon Doron <arilou@xxxxxxxxx> writes: > > > Microsoft's kdvm.dll dbgtransport module does not respect the hypercall > > page and simply identifies the CPU being used (AMD/Intel) and according > > to it simply makes hypercalls with the relevant instruction > > (vmmcall/vmcall respectively). > > > > The relevant function in kdvm is KdHvConnectHypervisor which first checks > > if the hypercall page has been enabled via HV_X64_MSR_HYPERCALL_ENABLE, > > and in case it was not it simply sets the HV_X64_MSR_GUEST_OS_ID to > > 0x1000101010001 which means: > > build_number = 0x0001 > > service_version = 0x01 > > minor_version = 0x01 > > major_version = 0x01 > > os_id = 0x00 (Undefined) > > vendor_id = 1 (Microsoft) > > os_type = 0 (A value of 0 indicates a proprietary, closed source OS) > > > > and starts issuing the hypercall without setting the hypercall page. > > > > To resolve this issue simply enable hypercalls if the guest_os_id is > > not 0. > > > > Signed-off-by: Jon Doron <arilou@xxxxxxxxx> > > --- > > arch/x86/kvm/hyperv.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > > index 13176ec23496..7ec962d433af 100644 > > --- a/arch/x86/kvm/hyperv.c > > +++ b/arch/x86/kvm/hyperv.c > > @@ -1615,7 +1615,7 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *current_vcpu, u64 ingpa, u64 outgpa, > > > > bool kvm_hv_hypercall_enabled(struct kvm *kvm) > > { > > - return READ_ONCE(kvm->arch.hyperv.hv_hypercall) & HV_X64_MSR_HYPERCALL_ENABLE; > > + return READ_ONCE(kvm->arch.hyperv.hv_guest_os_id) != 0; > > } > > > > static void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result) > > I would've enabled it in both cases, > > return (READ_ONCE(kvm->arch.hyperv.hv_hypercall) & > HV_X64_MSR_HYPERCALL_ENABLE) || (READ_ONCE(kvm->arch.hyperv.hv_guest_os_id) != 0); > > to be safe. We can also check what genuine Hyper-V does but I bet it has > hypercalls always enabled. Also, the function can be made inline, > there's a single caller. I dont have any Hyper-V setup at the moment to validate this, i believe your hunch is correct but ill do the implementation you have suggested. > > -- > Vitaly >