]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
KVM: arm/arm64: Report PMU overflow interrupts to userspace irqchip
authorChristoffer Dall <christoffer.dall@linaro.org>
Wed, 1 Feb 2017 11:51:52 +0000 (12:51 +0100)
committerChristoffer Dall <cdall@linaro.org>
Sun, 9 Apr 2017 14:49:39 +0000 (07:49 -0700)
When not using an in-kernel VGIC, but instead emulating an interrupt
controller in userspace, we should report the PMU overflow status to
that userspace interrupt controller using the KVM_CAP_ARM_USER_IRQ
feature.

Reviewed-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arch/arm/kvm/arm.c
include/kvm/arm_pmu.h
virt/kvm/arm/arch_timer.c
virt/kvm/arm/pmu.c

index ac6e57bcbe4d2c5f334a83558fc58b8a4a51a830..9eda2932f686c2dc7748913def6d8a26351bed7a 100644 (file)
@@ -635,11 +635,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 
                /*
                 * If we have a singal pending, or need to notify a userspace
-                * irqchip about timer level changes, then we exit (and update
-                * the timer level state in kvm_timer_update_run below).
+                * irqchip about timer or PMU level changes, then we exit (and
+                * update the timer level state in kvm_timer_update_run
+                * below).
                 */
                if (signal_pending(current) ||
-                   kvm_timer_should_notify_user(vcpu)) {
+                   kvm_timer_should_notify_user(vcpu) ||
+                   kvm_pmu_should_notify_user(vcpu)) {
                        ret = -EINTR;
                        run->exit_reason = KVM_EXIT_INTR;
                }
@@ -712,7 +714,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
        }
 
        /* Tell userspace about in-kernel device output levels */
-       kvm_timer_update_run(vcpu);
+       if (unlikely(!irqchip_in_kernel(vcpu->kvm))) {
+               kvm_timer_update_run(vcpu);
+               kvm_pmu_update_run(vcpu);
+       }
 
        if (vcpu->sigset_active)
                sigprocmask(SIG_SETMASK, &sigsaved, NULL);
index 92e7e97ca8ff0f95ef9dba95b3e7078dd8c73049..1ab4633adf4fd16971edfa32f197a9e7b24c2d7b 100644 (file)
@@ -50,6 +50,8 @@ void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val);
 void kvm_pmu_overflow_set(struct kvm_vcpu *vcpu, u64 val);
 void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu);
 void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu);
+bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu);
+void kvm_pmu_update_run(struct kvm_vcpu *vcpu);
 void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val);
 void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val);
 void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, u64 data,
@@ -85,6 +87,11 @@ static inline void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, u64 val) {}
 static inline void kvm_pmu_overflow_set(struct kvm_vcpu *vcpu, u64 val) {}
 static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {}
 static inline void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu) {}
+static inline bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
+{
+       return false;
+}
+static inline void kvm_pmu_update_run(struct kvm_vcpu *vcpu) {}
 static inline void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val) {}
 static inline void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) {}
 static inline void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu,
index 5dc216748d546f815a7bf087c5613d4668bd96cc..5976609ef27cb9bf47ca997e08be38833d51f5d3 100644 (file)
@@ -193,9 +193,6 @@ void kvm_timer_update_run(struct kvm_vcpu *vcpu)
        struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
        struct kvm_sync_regs *regs = &vcpu->run->s.regs;
 
-       if (likely(irqchip_in_kernel(vcpu->kvm)))
-               return;
-
        /* Populate the device bitmap with the timer states */
        regs->device_irq_level &= ~(KVM_ARM_DEV_EL1_VTIMER |
                                    KVM_ARM_DEV_EL1_PTIMER);
index 69ccce308458a4c3de79ab1b6ffceee0f2cfb47d..4b43e7f3b15801916d35e60101938e79df41b26c 100644 (file)
@@ -230,13 +230,44 @@ static void kvm_pmu_update_state(struct kvm_vcpu *vcpu)
                return;
 
        overflow = !!kvm_pmu_overflow_status(vcpu);
-       if (pmu->irq_level != overflow) {
-               pmu->irq_level = overflow;
-               kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id,
-                                   pmu->irq_num, overflow);
+       if (pmu->irq_level == overflow)
+               return;
+
+       pmu->irq_level = overflow;
+
+       if (likely(irqchip_in_kernel(vcpu->kvm))) {
+               int ret;
+               ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id,
+                                         pmu->irq_num, overflow);
+               WARN_ON(ret);
        }
 }
 
+bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
+{
+       struct kvm_pmu *pmu = &vcpu->arch.pmu;
+       struct kvm_sync_regs *sregs = &vcpu->run->s.regs;
+       bool run_level = sregs->device_irq_level & KVM_ARM_DEV_PMU;
+
+       if (likely(irqchip_in_kernel(vcpu->kvm)))
+               return false;
+
+       return pmu->irq_level != run_level;
+}
+
+/*
+ * Reflect the PMU overflow interrupt output level into the kvm_run structure
+ */
+void kvm_pmu_update_run(struct kvm_vcpu *vcpu)
+{
+       struct kvm_sync_regs *regs = &vcpu->run->s.regs;
+
+       /* Populate the timer bitmap for user space */
+       regs->device_irq_level &= ~KVM_ARM_DEV_PMU;
+       if (vcpu->arch.pmu.irq_level)
+               regs->device_irq_level |= KVM_ARM_DEV_PMU;
+}
+
 /**
  * kvm_pmu_flush_hwstate - flush pmu state to cpu
  * @vcpu: The vcpu pointer