]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/xe: Convert xe_bo_create_pin_map_at() for exhaustive eviction
authorThomas Hellström <thomas.hellstrom@linux.intel.com>
Mon, 8 Sep 2025 10:12:43 +0000 (12:12 +0200)
committerThomas Hellström <thomas.hellstrom@linux.intel.com>
Wed, 10 Sep 2025 07:16:05 +0000 (09:16 +0200)
Most users of xe_bo_create_pin_map_at() and
xe_bo_create_pin_map_at_aligned() are not using the vm parameter,
and that simplifies conversion. Introduce an
xe_bo_create_pin_map_at_novm() function and make the _aligned()
version static. Use xe_validation_guard() for conversion.

v2:
- Adapt to signature change of xe_validation_guard(). (Matt Brost)
- Fix up documentation.
v4:
- Postpone the change to i915_gem_stolen_insert_node_in_range() to
  a later patch.

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250908101246.65025-11-thomas.hellstrom@linux.intel.com
drivers/gpu/drm/xe/display/xe_fb_pin.c
drivers/gpu/drm/xe/display/xe_plane_initial.c
drivers/gpu/drm/xe/xe_bo.c
drivers/gpu/drm/xe/xe_bo.h
drivers/gpu/drm/xe/xe_eu_stall.c

index a5c35e9ff2ef14f8af81118ab743253deeb3154e..7e82e49544fa5ff18b7b19f6da5ab05cc5fe6d08 100644 (file)
@@ -102,29 +102,29 @@ static int __xe_pin_fb_vma_dpt(const struct intel_framebuffer *fb,
                                 XE_PAGE_SIZE);
 
        if (IS_DGFX(xe))
-               dpt = xe_bo_create_pin_map_at_aligned(xe, tile0, NULL,
-                                                     dpt_size, ~0ull,
-                                                     ttm_bo_type_kernel,
-                                                     XE_BO_FLAG_VRAM0 |
-                                                     XE_BO_FLAG_GGTT |
-                                                     XE_BO_FLAG_PAGETABLE,
-                                                     alignment);
+               dpt = xe_bo_create_pin_map_at_novm(xe, tile0,
+                                                  dpt_size, ~0ull,
+                                                  ttm_bo_type_kernel,
+                                                  XE_BO_FLAG_VRAM0 |
+                                                  XE_BO_FLAG_GGTT |
+                                                  XE_BO_FLAG_PAGETABLE,
+                                                  alignment, false);
        else
-               dpt = xe_bo_create_pin_map_at_aligned(xe, tile0, NULL,
-                                                     dpt_size,  ~0ull,
-                                                     ttm_bo_type_kernel,
-                                                     XE_BO_FLAG_STOLEN |
-                                                     XE_BO_FLAG_GGTT |
-                                                     XE_BO_FLAG_PAGETABLE,
-                                                     alignment);
+               dpt = xe_bo_create_pin_map_at_novm(xe, tile0,
+                                                  dpt_size,  ~0ull,
+                                                  ttm_bo_type_kernel,
+                                                  XE_BO_FLAG_STOLEN |
+                                                  XE_BO_FLAG_GGTT |
+                                                  XE_BO_FLAG_PAGETABLE,
+                                                  alignment, false);
        if (IS_ERR(dpt))
-               dpt = xe_bo_create_pin_map_at_aligned(xe, tile0, NULL,
-                                                     dpt_size,  ~0ull,
-                                                     ttm_bo_type_kernel,
-                                                     XE_BO_FLAG_SYSTEM |
-                                                     XE_BO_FLAG_GGTT |
-                                                     XE_BO_FLAG_PAGETABLE,
-                                                     alignment);
+               dpt = xe_bo_create_pin_map_at_novm(xe, tile0,
+                                                  dpt_size,  ~0ull,
+                                                  ttm_bo_type_kernel,
+                                                  XE_BO_FLAG_SYSTEM |
+                                                  XE_BO_FLAG_GGTT |
+                                                  XE_BO_FLAG_PAGETABLE,
+                                                  alignment, false);
        if (IS_ERR(dpt))
                return PTR_ERR(dpt);
 
index 00da1dff0c446dd12a16d039e43428c4a566ebf9..6d52d75cd9bf300573a17347a6afc12457a07d9c 100644 (file)
@@ -139,8 +139,8 @@ initial_plane_bo(struct xe_device *xe,
                        page_size);
        size -= base;
 
-       bo = xe_bo_create_pin_map_at(xe, tile0, NULL, size, phys_base,
-                                    ttm_bo_type_kernel, flags);
+       bo = xe_bo_create_pin_map_at_novm(xe, tile0, size, phys_base,
+                                         ttm_bo_type_kernel, flags, 0, false);
        if (IS_ERR(bo)) {
                drm_dbg(&xe->drm,
                        "Failed to create bo phys_base=%pa size %u with flags %x: %li\n",
index ad2863a7df77439cfd8afc17c4e163fbd52e2591..b7d7d14457905a16446b0fc531afb0d5d692be4b 100644 (file)
@@ -2428,27 +2428,17 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe,
        return bo;
 }
 
-struct xe_bo *xe_bo_create_pin_map_at(struct xe_device *xe, struct xe_tile *tile,
-                                     struct xe_vm *vm,
-                                     size_t size, u64 offset,
-                                     enum ttm_bo_type type, u32 flags)
-{
-       return xe_bo_create_pin_map_at_aligned(xe, tile, vm, size, offset,
-                                              type, flags, 0);
-}
-
-struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
-                                             struct xe_tile *tile,
-                                             struct xe_vm *vm,
-                                             size_t size, u64 offset,
-                                             enum ttm_bo_type type, u32 flags,
-                                             u64 alignment)
+static struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
+                                                    struct xe_tile *tile,
+                                                    struct xe_vm *vm,
+                                                    size_t size, u64 offset,
+                                                    enum ttm_bo_type type, u32 flags,
+                                                    u64 alignment, struct drm_exec *exec)
 {
        struct xe_bo *bo;
        int err;
        u64 start = offset == ~0ull ? 0 : offset;
-       u64 end = offset == ~0ull ? offset : start + size;
-       struct drm_exec *exec = vm ? xe_vm_validation_exec(vm) : XE_VALIDATION_UNIMPLEMENTED;
+       u64 end = offset == ~0ull ? ~0ull : start + size;
 
        if (flags & XE_BO_FLAG_STOLEN &&
            xe_ttm_stolen_cpu_access_needs_ggtt(xe))
@@ -2480,11 +2470,57 @@ err_put:
        return ERR_PTR(err);
 }
 
