A permanently wedged device must stop interrupt and DMA activity before userspace is notified that recovery is required.
Run the sleepable isolation steps from the wedge worker. Shut down and unregister the display, invalidate VRAM mappings, suspend interrupts and clear PCI bus mastering before sending the event. GTs are declared wedged before the work is queued, so pending fences are signalled before the worker waits for fault-side SRCU readers. Track display and isolation state so later teardown does not repeat these steps. Display shutdown already disables display power, so skip the runtime PM disable when unregister follows shutdown. System suspend may see the wedge flag before the worker is queued. Use a completion to close this window and flush the worker before skipping normal device suspend. The IRQ serialization keeps a racing resume from enabling interrupts after isolation. For a wedged device, resume restores PCI configuration and clears bus mastering. Do not call pci_enable_device() because suspend did not take the matching disable reference. Cc: Matthew Brost <[email protected]> Cc: Thomas Hellström <[email protected]> Cc: Himal Prasad Ghimiray <[email protected]> Cc: Rodrigo Vivi <[email protected]> Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Arvind Yadav <[email protected]> --- drivers/gpu/drm/xe/display/xe_display.c | 18 +++++++++--- drivers/gpu/drm/xe/xe_device.c | 38 +++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_device_types.h | 9 ++++++ drivers/gpu/drm/xe/xe_pci.c | 23 ++++++++++++++- 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/xe/display/xe_display.c b/drivers/gpu/drm/xe/display/xe_display.c index 7b25c0814674..ce9ebc6701ff 100644 --- a/drivers/gpu/drm/xe/display/xe_display.c +++ b/drivers/gpu/drm/xe/display/xe_display.c @@ -150,21 +150,28 @@ void xe_display_register(struct xe_device *xe) { struct intel_display *display = xe->display; - if (!xe->info.probe_display) + if (!xe->info.probe_display || xe->display_registered) return; intel_display_driver_register(display); intel_display_driver_runtime_pm_enable(display); + + xe->display_registered = true; } void xe_display_unregister(struct xe_device *xe) { struct intel_display *display = xe->display; - if (!xe->info.probe_display) + if (!xe->info.probe_display || !xe->display_registered) return; - intel_display_driver_runtime_pm_disable(display); + /* Make display unregister idempotent. */ + xe->display_registered = false; + + if (!xe->display_shutdown) + intel_display_driver_runtime_pm_disable(display); + intel_display_driver_unregister(display); } @@ -172,7 +179,8 @@ void xe_display_shutdown(struct xe_device *xe) { struct intel_display *display = xe->display; - if (!xe->info.probe_display) + if (!xe->info.probe_display || !xe->display_registered || + xe->display_shutdown) return; intel_display_driver_shutdown(display); @@ -180,6 +188,8 @@ void xe_display_shutdown(struct xe_device *xe) intel_opregion_suspend(display, PCI_D3cold); intel_dmc_suspend(display); + + xe->display_shutdown = true; } void xe_display_shutdown_late(struct xe_device *xe) diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c index 98ef5123c841..101cfa8e2102 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -538,6 +538,7 @@ int xe_device_init_early(struct xe_device *xe) int err; INIT_WORK(&xe->wedged.work, xe_device_wedged_work); + init_completion(&xe->wedged.prepared); xe->wedged.reported_method = ~0UL; err = ttm_device_init(&xe->ttm, &xe_ttm_funcs, xe->drm.dev, @@ -958,14 +959,44 @@ static int xe_debug_page_size_alloc_ctrl_init(struct xe_device *xe) } #endif +/* + * Isolate a permanently wedged device. + * + * May sleep and must be called from process context. + */ +static void xe_device_wedged_isolate(struct xe_device *xe) +{ + /* + * Wait until xe_device_declare_wedged() has finished scanning GT + * submission state before isolating the device. + */ + wait_for_completion(&xe->wedged.prepared); + + if (!xe->wedged.isolated) { + xe_display_shutdown(xe); + xe_display_unregister(xe); + + /* + * Drain faults and unmap VRAM before disabling IRQs and + * DMA. + */ + xe_bo_wedged_invalidate_mmaps(xe); + + /* Drain handlers before preventing any further device DMA. */ + xe_irq_suspend(xe); + pci_clear_master(to_pci_dev(xe->drm.dev)); + + xe->wedged.isolated = true; + } +} + static void xe_device_wedged_work(struct work_struct *work) { struct xe_device *xe = container_of(work, struct xe_device, wedged.work); unsigned long method; - /* Drain faults and invalidate existing VRAM mappings. */ - xe_bo_wedged_invalidate_mmaps(xe); + xe_device_wedged_isolate(xe); /* Report at most one recovery method per worker invocation. */ method = READ_ONCE(xe->wedged.method); @@ -1556,6 +1587,9 @@ void xe_device_declare_wedged(struct xe_device *xe) READ_ONCE(xe->wedged.method) != READ_ONCE(xe->wedged.reported_method)) queue_work(xe->unordered_wq, &xe->wedged.work); + + if (first) + complete_all(&xe->wedged.prepared); } /** diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index dda4d9919ca6..508ba3872e72 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -6,6 +6,7 @@ #ifndef _XE_DEVICE_TYPES_H_ #define _XE_DEVICE_TYPES_H_ +#include <linux/completion.h> #include <linux/mutex.h> #include <linux/pci.h> #include <linux/srcu.h> @@ -113,6 +114,10 @@ struct xe_device { #if IS_ENABLED(CONFIG_DRM_XE_DISPLAY) /** @display: display device data, must be placed after drm device member */ struct intel_display *display; + /** @display_registered: Display userspace interfaces are registered */ + bool display_registered; + /** @display_shutdown: Display hardware shutdown has completed */ + bool display_shutdown; #endif /** @devcoredump: device coredump */ @@ -547,8 +552,12 @@ struct xe_device { bool inconsistent_reset; /** @wedged.work: Runs sleepable wedge handling */ struct work_struct work; + /** @wedged.prepared: First wedge declaration finished and work was queued */ + struct completion prepared; /** @wedged.reported_method: Last recovery method reported to userspace */ unsigned long reported_method; + /** @wedged.isolated: Terminal device isolation has completed */ + bool isolated; } wedged; /** @devres_group: devres group */ diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c index ab4da1d9a9f1..aaeb7d068175 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -1332,6 +1332,16 @@ static int xe_pci_suspend(struct device *dev) if (xe_survivability_mode_is_boot_enabled(xe)) return -EBUSY; + /* + * Wait until wedge work is queued, then wait for isolation to + * finish before skipping normal suspend. + */ + if (xe_device_wedged(xe)) { + wait_for_completion(&xe->wedged.prepared); + flush_work(&xe->wedged.work); + return 0; + } + err = xe_pm_suspend(xe); if (err) return err; @@ -1353,6 +1363,7 @@ static int xe_pci_suspend(struct device *dev) static int xe_pci_resume(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); + struct xe_device *xe = pdev_to_xe_device(pdev); int err; /* Give back the D3Cold decision to the runtime P M*/ @@ -1364,13 +1375,23 @@ static int xe_pci_resume(struct device *dev) pci_restore_state(pdev); + /* + * Suspend skipped PCI disable for an already isolated device. Avoid + * incrementing enable_cnt and clear bus mastering restored from the + * saved configuration. + */ + if (xe_device_wedged(xe)) { + pci_clear_master(pdev); + return 0; + } + err = pci_enable_device(pdev); if (err) return err; pci_set_master(pdev); - err = xe_pm_resume(pdev_to_xe_device(pdev)); + err = xe_pm_resume(xe); if (err) return err; -- 2.43.0
