Skip to content

Commit 1f15417

Browse files
author
Thomas Hellström
committed
drm/xe: Rework instances of variants of xe_bo_create_locked()
A common pattern is to create a locked bo, pin it without mapping and then unlock it. Add a function to do that, which internally uses xe_validation_guard(). With that we can remove xe_bo_create_locked_range() and add exhaustive eviction to stolen, pf_provision_vf_lmem and psmi_alloc_object. v4: - New patch after reorganization. v5: - Replace DRM_XE_GEM_CPU_CACHING_WB with 0. (CI) 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-13-thomas.hellstrom@linux.intel.com
1 parent 59eabff commit 1f15417

File tree

5 files changed

+70
-87
lines changed

5 files changed

+70
-87
lines changed

drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_stolen.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ static inline int i915_gem_stolen_insert_node_in_range(struct xe_device *xe,
2121
u32 size, u32 align,
2222
u32 start, u32 end)
2323
{
24-
struct drm_exec *exec = XE_VALIDATION_UNIMPLEMENTED;
2524
struct xe_bo *bo;
2625
int err;
2726
u32 flags = XE_BO_FLAG_PINNED | XE_BO_FLAG_STOLEN;
@@ -34,21 +33,13 @@ static inline int i915_gem_stolen_insert_node_in_range(struct xe_device *xe,
3433
start = ALIGN(start, align);
3534
}
3635

37-
bo = xe_bo_create_locked_range(xe, xe_device_get_root_tile(xe),
38-
NULL, size, start, end,
39-
ttm_bo_type_kernel, flags, 0, exec);
36+
bo = xe_bo_create_pin_range_novm(xe, xe_device_get_root_tile(xe),
37+
size, start, end, ttm_bo_type_kernel, flags);
4038
if (IS_ERR(bo)) {
4139
err = PTR_ERR(bo);
4240
bo = NULL;
4341
return err;
4442
}
45-
err = xe_bo_pin(bo, exec);
46-
xe_bo_unlock_vm_held(bo);
47-
48-
if (err) {
49-
xe_bo_put(fb->bo);
50-
bo = NULL;
51-
}
5243

5344
fb->bo = bo;
5445

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,37 +2309,6 @@ __xe_bo_create_locked(struct xe_device *xe,
23092309
return ERR_PTR(err);
23102310
}
23112311

2312-
/**
2313-
* xe_bo_create_locked_range() - Create a BO with range- and alignment options
2314-
* @xe: The xe device.
2315-
* @tile: The tile to select for migration of this bo, and the tile used for
2316-
* GGTT binding if any. Only to be non-NULL for ttm_bo_type_kernel bos.
2317-
* @vm: The local vm or NULL for external objects.
2318-
* @size: The storage size to use for the bo.
2319-
* @start: Start of fixed VRAM range or 0.
2320-
* @end: End of fixed VRAM range or ~0ULL.
2321-
* @type: The TTM buffer object type.
2322-
* @flags: XE_BO_FLAG_ flags.
2323-
* @alignment: For GGTT buffer objects, the minimum GGTT alignment.
2324-
* @exec: The drm_exec transaction to use for exhaustive eviction.
2325-
*
2326-
* Create an Xe BO with range- and alignment options. If @start and @end indicate
2327-
* a fixed VRAM range, this must be a ttm_bo_type_kernel bo with VRAM placement
2328-
* only. The @alignment parameter can be used for GGTT alignment.
2329-
*
2330-
* Return: The buffer object on success. Negative error pointer on failure.
2331-
*/
2332-
struct xe_bo *
2333-
xe_bo_create_locked_range(struct xe_device *xe,
2334-
struct xe_tile *tile, struct xe_vm *vm,
2335-
size_t size, u64 start, u64 end,
2336-
enum ttm_bo_type type, u32 flags, u64 alignment,
2337-
struct drm_exec *exec)
2338-
{
2339-
return __xe_bo_create_locked(xe, tile, vm, size, start, end, 0, type,
2340-
flags, alignment, exec);
2341-
}
2342-
23432312
/**
23442313
* xe_bo_create_locked() - Create a BO
23452314
* @xe: The xe device.
@@ -2428,6 +2397,55 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe,
24282397
return bo;
24292398
}
24302399

2400+
/**
2401+
* xe_bo_create_pin_range_novm() - Create and pin a BO with range options.
2402+
* @xe: The xe device.
2403+
* @tile: The tile to select for migration of this bo, and the tile used for
2404+
* GGTT binding if any. Only to be non-NULL for ttm_bo_type_kernel bos.
2405+
* @size: The storage size to use for the bo.
2406+
* @start: Start of fixed VRAM range or 0.
2407+
* @end: End of fixed VRAM range or ~0ULL.
2408+
* @type: The TTM buffer object type.
2409+
* @flags: XE_BO_FLAG_ flags.
2410+
*
2411+
* Create an Xe BO with range- and options. If @start and @end indicate
2412+
* a fixed VRAM range, this must be a ttm_bo_type_kernel bo with VRAM placement
2413+
* only.
2414+
*
2415+
* Return: The buffer object on success. Negative error pointer on failure.
2416+
*/
2417+
struct xe_bo *xe_bo_create_pin_range_novm(struct xe_device *xe, struct xe_tile *tile,
2418+
size_t size, u64 start, u64 end,
2419+
enum ttm_bo_type type, u32 flags)
2420+
{
2421+
struct xe_validation_ctx ctx;
2422+
struct drm_exec exec;
2423+
struct xe_bo *bo;
2424+
int err = 0;
2425+
2426+
xe_validation_guard(&ctx, &xe->val, &exec, (struct xe_val_flags) {}, err) {
2427+
bo = __xe_bo_create_locked(xe, tile, NULL, size, start, end,
2428+
0, type, flags, 0, &exec);
2429+
if (IS_ERR(bo)) {
2430+
drm_exec_retry_on_contention(&exec);
2431+
err = PTR_ERR(bo);
2432+
xe_validation_retry_on_oom(&ctx, &err);
2433+
break;
2434+
}
2435+
2436+
err = xe_bo_pin(bo, &exec);
2437+
xe_bo_unlock(bo);
2438+
if (err) {
2439+
xe_bo_put(bo);
2440+
drm_exec_retry_on_contention(&exec);
2441+
xe_validation_retry_on_oom(&ctx, &err);
2442+
break;
2443+
}
2444+
}
2445+
2446+
return err ? ERR_PTR(err) : bo;
2447+
}
2448+
24312449
static struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
24322450
struct xe_tile *tile,
24332451
struct xe_vm *vm,
@@ -2444,9 +2462,9 @@ static struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
24442462
xe_ttm_stolen_cpu_access_needs_ggtt(xe))
24452463
flags |= XE_BO_FLAG_GGTT;
24462464