+/**
+ * xe_bo_create_pin_map_at_novm() - Create pinned and mapped bo at optional VRAM offset
+ * @xe: The xe device.
+ * @tile: The tile to select for migration of this bo, and the tile used for
+ * GGTT binding if any. Only to be non-NULL for ttm_bo_type_kernel bos.
+ * @size: The storage size to use for the bo.
+ * @offset: Optional VRAM offset or %~0ull for don't care.
+ * @type: The TTM buffer object type.
+ * @flags: XE_BO_FLAG_ flags.
+ * @alignment: GGTT alignment.
+ * @intr: Whether to execute any waits for backing store interruptible.
+ *
+ * Create a pinned and optionally mapped bo with VRAM offset and GGTT alignment
+ * options. The bo will be external and not associated with a VM.
+ *
+ * Return: The buffer object on success. Negative error pointer on failure.
+ * In particular, the function may return ERR_PTR(%-EINTR) if @intr was set
+ * to true on entry.
+ */
+struct xe_bo *
+xe_bo_create_pin_map_at_novm(struct xe_device *xe, struct xe_tile *tile,
+                            size_t size, u64 offset, enum ttm_bo_type type, u32 flags,
+                            u64 alignment, bool intr)
+{
+       struct xe_validation_ctx ctx;
+       struct drm_exec exec;
+       struct xe_bo *bo;
+       int ret = 0;
+
+       xe_validation_guard(&ctx, &xe->val, &exec, (struct xe_val_flags) {.interruptible = intr},
+                           ret) {
+               bo = xe_bo_create_pin_map_at_aligned(xe, tile, NULL, size, offset,
+                                                    type, flags, alignment, &exec);
+               if (IS_ERR(bo)) {
+                       drm_exec_retry_on_contention(&exec);
+                       ret = PTR_ERR(bo);
+                       xe_validation_retry_on_oom(&ctx, &ret);
+               }
+       }
+
+       return ret ? ERR_PTR(ret) : bo;
+}
+
 struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
                                   struct xe_vm *vm, size_t size,
                                   enum ttm_bo_type type, u32 flags)
 {
-       return xe_bo_create_pin_map_at(xe, tile, vm, size, ~0ull, type, flags);
+       struct drm_exec *exec = vm ? xe_vm_validation_exec(vm) : XE_VALIDATION_UNIMPLEMENTED;
+
+       return xe_bo_create_pin_map_at_aligned(xe, tile, vm, size, ~0ull, type, flags,
+                                              0, exec);
 }
 
 static void __xe_bo_unpin_map_no_vm(void *arg)
index ebca6e9f695913ac9d3d7d999181ca85bf567cbe..d9aef56ab8781aff7a5b4498c9f403291e70c5ff 100644 (file)
@@ -109,15 +109,10 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe, struct xe_vm *vm, size_t s
 struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
                                   struct xe_vm *vm, size_t size,
                                   enum ttm_bo_type type, u32 flags);
-struct xe_bo *xe_bo_create_pin_map_at(struct xe_device *xe, struct xe_tile *tile,
-                                     struct xe_vm *vm, size_t size, u64 offset,
-                                     enum ttm_bo_type type, u32 flags);
-struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
-                                             struct xe_tile *tile,
-                                             struct xe_vm *vm,
-                                             size_t size, u64 offset,
-                                             enum ttm_bo_type type, u32 flags,
-                                             u64 alignment);
+struct xe_bo *
+xe_bo_create_pin_map_at_novm(struct xe_device *xe, struct xe_tile *tile,
+                            size_t size, u64 offset, enum ttm_bo_type type,
+                            u32 flags, u64 alignment, bool intr);
 struct xe_bo *xe_managed_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
                                           size_t size, u32 flags);
 struct xe_bo *xe_managed_bo_create_from_data(struct xe_device *xe, struct xe_tile *tile,
index fdd514fec5ef959dc1d80f2e1a0342ab13a4df75..f5cfdf29fde345b92e9396d3cdc1fa24405cb691 100644 (file)
@@ -617,9 +617,8 @@ static int xe_eu_stall_data_buf_alloc(struct xe_eu_stall_data_stream *stream,
 
        size = stream->per_xecore_buf_size * last_xecore;
 
-       bo = xe_bo_create_pin_map_at_aligned(tile->xe, tile, NULL,
-                                            size, ~0ull, ttm_bo_type_kernel,
-                                            XE_BO_FLAG_SYSTEM | XE_BO_FLAG_GGTT, SZ_64);
+       bo = xe_bo_create_pin_map_at_novm(tile->xe, tile, size, ~0ull, ttm_bo_type_kernel,
+                                         XE_BO_FLAG_SYSTEM | XE_BO_FLAG_GGTT, SZ_64, false);
        if (IS_ERR(bo)) {
                kfree(stream->xecore_buf);
                return PTR_ERR(bo);