Skip to content

Commit 34e8042

Browse files
committed
drm/xe: Make xe_ggtt_node struct independent
In some rare cases, the drm_mm node cannot be removed synchronously due to runtime PM conditions. In this situation, the node removal will be delegated to a workqueue that will be able to wake up the device before removing the node. However, in this situation, the lifetime of the xe_ggtt_node cannot be restricted to the lifetime of the parent object. So, this patch introduces the infrastructure so the xe_ggtt_node struct can be allocated in advance and freed when needed. By having the ggtt backpointer, it also ensure that the init function is always called before any attempt to insert or reserve the node in the GGTT. v2: s/xe_ggtt_node_force_fini/xe_ggtt_node_fini and use it internaly (Brost) v3: - Use GF_NOFS for node allocation (CI) - Avoid ggtt argument, now that we have it inside the node (Lucas) - Fix some missed fini cases (CI) v4: - Fix SRIOV critical case where config->ggtt_region was lost (Michal) - Avoid ggtt argument also on removal (missed case on v3) (Michal) - Remove useless checks (Michal) - Return 0 instead of negative errno on a u32 addr. (Michal) - s/xe_ggtt_assign/xe_ggtt_node_assign for coherence, while we are touching it (Michal) v5: - Fix VFs' ggtt_balloon Cc: Matthew Auld <[email protected]> Cc: Michal Wajdeczko <[email protected]> Cc: Matthew Brost <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 15ca094 commit 34e8042

File tree

12 files changed

+214
-104
lines changed

12 files changed

+214
-104
lines changed

drivers/gpu/drm/xe/compat-i915-headers/i915_vma.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct xe_bo;
2020

2121
struct i915_vma {
2222
struct xe_bo *bo, *dpt;
23-
struct xe_ggtt_node node;
23+
struct xe_ggtt_node *node;
2424
};
2525

