diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2019-03-28 14:07:30 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2019-03-28 14:07:30 -0400 |
commit | 690edec54cbaa0e98dc592aae6864272f48f3c84 (patch) | |
tree | b2240e1aa7f39f65d042e0d1dee94df6b67d4a60 /virt/kvm | |
parent | e2788c4a41cb5fa68096f5a58bccacec1a700295 (diff) | |
parent | 8324c3d518cfd69f2a17866b52c13bf56d3042d8 (diff) |
Merge tag 'kvmarm-fixes-for-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into kvm-master
KVM/ARM fixes for 5.1
- Fix THP handling in the presence of pre-existing PTEs
- Honor request for PTE mappings even when THPs are available
- GICv4 performance improvement
- Take the srcu lock when writing to guest-controlled ITS data structures
- Reset the virtual PMU in preemptible context
- Various cleanups
Diffstat (limited to 'virt/kvm')
-rw-r--r-- | virt/kvm/arm/hyp/vgic-v3-sr.c | 4 | ||||
-rw-r--r-- | virt/kvm/arm/mmu.c | 125 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic-its.c | 31 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic-v3.c | 4 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic.c | 14 |
5 files changed, 106 insertions, 72 deletions
diff --git a/virt/kvm/arm/hyp/vgic-v3-sr.c b/virt/kvm/arm/hyp/vgic-v3-sr.c index 264d92da3240..370bd6c5e6cb 100644 --- a/virt/kvm/arm/hyp/vgic-v3-sr.c +++ b/virt/kvm/arm/hyp/vgic-v3-sr.c | |||
@@ -222,7 +222,7 @@ void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu) | |||
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | if (used_lrs) { | 225 | if (used_lrs || cpu_if->its_vpe.its_vm) { |
226 | int i; | 226 | int i; |
227 | u32 elrsr; | 227 | u32 elrsr; |
228 | 228 | ||
@@ -247,7 +247,7 @@ void __hyp_text __vgic_v3_restore_state(struct kvm_vcpu *vcpu) | |||
247 | u64 used_lrs = vcpu->arch.vgic_cpu.used_lrs; | 247 | u64 used_lrs = vcpu->arch.vgic_cpu.used_lrs; |
248 | int i; | 248 | int i; |
249 | 249 | ||
250 | if (used_lrs) { | 250 | if (used_lrs || cpu_if->its_vpe.its_vm) { |
251 | write_gicreg(cpu_if->vgic_hcr, ICH_HCR_EL2); | 251 | write_gicreg(cpu_if->vgic_hcr, ICH_HCR_EL2); |
252 | 252 | ||
253 | for (i = 0; i < used_lrs; i++) | 253 | for (i = 0; i < used_lrs; i++) |
diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index ffd7acdceac7..27c958306449 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c | |||
@@ -102,8 +102,7 @@ static bool kvm_is_device_pfn(unsigned long pfn) | |||
102 | * @addr: IPA | 102 | * @addr: IPA |
103 | * @pmd: pmd pointer for IPA | 103 | * @pmd: pmd pointer for IPA |
104 | * | 104 | * |
105 | * Function clears a PMD entry, flushes addr 1st and 2nd stage TLBs. Marks all | 105 | * Function clears a PMD entry, flushes addr 1st and 2nd stage TLBs. |
106 | * pages in the range dirty. | ||
107 | */ | 106 | */ |
108 | static void stage2_dissolve_pmd(struct kvm *kvm, phys_addr_t addr, pmd_t *pmd) | 107 | static void stage2_dissolve_pmd(struct kvm *kvm, phys_addr_t addr, pmd_t *pmd) |
109 | { | 108 | { |
@@ -121,8 +120,7 @@ static void stage2_dissolve_pmd(struct kvm *kvm, phys_addr_t addr, pmd_t *pmd) | |||
121 | * @addr: IPA | 120 | * @addr: IPA |
122 | * @pud: pud pointer for IPA | 121 | * @pud: pud pointer for IPA |
123 | * | 122 | * |
124 | * Function clears a PUD entry, flushes addr 1st and 2nd stage TLBs. Marks all | 123 | * Function clears a PUD entry, flushes addr 1st and 2nd stage TLBs. |
125 | * pages in the range dirty. | ||
126 | */ | 124 | */ |
127 | static void stage2_dissolve_pud(struct kvm *kvm, phys_addr_t addr, pud_t *pudp) | 125 | static void stage2_dissolve_pud(struct kvm *kvm, phys_addr_t addr, pud_t *pudp) |
128 | { | 126 | { |
@@ -899,9 +897,8 @@ int create_hyp_exec_mappings(phys_addr_t phys_addr, size_t size, | |||
899 | * kvm_alloc_stage2_pgd - allocate level-1 table for stage-2 translation. | 897 | * kvm_alloc_stage2_pgd - allocate level-1 table for stage-2 translation. |
900 | * @kvm: The KVM struct pointer for the VM. | 898 | * @kvm: The KVM struct pointer for the VM. |
901 | * | 899 | * |
902 | * Allocates only the stage-2 HW PGD level table(s) (can support either full | 900 | * Allocates only the stage-2 HW PGD level table(s) of size defined by |
903 | * 40-bit input addresses or limited to 32-bit input addresses). Clears the | 901 | * stage2_pgd_size(kvm). |
904 | * allocated pages. | ||
905 | * | 902 | * |
906 | * Note we don't need locking here as this is only called when the VM is | 903 | * Note we don't need locking here as this is only called when the VM is |
907 | * created, which can only be done once. | 904 | * created, which can only be done once. |
@@ -1067,25 +1064,43 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache | |||
1067 | { | 1064 | { |
1068 | pmd_t *pmd, old_pmd; | 1065 | pmd_t *pmd, old_pmd; |
1069 | 1066 | ||
1067 | retry: | ||
1070 | pmd = stage2_get_pmd(kvm, cache, addr); | 1068 | pmd = stage2_get_pmd(kvm, cache, addr); |
1071 | VM_BUG_ON(!pmd); | 1069 | VM_BUG_ON(!pmd); |
1072 | 1070 | ||
1073 | old_pmd = *pmd; | 1071 | old_pmd = *pmd; |
1072 | /* | ||
1073 | * Multiple vcpus faulting on the same PMD entry, can | ||
1074 | * lead to them sequentially updating the PMD with the | ||
1075 | * same value. Following the break-before-make | ||
1076 | * (pmd_clear() followed by tlb_flush()) process can | ||
1077 | * hinder forward progress due to refaults generated | ||
1078 | * on missing translations. | ||
1079 | * | ||
1080 | * Skip updating the page table if the entry is | ||
1081 | * unchanged. | ||
1082 | */ | ||
1083 | if (pmd_val(old_pmd) == pmd_val(*new_pmd)) | ||
1084 | return 0; | ||
1085 | |||
1074 | if (pmd_present(old_pmd)) { | 1086 | if (pmd_present(old_pmd)) { |
1075 | /* | 1087 | /* |
1076 | * Multiple vcpus faulting on the same PMD entry, can | 1088 | * If we already have PTE level mapping for this block, |
1077 | * lead to them sequentially updating the PMD with the | 1089 | * we must unmap it to avoid inconsistent TLB state and |
1078 | * same value. Following the break-before-make | 1090 | * leaking the table page. We could end up in this situation |
1079 | * (pmd_clear() followed by tlb_flush()) process can | 1091 | * if the memory slot was marked for dirty logging and was |
1080 | * hinder forward progress due to refaults generated | 1092 | * reverted, leaving PTE level mappings for the pages accessed |
1081 | * on missing translations. | 1093 | * during the period. So, unmap the PTE level mapping for this |
1094 | * block and retry, as we could have released the upper level | ||
1095 | * table in the process. | ||
1082 | * | 1096 | * |
1083 | * Skip updating the page table if the entry is | 1097 | * Normal THP split/merge follows mmu_notifier callbacks and do |
1084 | * unchanged. | 1098 | * get handled accordingly. |
1085 | */ | 1099 | */ |
1086 | if (pmd_val(old_pmd) == pmd_val(*new_pmd)) | 1100 | if (!pmd_thp_or_huge(old_pmd)) { |
1087 | return 0; | 1101 | unmap_stage2_range(kvm, addr & S2_PMD_MASK, S2_PMD_SIZE); |
1088 | 1102 | goto retry; | |
1103 | } | ||
1089 | /* | 1104 | /* |
1090 | * Mapping in huge pages should only happen through a | 1105 | * Mapping in huge pages should only happen through a |
1091 | * fault. If a page is merged into a transparent huge | 1106 | * fault. If a page is merged into a transparent huge |
@@ -1097,8 +1112,7 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache | |||
1097 | * should become splitting first, unmapped, merged, | 1112 | * should become splitting first, unmapped, merged, |
1098 | * and mapped back in on-demand. | 1113 | * and mapped back in on-demand. |
1099 | */ | 1114 | */ |
1100 | VM_BUG_ON(pmd_pfn(old_pmd) != pmd_pfn(*new_pmd)); | 1115 | WARN_ON_ONCE(pmd_pfn(old_pmd) != pmd_pfn(*new_pmd)); |
1101 | |||
1102 | pmd_clear(pmd); | 1116 | pmd_clear(pmd); |
1103 | kvm_tlb_flush_vmid_ipa(kvm, addr); | 1117 | kvm_tlb_flush_vmid_ipa(kvm, addr); |
1104 | } else { | 1118 | } else { |
@@ -1114,6 +1128,7 @@ static int stage2_set_pud_huge(struct kvm *kvm, struct kvm_mmu_memory_cache *cac | |||
1114 | { | 1128 | { |
1115 | pud_t *pudp, old_pud; | 1129 | pud_t *pudp, old_pud; |
1116 | 1130 | ||
1131 | retry: | ||
1117 | pudp = stage2_get_pud(kvm, cache, addr); | 1132 | pudp = stage2_get_pud(kvm, cache, addr); |
1118 | VM_BUG_ON(!pudp); | 1133 | VM_BUG_ON(!pudp); |
1119 | 1134 | ||
@@ -1121,14 +1136,23 @@ static int stage2_set_pud_huge(struct kvm *kvm, struct kvm_mmu_memory_cache *cac | |||
1121 | 1136 | ||
1122 | /* | 1137 | /* |
1123 | * A large number of vcpus faulting on the same stage 2 entry, | 1138 | * A large number of vcpus faulting on the same stage 2 entry, |
1124 | * can lead to a refault due to the | 1139 | * can lead to a refault due to the stage2_pud_clear()/tlb_flush(). |
1125 | * stage2_pud_clear()/tlb_flush(). Skip updating the page | 1140 | * Skip updating the page tables if there is no change. |
1126 | * tables if there is no change. | ||
1127 | */ | 1141 | */ |
1128 | if (pud_val(old_pud) == pud_val(*new_pudp)) | 1142 | if (pud_val(old_pud) == pud_val(*new_pudp)) |
1129 | return 0; | 1143 | return 0; |
1130 | 1144 | ||
1131 | if (stage2_pud_present(kvm, old_pud)) { | 1145 | if (stage2_pud_present(kvm, old_pud)) { |
1146 | /* | ||
1147 | * If we already have table level mapping for this block, unmap | ||
1148 | * the range for this block and retry. | ||
1149 | */ | ||
1150 | if (!stage2_pud_huge(kvm, old_pud)) { | ||
1151 | unmap_stage2_range(kvm, addr & S2_PUD_MASK, S2_PUD_SIZE); | ||
1152 | goto retry; | ||
1153 | } | ||
1154 | |||
1155 | WARN_ON_ONCE(kvm_pud_pfn(old_pud) != kvm_pud_pfn(*new_pudp)); | ||
1132 | stage2_pud_clear(kvm, pudp); | 1156 | stage2_pud_clear(kvm, pudp); |
1133 | kvm_tlb_flush_vmid_ipa(kvm, addr); | 1157 | kvm_tlb_flush_vmid_ipa(kvm, addr); |
1134 | } else { | 1158 | } else { |
@@ -1451,13 +1475,11 @@ static void stage2_wp_pmds(struct kvm *kvm, pud_t *pud, | |||
1451 | } | 1475 | } |
1452 | 1476 | ||
1453 | /** | 1477 | /** |
1454 | * stage2_wp_puds - write protect PGD range | 1478 | * stage2_wp_puds - write protect PGD range |
1455 | * @pgd: pointer to pgd entry | 1479 | * @pgd: pointer to pgd entry |
1456 | * @addr: range start address | 1480 | * @addr: range start address |
1457 | * @end: range end address | 1481 | * @end: range end address |
1458 | * | 1482 | */ |
1459 | * Process PUD entries, for a huge PUD we cause a panic. | ||
1460 | */ | ||
1461 | static void stage2_wp_puds(struct kvm *kvm, pgd_t *pgd, | 1483 | static void stage2_wp_puds(struct kvm *kvm, pgd_t *pgd, |
1462 | phys_addr_t addr, phys_addr_t end) | 1484 | phys_addr_t addr, phys_addr_t end) |
1463 | { | 1485 | { |
@@ -1594,8 +1616,9 @@ static void kvm_send_hwpoison_signal(unsigned long address, | |||
1594 | send_sig_mceerr(BUS_MCEERR_AR, (void __user *)address, lsb, current); | 1616 | send_sig_mceerr(BUS_MCEERR_AR, (void __user *)address, lsb, current); |
1595 | } | 1617 | } |
1596 | 1618 | ||
1597 | static bool fault_supports_stage2_pmd_mappings(struct kvm_memory_slot *memslot, | 1619 | static bool fault_supports_stage2_huge_mapping(struct kvm_memory_slot *memslot, |
1598 | unsigned long hva) | 1620 | unsigned long hva, |
1621 | unsigned long map_size) | ||
1599 | { | 1622 | { |
1600 | gpa_t gpa_start; | 1623 | gpa_t gpa_start; |
1601 | hva_t uaddr_start, uaddr_end; | 1624 | hva_t uaddr_start, uaddr_end; |
@@ -1610,34 +1633,34 @@ static bool fault_supports_stage2_pmd_mappings(struct kvm_memory_slot *memslot, | |||
1610 | 1633 | ||
1611 | /* | 1634 | /* |
1612 | * Pages belonging to memslots that don't have the same alignment | 1635 | * Pages belonging to memslots that don't have the same alignment |
1613 | * within a PMD for userspace and IPA cannot be mapped with stage-2 | 1636 | * within a PMD/PUD for userspace and IPA cannot be mapped with stage-2 |
1614 | * PMD entries, because we'll end up mapping the wrong pages. | 1637 | * PMD/PUD entries, because we'll end up mapping the wrong pages. |
1615 | * | 1638 | * |
1616 | * Consider a layout like the following: | 1639 | * Consider a layout like the following: |
1617 | * | 1640 | * |
1618 | * memslot->userspace_addr: | 1641 | * memslot->userspace_addr: |
1619 | * +-----+--------------------+--------------------+---+ | 1642 | * +-----+--------------------+--------------------+---+ |
1620 | * |abcde|fgh Stage-1 PMD | Stage-1 PMD tv|xyz| | 1643 | * |abcde|fgh Stage-1 block | Stage-1 block tv|xyz| |
1621 | * +-----+--------------------+--------------------+---+ | 1644 | * +-----+--------------------+--------------------+---+ |
1622 | * | 1645 | * |
1623 | * memslot->base_gfn << PAGE_SIZE: | 1646 | * memslot->base_gfn << PAGE_SIZE: |
1624 | * +---+--------------------+--------------------+-----+ | 1647 | * +---+--------------------+--------------------+-----+ |
1625 | * |abc|def Stage-2 PMD | Stage-2 PMD |tvxyz| | 1648 | * |abc|def Stage-2 block | Stage-2 block |tvxyz| |
1626 | * +---+--------------------+--------------------+-----+ | 1649 | * +---+--------------------+--------------------+-----+ |
1627 | * | 1650 | * |
1628 | * If we create those stage-2 PMDs, we'll end up with this incorrect | 1651 | * If we create those stage-2 blocks, we'll end up with this incorrect |
1629 | * mapping: | 1652 | * mapping: |
1630 | * d -> f | 1653 | * d -> f |
1631 | * e -> g | 1654 | * e -> g |
1632 | * f -> h | 1655 | * f -> h |
1633 | */ | 1656 | */ |
1634 | if ((gpa_start & ~S2_PMD_MASK) != (uaddr_start & ~S2_PMD_MASK)) | 1657 | if ((gpa_start & (map_size - 1)) != (uaddr_start & (map_size - 1))) |
1635 | return false; | 1658 | return false; |
1636 | 1659 | ||
1637 | /* | 1660 | /* |
1638 | * Next, let's make sure we're not trying to map anything not covered | 1661 | * Next, let's make sure we're not trying to map anything not covered |
1639 | * by the memslot. This means we have to prohibit PMD size mappings | 1662 | * by the memslot. This means we have to prohibit block size mappings |
1640 | * for the beginning and end of a non-PMD aligned and non-PMD sized | 1663 | * for the beginning and end of a non-block aligned and non-block sized |
1641 | * memory slot (illustrated by the head and tail parts of the | 1664 | * memory slot (illustrated by the head and tail parts of the |
1642 | * userspace view above containing pages 'abcde' and 'xyz', | 1665 | * userspace view above containing pages 'abcde' and 'xyz', |
1643 | * respectively). | 1666 | * respectively). |
@@ -1646,8 +1669,8 @@ static bool fault_supports_stage2_pmd_mappings(struct kvm_memory_slot *memslot, | |||
1646 | * userspace_addr or the base_gfn, as both are equally aligned (per | 1669 | * userspace_addr or the base_gfn, as both are equally aligned (per |
1647 | * the check above) and equally sized. | 1670 | * the check above) and equally sized. |
1648 | */ | 1671 | */ |
1649 | return (hva & S2_PMD_MASK) >= uaddr_start && | 1672 | return (hva & ~(map_size - 1)) >= uaddr_start && |
1650 | (hva & S2_PMD_MASK) + S2_PMD_SIZE <= uaddr_end; | 1673 | (hva & ~(map_size - 1)) + map_size <= uaddr_end; |
1651 | } | 1674 | } |
1652 | 1675 | ||
1653 | static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, | 1676 | static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, |
@@ -1676,12 +1699,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, | |||
1676 | return -EFAULT; | 1699 | return -EFAULT; |
1677 | } | 1700 | } |
1678 | 1701 | ||
1679 | if (!fault_supports_stage2_pmd_mappings(memslot, hva)) | ||
1680 | force_pte = true; | ||
1681 | |||
1682 | if (logging_active) | ||
1683 | force_pte = true; | ||
1684 | |||
1685 | /* Let's check if we will get back a huge page backed by hugetlbfs */ | 1702 | /* Let's check if we will get back a huge page backed by hugetlbfs */ |
1686 | down_read(¤t->mm->mmap_sem); | 1703 | down_read(¤t->mm->mmap_sem); |
1687 | vma = find_vma_intersection(current->mm, hva, hva + 1); | 1704 | vma = find_vma_intersection(current->mm, hva, hva + 1); |
@@ -1692,6 +1709,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, | |||
1692 | } | 1709 | } |
1693 | 1710 | ||
1694 | vma_pagesize = vma_kernel_pagesize(vma); | 1711 | vma_pagesize = vma_kernel_pagesize(vma); |
1712 | if (logging_active || | ||
1713 | !fault_supports_stage2_huge_mapping(memslot, hva, vma_pagesize)) { | ||
1714 | force_pte = true; | ||
1715 | vma_pagesize = PAGE_SIZE; | ||
1716 | } | ||
1717 | |||
1695 | /* | 1718 | /* |
1696 | * The stage2 has a minimum of 2 level table (For arm64 see | 1719 | * The stage2 has a minimum of 2 level table (For arm64 see |
1697 | * kvm_arm_setup_stage2()). Hence, we are guaranteed that we can | 1720 | * kvm_arm_setup_stage2()). Hence, we are guaranteed that we can |
@@ -1699,11 +1722,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, | |||
1699 | * As for PUD huge maps, we must make sure that we have at least | 1722 | * As for PUD huge maps, we must make sure that we have at least |
1700 | * 3 levels, i.e, PMD is not folded. | 1723 | * 3 levels, i.e, PMD is not folded. |
1701 | */ | 1724 | */ |
1702 | if ((vma_pagesize == PMD_SIZE || | 1725 | if (vma_pagesize == PMD_SIZE || |
1703 | (vma_pagesize == PUD_SIZE && kvm_stage2_has_pmd(kvm))) && | 1726 | (vma_pagesize == PUD_SIZE && kvm_stage2_has_pmd(kvm))) |
1704 | !force_pte) { | ||
1705 | gfn = (fault_ipa & huge_page_mask(hstate_vma(vma))) >> PAGE_SHIFT; | 1727 | gfn = (fault_ipa & huge_page_mask(hstate_vma(vma))) >> PAGE_SHIFT; |
1706 | } | ||
1707 | up_read(¤t->mm->mmap_sem); | 1728 | up_read(¤t->mm->mmap_sem); |
1708 | 1729 | ||
1709 | /* We need minimum second+third level pages */ | 1730 | /* We need minimum second+third level pages */ |
diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index ab3f47745d9c..44ceaccb18cf 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c | |||
@@ -754,8 +754,9 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id, | |||
754 | u64 indirect_ptr, type = GITS_BASER_TYPE(baser); | 754 | u64 indirect_ptr, type = GITS_BASER_TYPE(baser); |
755 | phys_addr_t base = GITS_BASER_ADDR_48_to_52(baser); | 755 | phys_addr_t base = GITS_BASER_ADDR_48_to_52(baser); |
756 | int esz = GITS_BASER_ENTRY_SIZE(baser); | 756 | int esz = GITS_BASER_ENTRY_SIZE(baser); |
757 | int index; | 757 | int index, idx; |
758 | gfn_t gfn; | 758 | gfn_t gfn; |
759 | bool ret; | ||
759 | 760 | ||
760 | switch (type) { | 761 | switch (type) { |
761 | case GITS_BASER_TYPE_DEVICE: | 762 | case GITS_BASER_TYPE_DEVICE: |
@@ -782,7 +783,8 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id, | |||
782 | 783 | ||
783 | if (eaddr) | 784 | if (eaddr) |
784 | *eaddr = addr; | 785 | *eaddr = addr; |
785 | return kvm_is_visible_gfn(its->dev->kvm, gfn); | 786 | |
787 | goto out; | ||
786 | } | 788 | } |
787 | 789 | ||
788 | /* calculate and check the index into the 1st level */ | 790 | /* calculate and check the index into the 1st level */ |
@@ -812,7 +814,12 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id, | |||
812 | 814 | ||
813 | if (eaddr) | 815 | if (eaddr) |
814 | *eaddr = indirect_ptr; | 816 | *eaddr = indirect_ptr; |
815 | return kvm_is_visible_gfn(its->dev->kvm, gfn); | 817 | |
818 | out: | ||
819 | idx = srcu_read_lock(&its->dev->kvm->srcu); | ||
820 | ret = kvm_is_visible_gfn(its->dev->kvm, gfn); | ||
821 | srcu_read_unlock(&its->dev->kvm->srcu, idx); | ||
822 | return ret; | ||
816 | } | 823 | } |
817 | 824 | ||
818 | static int vgic_its_alloc_collection(struct vgic_its *its, | 825 | static int vgic_its_alloc_collection(struct vgic_its *its, |
@@ -1729,8 +1736,8 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev) | |||
1729 | kfree(its); | 1736 | kfree(its); |
1730 | } | 1737 | } |
1731 | 1738 | ||
1732 | int vgic_its_has_attr_regs(struct kvm_device *dev, | 1739 | static int vgic_its_has_attr_regs(struct kvm_device *dev, |
1733 | struct kvm_device_attr *attr) | 1740 | struct kvm_device_attr *attr) |
1734 | { | 1741 | { |
1735 | const struct vgic_register_region *region; | 1742 | const struct vgic_register_region *region; |
1736 | gpa_t offset = attr->attr; | 1743 | gpa_t offset = attr->attr; |
@@ -1750,9 +1757,9 @@ int vgic_its_has_attr_regs(struct kvm_device *dev, | |||
1750 | return 0; | 1757 | return 0; |
1751 | } | 1758 | } |
1752 | 1759 | ||
1753 | int vgic_its_attr_regs_access(struct kvm_device *dev, | 1760 | static int vgic_its_attr_regs_access(struct kvm_device *dev, |
1754 | struct kvm_device_attr *attr, | 1761 | struct kvm_device_attr *attr, |
1755 | u64 *reg, bool is_write) | 1762 | u64 *reg, bool is_write) |
1756 | { | 1763 | { |
1757 | const struct vgic_register_region *region; | 1764 | const struct vgic_register_region *region; |
1758 | struct vgic_its *its; | 1765 | struct vgic_its *its; |
@@ -1919,7 +1926,7 @@ static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev, | |||
1919 | ((u64)ite->irq->intid << KVM_ITS_ITE_PINTID_SHIFT) | | 1926 | ((u64)ite->irq->intid << KVM_ITS_ITE_PINTID_SHIFT) | |
1920 | ite->collection->collection_id; | 1927 | ite->collection->collection_id; |
1921 | val = cpu_to_le64(val); | 1928 | val = cpu_to_le64(val); |
1922 | return kvm_write_guest(kvm, gpa, &val, ite_esz); | 1929 | return kvm_write_guest_lock(kvm, gpa, &val, ite_esz); |
1923 | } | 1930 | } |
1924 | 1931 | ||
1925 | /** | 1932 | /** |
@@ -2066,7 +2073,7 @@ static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev, | |||
2066 | (itt_addr_field << KVM_ITS_DTE_ITTADDR_SHIFT) | | 2073 | (itt_addr_field << KVM_ITS_DTE_ITTADDR_SHIFT) | |
2067 | (dev->num_eventid_bits - 1)); | 2074 | (dev->num_eventid_bits - 1)); |
2068 | val = cpu_to_le64(val); | 2075 | val = cpu_to_le64(val); |
2069 | return kvm_write_guest(kvm, ptr, &val, dte_esz); | 2076 | return kvm_write_guest_lock(kvm, ptr, &val, dte_esz); |
2070 | } | 2077 | } |
2071 | 2078 | ||
2072 | /** | 2079 | /** |
@@ -2246,7 +2253,7 @@ static int vgic_its_save_cte(struct vgic_its *its, | |||
2246 | ((u64)collection->target_addr << KVM_ITS_CTE_RDBASE_SHIFT) | | 2253 | ((u64)collection->target_addr << KVM_ITS_CTE_RDBASE_SHIFT) | |
2247 | collection->collection_id); | 2254 | collection->collection_id); |
2248 | val = cpu_to_le64(val); | 2255 | val = cpu_to_le64(val); |
2249 | return kvm_write_guest(its->dev->kvm, gpa, &val, esz); | 2256 | return kvm_write_guest_lock(its->dev->kvm, gpa, &val, esz); |
2250 | } | 2257 | } |
2251 | 2258 | ||
2252 | static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz) | 2259 | static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz) |
@@ -2317,7 +2324,7 @@ static int vgic_its_save_collection_table(struct vgic_its *its) | |||
2317 | */ | 2324 | */ |
2318 | val = 0; | 2325 | val = 0; |
2319 | BUG_ON(cte_esz > sizeof(val)); | 2326 | BUG_ON(cte_esz > sizeof(val)); |
2320 | ret = kvm_write_guest(its->dev->kvm, gpa, &val, cte_esz); | 2327 | ret = kvm_write_guest_lock(its->dev->kvm, gpa, &val, cte_esz); |
2321 | return ret; | 2328 | return ret; |
2322 | } | 2329 | } |
2323 | 2330 | ||
diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 408a78eb6a97..9f87e58dbd4a 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c | |||
@@ -358,7 +358,7 @@ retry: | |||
358 | if (status) { | 358 | if (status) { |
359 | /* clear consumed data */ | 359 | /* clear consumed data */ |
360 | val &= ~(1 << bit_nr); | 360 | val &= ~(1 << bit_nr); |
361 | ret = kvm_write_guest(kvm, ptr, &val, 1); | 361 | ret = kvm_write_guest_lock(kvm, ptr, &val, 1); |
362 | if (ret) | 362 | if (ret) |
363 | return ret; | 363 | return ret; |
364 | } | 364 | } |
@@ -409,7 +409,7 @@ int vgic_v3_save_pending_tables(struct kvm *kvm) | |||
409 | else | 409 | else |
410 | val &= ~(1 << bit_nr); | 410 | val &= ~(1 << bit_nr); |
411 | 411 | ||
412 | ret = kvm_write_guest(kvm, ptr, &val, 1); | 412 | ret = kvm_write_guest_lock(kvm, ptr, &val, 1); |
413 | if (ret) | 413 | if (ret) |
414 | return ret; | 414 | return ret; |
415 | } | 415 | } |
diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index abd9c7352677..3af69f2a3866 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c | |||
@@ -867,15 +867,21 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu) | |||
867 | * either observe the new interrupt before or after doing this check, | 867 | * either observe the new interrupt before or after doing this check, |
868 | * and introducing additional synchronization mechanism doesn't change | 868 | * and introducing additional synchronization mechanism doesn't change |
869 | * this. | 869 | * this. |
870 | * | ||
871 | * Note that we still need to go through the whole thing if anything | ||
872 | * can be directly injected (GICv4). | ||
870 | */ | 873 | */ |
871 | if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head)) | 874 | if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head) && |
875 | !vgic_supports_direct_msis(vcpu->kvm)) | ||
872 | return; | 876 | return; |
873 | 877 | ||
874 | DEBUG_SPINLOCK_BUG_ON(!irqs_disabled()); | 878 | DEBUG_SPINLOCK_BUG_ON(!irqs_disabled()); |
875 | 879 | ||
876 | raw_spin_lock(&vcpu->arch.vgic_cpu.ap_list_lock); | 880 | if (!list_empty(&vcpu->arch.vgic_cpu.ap_list_head)) { |
877 | vgic_flush_lr_state(vcpu); | 881 | raw_spin_lock(&vcpu->arch.vgic_cpu.ap_list_lock); |
878 | raw_spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock); | 882 | vgic_flush_lr_state(vcpu); |
883 | raw_spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock); | ||
884 | } | ||
879 | 885 | ||
880 | if (can_access_vgic_from_kernel()) | 886 | if (can_access_vgic_from_kernel()) |
881 | vgic_restore_state(vcpu); | 887 | vgic_restore_state(vcpu); |