Skip to content

Commit 976a40c

Browse files
Steve Sistarejgunthorpe
authored andcommitted
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/[email protected] Signed-off-by: Steve Sistare <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent f4986a7 commit 976a40c

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

drivers/iommu/iommufd/pages.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,11 +1814,11 @@ static int iopt_pages_fill_from_domain(struct iopt_pages *pages,
18141814
return 0;
18151815
}
18161816

1817-
static int iopt_pages_fill_from_mm(struct iopt_pages *pages,
1818-
struct pfn_reader_user *user,
1819-
unsigned long start_index,
1820-
unsigned long last_index,
1821-
struct page **out_pages)
1817+
static int iopt_pages_fill(struct iopt_pages *pages,
1818+
struct pfn_reader_user *user,
1819+
unsigned long start_index,
1820+
unsigned long last_index,
1821+
struct page **out_pages)
18221822
{
18231823
unsigned long cur_index = start_index;
18241824
int rc;
@@ -1892,8 +1892,8 @@ int iopt_pages_fill_xarray(struct iopt_pages *pages, unsigned long start_index,
18921892

18931893
/* hole */
18941894
cur_pages = out_pages + (span.start_hole - start_index);
1895-
rc = iopt_pages_fill_from_mm(pages, &user, span.start_hole,
1896-
span.last_hole, cur_pages);
1895+
rc = iopt_pages_fill(pages, &user, span.start_hole,
1896+
span.last_hole, cur_pages);
18971897
if (rc)
18981898
goto out_clean_xa;
18991899
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,
19731973
struct page *page = NULL;
19741974
int rc;
19751975

1976+
if (IS_ENABLED(CONFIG_IOMMUFD_TEST) &&
1977+
WARN_ON(pages->type != IOPT_ADDRESS_USER))
1978+
return -EINVAL;
1979+
19761980
if (!mmget_not_zero(pages->source_mm))
19771981
return iopt_pages_rw_slow(pages, index, index, offset, data,
19781982
length, flags);
@@ -2028,6 +2032,15 @@ int iopt_pages_rw_access(struct iopt_pages *pages, unsigned long start_byte,
20282032
if ((flags & IOMMUFD_ACCESS_RW_WRITE) && !pages->writable)
20292033
return -EPERM;
20302034

2035+
if (pages->type == IOPT_ADDRESS_FILE)
2036+
return iopt_pages_rw_slow(pages, start_index, last_index,
2037+
start_byte % PAGE_SIZE, data, length,
2038+
flags);
2039+
2040+
if (IS_ENABLED(CONFIG_IOMMUFD_TEST) &&
2041+
WARN_ON(pages->type != IOPT_ADDRESS_USER))
2042+
return -EINVAL;
2043+
20312044
if (!(flags & IOMMUFD_ACCESS_RW_KTHREAD) && change_mm) {
20322045
if (start_index == last_index)
20332046
return iopt_pages_rw_page(pages, start_index,

0 commit comments

Comments
 (0)