KVM: arm/arm64: use vcpu requests for irq injection
authorAndrew Jones <drjones@redhat.com>
Sun, 4 Jun 2017 12:43:59 +0000 (14:43 +0200)
committerChristoffer Dall <cdall@linaro.org>
Sun, 4 Jun 2017 14:53:56 +0000 (16:53 +0200)
Don't use request-less VCPU kicks when injecting IRQs, as a VCPU
kick meant to trigger the interrupt injection could be sent while
the VCPU is outside guest mode, which means no IPI is sent, and
after it has called kvm_vgic_flush_hwstate(), meaning it won't see
the updated GIC state until its next exit some time later for some
other reason.  The receiving VCPU only needs to check this request
in VCPU RUN to handle it.  By checking it, if it's pending, a
memory barrier will be issued that ensures all state is visible.
See "Ensuring Requests Are Seen" of
Documentation/virtual/kvm/vcpu-requests.rst

Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Christoffer Dall <cdall@linaro.org>
arch/arm/include/asm/kvm_host.h
arch/arm64/include/asm/kvm_host.h
virt/kvm/arm/arm.c
virt/kvm/arm/vgic/vgic.c

index fdd644c01c891710d3e41ebe56908e30b7735f4c..00ad56ee6455a78ed0bc0407077a0a47cca4b923 100644 (file)
@@ -46,6 +46,7 @@
 
 #define KVM_REQ_SLEEP \
        KVM_ARCH_REQ_FLAGS(0, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
+#define KVM_REQ_IRQ_PENDING    KVM_ARCH_REQ(1)
 
 u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
 int __attribute_const__ kvm_target_cpu(void);
index 9bd0d1040de970b99bed0039d739ecb853d3782c..0c4fd1f46e107cb483507b883df7cb2796c108bd 100644 (file)
@@ -43,6 +43,7 @@
 
 #define KVM_REQ_SLEEP \
        KVM_ARCH_REQ_FLAGS(0, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
+#define KVM_REQ_IRQ_PENDING    KVM_ARCH_REQ(1)
 
 int __attribute_const__ kvm_target_cpu(void);
 int kvm_reset_vcpu(struct kvm_vcpu *vcpu);
index ddc833987dfb1ca122e78ab0f47ca30acb60b449..cac5c2f2ddbabbd976c3e056c2d357ded0f0bd45 100644 (file)
@@ -580,6 +580,12 @@ static void check_vcpu_requests(struct kvm_vcpu *vcpu)
        if (kvm_request_pending(vcpu)) {
                if (kvm_check_request(KVM_REQ_SLEEP, vcpu))
                        vcpu_req_sleep(vcpu);
+
+               /*
+                * Clear IRQ_PENDING requests that were made to guarantee
+                * that a VCPU sees new virtual interrupts.
+                */
+               kvm_check_request(KVM_REQ_IRQ_PENDING, vcpu);
        }
 }
 
@@ -771,6 +777,7 @@ static int vcpu_interrupt_line(struct kvm_vcpu *vcpu, int number, bool level)
         * trigger a world-switch round on the running physical CPU to set the
         * virtual IRQ/FIQ fields in the HCR appropriately.
         */
+       kvm_make_request(KVM_REQ_IRQ_PENDING, vcpu);
        kvm_vcpu_kick(vcpu);
 
        return 0;
index aea080a2c4437ed2ddd7c7b7d53148a2b2d7a6e3..c66feaca2a5d905ef29e0e72ecf9991636ce6b49 100644 (file)
@@ -286,8 +286,10 @@ retry:
                 * won't see this one until it exits for some other
                 * reason.
                 */
-               if (vcpu)
+               if (vcpu) {
+                       kvm_make_request(KVM_REQ_IRQ_PENDING, vcpu);
                        kvm_vcpu_kick(vcpu);
+               }
                return false;
        }
 
@@ -333,6 +335,7 @@ retry:
        spin_unlock(&irq->irq_lock);
        spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock);
 
+       kvm_make_request(KVM_REQ_IRQ_PENDING, vcpu);
        kvm_vcpu_kick(vcpu);
 
        return true;
@@ -722,8 +725,10 @@ void vgic_kick_vcpus(struct kvm *kvm)
         * a good kick...
         */
        kvm_for_each_vcpu(c, vcpu, kvm) {
-               if (kvm_vgic_vcpu_pending_irq(vcpu))
+               if (kvm_vgic_vcpu_pending_irq(vcpu)) {
+                       kvm_make_request(KVM_REQ_IRQ_PENDING, vcpu);
                        kvm_vcpu_kick(vcpu);
+               }
        }
 }