Skip to content

Commit b886576

Browse files
kimphillchazy
authored andcommitted
ARM: KVM: user_mem_abort: support stage 2 MMIO page mapping
A userspace process can map device MMIO memory via VFIO or /dev/mem, e.g., for platform device passthrough support in QEMU. During early development, we found the PAGE_S2 memory type being used for MMIO mappings. This patch corrects that by using the more strongly ordered memory type for device MMIO mappings: PAGE_S2_DEVICE. Signed-off-by: Kim Phillips <kim.phillips@linaro.org> Acked-by: Christoffer Dall <christoffer.dall@linaro.org> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent df6ce24 commit b886576

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎arch/arm/kvm/mmu.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
759759
struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache;
760760
struct vm_area_struct *vma;
761761
pfn_t pfn;
762+
pgprot_t mem_type = PAGE_S2;
762763

763764
write_fault = kvm_is_write_fault(kvm_vcpu_get_hsr(vcpu));
764765
if (fault_status == FSC_PERM && !write_fault) {
@@ -809,14 +810,17 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
809810
if (is_error_pfn(pfn))
810811
return -EFAULT;
811812

813+
if (kvm_is_mmio_pfn(pfn))
814+
mem_type = PAGE_S2_DEVICE;
815+
812816
spin_lock(&kvm->mmu_lock);
813817
if (mmu_notifier_retry(kvm, mmu_seq))
814818
goto out_unlock;
815819
if (!hugetlb && !force_pte)
816820
hugetlb = transparent_hugepage_adjust(&pfn, &fault_ipa);
817821

818822
if (hugetlb) {
819-
pmd_t new_pmd = pfn_pmd(pfn, PAGE_S2);
823+
pmd_t new_pmd = pfn_pmd(pfn, mem_type);
820824
new_pmd = pmd_mkhuge(new_pmd);
821825
if (writable) {
822826
kvm_set_s2pmd_writable(&new_pmd);
@@ -825,13 +829,14 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
825829
coherent_cache_guest_page(vcpu, hva & PMD_MASK, PMD_SIZE);
826830
ret = stage2_set_pmd_huge(kvm, memcache, fault_ipa, &new_pmd);
827831
} else {
828-
pte_t new_pte = pfn_pte(pfn, PAGE_S2);
832+
pte_t new_pte = pfn_pte(pfn, mem_type);
829833
if (writable) {
830834
kvm_set_s2pte_writable(&new_pte);
831835
kvm_set_pfn_dirty(pfn);
832836
}
833837
coherent_cache_guest_page(vcpu, hva, PAGE_SIZE);
834-
ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte, false);
838+
ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte,
839+
mem_type == PAGE_S2_DEVICE);
835840
}
836841

837842

0 commit comments

Comments
 (0)