xe_bo_vm_access() may acquire a runtime PM reference and access a BO during PCI error recovery, after a permanent wedge or during device unplug.
Use xe_device_io_get() to protect against unplug, PCI error recovery and permanent wedging. Keep both protections until the runtime PM reference has been released. Return -EIO for a permanent wedge, -ECANCELED during PCI error recovery and -ENODEV after device unplug. v2: - Replace the runtime-PM scoped guard with explicit get/put calls to avoid mixing scope-based and goto-based cleanup. (Sashiko) - Replace the private VRAM SRCU lock with the common device I/O gate. - Preserve -EIO for BO access after a permanent wedge. 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/xe_bo.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 73dcd397dc13..5372bc07aa4e 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -2235,9 +2235,18 @@ static int xe_bo_vm_access(struct vm_area_struct *vma, unsigned long addr, struct ttm_buffer_object *ttm_bo = vma->vm_private_data; struct xe_bo *bo = ttm_to_xe_bo(ttm_bo); struct xe_device *xe = xe_bo_device(bo); + int idx, ret; - guard(xe_pm_runtime)(xe); - return ttm_bo_vm_access(vma, addr, buf, len, write); + ret = xe_device_io_get(xe, &idx); + if (ret) + return ret == -ECANCELED && xe_device_wedged(xe) ? -EIO : ret; + + xe_pm_runtime_get(xe); + ret = ttm_bo_vm_access(vma, addr, buf, len, write); + xe_pm_runtime_put(xe); + + xe_device_io_put(idx); + return ret; } /** -- 2.43.0
