Commit 976a40c0 authored by Steve Sistare's avatar Steve Sistare Committed by Jason Gunthorpe
Browse files

iommufd: File mappings for mdev

Support file mappings for mediated devices, aka mdevs.  Access is
initiated by the vfio_pin_pages() and vfio_dma_rw() kernel interfaces.

Link: https://patch.msgid.link/r/1729861919-234514-9-git-send-email-steven.sistare@oracle.com


Signed-off-by: default avatarSteve Sistare <steven.sistare@oracle.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent f4986a72
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -1814,7 +1814,7 @@ static int iopt_pages_fill_from_domain(struct iopt_pages *pages,
	return 0;
}

static int iopt_pages_fill_from_mm(struct iopt_pages *pages,
static int iopt_pages_fill(struct iopt_pages *pages,
			   struct pfn_reader_user *user,
			   unsigned long start_index,
			   unsigned long last_index,
@@ -1892,7 +1892,7 @@ int iopt_pages_fill_xarray(struct iopt_pages *pages, unsigned long start_index,

		/* hole */
		cur_pages = out_pages + (span.start_hole - start_index);
		rc = iopt_pages_fill_from_mm(pages, &user, span.start_hole,
		rc = iopt_pages_fill(pages, &user, span.start_hole,
				     span.last_hole, cur_pages);
		if (rc)
			goto out_clean_xa;
@@ -1973,6 +1973,10 @@ static int iopt_pages_rw_page(struct iopt_pages *pages, unsigned long index,
	struct page *page = NULL;
	int rc;

	if (IS_ENABLED(CONFIG_IOMMUFD_TEST) &&
	    WARN_ON(pages->type != IOPT_ADDRESS_USER))
		return -EINVAL;

	if (!mmget_not_zero(pages->source_mm))
		return iopt_pages_rw_slow(pages, index, index, offset, data,
					  length, flags);
@@ -2028,6 +2032,15 @@ int iopt_pages_rw_access(struct iopt_pages *pages, unsigned long start_byte,
	if ((flags & IOMMUFD_ACCESS_RW_WRITE) && !pages->writable)
		return -EPERM;

	if (pages->type == IOPT_ADDRESS_FILE)
		return iopt_pages_rw_slow(pages, start_index, last_index,
					  start_byte % PAGE_SIZE, data, length,
					  flags);

	if (IS_ENABLED(CONFIG_IOMMUFD_TEST) &&
	    WARN_ON(pages->type != IOPT_ADDRESS_USER))
		return -EINVAL;

	if (!(flags & IOMMUFD_ACCESS_RW_KTHREAD) && change_mm) {
		if (start_index == last_index)
			return iopt_pages_rw_page(pages, start_index,