Skip to content

Commit 01f2557

Browse files
mbrost05Thomas Hellström
authored andcommitted
drm/xe: Open-code GGTT MMIO access protection
GGTT MMIO access is currently protected by hotplug (drm_dev_enter), which works correctly when the driver loads successfully and is later unbound or unloaded. However, if driver load fails, this protection is insufficient because drm_dev_unplug() is never called. Additionally, devm release functions cannot guarantee that all BOs with GGTT mappings are destroyed before the GGTT MMIO region is removed, as some BOs may be freed asynchronously by worker threads. To address this, introduce an open-coded flag, protected by the GGTT lock, that guards GGTT MMIO access. The flag is cleared during the dev_fini_ggtt devm release function to ensure MMIO access is disabled once teardown begins. Cc: [email protected] Fixes: 919bb54 ("drm/xe: Fix missing runtime outer protection for ggtt_remove_node") Reviewed-by: Zhanjun Dong <[email protected]> Signed-off-by: Matthew Brost <[email protected]> Link: https://patch.msgid.link/[email protected] (cherry picked from commit 4f3a998) Signed-off-by: Thomas Hellström <[email protected]>
1 parent e6e3ea5 commit 01f2557

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/gpu/drm/xe/xe_ggtt.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ static void dev_fini_ggtt(void *arg)
313313
{
314314
struct xe_ggtt *ggtt = arg;
315315

316+
scoped_guard(mutex, &ggtt->lock)
317+
ggtt->flags &= ~XE_GGTT_FLAGS_ONLINE;
316318
drain_workqueue(ggtt->wq);
317319
}
318320

@@ -377,6 +379,7 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
377379
if (err)
378380
return err;
379381

382+
ggtt->flags |= XE_GGTT_FLAGS_ONLINE;
380383
err = devm_add_action_or_reset(xe->drm.dev, dev_fini_ggtt, ggtt);
381384
if (err)
382385
return err;
@@ -410,13 +413,10 @@ static void xe_ggtt_initial_clear(struct xe_ggtt *ggtt)
410413
static void ggtt_node_remove(struct xe_ggtt_node *node)
411414
{
412415
struct xe_ggtt *ggtt = node->ggtt;
413-
struct xe_device *xe = tile_to_xe(ggtt->tile);
414416
bool bound;
415-
int idx;
416-
417-
bound = drm_dev_enter(&xe->drm, &idx);
418417

419418
mutex_lock(&ggtt->lock);
419+
bound = ggtt->flags & XE_GGTT_FLAGS_ONLINE;
420420
if (bound)
421421
xe_ggtt_clear(ggtt, node->base.start, node->base.size);
422422
drm_mm_remove_node(&node->base);
@@ -429,8 +429,6 @@ static void ggtt_node_remove(struct xe_ggtt_node *node)
429429
if (node->invalidate_on_remove)
430430
xe_ggtt_invalidate(ggtt);
431431

432-
drm_dev_exit(idx);
433-
434432
free_node:
435433
xe_ggtt_node_fini(node);
436434
}

drivers/gpu/drm/xe/xe_ggtt_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ struct xe_ggtt {
2828
/** @size: Total usable size of this GGTT */
2929
u64 size;
3030

31-
#define XE_GGTT_FLAGS_64K BIT(0)
31+
#define XE_GGTT_FLAGS_64K BIT(0)
32+
#define XE_GGTT_FLAGS_ONLINE BIT(1)
3233
/**
3334
* @flags: Flags for this GGTT
3435
* Acceptable flags:
3536
* - %XE_GGTT_FLAGS_64K - if PTE size is 64K. Otherwise, regular is 4K.
37+
* - %XE_GGTT_FLAGS_ONLINE - is GGTT online, protected by ggtt->lock
38+
* after init
3639
*/
3740
unsigned int flags;
3841
/** @scratch: Internal object allocation used as a scratch page */

0 commit comments

Comments
 (0)