aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Kagan <rkagan@virtuozzo.com>2017-06-22 09:51:01 -0400
committerRadim Krčmář <rkrcmar@redhat.com>2017-07-13 11:41:04 -0400
commitefc479e6900c22bad9a2b649d13405ed9cde2d53 (patch)
tree517b287129af96017f2aad22e7dd352ce725cbe6
parenta826faf108e2d855929342268e68c43ba667379a (diff)
kvm: x86: hyperv: add KVM_CAP_HYPERV_SYNIC2
There is a flaw in the Hyper-V SynIC implementation in KVM: when message page or event flags page is enabled by setting the corresponding msr, KVM zeroes it out. This is problematic because on migration the corresponding MSRs are loaded on the destination, so the content of those pages is lost. This went unnoticed so far because the only user of those pages was in-KVM hyperv synic timers, which could continue working despite that zeroing. Newer QEMU uses those pages for Hyper-V VMBus implementation, and zeroing them breaks the migration. Besides, in newer QEMU the content of those pages is fully managed by QEMU, so zeroing them is undesirable even when writing the MSRs from the guest side. To support this new scheme, introduce a new capability, KVM_CAP_HYPERV_SYNIC2, which, when enabled, makes sure that the synic pages aren't zeroed out in KVM. Signed-off-by: Roman Kagan <rkagan@virtuozzo.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
-rw-r--r--Documentation/virtual/kvm/api.txt9
-rw-r--r--arch/x86/include/asm/kvm_host.h1
-rw-r--r--arch/x86/kvm/hyperv.c13
-rw-r--r--arch/x86/kvm/hyperv.h2
-rw-r--r--arch/x86/kvm/x86.c7
-rw-r--r--include/uapi/linux/kvm.h1
6 files changed, 27 insertions, 6 deletions
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 3a9831b72945..78ac577c9378 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -4329,3 +4329,12 @@ Querying this capability returns a bitmap indicating the possible
4329virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N 4329virtual SMT modes that can be set using KVM_CAP_PPC_SMT. If bit N
4330(counting from the right) is set, then a virtual SMT mode of 2^N is 4330(counting from the right) is set, then a virtual SMT mode of 2^N is
4331available. 4331available.
4332
43338.11 KVM_CAP_HYPERV_SYNIC2
4334
4335Architectures: x86
4336
4337This capability enables a newer version of Hyper-V Synthetic interrupt
4338controller (SynIC). The only difference with KVM_CAP_HYPERV_SYNIC is that KVM
4339doesn't clear SynIC message and event flags pages when they are enabled by
4340writing to the respective MSRs.
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index ef37d0dc61bd..9d8de5dd7546 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -462,6 +462,7 @@ struct kvm_vcpu_hv_synic {
462 DECLARE_BITMAP(auto_eoi_bitmap, 256); 462 DECLARE_BITMAP(auto_eoi_bitmap, 256);
463 DECLARE_BITMAP(vec_bitmap, 256); 463 DECLARE_BITMAP(vec_bitmap, 256);
464 bool active; 464 bool active;
465 bool dont_zero_synic_pages;
465}; 466};
466 467
467/* Hyper-V per vcpu emulation context */ 468/* Hyper-V per vcpu emulation context */
diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index ebae57ac5902..a8084406707e 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -221,7 +221,8 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
221 synic->version = data; 221 synic->version = data;
222 break; 222 break;
223 case HV_X64_MSR_SIEFP: 223 case HV_X64_MSR_SIEFP:
224 if (data & HV_SYNIC_SIEFP_ENABLE) 224 if ((data & HV_SYNIC_SIEFP_ENABLE) && !host &&
225 !synic->dont_zero_synic_pages)
225 if (kvm_clear_guest(vcpu->kvm, 226 if (kvm_clear_guest(vcpu->kvm,
226 data & PAGE_MASK, PAGE_SIZE)) { 227 data & PAGE_MASK, PAGE_SIZE)) {
227 ret = 1; 228 ret = 1;
@@ -232,7 +233,8 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic,
232 synic_exit(synic, msr); 233 synic_exit(synic, msr);
233 break; 234 break;
234 case HV_X64_MSR_SIMP: 235 case HV_X64_MSR_SIMP:
235 if (data & HV_SYNIC_SIMP_ENABLE) 236 if ((data & HV_SYNIC_SIMP_ENABLE) && !host &&
237 !synic->dont_zero_synic_pages)
236 if (kvm_clear_guest(vcpu->kvm, 238 if (kvm_clear_guest(vcpu->kvm,
237 data & PAGE_MASK, PAGE_SIZE)) { 239 data & PAGE_MASK, PAGE_SIZE)) {
238 ret = 1; 240 ret = 1;
@@ -687,14 +689,17 @@ void kvm_hv_vcpu_init(struct kvm_vcpu *vcpu)
687 stimer_init(&hv_vcpu->stimer[i], i); 689 stimer_init(&hv_vcpu->stimer[i], i);
688} 690}
689 691
690int kvm_hv_activate_synic(struct kvm_vcpu *vcpu) 692int kvm_hv_activate_synic(struct kvm_vcpu *vcpu, bool dont_zero_synic_pages)
691{ 693{
694 struct kvm_vcpu_hv_synic *synic = vcpu_to_synic(vcpu);
695
692 /* 696 /*
693 * Hyper-V SynIC auto EOI SINT's are 697 * Hyper-V SynIC auto EOI SINT's are
694 * not compatible with APICV, so deactivate APICV 698 * not compatible with APICV, so deactivate APICV
695 */ 699 */
696 kvm_vcpu_deactivate_apicv(vcpu); 700 kvm_vcpu_deactivate_apicv(vcpu);
697 vcpu_to_synic(vcpu)->active = true; 701 synic->active = true;
702 synic->dont_zero_synic_pages = dont_zero_synic_pages;
698 return 0; 703 return 0;
699} 704}
700 705
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
index cd1119538add..12f65fe1011d 100644
--- a/arch/x86/kvm/hyperv.h
+++ b/arch/x86/kvm/hyperv.h
@@ -56,7 +56,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
56void kvm_hv_irq_routing_update(struct kvm *kvm); 56void kvm_hv_irq_routing_update(struct kvm *kvm);
57int kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint); 57int kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint);
58void kvm_hv_synic_send_eoi(struct kvm_vcpu *vcpu, int vector); 58void kvm_hv_synic_send_eoi(struct kvm_vcpu *vcpu, int vector);
59int kvm_hv_activate_synic(struct kvm_vcpu *vcpu); 59int kvm_hv_activate_synic(struct kvm_vcpu *vcpu, bool dont_zero_synic_pages);
60 60
61void kvm_hv_vcpu_init(struct kvm_vcpu *vcpu); 61void kvm_hv_vcpu_init(struct kvm_vcpu *vcpu);
62void kvm_hv_vcpu_uninit(struct kvm_vcpu *vcpu); 62void kvm_hv_vcpu_uninit(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 08aa5e442aa7..4f41c5222ecd 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2659,6 +2659,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
2659 case KVM_CAP_HYPERV_VAPIC: 2659 case KVM_CAP_HYPERV_VAPIC:
2660 case KVM_CAP_HYPERV_SPIN: 2660 case KVM_CAP_HYPERV_SPIN:
2661 case KVM_CAP_HYPERV_SYNIC: 2661 case KVM_CAP_HYPERV_SYNIC:
2662 case KVM_CAP_HYPERV_SYNIC2:
2662 case KVM_CAP_PCI_SEGMENT: 2663 case KVM_CAP_PCI_SEGMENT:
2663 case KVM_CAP_DEBUGREGS: 2664 case KVM_CAP_DEBUGREGS:
2664 case KVM_CAP_X86_ROBUST_SINGLESTEP: 2665 case KVM_CAP_X86_ROBUST_SINGLESTEP:
@@ -3382,10 +3383,14 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
3382 return -EINVAL; 3383 return -EINVAL;
3383 3384
3384 switch (cap->cap) { 3385 switch (cap->cap) {
3386 case KVM_CAP_HYPERV_SYNIC2:
3387 if (cap->args[0])
3388 return -EINVAL;
3385 case KVM_CAP_HYPERV_SYNIC: 3389 case KVM_CAP_HYPERV_SYNIC:
3386 if (!irqchip_in_kernel(vcpu->kvm)) 3390 if (!irqchip_in_kernel(vcpu->kvm))
3387 return -EINVAL; 3391 return -EINVAL;
3388 return kvm_hv_activate_synic(vcpu); 3392 return kvm_hv_activate_synic(vcpu, cap->cap ==
3393 KVM_CAP_HYPERV_SYNIC2);
3389 default: 3394 default:
3390 return -EINVAL; 3395 return -EINVAL;
3391 } 3396 }
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index ebd604c222d8..38b2cfbc8112 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -927,6 +927,7 @@ struct kvm_ppc_resize_hpt {
927#define KVM_CAP_S390_CMMA_MIGRATION 145 927#define KVM_CAP_S390_CMMA_MIGRATION 145
928#define KVM_CAP_PPC_FWNMI 146 928#define KVM_CAP_PPC_FWNMI 146
929#define KVM_CAP_PPC_SMT_POSSIBLE 147 929#define KVM_CAP_PPC_SMT_POSSIBLE 147
930#define KVM_CAP_HYPERV_SYNIC2 148
930 931
931#ifdef KVM_CAP_IRQ_ROUTING 932#ifdef KVM_CAP_IRQ_ROUTING
932 933