Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull KVM bugfixes from Paolo Bonzini:
"Bug fixes for ARM, mostly 4.3 regressions related to virtual interrupt
controller changes"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
arm/arm64: KVM: Fix disabled distributor operation
arm/arm64: KVM: Clear map->active on pend/active clear
arm/arm64: KVM: Fix arch timer behavior for disabled interrupts
KVM: arm: use GIC support unconditionally
KVM: arm/arm64: Fix memory leak if timer initialization fails
KVM: arm/arm64: Do not inject spurious interrupts

+76 -41
+1
arch/arm/kvm/Kconfig
··· 21 21 depends on MMU && OF 22 22 select PREEMPT_NOTIFIERS 23 23 select ANON_INODES 24 + select ARM_GIC 24 25 select HAVE_KVM_CPU_RELAX_INTERCEPT 25 26 select HAVE_KVM_ARCH_TLB_FLUSH_ALL 26 27 select KVM_MMIO
+1 -1
arch/arm/kvm/arm.c
··· 1080 1080 */ 1081 1081 err = kvm_timer_hyp_init(); 1082 1082 if (err) 1083 - goto out_free_mappings; 1083 + goto out_free_context; 1084 1084 1085 1085 #ifndef CONFIG_HOTPLUG_CPU 1086 1086 free_boot_hyp_pgd();
+19
virt/kvm/arm/arch_timer.c
··· 137 137 void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu) 138 138 { 139 139 struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; 140 + bool phys_active; 141 + int ret; 140 142 141 143 /* 142 144 * We're about to run this vcpu again, so there is no need to ··· 153 151 */ 154 152 if (kvm_timer_should_fire(vcpu)) 155 153 kvm_timer_inject_irq(vcpu); 154 + 155 + /* 156 + * We keep track of whether the edge-triggered interrupt has been 157 + * signalled to the vgic/guest, and if so, we mask the interrupt and 158 + * the physical distributor to prevent the timer from raising a 159 + * physical interrupt whenever we run a guest, preventing forward 160 + * VCPU progress. 161 + */ 162 + if (kvm_vgic_get_phys_irq_active(timer->map)) 163 + phys_active = true; 164 + else 165 + phys_active = false; 166 + 167 + ret = irq_set_irqchip_state(timer->map->irq, 168 + IRQCHIP_STATE_ACTIVE, 169 + phys_active); 170 + WARN_ON(ret); 156 171 } 157 172 158 173 /**
+55 -40
virt/kvm/arm/vgic.c
··· 531 531 return false; 532 532 } 533 533 534 + /* 535 + * If a mapped interrupt's state has been modified by the guest such that it 536 + * is no longer active or pending, without it have gone through the sync path, 537 + * then the map->active field must be cleared so the interrupt can be taken 538 + * again. 539 + */ 540 + static void vgic_handle_clear_mapped_irq(struct kvm_vcpu *vcpu) 541 + { 542 + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 543 + struct list_head *root; 544 + struct irq_phys_map_entry *entry; 545 + struct irq_phys_map *map; 546 + 547 + rcu_read_lock(); 548 + 549 + /* Check for PPIs */ 550 + root = &vgic_cpu->irq_phys_map_list; 551 + list_for_each_entry_rcu(entry, root, entry) { 552 + map = &entry->map; 553 + 554 + if (!vgic_dist_irq_is_pending(vcpu, map->virt_irq) && 555 + !vgic_irq_is_active(vcpu, map->virt_irq)) 556 + map->active = false; 557 + } 558 + 559 + rcu_read_unlock(); 560 + } 561 + 534 562 bool vgic_handle_clear_pending_reg(struct kvm *kvm, 535 563 struct kvm_exit_mmio *mmio, 536 564 phys_addr_t offset, int vcpu_id) ··· 589 561 vcpu_id, offset); 590 562 vgic_reg_access(mmio, reg, offset, mode); 591 563 564 + vgic_handle_clear_mapped_irq(kvm_get_vcpu(kvm, vcpu_id)); 592 565 vgic_update_state(kvm); 593 566 return true; 594 567 } ··· 627 598 ACCESS_READ_VALUE | ACCESS_WRITE_CLEARBIT); 628 599 629 600 if (mmio->is_write) { 601 + vgic_handle_clear_mapped_irq(kvm_get_vcpu(kvm, vcpu_id)); 630 602 vgic_update_state(kvm); 631 603 return true; 632 604 } ··· 1012 982 pend_percpu = vcpu->arch.vgic_cpu.pending_percpu; 1013 983 pend_shared = vcpu->arch.vgic_cpu.pending_shared; 1014 984 985 + if (!dist->enabled) { 986 + bitmap_zero(pend_percpu, VGIC_NR_PRIVATE_IRQS); 987 + bitmap_zero(pend_shared, nr_shared); 988 + return 0; 989 + } 990 + 1015 991 pending = vgic_bitmap_get_cpu_map(&dist->irq_pending, vcpu_id); 1016 992 enabled = vgic_bitmap_get_cpu_map(&dist->irq_enabled, vcpu_id); 1017 993 bitmap_and(pend_percpu, pending, enabled, VGIC_NR_PRIVATE_IRQS); ··· 1044 1008 struct vgic_dist *dist = &kvm->arch.vgic; 1045 1009 struct kvm_vcpu *vcpu; 1046 1010 int c; 1047 - 1048 - if (!dist->enabled) { 1049 - set_bit(0, dist->irq_pending_on_cpu); 1050 - return; 1051 - } 1052 1011 1053 1012 kvm_for_each_vcpu(c, vcpu, kvm) { 1054 1013 if (compute_pending_for_cpu(vcpu)) ··· 1123 1092 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 1124 1093 struct vgic_lr vlr = vgic_get_lr(vcpu, lr_nr); 1125 1094 1095 + /* 1096 + * We must transfer the pending state back to the distributor before 1097 + * retiring the LR, otherwise we may loose edge-triggered interrupts. 1098 + */ 1099 + if (vlr.state & LR_STATE_PENDING) { 1100 + vgic_dist_irq_set_pending(vcpu, irq); 1101 + vlr.hwirq = 0; 1102 + } 1103 + 1126 1104 vlr.state = 0; 1127 1105 vgic_set_lr(vcpu, lr_nr, vlr); 1128 1106 clear_bit(lr_nr, vgic_cpu->lr_used); ··· 1172 1132 kvm_debug("Set active, clear distributor: 0x%x\n", vlr.state); 1173 1133 vgic_irq_clear_active(vcpu, irq); 1174 1134 vgic_update_state(vcpu->kvm); 1175 - } else if (vgic_dist_irq_is_pending(vcpu, irq)) { 1135 + } else { 1136 + WARN_ON(!vgic_dist_irq_is_pending(vcpu, irq)); 1176 1137 vlr.state |= LR_STATE_PENDING; 1177 1138 kvm_debug("Set pending: 0x%x\n", vlr.state); 1178 1139 } ··· 1281 1240 struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; 1282 1241 struct vgic_dist *dist = &vcpu->kvm->arch.vgic; 1283 1242 unsigned long *pa_percpu, *pa_shared; 1284 - int i, vcpu_id, lr, ret; 1243 + int i, vcpu_id; 1285 1244 int overflow = 0; 1286 1245 int nr_shared = vgic_nr_shared_irqs(dist); 1287 1246 ··· 1335 1294 * adjust that if needed while exiting. 1336 1295 */ 1337 1296 clear_bit(vcpu_id, dist->irq_pending_on_cpu); 1338 - } 1339 - 1340 - for (lr = 0; lr < vgic->nr_lr; lr++) { 1341 - struct vgic_lr vlr; 1342 - 1343 - if (!test_bit(lr, vgic_cpu->lr_used)) 1344 - continue; 1345 - 1346 - vlr = vgic_get_lr(vcpu, lr); 1347 - 1348 - /* 1349 - * If we have a mapping, and the virtual interrupt is 1350 - * presented to the guest (as pending or active), then we must 1351 - * set the state to active in the physical world. See 1352 - * Documentation/virtual/kvm/arm/vgic-mapped-irqs.txt. 1353 - */ 1354 - if (vlr.state & LR_HW) { 1355 - struct irq_phys_map *map; 1356 - map = vgic_irq_map_search(vcpu, vlr.irq); 1357 - 1358 - ret = irq_set_irqchip_state(map->irq, 1359 - IRQCHIP_STATE_ACTIVE, 1360 - true); 1361 - WARN_ON(ret); 1362 - } 1363 1297 } 1364 1298 } 1365 1299 ··· 1437 1421 return 0; 1438 1422 1439 1423 map = vgic_irq_map_search(vcpu, vlr.irq); 1440 - BUG_ON(!map || !map->active); 1424 + BUG_ON(!map); 1441 1425 1442 1426 ret = irq_get_irqchip_state(map->irq, 1443 1427 IRQCHIP_STATE_ACTIVE, ··· 1445 1429 1446 1430 WARN_ON(ret); 1447 1431 1448 - if (map->active) { 1449 - ret = irq_set_irqchip_state(map->irq, 1450 - IRQCHIP_STATE_ACTIVE, 1451 - false); 1452 - WARN_ON(ret); 1432 + if (map->active) 1453 1433 return 0; 1454 - } 1455 1434 1456 1435 return 1; 1457 1436 } ··· 1618 1607 } else { 1619 1608 if (level_triggered) { 1620 1609 vgic_dist_irq_clear_level(vcpu, irq_num); 1621 - if (!vgic_dist_irq_soft_pend(vcpu, irq_num)) 1610 + if (!vgic_dist_irq_soft_pend(vcpu, irq_num)) { 1622 1611 vgic_dist_irq_clear_pending(vcpu, irq_num); 1612 + vgic_cpu_irq_clear(vcpu, irq_num); 1613 + if (!compute_pending_for_cpu(vcpu)) 1614 + clear_bit(cpuid, dist->irq_pending_on_cpu); 1615 + } 1623 1616 } 1624 1617 1625 1618 ret = false;