]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommufd: File mappings for mdev
authorSteve Sistare <steven.sistare@oracle.com>
Fri, 25 Oct 2024 13:11:58 +0000 (06:11 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Mon, 28 Oct 2024 16:24:24 +0000 (13:24 -0300)
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>
drivers/iommu/iommufd/pages.c

index 2ee6fcd2b5516a36e6f537863c5d28c8eafc448e..8f249169831a77f0fb34df055f7c6d3b82b2a223 100644 (file)
@@ -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,