aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoffer Dall <christoffer.dall@linaro.org>2015-11-24 10:23:05 -0500
committerChristoffer Dall <christoffer.dall@linaro.org>2015-11-24 12:07:40 -0500
commit0e3dfda91d9fe8e2c4d0b5d21434b173a241eeaf (patch)
tree0f976f6b44f4ded62834c26579d9265406531a8f
parent7e16aa81f9f6a7cfe2287b788a7d62abc2880185 (diff)
KVM: arm/arm64: arch_timer: Preserve physical dist. active state on LR.active
We were incorrectly removing the active state from the physical distributor on the timer interrupt when the timer output level was deasserted. We shouldn't be doing this without considering the virtual interrupt's active state, because the architecture requires that when an LR has the HW bit set and the pending or active bits set, then the physical interrupt must also have the corresponding bits set. This addresses an issue where we have been observing an inconsistency between the LR state and the physical distributor state where the LR state was active and the physical distributor was not active, which shouldn't happen. Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
-rw-r--r--include/kvm/arm_vgic.h2
-rw-r--r--virt/kvm/arm/arch_timer.c28
-rw-r--r--virt/kvm/arm/vgic.c34
3 files changed, 40 insertions, 24 deletions
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index 9c747cb14ad8..d2f41477f8ae 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -342,10 +342,10 @@ int kvm_vgic_inject_mapped_irq(struct kvm *kvm, int cpuid,
342 struct irq_phys_map *map, bool level); 342 struct irq_phys_map *map, bool level);
343void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg); 343void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg);
344int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu); 344int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu);
345int kvm_vgic_vcpu_active_irq(struct kvm_vcpu *vcpu);
346struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, 345struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu,
347 int virt_irq, int irq); 346 int virt_irq, int irq);
348int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, struct irq_phys_map *map); 347int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, struct irq_phys_map *map);
348bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, struct irq_phys_map *map);
349 349
350#define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel)) 350#define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel))
351#define vgic_initialized(k) (!!((k)->arch.vgic.nr_cpus)) 351#define vgic_initialized(k) (!!((k)->arch.vgic.nr_cpus))
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index 21a0ab2d8919..69bca185c471 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -221,17 +221,23 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)
221 kvm_timer_update_state(vcpu); 221 kvm_timer_update_state(vcpu);
222 222
223 /* 223 /*
224 * If we enter the guest with the virtual input level to the VGIC 224 * If we enter the guest with the virtual input level to the VGIC
225 * asserted, then we have already told the VGIC what we need to, and 225 * asserted, then we have already told the VGIC what we need to, and
226 * we don't need to exit from the guest until the guest deactivates 226 * we don't need to exit from the guest until the guest deactivates
227 * the already injected interrupt, so therefore we should set the 227 * the already injected interrupt, so therefore we should set the
228 * hardware active state to prevent unnecessary exits from the guest. 228 * hardware active state to prevent unnecessary exits from the guest.
229 * 229 *
230 * Conversely, if the virtual input level is deasserted, then always 230 * Also, if we enter the guest with the virtual timer interrupt active,
231 * clear the hardware active state to ensure that hardware interrupts 231 * then it must be active on the physical distributor, because we set
232 * from the timer triggers a guest exit. 232 * the HW bit and the guest must be able to deactivate the virtual and
233 */ 233 * physical interrupt at the same time.
234 if (timer->irq.level) 234 *
235 * Conversely, if the virtual input level is deasserted and the virtual
236 * interrupt is not active, then always clear the hardware active state
237 * to ensure that hardware interrupts from the timer triggers a guest
238 * exit.
239 */
240 if (timer->irq.level || kvm_vgic_map_is_active(vcpu, timer->map))
235 phys_active = true; 241 phys_active = true;
236 else 242 else
237 phys_active = false; 243 phys_active = false;
diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 533538385d5d..97e2c088e1e9 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -1096,6 +1096,27 @@ static void vgic_retire_lr(int lr_nr, struct kvm_vcpu *vcpu)
1096 vgic_set_lr(vcpu, lr_nr, vlr); 1096 vgic_set_lr(vcpu, lr_nr, vlr);
1097} 1097}
1098 1098
1099static bool dist_active_irq(struct kvm_vcpu *vcpu)
1100{
1101 struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
1102
1103 return test_bit(vcpu->vcpu_id, dist->irq_active_on_cpu);
1104}
1105
1106bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, struct irq_phys_map *map)
1107{
1108 int i;
1109
1110 for (i = 0; i < vcpu->arch.vgic_cpu.nr_lr; i++) {
1111 struct vgic_lr vlr = vgic_get_lr(vcpu, i);
1112
1113 if (vlr.irq == map->virt_irq && vlr.state & LR_STATE_ACTIVE)
1114 return true;
1115 }
1116
1117 return dist_active_irq(vcpu);
1118}
1119
1099/* 1120/*
1100 * An interrupt may have been disabled after being made pending on the 1121 * An interrupt may have been disabled after being made pending on the
1101 * CPU interface (the classic case is a timer running while we're 1122 * CPU interface (the classic case is a timer running while we're
@@ -1248,7 +1269,7 @@ static void __kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)
1248 * may have been serviced from another vcpu. In all cases, 1269 * may have been serviced from another vcpu. In all cases,
1249 * move along. 1270 * move along.
1250 */ 1271 */
1251 if (!kvm_vgic_vcpu_pending_irq(vcpu) && !kvm_vgic_vcpu_active_irq(vcpu)) 1272 if (!kvm_vgic_vcpu_pending_irq(vcpu) && !dist_active_irq(vcpu))
1252 goto epilog; 1273 goto epilog;
1253 1274
1254 /* SGIs */ 1275 /* SGIs */
@@ -1479,17 +1500,6 @@ int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu)
1479 return test_bit(vcpu->vcpu_id, dist->irq_pending_on_cpu); 1500 return test_bit(vcpu->vcpu_id, dist->irq_pending_on_cpu);
1480} 1501}
1481 1502
1482int kvm_vgic_vcpu_active_irq(struct kvm_vcpu *vcpu)
1483{
1484 struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
1485
1486 if (!irqchip_in_kernel(vcpu->kvm))
1487 return 0;
1488
1489 return test_bit(vcpu->vcpu_id, dist->irq_active_on_cpu);
1490}
1491
1492
1493void vgic_kick_vcpus(struct kvm *kvm) 1503void vgic_kick_vcpus(struct kvm *kvm)
1494{ 1504{
1495 struct kvm_vcpu *vcpu; 1505 struct kvm_vcpu *vcpu;