Skip to content
/ linux Public

Commit 1e9e264

Browse files
mbrost05gregkh
authored andcommitted
drm/xe: Open-code GGTT MMIO access protection
commit 01f2557 upstream. 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: stable@vger.kernel.org Fixes: 919bb54 ("drm/xe: Fix missing runtime outer protection for ggtt_remove_node") Reviewed-by: Zhanjun Dong <zhanjun.dong@intel.com> Signed-off-by: Matthew Brost <matthew.brost@intel.com> Link: https://patch.msgid.link/20260310225039.1320161-8-zhanjun.dong@intel.com (cherry picked from commit 4f3a998a173b4325c2efd90bdadc6ccd3ad9a431) Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8613cca commit 1e9e264

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

drivers/gpu/drm/xe/xe_ggtt.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ static void dev_fini_ggtt(void *arg)
243243
{
244244
struct xe_ggtt *ggtt = arg;
245245

246+
scoped_guard(mutex, &ggtt->lock)
247+
ggtt->flags &= ~XE_GGTT_FLAGS_ONLINE;
246248
drain_workqueue(ggtt->wq);
247249
}
248250

@@ -301,6 +303,7 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
301303
if (err)
302304
return err;
303305

306+
ggtt->flags |= XE_GGTT_FLAGS_ONLINE;
304307
err = devm_add_action_or_reset(xe->drm.dev, dev_fini_ggtt, ggtt);
305308
if (err)
306309
return err;
@@ -334,13 +337,10 @@ static void xe_ggtt_initial_clear(struct xe_ggtt *ggtt)
334337
static void ggtt_node_remove(struct xe_ggtt_node *node)
335338
{
336339
struct xe_ggtt *ggtt = node->ggtt;
337-
struct xe_device *xe = tile_to_xe(ggtt->tile);
338340
bool bound;
339-
int idx;
340-
341-
bound = drm_dev_enter(&xe->drm, &idx);
342341

343342
mutex_lock(&ggtt->lock);
343+
bound = ggtt->flags & XE_GGTT_FLAGS_ONLINE;
344344
if (bound)
345345
xe_ggtt_clear(ggtt, node->base.start, node->base.size);
346346
drm_mm_remove_node(&node->base);
@@ -353,8 +353,6 @@ static void ggtt_node_remove(struct xe_ggtt_node *node)
353353
if (node->invalidate_on_remove)
354354
xe_ggtt_invalidate(ggtt);
355355

356-
drm_dev_exit(idx);
357-
358356
free_node:
359357
xe_ggtt_node_fini(node);
360358
}

drivers/gpu/drm/xe/xe_ggtt_types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ struct xe_ggtt {
2525
/** @size: Total size of this GGTT */
2626
u64 size;
2727

28-
#define XE_GGTT_FLAGS_64K BIT(0)
28+
#define XE_GGTT_FLAGS_64K BIT(0)
29+
#define XE_GGTT_FLAGS_ONLINE BIT(1)
2930
/**
3031
* @flags: Flags for this GGTT
3132
* Acceptable flags:
3233
* - %XE_GGTT_FLAGS_64K - if PTE size is 64K. Otherwise, regular is 4K.
34+
* - %XE_GGTT_FLAGS_ONLINE - is GGTT online, protected by ggtt->lock
35+
* after init
3336
*/
3437
unsigned int flags;
3538
/** @scratch: Internal object allocation used as a scratch page */

0 commit comments

Comments
 (0)