2447-
bo = xe_bo_create_locked_range(xe, tile, vm, size, start, end, type,
2448-
flags | XE_BO_FLAG_NEEDS_CPU_ACCESS | XE_BO_FLAG_PINNED,
2449-
alignment, exec);
2465+
bo = __xe_bo_create_locked(xe, tile, vm, size, start, end, 0, type,
2466+
flags | XE_BO_FLAG_NEEDS_CPU_ACCESS | XE_BO_FLAG_PINNED,
2467+
alignment, exec);
24502468
if (IS_ERR(bo))
24512469
return bo;
24522470

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ struct xe_bo *xe_bo_init_locked(struct xe_device *xe, struct xe_bo *bo,
9494
struct ttm_lru_bulk_move *bulk, size_t size,
9595
u16 cpu_caching, enum ttm_bo_type type,
9696
u32 flags, struct drm_exec *exec);
97-
struct xe_bo *
98-
xe_bo_create_locked_range(struct xe_device *xe,
99-
struct xe_tile *tile, struct xe_vm *vm,
100-
size_t size, u64 start, u64 end,
101-
enum ttm_bo_type type, u32 flags, u64 alignment,
102-
struct drm_exec *exec);
10397
struct xe_bo *xe_bo_create_locked(struct xe_device *xe, struct xe_tile *tile,
10498
struct xe_vm *vm, size_t size,
10599
enum ttm_bo_type type, u32 flags,
@@ -113,6 +107,9 @@ struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
113107
struct xe_bo *xe_bo_create_pin_map_novm(struct xe_device *xe, struct xe_tile *tile,
114108
size_t size, enum ttm_bo_type type, u32 flags,
115109
bool intr);
110+
struct xe_bo *xe_bo_create_pin_range_novm(struct xe_device *xe, struct xe_tile *tile,
111+
size_t size, u64 start, u64 end,
112+
enum ttm_bo_type type, u32 flags);
116113
struct xe_bo *
117114
xe_bo_create_pin_map_at_novm(struct xe_device *xe, struct xe_tile *tile,
118115
size_t size, u64 offset, enum ttm_bo_type type,

drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,6 @@ static bool pf_release_vf_config_lmem(struct xe_gt *gt, struct xe_gt_sriov_confi
14521452
static int pf_provision_vf_lmem(struct xe_gt *gt, unsigned int vfid, u64 size)
14531453
{
14541454
struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
1455-
struct drm_exec *exec = XE_VALIDATION_UNIMPLEMENTED;
14561455
struct xe_device *xe = gt_to_xe(gt);
14571456
struct xe_tile *tile = gt_to_tile(gt);
14581457
struct xe_bo *bo;
@@ -1479,24 +1478,16 @@ static int pf_provision_vf_lmem(struct xe_gt *gt, unsigned int vfid, u64 size)
14791478
return 0;
14801479

14811480
xe_gt_assert(gt, pf_get_lmem_alignment(gt) == SZ_2M);
1482-
bo = xe_bo_create_locked(xe, tile, NULL,
1483-
ALIGN(size, PAGE_SIZE),
1484-
ttm_bo_type_kernel,
1485-
XE_BO_FLAG_VRAM_IF_DGFX(tile) |
1486-
XE_BO_FLAG_NEEDS_2M |
1487-
XE_BO_FLAG_PINNED |
1488-
XE_BO_FLAG_PINNED_LATE_RESTORE,
1489-
exec);
1481+
bo = xe_bo_create_pin_range_novm(xe, tile,
1482+
ALIGN(size, PAGE_SIZE), 0, ~0ull,
1483+
ttm_bo_type_kernel,
1484+
XE_BO_FLAG_VRAM_IF_DGFX(tile) |
1485+
XE_BO_FLAG_NEEDS_2M |
1486+
XE_BO_FLAG_PINNED |
1487+
XE_BO_FLAG_PINNED_LATE_RESTORE);
14901488
if (IS_ERR(bo))
14911489
return PTR_ERR(bo);
14921490

1493-
err = xe_bo_pin(bo, exec);
1494-
xe_bo_unlock(bo);
1495-
if (unlikely(err)) {
1496-
xe_bo_put(bo);
1497-
return err;
1498-
}
1499-
15001491
config->lmem_obj = bo;
15011492

15021493
if (xe_device_has_lmtt(xe)) {

drivers/gpu/drm/xe/xe_psmi.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,34 +68,20 @@ static void psmi_cleanup(struct xe_device *xe)
6868
static struct xe_bo *psmi_alloc_object(struct xe_device *xe,
6969
unsigned int id, size_t bo_size)
7070
{
71-
struct drm_exec *exec = XE_VALIDATION_UNIMPLEMENTED;
72-
struct xe_bo *bo = NULL;
7371
struct xe_tile *tile;
74-
int err;
7572

7673
if (!id || !bo_size)
7774
return NULL;
7875

7976
tile = &xe->tiles[id - 1];
8077

8178
/* VRAM: Allocate GEM object for the capture buffer */
82-
bo = xe_bo_create_locked(xe, tile, NULL, bo_size,
83-
ttm_bo_type_kernel,
84-
XE_BO_FLAG_VRAM_IF_DGFX(tile) |
85-
XE_BO_FLAG_PINNED |
86-
XE_BO_FLAG_PINNED_LATE_RESTORE |
87-
XE_BO_FLAG_NEEDS_CPU_ACCESS,
88-
exec);
89-
90-
if (!IS_ERR(bo)) {
91-
/* Buffer written by HW, ensure stays resident */
92-
err = xe_bo_pin(bo, exec);
93-
if (err)
94-
bo = ERR_PTR(err);
95-
xe_bo_unlock(bo);
96-
}
97-
98-
return bo;
79+
return xe_bo_create_pin_range_novm(xe, tile, bo_size, 0, ~0ull,
80+
ttm_bo_type_kernel,
81+
XE_BO_FLAG_VRAM_IF_DGFX(tile) |
82+
XE_BO_FLAG_PINNED |
83+
XE_BO_FLAG_PINNED_LATE_RESTORE |
84+
XE_BO_FLAG_NEEDS_CPU_ACCESS);
9985
}
10086

10187
/*

0 commit comments

Comments
 (0)