@@ -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);
@@ -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;
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.xu@linux.intel.com> --- arch/x86/kvm/mmu/mmu.c | 16 ++++++++++++++++ include/linux/kvm_host.h | 5 +++++ 2 files changed, 21 insertions(+)