Skip to content

Commit e6108ea

Browse files
author
Thomas Hellström
committed
drm/xe: Convert xe_bo_create_pin_map_at() for exhaustive eviction
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
1 parent 550a42a commit e6108ea

File tree

5 files changed

+83
-53
lines changed

5 files changed

+83
-53
lines changed

drivers/gpu/drm/xe/display/xe_fb_pin.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,29 @@ static int __xe_pin_fb_vma_dpt(const struct intel_framebuffer *fb,
102102
XE_PAGE_SIZE);
103103

104104
if (IS_DGFX(xe))
105-
dpt = xe_bo_create_pin_map_at_aligned(xe, tile0, NULL,
106-
dpt_size, ~0ull,
107-
ttm_bo_type_kernel,
108-
XE_BO_FLAG_VRAM0 |
109-
XE_BO_FLAG_GGTT |
110-
XE_BO_FLAG_PAGETABLE,
111-
alignment);
105+
dpt = xe_bo_create_pin_map_at_novm(xe, tile0,
106+
dpt_size, ~0ull,
107+
ttm_bo_type_kernel,
108+
XE_BO_FLAG_VRAM0 |
109+
XE_BO_FLAG_GGTT |
110+
XE_BO_FLAG_PAGETABLE,
111+
alignment, false);
112112
else
113-
dpt = xe_bo_create_pin_map_at_aligned(xe, tile0, NULL,
114-
dpt_size, ~0ull,
115-
ttm_bo_type_kernel,
116-
XE_BO_FLAG_STOLEN |
117-
XE_BO_FLAG_GGTT |
118-
XE_BO_FLAG_PAGETABLE,
119-
alignment);
113+
dpt = xe_bo_create_pin_map_at_novm(xe, tile0,
114+
dpt_size, ~0ull,
115+
ttm_bo_type_kernel,
116+
XE_BO_FLAG_STOLEN |
117+
XE_BO_FLAG_GGTT |
118+
XE_BO_FLAG_PAGETABLE,
119+
alignment, false);
120120
if (IS_ERR(dpt))
121-
dpt = xe_bo_create_pin_map_at_aligned(xe, tile0, NULL,
122-
dpt_size, ~0ull,
123-
ttm_bo_type_kernel,
124-
XE_BO_FLAG_SYSTEM |
125-
XE_BO_FLAG_GGTT |
126-
XE_BO_FLAG_PAGETABLE,
127-
alignment);
121+
dpt = xe_bo_create_pin_map_at_novm(xe, tile0,
122+
dpt_size, ~0ull,
123+
ttm_bo_type_kernel,
124+
XE_BO_FLAG_SYSTEM |
125+
XE_BO_FLAG_GGTT |
126+
XE_BO_FLAG_PAGETABLE,
127+
alignment, false);
128128
if (IS_ERR(dpt))
129129
return PTR_ERR(dpt);
130130

drivers/gpu/drm/xe/display/xe_plane_initial.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ initial_plane_bo(struct xe_device *xe,
139139
page_size);
140140
size -= base;
141141

142-
bo = xe_bo_create_pin_map_at(xe, tile0, NULL, size, phys_base,
143-
ttm_bo_type_kernel, flags);
142+
bo = xe_bo_create_pin_map_at_novm(xe, tile0, size, phys_base,
143+
ttm_bo_type_kernel, flags, 0, false);
144144
if (IS_ERR(bo)) {
145145
drm_dbg(&xe->drm,
146146
"Failed to create bo phys_base=%pa size %u with flags %x: %li\n",

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,27 +2428,17 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe,
24282428
return bo;
24292429
}
24302430

2431-
struct xe_bo *xe_bo_create_pin_map_at(struct xe_device *xe, struct xe_tile *tile,
2432-
struct xe_vm *vm,
2433-
size_t size, u64 offset,
2434-
enum ttm_bo_type type, u32 flags)
2435-
{
2436-
return xe_bo_create_pin_map_at_aligned(xe, tile, vm, size, offset,
2437-
type, flags, 0);
2438-
}
2439-
2440-
struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
2441-
struct xe_tile *tile,
2442-
struct xe_vm *vm,
2443-
size_t size, u64 offset,
2444-
enum ttm_bo_type type, u32 flags,
2445-
u64 alignment)
2431+
static struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
2432+
struct xe_tile *tile,
2433+
struct xe_vm *vm,
2434+
size_t size, u64 offset,
2435+
enum ttm_bo_type type, u32 flags,
2436+
u64 alignment, struct drm_exec *exec)
24462437
{
24472438
struct xe_bo *bo;
24482439
int err;
24492440
u64 start = offset == ~0ull ? 0 : offset;
2450-
u64 end = offset == ~0ull ? offset : start + size;
2451-
struct drm_exec *exec = vm ? xe_vm_validation_exec(vm) : XE_VALIDATION_UNIMPLEMENTED;
2441+
u64 end = offset == ~0ull ? ~0ull : start + size;
24522442

24532443
if (flags & XE_BO_FLAG_STOLEN &&
24542444
xe_ttm_stolen_cpu_access_needs_ggtt(xe))
@@ -2480,11 +2470,57 @@ struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
24802470
return ERR_PTR(err);
24812471
}
24822472

