Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/gpusvm, drm/xe: Allow mixed mappings for userptr

Compute kernels often issue memory copies immediately after completion.
If the memory being copied is an SVM pointer that was faulted into the
device and then bound via userptr, it is undesirable to move that
memory. Worse, if userptr is mixed between system and device memory, the
bind operation may be rejected.

Xe already has the necessary plumbing to support userptr with mixed
mappings. This update modifies GPUSVM's get_pages to correctly locate
pages in such mixed mapping scenarios.

v2:
- Rebase (Thomas Hellström)
v3:
- Remove Fixes tag.
v4:
- Break out from series since the other patch was merged.
- Update patch subject, ensure dri-devel and Maarten are CC'd.

Cc: Maarten Lankhorst <maarten.lankhorst@intel.com>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Link: https://lore.kernel.org/r/20251015120320.176338-1-thomas.hellstrom@linux.intel.com
Acked-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>

authored by

Matthew Brost and committed by
Thomas Hellström
bce13d6e 95af8155

+11 -3
+4 -2
drivers/gpu/drm/drm_gpusvm.c
··· 1363 1363 order = drm_gpusvm_hmm_pfn_to_order(pfns[i], i, npages); 1364 1364 if (is_device_private_page(page) || 1365 1365 is_device_coherent_page(page)) { 1366 - if (zdd != page->zone_device_data && i > 0) { 1366 + if (!ctx->allow_mixed && 1367 + zdd != page->zone_device_data && i > 0) { 1367 1368 err = -EOPNOTSUPP; 1368 1369 goto err_unmap; 1369 1370 } ··· 1400 1399 } else { 1401 1400 dma_addr_t addr; 1402 1401 1403 - if (is_zone_device_page(page) || pagemap) { 1402 + if (is_zone_device_page(page) || 1403 + (pagemap && !ctx->allow_mixed)) { 1404 1404 err = -EOPNOTSUPP; 1405 1405 goto err_unmap; 1406 1406 }
+3 -1
drivers/gpu/drm/xe/xe_userptr.c
··· 3 3 * Copyright © 2025 Intel Corporation 4 4 */ 5 5 6 + #include "xe_svm.h" 6 7 #include "xe_userptr.h" 7 8 8 9 #include <linux/mm.h> ··· 55 54 struct xe_device *xe = vm->xe; 56 55 struct drm_gpusvm_ctx ctx = { 57 56 .read_only = xe_vma_read_only(vma), 58 - .device_private_page_owner = NULL, 57 + .device_private_page_owner = xe_svm_devm_owner(xe), 58 + .allow_mixed = true, 59 59 }; 60 60 61 61 lockdep_assert_held(&vm->lock);
+4
include/drm/drm_gpusvm.h
··· 235 235 * @read_only: operating on read-only memory 236 236 * @devmem_possible: possible to use device memory 237 237 * @devmem_only: use only device memory 238 + * @allow_mixed: Allow mixed mappings in get pages. Mixing between system and 239 + * single dpagemap is supported, mixing between multiple dpagemap 240 + * is unsupported. 238 241 * 239 242 * Context that is DRM GPUSVM is operating in (i.e. user arguments). 240 243 */ ··· 249 246 unsigned int read_only :1; 250 247 unsigned int devmem_possible :1; 251 248 unsigned int devmem_only :1; 249 + unsigned int allow_mixed :1; 252 250 }; 253 251 254 252 int drm_gpusvm_init(struct drm_gpusvm *gpusvm,