[RHEL7,COMMIT] x86/kvm/hyper-v: inject #GP only when invalid SINTx vector is unmasked

Submitted by Konstantin Khorenko on April 27, 2018, 10:34 a.m.

Details

Message ID 201804271034.w3RAYrNK000642@finist_ce7.work
State New
Series "assorted hyperv-related backports"
Headers show

Commit Message

Konstantin Khorenko April 27, 2018, 10:34 a.m.
The commit is pushed to "branch-rh7-3.10.0-693.21.1.vz7.47.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.21.1.vz7.47.2
------>
commit 0e6ec9912f58c2bf2f0728421fcf74f19990d8d6
Author: Vitaly Kuznetsov <vkuznets@redhat.com>
Date:   Fri Apr 27 13:34:53 2018 +0300

    x86/kvm/hyper-v: inject #GP only when invalid SINTx vector is unmasked
    
    Hyper-V 2016 on KVM with SynIC enabled doesn't boot with the following
    trace:
    
        kvm_entry:            vcpu 0
        kvm_exit:             reason MSR_WRITE rip 0xfffff8000131c1e5 info 0 0
        kvm_hv_synic_set_msr: vcpu_id 0 msr 0x40000090 data 0x10000 host 0
        kvm_msr:              msr_write 40000090 = 0x10000 (#GP)
        kvm_inj_exception:    #GP (0x0)
    
    KVM acts according to the following statement from TLFS:
    
    "
    11.8.4 SINTx Registers
    ...
    Valid values for vector are 16-255 inclusive. Specifying an invalid
    vector number results in #GP.
    "
    
    However, I checked and genuine Hyper-V doesn't #GP when we write 0x10000
    to SINTx. I checked with Microsoft and they confirmed that if either the
    Masked bit (bit 16) or the Polling bit (bit 18) is set to 1, then they
    ignore the value of Vector. Make KVM act accordingly.
    
    Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
    Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
    Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
    
    (cherry picked from commit 915e6f78bd0641da692ffa7e0b766e633e12e628)
    Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 arch/x86/kvm/hyperv.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 6f65fa0d8c4c..c6d95a97c44c 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -95,9 +95,17 @@  static int synic_set_sint(struct kvm_vcpu_hv_synic *synic, int sint,
 			  u64 data, bool host)
 {
 	int vector, old_vector;
+	bool masked;
 
 	vector = data & HV_SYNIC_SINT_VECTOR_MASK;
-	if (vector < HV_SYNIC_FIRST_VALID_VECTOR && !host)
+	masked = data & HV_SYNIC_SINT_MASKED;
+
+	/*
+	 * Valid vectors are 16-255, however, nested Hyper-V attempts to write
+	 * default '0x10000' value on boot and this should not #GP. We need to
+	 * allow zero-initing the register from host as well.
+	 */
+	if (vector < HV_SYNIC_FIRST_VALID_VECTOR && !host && !masked)
 		return 1;
 	/*
 	 * Guest may configure multiple SINTs to use the same vector, so