Commit ad70e289 authored by Matthew Auld's avatar Matthew Auld
Browse files

drm/gpusvm: use more selective dma dir in get_pages()



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: default avatarMatthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: default avatarMatthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250828142430.615826-12-matthew.auld@intel.com
parent c50729c6
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -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 @@ int drm_gpusvm_range_get_pages(struct drm_gpusvm *gpusvm,
				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 @@ int drm_gpusvm_range_get_pages(struct drm_gpusvm *gpusvm,
			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 @@ int drm_gpusvm_range_get_pages(struct drm_gpusvm *gpusvm,

			range->dma_addr[j] = drm_pagemap_addr_encode
				(addr, DRM_INTERCONNECT_SYSTEM, order,
				 DMA_BIDIRECTIONAL);
				 dma_dir);
		}
		i += 1 << order;
		num_dma_mapped = i;