Skip to content

Commit 59eabff

Browse files
author
Thomas Hellström
committed
drm/xe: Convert xe_bo_create_pin_map() for exhaustive eviction
Introduce an xe_bo_create_pin_map_novm() function that does not take the drm_exec paramenter to simplify the conversion of many callsites. For the rest, ensure that the same drm_exec context that was used for locking the vm is passed down to validation. Use xe_validation_guard() where appropriate. v2: - Avoid gotos from within xe_validation_guard(). (Matt Brost) - Break out the change to pf_provision_vf_lmem8 to a separate patch. - Adapt to signature change of xe_validation_guard(). 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-12-thomas.hellstrom@linux.intel.com
1 parent e6108ea commit 59eabff

File tree

17 files changed

+231
-130
lines changed

17 files changed

+231
-130
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ struct intel_framebuffer *intel_fbdev_fb_alloc(struct drm_fb_helper *helper,
4242
obj = ERR_PTR(-ENODEV);
4343

4444
if (!IS_DGFX(xe) && !XE_GT_WA(xe_root_mmio_gt(xe), 22019338487_display)) {
45-
obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe),
46-
NULL, size,
47-
ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
48-
XE_BO_FLAG_STOLEN |
49-
XE_BO_FLAG_GGTT);
45+
obj = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe),
46+
size,
47+
ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
48+
XE_BO_FLAG_STOLEN |
49+
XE_BO_FLAG_GGTT, false);
5050
if (!IS_ERR(obj))
5151
drm_info(&xe->drm, "Allocated fbdev into stolen\n");
5252
else
5353
drm_info(&xe->drm, "Allocated fbdev into stolen failed: %li\n", PTR_ERR(obj));
5454
}
5555

5656
if (IS_ERR(obj)) {
57-
obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe), NULL, size,
58-
ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
59-
XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
60-
XE_BO_FLAG_GGTT);
57+
obj = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe), size,
58+
ttm_bo_type_kernel, XE_BO_FLAG_SCANOUT |
59+
XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
60+
XE_BO_FLAG_GGTT, false);
6161
}
6262

6363
if (IS_ERR(obj)) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct intel_dsb_buffer *d
4343
return false;
4444