2473+
/**
2474+
* xe_bo_create_pin_map_at_novm() - Create pinned and mapped bo at optional VRAM offset
2475+
* @xe: The xe device.
2476+
* @tile: The tile to select for migration of this bo, and the tile used for
2477+
* GGTT binding if any. Only to be non-NULL for ttm_bo_type_kernel bos.
2478+
* @size: The storage size to use for the bo.
2479+
* @offset: Optional VRAM offset or %~0ull for don't care.
2480+
* @type: The TTM buffer object type.
2481+
* @flags: XE_BO_FLAG_ flags.
2482+
* @alignment: GGTT alignment.
2483+
* @intr: Whether to execute any waits for backing store interruptible.
2484+
*
2485+
* Create a pinned and optionally mapped bo with VRAM offset and GGTT alignment
2486+
* options. The bo will be external and not associated with a VM.
2487+
*
2488+
* Return: The buffer object on success. Negative error pointer on failure.
2489+
* In particular, the function may return ERR_PTR(%-EINTR) if @intr was set
2490+
* to true on entry.
2491+
*/
2492+
struct xe_bo *
2493+
xe_bo_create_pin_map_at_novm(struct xe_device *xe, struct xe_tile *tile,
2494+
size_t size, u64 offset, enum ttm_bo_type type, u32 flags,
2495+
u64 alignment, bool intr)
2496+
{
2497+
struct xe_validation_ctx ctx;
2498+
struct drm_exec exec;
2499+
struct xe_bo *bo;
2500+
int ret = 0;
2501+
2502+
xe_validation_guard(&ctx, &xe->val, &exec, (struct xe_val_flags) {.interruptible = intr},
2503+
ret) {
2504+
bo = xe_bo_create_pin_map_at_aligned(xe, tile, NULL, size, offset,
2505+
type, flags, alignment, &exec);
2506+
if (IS_ERR(bo)) {
2507+
drm_exec_retry_on_contention(&exec);
2508+
ret = PTR_ERR(bo);
2509+
xe_validation_retry_on_oom(&ctx, &ret);
2510+
}
2511+
}
2512+
2513+
return ret ? ERR_PTR(ret) : bo;
2514+
}
2515+
24832516
struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
24842517
struct xe_vm *vm, size_t size,
24852518
enum ttm_bo_type type, u32 flags)
24862519
{
2487-
return xe_bo_create_pin_map_at(xe, tile, vm, size, ~0ull, type, flags);
2520+
struct drm_exec *exec = vm ? xe_vm_validation_exec(vm) : XE_VALIDATION_UNIMPLEMENTED;
2521+
2522+
return xe_bo_create_pin_map_at_aligned(xe, tile, vm, size, ~0ull, type, flags,
2523+
0, exec);
24882524
}
24892525

24902526
static void __xe_bo_unpin_map_no_vm(void *arg)

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,10 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe, struct xe_vm *vm, size_t s
109109
struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
110110
struct xe_vm *vm, size_t size,
111111
enum ttm_bo_type type, u32 flags);
112-
struct xe_bo *xe_bo_create_pin_map_at(struct xe_device *xe, struct xe_tile *tile,
113-
struct xe_vm *vm, size_t size, u64 offset,
114-
enum ttm_bo_type type, u32 flags);
115-
struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
116-
struct xe_tile *tile,
117-
struct xe_vm *vm,
118-
size_t size, u64 offset,
119-
enum ttm_bo_type type, u32 flags,
120-
u64 alignment);
112+
struct xe_bo *
113+
xe_bo_create_pin_map_at_novm(struct xe_device *xe, struct xe_tile *tile,
114+
size_t size, u64 offset, enum ttm_bo_type type,
115+
u32 flags, u64 alignment, bool intr);
121116
struct xe_bo *xe_managed_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
122117
size_t size, u32 flags);
123118
struct xe_bo *xe_managed_bo_create_from_data(struct xe_device *xe, struct xe_tile *tile,

drivers/gpu/drm/xe/xe_eu_stall.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,8 @@ static int xe_eu_stall_data_buf_alloc(struct xe_eu_stall_data_stream *stream,
617617

618618
size = stream->per_xecore_buf_size * last_xecore;
619619

620-
bo = xe_bo_create_pin_map_at_aligned(tile->xe, tile, NULL,
621-
size, ~0ull, ttm_bo_type_kernel,
622-
XE_BO_FLAG_SYSTEM | XE_BO_FLAG_GGTT, SZ_64);
620+
bo = xe_bo_create_pin_map_at_novm(tile->xe, tile, size, ~0ull, ttm_bo_type_kernel,
621+
XE_BO_FLAG_SYSTEM | XE_BO_FLAG_GGTT, SZ_64, false);
623622
if (IS_ERR(bo)) {
624623
kfree(stream->xecore_buf);
625624
return PTR_ERR(bo);

0 commit comments

Comments
 (0)