]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/gpusvm: use more selective dma dir in get_pages()
authorMatthew Auld <matthew.auld@intel.com>
Thu, 28 Aug 2025 14:24:33 +0000 (15:24 +0100)
committerMatthew Auld <matthew.auld@intel.com>
Fri, 5 Sep 2025 10:45:46 +0000 (11:45 +0100)
If we are only reading the memory then from the device pov the direction
can be DMA_TO_DEVICE. This aligns with the xe-userptr code. Using the
most restrictive data direction to represent the access is normally a
good idea.

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250828142430.615826-12-matthew.auld@intel.com
drivers/gpu/drm/drm_gpusvm.c

index 49f64d26625d8fb484d86c6edf42c5c89e87c051..b2920b8551f59f61fbf27b788a178b723faac99d 100644 (file)
@@ -1224,6 +1224,8 @@ int drm_gpusvm_range_get_pages(struct drm_gpusvm *gpusvm,
        struct dev_pagemap *pagemap;
        struct drm_pagemap *dpagemap;
        struct drm_gpusvm_range_flags flags;
+       enum dma_data_direction dma_dir = ctx->read_only ? DMA_TO_DEVICE :
+                                                          DMA_BIDIRECTIONAL;
 
 retry:
        hmm_range.notifier_seq = mmu_interval_read_begin(notifier);
@@ -1329,7 +1331,7 @@ map_pages:
                                dpagemap->ops->device_map(dpagemap,
                                                          gpusvm->drm->dev,
                                                          page, order,
-                                                         DMA_BIDIRECTIONAL);
+                                                         dma_dir);
                        if (dma_mapping_error(gpusvm->drm->dev,
                                              range->dma_addr[j].addr)) {
                                err = -EFAULT;
@@ -1351,7 +1353,7 @@ map_pages:
                        addr = dma_map_page(gpusvm->drm->dev,
                                            page, 0,
                                            PAGE_SIZE << order,
-                                           DMA_BIDIRECTIONAL);
+                                           dma_dir);
                        if (dma_mapping_error(gpusvm->drm->dev, addr)) {
                                err = -EFAULT;
                                goto err_unmap;
@@ -1359,7 +1361,7 @@ map_pages:
 
                        range->dma_addr[j] = drm_pagemap_addr_encode
                                (addr, DRM_INTERCONNECT_SYSTEM, order,
-                                DMA_BIDIRECTIONAL);
+                                dma_dir);
                }
                i += 1 << order;
                num_dma_mapped = i;