[PATCH 3/8] drm/xe/ggtt: use drm_dev_enter to mark device section

Matthew Auld matthew.auld at intel.com
Mon Apr 29 12:14:39 UTC 2024


Device can be hotunplugged before we start destroying gem objects. In
such a case don't touch the GGTT entries, trigger any invalidations or
mess around with rpm.  This should already be taken care of when
removing the device, we just need to take care of dealing with the
software state, like removing the mm node.

References: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/1717
Signed-off-by: Matthew Auld <matthew.auld at intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi at intel.com>
---
 drivers/gpu/drm/xe/xe_ggtt.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index 0d541f55b4fc..7c05d3f7e1a4 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -8,6 +8,7 @@
 #include <linux/io-64-nonatomic-lo-hi.h>
 #include <linux/sizes.h>
 
+#include <drm/drm_drv.h>
 #include <drm/drm_managed.h>
 #include <drm/i915_drm.h>
 
@@ -433,18 +434,27 @@ int xe_ggtt_insert_bo(struct xe_ggtt *ggtt, struct xe_bo *bo)
 void xe_ggtt_remove_node(struct xe_ggtt *ggtt, struct drm_mm_node *node,
 			 bool invalidate)
 {
-	xe_pm_runtime_get_noresume(tile_to_xe(ggtt->tile));
-
-	mutex_lock(&ggtt->lock);
-	xe_ggtt_clear(ggtt, node->start, node->size);
-	drm_mm_remove_node(node);
-	node->size = 0;
-	mutex_unlock(&ggtt->lock);
-
-	if (invalidate)
-		xe_ggtt_invalidate(ggtt);
-
-	xe_pm_runtime_put(tile_to_xe(ggtt->tile));
+	struct xe_device *xe = tile_to_xe(ggtt->tile);
+	int idx;
+
+	if (drm_dev_enter(&xe->drm, &idx)) {
+		xe_pm_runtime_get_noresume(xe);
+		mutex_lock(&ggtt->lock);
+		xe_ggtt_clear(ggtt, node->start, node->size);
+		drm_mm_remove_node(node);
+		node->size = 0;
+		mutex_unlock(&ggtt->lock);
+
+		if (invalidate)
+			xe_ggtt_invalidate(ggtt);
+		xe_pm_runtime_put(xe);
+		drm_dev_exit(idx);
+	} else {
+		mutex_lock(&ggtt->lock);
+		drm_mm_remove_node(node);
+		node->size = 0;
+		mutex_unlock(&ggtt->lock);
+	}
 }
 
 void xe_ggtt_remove_bo(struct xe_ggtt *ggtt, struct xe_bo *bo)
-- 
2.44.0



More information about the Intel-xe mailing list