From: Piotr Piórkowski Date: Fri, 3 Oct 2025 16:26:16 +0000 (+0200) Subject: drm/xe: Introduce new BO flag XE_BO_FLAG_FORCE_USER_VRAM X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d290ab0b5a054cf5bb39a80b90140fa22704f61;p=thirdparty%2Fkernel%2Flinux.git drm/xe: Introduce new BO flag XE_BO_FLAG_FORCE_USER_VRAM When using a separate VRAM region for kernel allocations, some kernel structures, such as context userspace data, should not reside in the VRAM region dedicated to the kernel. The VRAM kernel region is intended only for allocations necessary for driver operation. Allocations created via ioctl are long-lived and not easily evictable. If this region runs out of space, there may not be a fallback, which could cause failures. To prevent this, add a new BO flag that explicitly forces the BO to be allocated in the general-purpose VRAM region accessible to userspace, avoiding the kernel-only VRAM region. v2: - update commit message (Matthew) Signed-off-by: Piotr Piórkowski Cc: Matthew Auld Reviewed-by: Matthew Auld Signed-off-by: Michal Wajdeczko Link: https://lore.kernel.org/r/20251003162619.1984236-3-piotr.piorkowski@intel.com --- diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index ce20f58ee80e5..a1302afb31b97 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -226,14 +226,14 @@ static u8 vram_bo_flag_to_tile_id(struct xe_device *xe, u32 vram_bo_flag) return __ffs(vram_bo_flag >> (__ffs(XE_BO_FLAG_VRAM0) - 1)) - 1; } -static u32 bo_vram_flags_to_vram_placement(struct xe_device *xe, u32 vram_flag, +static u32 bo_vram_flags_to_vram_placement(struct xe_device *xe, u32 bo_flags, u32 vram_flag, enum ttm_bo_type type) { u8 tile_id = vram_bo_flag_to_tile_id(xe, vram_flag); xe_assert(xe, tile_id < xe->info.tile_count); - if (type == ttm_bo_type_kernel) + if (type == ttm_bo_type_kernel && !(bo_flags & XE_BO_FLAG_FORCE_USER_VRAM)) return xe->tiles[tile_id].mem.kernel_vram->placement; else return xe->tiles[tile_id].mem.vram->placement; @@ -276,7 +276,7 @@ static void try_add_vram(struct xe_device *xe, struct xe_bo *bo, u32 vram_flag; for_each_set_bo_vram_flag(vram_flag, bo_flags) { - u32 pl = bo_vram_flags_to_vram_placement(xe, vram_flag, type); + u32 pl = bo_vram_flags_to_vram_placement(xe, bo_flags, vram_flag, type); add_vram(xe, bo, bo->placements, bo_flags, pl, c); } @@ -2275,7 +2275,7 @@ static int __xe_bo_fixed_placement(struct xe_device *xe, if (flags & XE_BO_FLAG_STOLEN) place->mem_type = XE_PL_STOLEN; else - place->mem_type = bo_vram_flags_to_vram_placement(xe, vram_flag, type); + place->mem_type = bo_vram_flags_to_vram_placement(xe, flags, vram_flag, type); bo->placement = (struct ttm_placement) { .num_placement = 1, diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h index 9a8401300b15c..353d607d301da 100644 --- a/drivers/gpu/drm/xe/xe_bo.h +++ b/drivers/gpu/drm/xe/xe_bo.h @@ -49,6 +49,7 @@ #define XE_BO_FLAG_GGTT2 BIT(22) #define XE_BO_FLAG_GGTT3 BIT(23) #define XE_BO_FLAG_CPU_ADDR_MIRROR BIT(24) +#define XE_BO_FLAG_FORCE_USER_VRAM BIT(25) /* this one is trigger internally only */ #define XE_BO_FLAG_INTERNAL_TEST BIT(30)