Add support for resolving page faults on vfio_dmabuf backed MMIO. Now only support setup KVM MMU mapping on shared roots, i.e. vfio_dmabuf works for shared assigned devices.
Further work is to support private MMIO for private assigned devices (known as TDI in TDISP spec). Signed-off-by: Xu Yilun <yilun...@linux.intel.com> --- arch/x86/kvm/mmu/mmu.c | 16 ++++++++++++++++ include/linux/kvm_host.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 63bb77ee1bb1..40d33bd6b532 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4523,6 +4523,22 @@ static int __kvm_mmu_faultin_pfn(struct kvm_vcpu *vcpu, if (fault->is_private) return kvm_mmu_faultin_pfn_private(vcpu, fault); + /* vfio_dmabuf slot is also applicable for shared mapping */ + if (kvm_slot_is_vfio_dmabuf(fault->slot)) { + int max_order, r; + + r = kvm_vfio_dmabuf_get_pfn(vcpu->kvm, fault->slot, fault->gfn, + &fault->pfn, &max_order); + if (r) + return r; + + fault->max_level = min(kvm_max_level_for_order(max_order), + fault->max_level); + fault->map_writable = !(fault->slot->flags & KVM_MEM_READONLY); + + return RET_PF_CONTINUE; + } + foll |= FOLL_NOWAIT; fault->pfn = __kvm_faultin_pfn(fault->slot, fault->gfn, foll, &fault->map_writable, &fault->refcounted_page); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index d16f47c3d008..b850d3cff83c 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -623,6 +623,11 @@ static inline bool kvm_slot_can_be_private(const struct kvm_memory_slot *slot) return slot && (slot->flags & KVM_MEM_GUEST_MEMFD); } +static inline bool kvm_slot_is_vfio_dmabuf(const struct kvm_memory_slot *slot) +{ + return slot && (slot->flags & KVM_MEM_VFIO_DMABUF); +} + static inline bool kvm_slot_dirty_track_enabled(const struct kvm_memory_slot *slot) { return slot->flags & KVM_MEM_LOG_DIRTY_PAGES; -- 2.25.1