4545
/* Set scanout flag for WC mapping */
46-
obj = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe),
47-
NULL, PAGE_ALIGN(size),
48-
ttm_bo_type_kernel,
49-
XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
50-
XE_BO_FLAG_SCANOUT | XE_BO_FLAG_GGTT);
46+
obj = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe),
47+
PAGE_ALIGN(size),
48+
ttm_bo_type_kernel,
49+
XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(xe)) |
50+
XE_BO_FLAG_SCANOUT | XE_BO_FLAG_GGTT, false);
5151
if (IS_ERR(obj)) {
5252
kfree(vma);
5353
return false;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ static int intel_hdcp_gsc_initialize_message(struct xe_device *xe,
7272
int ret = 0;
7373

7474
/* allocate object of two page for HDCP command memory and store it */
75-
bo = xe_bo_create_pin_map(xe, xe_device_get_root_tile(xe), NULL, PAGE_SIZE * 2,
76-
ttm_bo_type_kernel,
77-
XE_BO_FLAG_SYSTEM |
78-
XE_BO_FLAG_GGTT);
75+
bo = xe_bo_create_pin_map_novm(xe, xe_device_get_root_tile(xe), PAGE_SIZE * 2,
76+
ttm_bo_type_kernel,
77+
XE_BO_FLAG_SYSTEM |
78+
XE_BO_FLAG_GGTT, false);
7979

8080
if (IS_ERR(bo)) {
8181
drm_err(&xe->drm, "Failed to allocate bo for HDCP streaming command!\n");

drivers/gpu/drm/xe/tests/xe_migrate.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,17 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test,
204204

205205
big = xe_bo_create_pin_map(xe, tile, m->q->vm, SZ_4M,
206206
ttm_bo_type_kernel,
207-
XE_BO_FLAG_VRAM_IF_DGFX(tile));
207+
XE_BO_FLAG_VRAM_IF_DGFX(tile),
208+
exec);
208209
if (IS_ERR(big)) {
209210
KUNIT_FAIL(test, "Failed to allocate bo: %li\n", PTR_ERR(big));
210211
goto vunmap;
211212
}
212213

213214
pt = xe_bo_create_pin_map(xe, tile, m->q->vm, XE_PAGE_SIZE,
214215
ttm_bo_type_kernel,
215-
XE_BO_FLAG_VRAM_IF_DGFX(tile));
216+
XE_BO_FLAG_VRAM_IF_DGFX(tile),
217+
exec);
216218
if (IS_ERR(pt)) {
217219
KUNIT_FAIL(test, "Failed to allocate fake pt: %li\n",
218220
PTR_ERR(pt));
@@ -222,7 +224,8 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test,
222224
tiny = xe_bo_create_pin_map(xe, tile, m->q->vm,
223225
2 * SZ_4K,
224226
ttm_bo_type_kernel,
225-
XE_BO_FLAG_VRAM_IF_DGFX(tile));
227+
XE_BO_FLAG_VRAM_IF_DGFX(tile),
228+
exec);
226229
if (IS_ERR(tiny)) {
227230
KUNIT_FAIL(test, "Failed to allocate tiny fake pt: %li\n",
228231
PTR_ERR(tiny));

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,16 +2513,59 @@ xe_bo_create_pin_map_at_novm(struct xe_device *xe, struct xe_tile *tile,
25132513
return ret ? ERR_PTR(ret) : bo;
25142514
}
25152515

2516+
/**
2517+
* xe_bo_create_pin_map() - Create pinned and mapped bo
2518+
* @xe: The xe device.
2519+
* @tile: The tile to select for migration of this bo, and the tile used for
2520+
* @vm: The vm to associate the buffer object with. The vm's resv must be locked
2521+
* with the transaction represented by @exec.
2522+
* GGTT binding if any. Only to be non-NULL for ttm_bo_type_kernel bos.
2523+
* @size: The storage size to use for the bo.
2524+
* @type: The TTM buffer object type.
2525+
* @flags: XE_BO_FLAG_ flags.
2526+
* @exec: The drm_exec transaction to use for exhaustive eviction, and
2527+
* previously used for locking @vm's resv.
2528+
*
2529+
* Create a pinned and mapped bo. The bo will be external and not associated
2530+
* with a VM.
2531+
*
2532+
* Return: The buffer object on success. Negative error pointer on failure.
2533+
* In particular, the function may return ERR_PTR(%-EINTR) if @exec was
2534+
* configured for interruptible locking.
2535+
*/
25162536
struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
25172537
struct xe_vm *vm, size_t size,
2518-
enum ttm_bo_type type, u32 flags)
2538+
enum ttm_bo_type type, u32 flags,
2539+
struct drm_exec *exec)
25192540
{
2520-
struct drm_exec *exec = vm ? xe_vm_validation_exec(vm) : XE_VALIDATION_UNIMPLEMENTED;
2521-
25222541
return xe_bo_create_pin_map_at_aligned(xe, tile, vm, size, ~0ull, type, flags,
25232542
0, exec);
25242543
}
25252544

