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: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
This commit is contained in:
committed by
Jason Gunthorpe
parent
f4986a72d6
commit
976a40c075
@@ -1814,11 +1814,11 @@ static int iopt_pages_fill_from_domain(struct iopt_pages *pages,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iopt_pages_fill_from_mm(struct iopt_pages *pages,
|
||||
struct pfn_reader_user *user,
|
||||
unsigned long start_index,
|
||||
unsigned long last_index,
|
||||
struct page **out_pages)
|
||||
static int iopt_pages_fill(struct iopt_pages *pages,
|
||||
struct pfn_reader_user *user,
|
||||
unsigned long start_index,
|
||||
unsigned long last_index,
|
||||
struct page **out_pages)
|
||||
{
|
||||
unsigned long cur_index = start_index;
|
||||
int rc;
|
||||
@@ -1892,8 +1892,8 @@ 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,
|
||||
span.last_hole, cur_pages);
|
||||
rc = iopt_pages_fill(pages, &user, span.start_hole,
|
||||
span.last_hole, cur_pages);
|
||||
if (rc)
|
||||
goto out_clean_xa;
|
||||
rc = pages_to_xarray(&pages->pinned_pfns, span.start_hole,
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user