xe_device_remove() calls xe_display_unregister() and then
xe_bo_pci_dev_remove_all(), which drops all DMA mappings by evicting
every bo. Framebuffers pinned for scanout via ttm_bo_pin() are on the
unevictable list and are not on the xe pinned lists, so they rely on
drm_atomic_helper_shutdown() in intel_display_driver_unregister() to be
unpinned first.

However, the shutdown commit unpins the old plane state from the
asynchronous cleanup work (intel_atomic_cleanup_work()), which is not
flushed until intel_display_driver_remove() runs from a devm action,
after xe_device_remove(). A scanout bo can therefore still be pinned
when xe_bo_pci_dev_remove_all() runs and keep its DMA mapping past
device removal. Unmapping it on final release, after the pci device has
left its IOMMU group, dereferences a NULL iommu group.

Flush the cleanup work in xe_display_unregister() so all framebuffers are
unpinned before the bos are evicted.

Fixes: 3cbb651117ff ("drm/xe/bo: Add a bo remove callback")
Cc: Thomas Hellström <[email protected]>
Cc: Matthew Auld <[email protected]>
Cc: Jani Nikula <[email protected]>
Cc: [email protected] # v6.16+
Signed-off-by: Matthew Brost <[email protected]>
---
 drivers/gpu/drm/xe/display/xe_display.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/xe/display/xe_display.c 
b/drivers/gpu/drm/xe/display/xe_display.c
index b1a6008bf15c..68d29d78dc8b 100644
--- a/drivers/gpu/drm/xe/display/xe_display.c
+++ b/drivers/gpu/drm/xe/display/xe_display.c
@@ -155,6 +155,14 @@ void xe_display_unregister(struct xe_device *xe)
 
        intel_display_driver_runtime_pm_disable(display);
        intel_display_driver_unregister(display);
+
+       /*
+        * The shutdown commit unpins the framebuffers from the asynchronous
+        * cleanup work. Flush it so they are unpinned, and thus visible to
+        * the eviction in xe_bo_pci_dev_remove_all(), before the device
+        * is removed.
+        */
+       intel_display_flush_cleanup_work(display);
 }
 
 void xe_display_shutdown(struct xe_device *xe)
-- 
2.34.1

Reply via email to