diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2016-08-18 06:19:19 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-08-18 06:19:19 -0400 |
commit | 2eeb321fd2e24c0910e96e82509a961d1531fa29 (patch) | |
tree | 800cea75783554f02e9b0254707346d54516546e | |
parent | c95ba92afb238ac565c68968fc72e38ca8d1b6e8 (diff) | |
parent | f7f6f2d94f0027242ddfd665289b107a873fde43 (diff) |
Merge tag 'kvm-arm-for-v4.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD
KVM/ARM Fixes for v4.8-rc3
This tag contains the following fixes on top of v4.8-rc1:
- ITS init issues
- ITS error handling issues
- ITS IRQ leakage fix
- Plug a couple of ITS race conditions
- An erratum workaround for timers
- Some removal of misleading use of errors and comments
- A fix for GICv3 on 32-bit guests
-rw-r--r-- | Documentation/arm64/silicon-errata.txt | 1 | ||||
-rw-r--r-- | arch/arm/kvm/mmu.c | 2 | ||||
-rw-r--r-- | arch/arm64/kvm/hyp/switch.c | 2 | ||||
-rw-r--r-- | arch/arm64/kvm/sys_regs.c | 10 | ||||
-rw-r--r-- | include/linux/irqchip/arm-gic-v3.h | 1 | ||||
-rw-r--r-- | virt/kvm/arm/arch_timer.c | 11 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic-its.c | 158 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic-mmio-v3.c | 26 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic-v3.c | 8 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic.c | 10 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic.h | 6 |
11 files changed, 164 insertions, 71 deletions
diff --git a/Documentation/arm64/silicon-errata.txt b/Documentation/arm64/silicon-errata.txt index 4da60b463995..ccc60324e738 100644 --- a/Documentation/arm64/silicon-errata.txt +++ b/Documentation/arm64/silicon-errata.txt | |||
@@ -53,6 +53,7 @@ stable kernels. | |||
53 | | ARM | Cortex-A57 | #832075 | ARM64_ERRATUM_832075 | | 53 | | ARM | Cortex-A57 | #832075 | ARM64_ERRATUM_832075 | |
54 | | ARM | Cortex-A57 | #852523 | N/A | | 54 | | ARM | Cortex-A57 | #852523 | N/A | |
55 | | ARM | Cortex-A57 | #834220 | ARM64_ERRATUM_834220 | | 55 | | ARM | Cortex-A57 | #834220 | ARM64_ERRATUM_834220 | |
56 | | ARM | Cortex-A72 | #853709 | N/A | | ||
56 | | ARM | MMU-500 | #841119,#826419 | N/A | | 57 | | ARM | MMU-500 | #841119,#826419 | N/A | |
57 | | | | | | | 58 | | | | | | |
58 | | Cavium | ThunderX ITS | #22375, #24313 | CAVIUM_ERRATUM_22375 | | 59 | | Cavium | ThunderX ITS | #22375, #24313 | CAVIUM_ERRATUM_22375 | |
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index bda27b6b1aa2..29d0b23af2a9 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c | |||
@@ -1309,7 +1309,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, | |||
1309 | smp_rmb(); | 1309 | smp_rmb(); |
1310 | 1310 | ||
1311 | pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writable); | 1311 | pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writable); |
1312 | if (is_error_pfn(pfn)) | 1312 | if (is_error_noslot_pfn(pfn)) |
1313 | return -EFAULT; | 1313 | return -EFAULT; |
1314 | 1314 | ||
1315 | if (kvm_is_device_pfn(pfn)) { | 1315 | if (kvm_is_device_pfn(pfn)) { |
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index ae7855f16ec2..5a84b4562603 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c | |||
@@ -256,7 +256,7 @@ static int __hyp_text __guest_run(struct kvm_vcpu *vcpu) | |||
256 | 256 | ||
257 | /* | 257 | /* |
258 | * We must restore the 32-bit state before the sysregs, thanks | 258 | * We must restore the 32-bit state before the sysregs, thanks |
259 | * to Cortex-A57 erratum #852523. | 259 | * to erratum #852523 (Cortex-A57) or #853709 (Cortex-A72). |
260 | */ | 260 | */ |
261 | __sysreg32_restore_state(vcpu); | 261 | __sysreg32_restore_state(vcpu); |
262 | __sysreg_restore_guest_state(guest_ctxt); | 262 | __sysreg_restore_guest_state(guest_ctxt); |
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index b0b225ceca18..e51367d159d0 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c | |||
@@ -823,14 +823,6 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, | |||
823 | * Architected system registers. | 823 | * Architected system registers. |
824 | * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 | 824 | * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 |
825 | * | 825 | * |
826 | * We could trap ID_DFR0 and tell the guest we don't support performance | ||
827 | * monitoring. Unfortunately the patch to make the kernel check ID_DFR0 was | ||
828 | * NAKed, so it will read the PMCR anyway. | ||
829 | * | ||
830 | * Therefore we tell the guest we have 0 counters. Unfortunately, we | ||
831 | * must always support PMCCNTR (the cycle counter): we just RAZ/WI for | ||
832 | * all PM registers, which doesn't crash the guest kernel at least. | ||
833 | * | ||
834 | * Debug handling: We do trap most, if not all debug related system | 826 | * Debug handling: We do trap most, if not all debug related system |
835 | * registers. The implementation is good enough to ensure that a guest | 827 | * registers. The implementation is good enough to ensure that a guest |
836 | * can use these with minimal performance degradation. The drawback is | 828 | * can use these with minimal performance degradation. The drawback is |
@@ -1360,7 +1352,7 @@ static const struct sys_reg_desc cp15_regs[] = { | |||
1360 | { Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, c10_AMAIR1 }, | 1352 | { Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, c10_AMAIR1 }, |
1361 | 1353 | ||
1362 | /* ICC_SRE */ | 1354 | /* ICC_SRE */ |
1363 | { Op1( 0), CRn(12), CRm(12), Op2( 5), trap_raz_wi }, | 1355 | { Op1( 0), CRn(12), CRm(12), Op2( 5), access_gic_sre }, |
1364 | 1356 | ||
1365 | { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID }, | 1357 | { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID }, |
1366 | 1358 | ||
diff --git a/include/linux/irqchip/arm-gic-v3.h b/include/linux/irqchip/arm-gic-v3.h index 56b0b7ec66aa..99ac022edc60 100644 --- a/include/linux/irqchip/arm-gic-v3.h +++ b/include/linux/irqchip/arm-gic-v3.h | |||
@@ -337,6 +337,7 @@ | |||
337 | */ | 337 | */ |
338 | #define E_ITS_MOVI_UNMAPPED_INTERRUPT 0x010107 | 338 | #define E_ITS_MOVI_UNMAPPED_INTERRUPT 0x010107 |
339 | #define E_ITS_MOVI_UNMAPPED_COLLECTION 0x010109 | 339 | #define E_ITS_MOVI_UNMAPPED_COLLECTION 0x010109 |
340 | #define E_ITS_INT_UNMAPPED_INTERRUPT 0x010307 | ||
340 | #define E_ITS_CLEAR_UNMAPPED_INTERRUPT 0x010507 | 341 | #define E_ITS_CLEAR_UNMAPPED_INTERRUPT 0x010507 |
341 | #define E_ITS_MAPD_DEVICE_OOR 0x010801 | 342 | #define E_ITS_MAPD_DEVICE_OOR 0x010801 |
342 | #define E_ITS_MAPC_PROCNUM_OOR 0x010902 | 343 | #define E_ITS_MAPC_PROCNUM_OOR 0x010902 |
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c index 4fde8c7dfcfe..77e6ccf14901 100644 --- a/virt/kvm/arm/arch_timer.c +++ b/virt/kvm/arm/arch_timer.c | |||
@@ -33,6 +33,7 @@ | |||
33 | static struct timecounter *timecounter; | 33 | static struct timecounter *timecounter; |
34 | static struct workqueue_struct *wqueue; | 34 | static struct workqueue_struct *wqueue; |
35 | static unsigned int host_vtimer_irq; | 35 | static unsigned int host_vtimer_irq; |
36 | static u32 host_vtimer_irq_flags; | ||
36 | 37 | ||
37 | void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu) | 38 | void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu) |
38 | { | 39 | { |
@@ -365,7 +366,7 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) | |||
365 | 366 | ||
366 | static void kvm_timer_init_interrupt(void *info) | 367 | static void kvm_timer_init_interrupt(void *info) |
367 | { | 368 | { |
368 | enable_percpu_irq(host_vtimer_irq, 0); | 369 | enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags); |
369 | } | 370 | } |
370 | 371 | ||
371 | int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) | 372 | int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) |
@@ -432,6 +433,14 @@ int kvm_timer_hyp_init(void) | |||
432 | } | 433 | } |
433 | host_vtimer_irq = info->virtual_irq; | 434 | host_vtimer_irq = info->virtual_irq; |
434 | 435 | ||
436 | host_vtimer_irq_flags = irq_get_trigger_type(host_vtimer_irq); | ||
437 | if (host_vtimer_irq_flags != IRQF_TRIGGER_HIGH && | ||
438 | host_vtimer_irq_flags != IRQF_TRIGGER_LOW) { | ||
439 | kvm_err("Invalid trigger for IRQ%d, assuming level low\n", | ||
440 | host_vtimer_irq); | ||
441 | host_vtimer_irq_flags = IRQF_TRIGGER_LOW; | ||
442 | } | ||
443 | |||
435 | err = request_percpu_irq(host_vtimer_irq, kvm_arch_timer_handler, | 444 | err = request_percpu_irq(host_vtimer_irq, kvm_arch_timer_handler, |
436 | "kvm guest timer", kvm_get_running_vcpus()); | 445 | "kvm guest timer", kvm_get_running_vcpus()); |
437 | if (err) { | 446 | if (err) { |
diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 07411cf967b9..4660a7d04eea 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c | |||
@@ -51,7 +51,7 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid) | |||
51 | 51 | ||
52 | irq = kzalloc(sizeof(struct vgic_irq), GFP_KERNEL); | 52 | irq = kzalloc(sizeof(struct vgic_irq), GFP_KERNEL); |
53 | if (!irq) | 53 | if (!irq) |
54 | return NULL; | 54 | return ERR_PTR(-ENOMEM); |
55 | 55 | ||
56 | INIT_LIST_HEAD(&irq->lpi_list); | 56 | INIT_LIST_HEAD(&irq->lpi_list); |
57 | INIT_LIST_HEAD(&irq->ap_list); | 57 | INIT_LIST_HEAD(&irq->ap_list); |
@@ -441,39 +441,63 @@ static unsigned long vgic_mmio_read_its_idregs(struct kvm *kvm, | |||
441 | * Find the target VCPU and the LPI number for a given devid/eventid pair | 441 | * Find the target VCPU and the LPI number for a given devid/eventid pair |
442 | * and make this IRQ pending, possibly injecting it. | 442 | * and make this IRQ pending, possibly injecting it. |
443 | * Must be called with the its_lock mutex held. | 443 | * Must be called with the its_lock mutex held. |
444 | * Returns 0 on success, a positive error value for any ITS mapping | ||
445 | * related errors and negative error values for generic errors. | ||
444 | */ | 446 | */ |
445 | static void vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its, | 447 | static int vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its, |
446 | u32 devid, u32 eventid) | 448 | u32 devid, u32 eventid) |
447 | { | 449 | { |
450 | struct kvm_vcpu *vcpu; | ||
448 | struct its_itte *itte; | 451 | struct its_itte *itte; |
449 | 452 | ||
450 | if (!its->enabled) | 453 | if (!its->enabled) |
451 | return; | 454 | return -EBUSY; |
452 | 455 | ||
453 | itte = find_itte(its, devid, eventid); | 456 | itte = find_itte(its, devid, eventid); |
454 | /* Triggering an unmapped IRQ gets silently dropped. */ | 457 | if (!itte || !its_is_collection_mapped(itte->collection)) |
455 | if (itte && its_is_collection_mapped(itte->collection)) { | 458 | return E_ITS_INT_UNMAPPED_INTERRUPT; |
456 | struct kvm_vcpu *vcpu; | 459 | |
457 | 460 | vcpu = kvm_get_vcpu(kvm, itte->collection->target_addr); | |
458 | vcpu = kvm_get_vcpu(kvm, itte->collection->target_addr); | 461 | if (!vcpu) |
459 | if (vcpu && vcpu->arch.vgic_cpu.lpis_enabled) { | 462 | return E_ITS_INT_UNMAPPED_INTERRUPT; |
460 | spin_lock(&itte->irq->irq_lock); | 463 | |
461 | itte->irq->pending = true; | 464 | if (!vcpu->arch.vgic_cpu.lpis_enabled) |
462 | vgic_queue_irq_unlock(kvm, itte->irq); | 465 | return -EBUSY; |
463 | } | 466 | |
464 | } | 467 | spin_lock(&itte->irq->irq_lock); |
468 | itte->irq->pending = true; | ||
469 | vgic_queue_irq_unlock(kvm, itte->irq); | ||
470 | |||
471 | return 0; | ||
472 | } | ||
473 | |||
474 | static struct vgic_io_device *vgic_get_its_iodev(struct kvm_io_device *dev) | ||
475 | { | ||
476 | struct vgic_io_device *iodev; | ||
477 | |||
478 | if (dev->ops != &kvm_io_gic_ops) | ||
479 | return NULL; | ||
480 | |||
481 | iodev = container_of(dev, struct vgic_io_device, dev); | ||
482 | |||
483 | if (iodev->iodev_type != IODEV_ITS) | ||
484 | return NULL; | ||
485 | |||
486 | return iodev; | ||
465 | } | 487 | } |
466 | 488 | ||
467 | /* | 489 | /* |
468 | * Queries the KVM IO bus framework to get the ITS pointer from the given | 490 | * Queries the KVM IO bus framework to get the ITS pointer from the given |
469 | * doorbell address. | 491 | * doorbell address. |
470 | * We then call vgic_its_trigger_msi() with the decoded data. | 492 | * We then call vgic_its_trigger_msi() with the decoded data. |
493 | * According to the KVM_SIGNAL_MSI API description returns 1 on success. | ||
471 | */ | 494 | */ |
472 | int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi) | 495 | int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi) |
473 | { | 496 | { |
474 | u64 address; | 497 | u64 address; |
475 | struct kvm_io_device *kvm_io_dev; | 498 | struct kvm_io_device *kvm_io_dev; |
476 | struct vgic_io_device *iodev; | 499 | struct vgic_io_device *iodev; |
500 | int ret; | ||
477 | 501 | ||
478 | if (!vgic_has_its(kvm)) | 502 | if (!vgic_has_its(kvm)) |
479 | return -ENODEV; | 503 | return -ENODEV; |
@@ -485,15 +509,28 @@ int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi) | |||
485 | 509 | ||
486 | kvm_io_dev = kvm_io_bus_get_dev(kvm, KVM_MMIO_BUS, address); | 510 | kvm_io_dev = kvm_io_bus_get_dev(kvm, KVM_MMIO_BUS, address); |
487 | if (!kvm_io_dev) | 511 | if (!kvm_io_dev) |
488 | return -ENODEV; | 512 | return -EINVAL; |
489 | 513 | ||
490 | iodev = container_of(kvm_io_dev, struct vgic_io_device, dev); | 514 | iodev = vgic_get_its_iodev(kvm_io_dev); |
515 | if (!iodev) | ||
516 | return -EINVAL; | ||
491 | 517 | ||
492 | mutex_lock(&iodev->its->its_lock); | 518 | mutex_lock(&iodev->its->its_lock); |
493 | vgic_its_trigger_msi(kvm, iodev->its, msi->devid, msi->data); | 519 | ret = vgic_its_trigger_msi(kvm, iodev->its, msi->devid, msi->data); |
494 | mutex_unlock(&iodev->its->its_lock); | 520 | mutex_unlock(&iodev->its->its_lock); |
495 | 521 | ||
496 | return 0; | 522 | if (ret < 0) |
523 | return ret; | ||
524 | |||
525 | /* | ||
526 | * KVM_SIGNAL_MSI demands a return value > 0 for success and 0 | ||
527 | * if the guest has blocked the MSI. So we map any LPI mapping | ||
528 | * related error to that. | ||
529 | */ | ||
530 | if (ret) | ||
531 | return 0; | ||
532 | else | ||
533 | return 1; | ||
497 | } | 534 | } |
498 | 535 | ||
499 | /* Requires the its_lock to be held. */ | 536 | /* Requires the its_lock to be held. */ |
@@ -502,7 +539,8 @@ static void its_free_itte(struct kvm *kvm, struct its_itte *itte) | |||
502 | list_del(&itte->itte_list); | 539 | list_del(&itte->itte_list); |
503 | 540 | ||
504 | /* This put matches the get in vgic_add_lpi. */ | 541 | /* This put matches the get in vgic_add_lpi. */ |
505 | vgic_put_irq(kvm, itte->irq); | 542 | if (itte->irq) |
543 | vgic_put_irq(kvm, itte->irq); | ||
506 | 544 | ||
507 | kfree(itte); | 545 | kfree(itte); |
508 | } | 546 | } |
@@ -697,6 +735,7 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, | |||
697 | struct its_device *device; | 735 | struct its_device *device; |
698 | struct its_collection *collection, *new_coll = NULL; | 736 | struct its_collection *collection, *new_coll = NULL; |
699 | int lpi_nr; | 737 | int lpi_nr; |
738 | struct vgic_irq *irq; | ||
700 | 739 | ||
701 | device = find_its_device(its, device_id); | 740 | device = find_its_device(its, device_id); |
702 | if (!device) | 741 | if (!device) |
@@ -710,6 +749,10 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, | |||
710 | lpi_nr >= max_lpis_propbaser(kvm->arch.vgic.propbaser)) | 749 | lpi_nr >= max_lpis_propbaser(kvm->arch.vgic.propbaser)) |
711 | return E_ITS_MAPTI_PHYSICALID_OOR; | 750 | return E_ITS_MAPTI_PHYSICALID_OOR; |
712 | 751 | ||
752 | /* If there is an existing mapping, behavior is UNPREDICTABLE. */ | ||
753 | if (find_itte(its, device_id, event_id)) | ||
754 | return 0; | ||
755 | |||
713 | collection = find_collection(its, coll_id); | 756 | collection = find_collection(its, coll_id); |
714 | if (!collection) { | 757 | if (!collection) { |
715 | int ret = vgic_its_alloc_collection(its, &collection, coll_id); | 758 | int ret = vgic_its_alloc_collection(its, &collection, coll_id); |
@@ -718,22 +761,28 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, | |||
718 | new_coll = collection; | 761 | new_coll = collection; |
719 | } | 762 | } |
720 | 763 | ||
721 | itte = find_itte(its, device_id, event_id); | 764 | itte = kzalloc(sizeof(struct its_itte), GFP_KERNEL); |
722 | if (!itte) { | 765 | if (!itte) { |
723 | itte = kzalloc(sizeof(struct its_itte), GFP_KERNEL); | 766 | if (new_coll) |
724 | if (!itte) { | 767 | vgic_its_free_collection(its, coll_id); |
725 | if (new_coll) | 768 | return -ENOMEM; |
726 | vgic_its_free_collection(its, coll_id); | ||
727 | return -ENOMEM; | ||
728 | } | ||
729 | |||
730 | itte->event_id = event_id; | ||
731 | list_add_tail(&itte->itte_list, &device->itt_head); | ||
732 | } | 769 | } |
733 | 770 | ||
771 | itte->event_id = event_id; | ||
772 | list_add_tail(&itte->itte_list, &device->itt_head); | ||
773 | |||
734 | itte->collection = collection; | 774 | itte->collection = collection; |
735 | itte->lpi = lpi_nr; | 775 | itte->lpi = lpi_nr; |
736 | itte->irq = vgic_add_lpi(kvm, lpi_nr); | 776 | |
777 | irq = vgic_add_lpi(kvm, lpi_nr); | ||
778 | if (IS_ERR(irq)) { | ||
779 | if (new_coll) | ||
780 | vgic_its_free_collection(its, coll_id); | ||
781 | its_free_itte(kvm, itte); | ||
782 | return PTR_ERR(irq); | ||
783 | } | ||
784 | itte->irq = irq; | ||
785 | |||
737 | update_affinity_itte(kvm, itte); | 786 | update_affinity_itte(kvm, itte); |
738 | 787 | ||
739 | /* | 788 | /* |
@@ -981,9 +1030,7 @@ static int vgic_its_cmd_handle_int(struct kvm *kvm, struct vgic_its *its, | |||
981 | u32 msi_data = its_cmd_get_id(its_cmd); | 1030 | u32 msi_data = its_cmd_get_id(its_cmd); |
982 | u64 msi_devid = its_cmd_get_deviceid(its_cmd); | 1031 | u64 msi_devid = its_cmd_get_deviceid(its_cmd); |
983 | 1032 | ||
984 | vgic_its_trigger_msi(kvm, its, msi_devid, msi_data); | 1033 | return vgic_its_trigger_msi(kvm, its, msi_devid, msi_data); |
985 | |||
986 | return 0; | ||
987 | } | 1034 | } |
988 | 1035 | ||
989 | /* | 1036 | /* |
@@ -1288,13 +1335,13 @@ void vgic_enable_lpis(struct kvm_vcpu *vcpu) | |||
1288 | its_sync_lpi_pending_table(vcpu); | 1335 | its_sync_lpi_pending_table(vcpu); |
1289 | } | 1336 | } |
1290 | 1337 | ||
1291 | static int vgic_its_init_its(struct kvm *kvm, struct vgic_its *its) | 1338 | static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its) |
1292 | { | 1339 | { |
1293 | struct vgic_io_device *iodev = &its->iodev; | 1340 | struct vgic_io_device *iodev = &its->iodev; |
1294 | int ret; | 1341 | int ret; |
1295 | 1342 | ||
1296 | if (its->initialized) | 1343 | if (!its->initialized) |
1297 | return 0; | 1344 | return -EBUSY; |
1298 | 1345 | ||
1299 | if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base)) | 1346 | if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base)) |
1300 | return -ENXIO; | 1347 | return -ENXIO; |
@@ -1311,9 +1358,6 @@ static int vgic_its_init_its(struct kvm *kvm, struct vgic_its *its) | |||
1311 | KVM_VGIC_V3_ITS_SIZE, &iodev->dev); | 1358 | KVM_VGIC_V3_ITS_SIZE, &iodev->dev); |
1312 | mutex_unlock(&kvm->slots_lock); | 1359 | mutex_unlock(&kvm->slots_lock); |
1313 | 1360 | ||
1314 | if (!ret) | ||
1315 | its->initialized = true; | ||
1316 | |||
1317 | return ret; | 1361 | return ret; |
1318 | } | 1362 | } |
1319 | 1363 | ||
@@ -1435,9 +1479,6 @@ static int vgic_its_set_attr(struct kvm_device *dev, | |||
1435 | if (type != KVM_VGIC_ITS_ADDR_TYPE) | 1479 | if (type != KVM_VGIC_ITS_ADDR_TYPE) |
1436 | return -ENODEV; | 1480 | return -ENODEV; |
1437 | 1481 | ||
1438 | if (its->initialized) | ||
1439 | return -EBUSY; | ||
1440 | |||
1441 | if (copy_from_user(&addr, uaddr, sizeof(addr))) | 1482 | if (copy_from_user(&addr, uaddr, sizeof(addr))) |
1442 | return -EFAULT; | 1483 | return -EFAULT; |
1443 | 1484 | ||
@@ -1453,7 +1494,9 @@ static int vgic_its_set_attr(struct kvm_device *dev, | |||
1453 | case KVM_DEV_ARM_VGIC_GRP_CTRL: | 1494 | case KVM_DEV_ARM_VGIC_GRP_CTRL: |
1454 | switch (attr->attr) { | 1495 | switch (attr->attr) { |
1455 | case KVM_DEV_ARM_VGIC_CTRL_INIT: | 1496 | case KVM_DEV_ARM_VGIC_CTRL_INIT: |
1456 | return vgic_its_init_its(dev->kvm, its); | 1497 | its->initialized = true; |
1498 | |||
1499 | return 0; | ||
1457 | } | 1500 | } |
1458 | break; | 1501 | break; |
1459 | } | 1502 | } |
@@ -1498,3 +1541,30 @@ int kvm_vgic_register_its_device(void) | |||
1498 | return kvm_register_device_ops(&kvm_arm_vgic_its_ops, | 1541 | return kvm_register_device_ops(&kvm_arm_vgic_its_ops, |
1499 | KVM_DEV_TYPE_ARM_VGIC_ITS); | 1542 | KVM_DEV_TYPE_ARM_VGIC_ITS); |
1500 | } | 1543 | } |
1544 | |||
1545 | /* | ||
1546 | * Registers all ITSes with the kvm_io_bus framework. | ||
1547 | * To follow the existing VGIC initialization sequence, this has to be | ||
1548 | * done as late as possible, just before the first VCPU runs. | ||
1549 | */ | ||
1550 | int vgic_register_its_iodevs(struct kvm *kvm) | ||
1551 | { | ||
1552 | struct kvm_device *dev; | ||
1553 | int ret = 0; | ||
1554 | |||
1555 | list_for_each_entry(dev, &kvm->devices, vm_node) { | ||
1556 | if (dev->ops != &kvm_arm_vgic_its_ops) | ||
1557 | continue; | ||
1558 | |||
1559 | ret = vgic_register_its_iodev(kvm, dev->private); | ||
1560 | if (ret) | ||
1561 | return ret; | ||
1562 | /* | ||
1563 | * We don't need to care about tearing down previously | ||
1564 | * registered ITSes, as the kvm_io_bus framework removes | ||
1565 | * them for us if the VM gets destroyed. | ||
1566 | */ | ||
1567 | } | ||
1568 | |||
1569 | return ret; | ||
1570 | } | ||
diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c index ff668e0dd586..90d81811fdda 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c | |||
@@ -306,16 +306,19 @@ static void vgic_mmio_write_propbase(struct kvm_vcpu *vcpu, | |||
306 | { | 306 | { |
307 | struct vgic_dist *dist = &vcpu->kvm->arch.vgic; | 307 | struct vgic_dist *dist = &vcpu->kvm->arch.vgic; |
308 | struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; | 308 | struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; |
309 | u64 propbaser = dist->propbaser; | 309 | u64 old_propbaser, propbaser; |
310 | 310 | ||
311 | /* Storing a value with LPIs already enabled is undefined */ | 311 | /* Storing a value with LPIs already enabled is undefined */ |
312 | if (vgic_cpu->lpis_enabled) | 312 | if (vgic_cpu->lpis_enabled) |
313 | return; | 313 | return; |
314 | 314 | ||
315 | propbaser = update_64bit_reg(propbaser, addr & 4, len, val); | 315 | do { |
316 | propbaser = vgic_sanitise_propbaser(propbaser); | 316 | old_propbaser = dist->propbaser; |
317 | 317 | propbaser = old_propbaser; | |
318 | dist->propbaser = propbaser; | 318 | propbaser = update_64bit_reg(propbaser, addr & 4, len, val); |
319 | propbaser = vgic_sanitise_propbaser(propbaser); | ||
320 | } while (cmpxchg64(&dist->propbaser, old_propbaser, | ||
321 | propbaser) != old_propbaser); | ||
319 | } | 322 | } |
320 | 323 | ||
321 | static unsigned long vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu, | 324 | static unsigned long vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu, |
@@ -331,16 +334,19 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, | |||
331 | unsigned long val) | 334 | unsigned long val) |
332 | { | 335 | { |
333 | struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; | 336 | struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; |
334 | u64 pendbaser = vgic_cpu->pendbaser; | 337 | u64 old_pendbaser, pendbaser; |
335 | 338 | ||
336 | /* Storing a value with LPIs already enabled is undefined */ | 339 | /* Storing a value with LPIs already enabled is undefined */ |
337 | if (vgic_cpu->lpis_enabled) | 340 | if (vgic_cpu->lpis_enabled) |
338 | return; | 341 | return; |
339 | 342 | ||
340 | pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); | 343 | do { |
341 | pendbaser = vgic_sanitise_pendbaser(pendbaser); | 344 | old_pendbaser = vgic_cpu->pendbaser; |
342 | 345 | pendbaser = old_pendbaser; | |
343 | vgic_cpu->pendbaser = pendbaser; | 346 | pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); |
347 | pendbaser = vgic_sanitise_pendbaser(pendbaser); | ||
348 | } while (cmpxchg64(&vgic_cpu->pendbaser, old_pendbaser, | ||
349 | pendbaser) != old_pendbaser); | ||
344 | } | 350 | } |
345 | 351 | ||
346 | /* | 352 | /* |
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 0506543df38a..9f0dae397d9c 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c | |||
@@ -289,6 +289,14 @@ int vgic_v3_map_resources(struct kvm *kvm) | |||
289 | goto out; | 289 | goto out; |
290 | } | 290 | } |
291 | 291 | ||
292 | if (vgic_has_its(kvm)) { | ||
293 | ret = vgic_register_its_iodevs(kvm); | ||
294 | if (ret) { | ||
295 | kvm_err("Unable to register VGIC ITS MMIO regions\n"); | ||
296 | goto out; | ||
297 | } | ||
298 | } | ||
299 | |||
292 | dist->ready = true; | 300 | dist->ready = true; |
293 | 301 | ||
294 | out: | 302 | out: |
diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index e7aeac719e09..e83b7fe4baae 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c | |||
@@ -117,17 +117,17 @@ static void vgic_irq_release(struct kref *ref) | |||
117 | 117 | ||
118 | void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) | 118 | void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) |
119 | { | 119 | { |
120 | struct vgic_dist *dist; | 120 | struct vgic_dist *dist = &kvm->arch.vgic; |
121 | 121 | ||
122 | if (irq->intid < VGIC_MIN_LPI) | 122 | if (irq->intid < VGIC_MIN_LPI) |
123 | return; | 123 | return; |
124 | 124 | ||
125 | if (!kref_put(&irq->refcount, vgic_irq_release)) | 125 | spin_lock(&dist->lpi_list_lock); |
126 | if (!kref_put(&irq->refcount, vgic_irq_release)) { | ||
127 | spin_unlock(&dist->lpi_list_lock); | ||
126 | return; | 128 | return; |
129 | }; | ||
127 | 130 | ||
128 | dist = &kvm->arch.vgic; | ||
129 | |||
130 | spin_lock(&dist->lpi_list_lock); | ||
131 | list_del(&irq->lpi_list); | 131 | list_del(&irq->lpi_list); |
132 | dist->lpi_list_count--; | 132 | dist->lpi_list_count--; |
133 | spin_unlock(&dist->lpi_list_lock); | 133 | spin_unlock(&dist->lpi_list_lock); |
diff --git a/virt/kvm/arm/vgic/vgic.h b/virt/kvm/arm/vgic/vgic.h index 1d8e21d5c13f..6c4625c46368 100644 --- a/virt/kvm/arm/vgic/vgic.h +++ b/virt/kvm/arm/vgic/vgic.h | |||
@@ -84,6 +84,7 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu); | |||
84 | int vgic_v3_probe(const struct gic_kvm_info *info); | 84 | int vgic_v3_probe(const struct gic_kvm_info *info); |
85 | int vgic_v3_map_resources(struct kvm *kvm); | 85 | int vgic_v3_map_resources(struct kvm *kvm); |
86 | int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address); | 86 | int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address); |
87 | int vgic_register_its_iodevs(struct kvm *kvm); | ||
87 | bool vgic_has_its(struct kvm *kvm); | 88 | bool vgic_has_its(struct kvm *kvm); |
88 | int kvm_vgic_register_its_device(void); | 89 | int kvm_vgic_register_its_device(void); |
89 | void vgic_enable_lpis(struct kvm_vcpu *vcpu); | 90 | void vgic_enable_lpis(struct kvm_vcpu *vcpu); |
@@ -140,6 +141,11 @@ static inline int vgic_register_redist_iodevs(struct kvm *kvm, | |||
140 | return -ENODEV; | 141 | return -ENODEV; |
141 | } | 142 | } |
142 | 143 | ||
144 | static inline int vgic_register_its_iodevs(struct kvm *kvm) | ||
145 | { | ||
146 | return -ENODEV; | ||
147 | } | ||
148 | |||
143 | static inline bool vgic_has_its(struct kvm *kvm) | 149 | static inline bool vgic_has_its(struct kvm *kvm) |
144 | { | 150 | { |
145 | return false; | 151 | return false; |