2545+
/**
2546+
* xe_bo_create_pin_map_novm() - Create pinned and mapped bo
2547+
* @xe: The xe device.
2548+
* @tile: The tile to select for migration of this bo, and the tile used for
2549+
* GGTT binding if any. Only to be non-NULL for ttm_bo_type_kernel bos.
2550+
* @size: The storage size to use for the bo.
2551+
* @type: The TTM buffer object type.
2552+
* @flags: XE_BO_FLAG_ flags.
2553+
* @intr: Whether to execut any waits for backing store interruptible.
2554+
*
2555+
* Create a pinned and mapped bo. The bo will be external and not associated
2556+
* with a VM.
2557+
*
2558+
* Return: The buffer object on success. Negative error pointer on failure.
2559+
* In particular, the function may return ERR_PTR(%-EINTR) if @intr was set
2560+
* to true on entry.
2561+
*/
2562+
struct xe_bo *xe_bo_create_pin_map_novm(struct xe_device *xe, struct xe_tile *tile,
2563+
size_t size, enum ttm_bo_type type, u32 flags,
2564+
bool intr)
2565+
{
2566+
return xe_bo_create_pin_map_at_novm(xe, tile, size, ~0ull, type, flags, 0, intr);
2567+
}
2568+
25262569
static void __xe_bo_unpin_map_no_vm(void *arg)
25272570
{
25282571
xe_bo_unpin_map_no_vm(arg);
@@ -2535,8 +2578,7 @@ struct xe_bo *xe_managed_bo_create_pin_map(struct xe_device *xe, struct xe_tile
25352578
int ret;
25362579

25372580
KUNIT_STATIC_STUB_REDIRECT(xe_managed_bo_create_pin_map, xe, tile, size, flags);
2538-
2539-
bo = xe_bo_create_pin_map(xe, tile, NULL, size, ttm_bo_type_kernel, flags);
2581+
bo = xe_bo_create_pin_map_novm(xe, tile, size, ttm_bo_type_kernel, flags, true);
25402582
if (IS_ERR(bo))
25412583
return bo;
25422584

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe, struct xe_vm *vm, size_t s
108108
u16 cpu_caching, u32 flags, struct drm_exec *exec);
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,
111-
enum ttm_bo_type type, u32 flags);
111+
enum ttm_bo_type type, u32 flags,
112+
struct drm_exec *exec);
113+
struct xe_bo *xe_bo_create_pin_map_novm(struct xe_device *xe, struct xe_tile *tile,
114+
size_t size, enum ttm_bo_type type, u32 flags,
115+
bool intr);
112116
struct xe_bo *
113117
xe_bo_create_pin_map_at_novm(struct xe_device *xe, struct xe_tile *tile,
114118
size_t size, u64 offset, enum ttm_bo_type type,

drivers/gpu/drm/xe/xe_gsc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ static int query_compatibility_version(struct xe_gsc *gsc)
136136
u64 ggtt_offset;
137137
int err;
138138

139-
bo = xe_bo_create_pin_map(xe, tile, NULL, GSC_VER_PKT_SZ * 2,
140-
ttm_bo_type_kernel,
141-
XE_BO_FLAG_SYSTEM |
142-
XE_BO_FLAG_GGTT);
139+
bo = xe_bo_create_pin_map_novm(xe, tile, GSC_VER_PKT_SZ * 2,
140+
ttm_bo_type_kernel,
141+
XE_BO_FLAG_SYSTEM |
142+
XE_BO_FLAG_GGTT, false);
143143
if (IS_ERR(bo)) {
144144
xe_gt_err(gt, "failed to allocate bo for GSC version query\n");
145145
return PTR_ERR(bo);

drivers/gpu/drm/xe/xe_gt_sriov_pf_migration.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ static int pf_send_guc_save_vf_state(struct xe_gt *gt, unsigned int vfid,
5555
xe_gt_assert(gt, size % sizeof(u32) == 0);
5656
xe_gt_assert(gt, size == ndwords * sizeof(u32));
5757

58-
bo = xe_bo_create_pin_map(xe, tile, NULL,
59-
ALIGN(size, PAGE_SIZE),
60-
ttm_bo_type_kernel,
61-
XE_BO_FLAG_SYSTEM |
62-
XE_BO_FLAG_GGTT |
63-
XE_BO_FLAG_GGTT_INVALIDATE);
58+
bo = xe_bo_create_pin_map_novm(xe, tile,
59+
ALIGN(size, PAGE_SIZE),
60+
ttm_bo_type_kernel,
61+
XE_BO_FLAG_SYSTEM |
62+
XE_BO_FLAG_GGTT |
63+
XE_BO_FLAG_GGTT_INVALIDATE, false);
6464
if (IS_ERR(bo))
6565
return PTR_ERR(bo);
6666

@@ -91,12 +91,12 @@ static int pf_send_guc_restore_vf_state(struct xe_gt *gt, unsigned int vfid,
9191
xe_gt_assert(gt, size % sizeof(u32) == 0);
9292
xe_gt_assert(gt, size == ndwords * sizeof(u32));
9393

94-
bo = xe_bo_create_pin_map(xe, tile, NULL,
95-
ALIGN(size, PAGE_SIZE),
96-
ttm_bo_type_kernel,
97-
XE_BO_FLAG_SYSTEM |
98-
XE_BO_FLAG_GGTT |
99-
XE_BO_FLAG_GGTT_INVALIDATE);
94+
bo = xe_bo_create_pin_map_novm(xe, tile,
95+
ALIGN(size, PAGE_SIZE),
96+
ttm_bo_type_kernel,
97+
XE_BO_FLAG_SYSTEM |
98+
XE_BO_FLAG_GGTT |
99+
XE_BO_FLAG_GGTT_INVALIDATE, false);
100100
if (IS_ERR(bo))
101101
return PTR_ERR(bo);
102102

drivers/gpu/drm/xe/xe_guc_engine_activity.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,17 @@ static int allocate_engine_activity_buffers(struct xe_guc *guc,
9494
struct xe_tile *tile = gt_to_tile(gt);
9595
struct xe_bo *bo, *metadata_bo;
9696

97-
metadata_bo = xe_bo_create_pin_map(gt_to_xe(gt), tile, NULL, PAGE_ALIGN(metadata_size),
98-
ttm_bo_type_kernel, XE_BO_FLAG_SYSTEM |
99-
XE_BO_FLAG_GGTT | XE_BO_FLAG_GGTT_INVALIDATE);
97+
metadata_bo = xe_bo_create_pin_map_novm(gt_to_xe(gt), tile, PAGE_ALIGN(metadata_size),
98+
ttm_bo_type_kernel, XE_BO_FLAG_SYSTEM |
99+
XE_BO_FLAG_GGTT | XE_BO_FLAG_GGTT_INVALIDATE,
100+
false);
100101

101102
if (IS_ERR(metadata_bo))
102103
return PTR_ERR(metadata_bo);
103104

104-
bo = xe_bo_create_pin_map(gt_to_xe(gt), tile, NULL, PAGE_ALIGN(size),
105-
ttm_bo_type_kernel, XE_BO_FLAG_VRAM_IF_DGFX(tile) |
106-
XE_BO_FLAG_GGTT | XE_BO_FLAG_GGTT_INVALIDATE);
105+
bo = xe_bo_create_pin_map_novm(gt_to_xe(gt), tile, PAGE_ALIGN(size),
106+
ttm_bo_type_kernel, XE_BO_FLAG_VRAM_IF_DGFX(tile) |
107+
XE_BO_FLAG_GGTT | XE_BO_FLAG_GGTT_INVALIDATE, false);
107108

108109
if (IS_ERR(bo)) {
109110
xe_bo_unpin_map_no_vm(metadata_bo);

drivers/gpu/drm/xe/xe_lmtt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ static struct xe_lmtt_pt *lmtt_pt_alloc(struct xe_lmtt *lmtt, unsigned int level
6767
goto out;
6868
}
6969

70-
bo = xe_bo_create_pin_map(lmtt_to_xe(lmtt), lmtt_to_tile(lmtt), NULL,
71-
PAGE_ALIGN(lmtt->ops->lmtt_pte_size(level) *
72-
lmtt->ops->lmtt_pte_num(level)),
73-
ttm_bo_type_kernel,
74-
XE_BO_FLAG_VRAM_IF_DGFX(lmtt_to_tile(lmtt)) |
75-
XE_BO_FLAG_NEEDS_64K);
70+
bo = xe_bo_create_pin_map_novm(lmtt_to_xe(lmtt), lmtt_to_tile(lmtt),
71+
PAGE_ALIGN(lmtt->ops->lmtt_pte_size(level) *
72+
lmtt->ops->lmtt_pte_num(level)),
73+
ttm_bo_type_kernel,
74+
XE_BO_FLAG_VRAM_IF_DGFX(lmtt_to_tile(lmtt)) |
75+
XE_BO_FLAG_NEEDS_64K, false);
7676
if (IS_ERR(bo)) {
7777
err = PTR_ERR(bo);
7878
goto out_free_pt;

0 commit comments

Comments
 (0)