]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe: Introduce new BO flag XE_BO_FLAG_FORCE_USER_VRAM
authorPiotr Piórkowski <piotr.piorkowski@intel.com>
Fri, 3 Oct 2025 16:26:16 +0000 (18:26 +0200)
committerMichal Wajdeczko <michal.wajdeczko@intel.com>
Mon, 6 Oct 2025 06:33:48 +0000 (08:33 +0200)
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 <piotr.piorkowski@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Link: https://lore.kernel.org/r/20251003162619.1984236-3-piotr.piorkowski@intel.com
drivers/gpu/drm/xe/xe_bo.c
drivers/gpu/drm/xe/xe_bo.h

index ce20f58ee80e599d5dad8cf029328f6d80bf32c9..a1302afb31b97142cc686b684400e403982b6e97 100644 (file)
@@ -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,
index 9a8401300b15ccd9a587cb0cdb82144b93c8d5e2..353d607d301da5dfce6a6aa83b25673f5b0af67c 100644 (file)
@@ -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)