2626
#define i915_ggtt_clear_scanout(bo) do { } while (0)
@@ -29,7 +29,7 @@ struct i915_vma {
2929

3030
static inline u32 i915_ggtt_offset(const struct i915_vma *vma)
3131
{
32-
return vma->node.base.start;
32+
return vma->node->base.start;
3333
}
3434

3535
#endif

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,28 @@ static int __xe_pin_fb_vma_ggtt(const struct intel_framebuffer *fb,
204204
if (xe_bo_is_vram(bo) && ggtt->flags & XE_GGTT_FLAGS_64K)
205205
align = max_t(u32, align, SZ_64K);
206206

207-
if (bo->ggtt_node.base.size && view->type == I915_GTT_VIEW_NORMAL) {
207+
if (bo->ggtt_node && view->type == I915_GTT_VIEW_NORMAL) {
208208
vma->node = bo->ggtt_node;
209209
} else if (view->type == I915_GTT_VIEW_NORMAL) {
210210
u32 x, size = bo->ttm.base.size;
211211

212-
ret = xe_ggtt_node_insert_locked(ggtt, &vma->node, size, align, 0);
213-
if (ret)
212+
vma->node = xe_ggtt_node_init(ggtt);
213+
if (IS_ERR(vma->node)) {
214+
ret = PTR_ERR(vma->node);
214215
goto out_unlock;
216+
}
217+
218+
ret = xe_ggtt_node_insert_locked(vma->node, size, align, 0);
219+
if (ret) {
220+
xe_ggtt_node_fini(vma->node);
221+
goto out_unlock;
222+
}
215223

216224
for (x = 0; x < size; x += XE_PAGE_SIZE) {
217225
u64 pte = ggtt->pt_ops->pte_encode_bo(bo, x,
218226
xe->pat.idx[XE_CACHE_NONE]);
219227

220-
ggtt->pt_ops->ggtt_set_pte(ggtt, vma->node.base.start + x, pte);
228+
ggtt->pt_ops->ggtt_set_pte(ggtt, vma->node->base.start + x, pte);
221229
}
222230
} else {
223231
u32 i, ggtt_ofs;
@@ -226,11 +234,19 @@ static int __xe_pin_fb_vma_ggtt(const struct intel_framebuffer *fb,
226234
/* display seems to use tiles instead of bytes here, so convert it back.. */
227235
u32 size = intel_rotation_info_size(rot_info) * XE_PAGE_SIZE;
228236

229-
ret = xe_ggtt_node_insert_locked(ggtt, &vma->node, size, align, 0);
230-
if (ret)
237+
vma->node = xe_ggtt_node_init(ggtt);
238+
if (IS_ERR(vma->node)) {
239+
ret = PTR_ERR(vma->node);
240+
goto out_unlock;
241+
}
242+
243+
ret = xe_ggtt_node_insert_locked(vma->node, size, align, 0);
244+
if (ret) {
245+
xe_ggtt_node_fini(vma->node);
231246
goto out_unlock;
247+
}
232248

233-
ggtt_ofs = vma->node.base.start;
249+
ggtt_ofs = vma->node->base.start;
234250

235251
for (i = 0; i < ARRAY_SIZE(rot_info->plane); i++)
236252
write_ggtt_rotated(bo, ggtt, &ggtt_ofs,
@@ -318,14 +334,11 @@ static struct i915_vma *__xe_pin_fb_vma(const struct intel_framebuffer *fb,
318334

319335
static void __xe_unpin_fb_vma(struct i915_vma *vma)
320336
{
321-
struct xe_device *xe = to_xe_device(vma->bo->ttm.base.dev);
322-
struct xe_ggtt *ggtt = xe_device_get_root_tile(xe)->mem.ggtt;
323-
324337
if (vma->dpt)
325338
xe_bo_unpin_map_no_vm(vma->dpt);
326-
else if (!xe_ggtt_node_allocated(&vma->bo->ggtt_node) ||
327-
vma->bo->ggtt_node.base.start != vma->node.base.start)
328-
xe_ggtt_node_remove(ggtt, &vma->node, false);
339+
else if (!xe_ggtt_node_allocated(vma->bo->ggtt_node) ||
340+
vma->bo->ggtt_node->base.start != vma->node->base.start)
341+
xe_ggtt_node_remove(vma->node, false);
329342

330343
ttm_bo_reserve(&vma->bo->ttm, false, false, NULL);
331344
ttm_bo_unpin(&vma->bo->ttm);

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ static void xe_ttm_bo_destroy(struct ttm_buffer_object *ttm_bo)
11201120

11211121
xe_assert(xe, list_empty(&ttm_bo->base.gpuva.list));
11221122

1123-
if (bo->ggtt_node.base.size)
1123+
if (bo->ggtt_node && bo->ggtt_node->base.size)
11241124
xe_ggtt_remove_bo(bo->tile->mem.ggtt, bo);
11251125

11261126
#ifdef CONFIG_PROC_FS

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,12 @@ xe_bo_main_addr(struct xe_bo *bo, size_t page_size)
194194
static inline u32
195195
xe_bo_ggtt_addr(struct xe_bo *bo)
196196
{
197-
XE_WARN_ON(bo->ggtt_node.base.size > bo->size);
198-
XE_WARN_ON(bo->ggtt_node.base.start + bo->ggtt_node.base.size > (1ull << 32));
199-
return bo->ggtt_node.base.start;
197+
if (XE_WARN_ON(!bo->ggtt_node))
198+
return 0;
199+
200+
XE_WARN_ON(bo->ggtt_node->base.size > bo->size);
201+
XE_WARN_ON(bo->ggtt_node->base.start + bo->ggtt_node->base.size > (1ull << 32));
202+
return bo->ggtt_node->base.start;
200203
}
201204

202205
int xe_bo_vmap(struct xe_bo *bo);

drivers/gpu/drm/xe/xe_bo_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct xe_bo {
4040
/** @placement: current placement for this BO */
4141
struct ttm_placement placement;
4242
/** @ggtt_node: GGTT node if this BO is mapped in the GGTT */
43-
struct xe_ggtt_node ggtt_node;
43+
struct xe_ggtt_node *ggtt_node;
4444
/** @vmap: iosys map of this buffer */
4545
struct iosys_map vmap;
4646
/** @ttm_kmap: TTM bo kmap object for internal use only. Keep off. */

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ struct xe_tile {
204204
struct xe_memirq memirq;
205205

206206
/** @sriov.vf.ggtt_balloon: GGTT regions excluded from use. */
207-
struct xe_ggtt_node ggtt_balloon[2];
207+
struct xe_ggtt_node *ggtt_balloon[2];
208208
} vf;
209209
} sriov;
210210

0 commit comments

Comments
 (0)