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

Configure Feed

Select the types of activity you want to include in your feed.

drm/xe/madvise: Update migration policy based on preferred location

When the user sets the valid devmem_fd as a preferred location, GPU fault
will trigger migration to tile of device associated with devmem_fd.

If the user sets an invalid devmem_fd the preferred location is current
placement(smem) only.

v2(Matthew Brost)
- Default should be faulting tile
- remove devmem_fd used as region

v3 (Matthew Brost)
- Add migration_policy
- Fix return condition
- fix migrate condition

v4
-Rebase

v5
- Add check for userptr and bo based vmas

Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250821173104.3030148-11-himal.prasad.ghimiray@intel.com
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>

+76 -2
+44 -1
drivers/gpu/drm/xe/xe_svm.c
··· 806 806 }; 807 807 struct xe_svm_range *range; 808 808 struct dma_fence *fence; 809 + struct drm_pagemap *dpagemap; 809 810 struct xe_tile *tile = gt_to_tile(gt); 810 811 int migrate_try_count = ctx.devmem_only ? 3 : 1; 811 812 ktime_t end = 0; ··· 836 835 837 836 range_debug(range, "PAGE FAULT"); 838 837 838 + dpagemap = xe_vma_resolve_pagemap(vma, tile); 839 839 if (--migrate_try_count >= 0 && 840 - xe_svm_range_needs_migrate_to_vram(range, vma, IS_DGFX(vm->xe))) { 840 + xe_svm_range_needs_migrate_to_vram(range, vma, !!dpagemap || ctx.devmem_only)) { 841 + /* TODO : For multi-device dpagemap will be used to find the 842 + * remote tile and remote device. Will need to modify 843 + * xe_svm_alloc_vram to use dpagemap for future multi-device 844 + * support. 845 + */ 841 846 err = xe_svm_alloc_vram(tile, range, &ctx); 842 847 ctx.timeslice_ms <<= 1; /* Double timeslice if we have to retry */ 843 848 if (err) { ··· 1108 1101 } 1109 1102 1110 1103 /** 1104 + * xe_vma_resolve_pagemap - Resolve the appropriate DRM pagemap for a VMA 1105 + * @vma: Pointer to the xe_vma structure containing memory attributes 1106 + * @tile: Pointer to the xe_tile structure used as fallback for VRAM mapping 1107 + * 1108 + * This function determines the correct DRM pagemap to use for a given VMA. 1109 + * It first checks if a valid devmem_fd is provided in the VMA's preferred 1110 + * location. If the devmem_fd is negative, it returns NULL, indicating no 1111 + * pagemap is available and smem to be used as preferred location. 1112 + * If the devmem_fd is equal to the default faulting 1113 + * GT identifier, it returns the VRAM pagemap associated with the tile. 1114 + * 1115 + * Future support for multi-device configurations may use drm_pagemap_from_fd() 1116 + * to resolve pagemaps from arbitrary file descriptors. 1117 + * 1118 + * Return: A pointer to the resolved drm_pagemap, or NULL if none is applicable. 1119 + */ 1120 + struct drm_pagemap *xe_vma_resolve_pagemap(struct xe_vma *vma, struct xe_tile *tile) 1121 + { 1122 + s32 fd = (s32)vma->attr.preferred_loc.devmem_fd; 1123 + 1124 + if (fd == DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM) 1125 + return NULL; 1126 + 1127 + if (fd == DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE) 1128 + return IS_DGFX(tile_to_xe(tile)) ? tile_local_pagemap(tile) : NULL; 1129 + 1130 + /* TODO: Support multi-device with drm_pagemap_from_fd(fd) */ 1131 + return NULL; 1132 + } 1133 + 1134 + /** 1111 1135 * xe_svm_alloc_vram()- Allocate device memory pages for range, 1112 1136 * migrating existing data. 1113 1137 * @tile: tile to allocate vram from ··· 1249 1211 int xe_devm_add(struct xe_tile *tile, struct xe_vram_region *vr) 1250 1212 { 1251 1213 return 0; 1214 + } 1215 + 1216 + struct drm_pagemap *xe_vma_resolve_pagemap(struct xe_vma *vma, struct xe_tile *tile) 1217 + { 1218 + return NULL; 1252 1219 } 1253 1220 #endif 1254 1221
+8
drivers/gpu/drm/xe/xe_svm.h
··· 94 94 95 95 u8 xe_svm_ranges_zap_ptes_in_range(struct xe_vm *vm, u64 start, u64 end); 96 96 97 + struct drm_pagemap *xe_vma_resolve_pagemap(struct xe_vma *vma, struct xe_tile *tile); 98 + 97 99 /** 98 100 * xe_svm_range_has_dma_mapping() - SVM range has DMA mapping 99 101 * @range: SVM range ··· 318 316 u8 xe_svm_ranges_zap_ptes_in_range(struct xe_vm *vm, u64 start, u64 end) 319 317 { 320 318 return 0; 319 + } 320 + 321 + static inline 322 + struct drm_pagemap *xe_vma_resolve_pagemap(struct xe_vma *vma, struct xe_tile *tile) 323 + { 324 + return NULL; 321 325 } 322 326 323 327 #define xe_svm_assert_in_notifier(...) do {} while (0)
+24 -1
drivers/gpu/drm/xe/xe_vm_madvise.c
··· 78 78 struct xe_vma **vmas, int num_vmas, 79 79 struct drm_xe_madvise *op) 80 80 { 81 - /* Implementation pending */ 81 + int i; 82 + 83 + xe_assert(vm->xe, op->type == DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC); 84 + 85 + for (i = 0; i < num_vmas; i++) { 86 + /*TODO: Extend attributes to bo based vmas */ 87 + if (!xe_vma_is_cpu_addr_mirror(vmas[i])) 88 + continue; 89 + 90 + vmas[i]->attr.preferred_loc.devmem_fd = op->preferred_mem_loc.devmem_fd; 91 + 92 + /* Till multi-device support is not added migration_policy 93 + * is of no use and can be ignored. 94 + */ 95 + vmas[i]->attr.preferred_loc.migration_policy = 96 + op->preferred_mem_loc.migration_policy; 97 + } 82 98 } 83 99 84 100 static void madvise_atomic(struct xe_device *xe, struct xe_vm *vm, ··· 200 184 201 185 switch (args->type) { 202 186 case DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC: 187 + { 188 + s32 fd = (s32)args->preferred_mem_loc.devmem_fd; 189 + 190 + if (XE_IOCTL_DBG(xe, fd < DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM)) 191 + return false; 192 + 203 193 if (XE_IOCTL_DBG(xe, args->preferred_mem_loc.migration_policy > 204 194 DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES)) 205 195 return false; ··· 216 194 if (XE_IOCTL_DBG(xe, args->atomic.reserved)) 217 195 return false; 218 196 break; 197 + } 219 198 case DRM_XE_MEM_RANGE_ATTR_ATOMIC: 220 199 if (XE_IOCTL_DBG(xe, args->atomic.val > DRM_XE_ATOMIC_CPU)) 221 200 return false;