From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2490D606A322 for ; Thu, 3 Dec 2026 10:47:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nQCfDP8e Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E02B41127BB; Thu, 3 Dec 2026 10:47:53 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1E7B51127C0; Thu, 3 Dec 2026 10:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796294868; x=1827830868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EXwI4alRa9W+UW7D+GYBolrHPA1S0JthdFzwlJvWG24=; b=nQCfDP8eWy5luHkSSAmjVP0TAMyjnFYEH+ix5s0RB30qYUT7YfpBEouM riltf+xAgoFG2XYJ4/vVDgZosGHdd+xMTlfzcOHqornHX4Li3MEBIIkKd I3F5kcwgO5LCM4mbm5n5wu585VN6MLlAA+rXzV+0byH0oVP7BYM1G1e9U oOXAUQDT5YdHBsnezJvE5jJUq+/311GGoiqKJa21N8L1SzTGfmvdMOzvC M+NbX93JibjA9M7UfwJ4QvwuN2++0o/9HP5xoQMNshXl9DdnYb1rqHqTW xJmtk+gixNmKj9MDgFkFheEnhpcfEOVUvbnZxENXOQ36maXn82h7C+i16 w==; X-CSE-ConnectionGUID: oDnBkD5ySb6TKjL336TqiQ== X-CSE-MsgGUID: FIWrHBSZROSOn4mPESgsGA== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5161228" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5161228" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 02:47:48 -0800 X-CSE-ConnectionGUID: eIM66KdSTASMeBMnbv5hlg== X-CSE-MsgGUID: Ki1bkIfMSUuhCwNjzex7kg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="13761696" Received: from ettammin-mobl3.ger.corp.intel.com (HELO fedora) ([10.245.244.105]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 02:47:46 -0800 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= To: intel-xe@lists.freedesktop.org Cc: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Auld , Satyanarayana K V P , Matthew Brost , Rodrigo Vivi , stable@vger.kernel.org, Natalie Vock , Arun Pravin , DRI-devel Subject: [PATCH v3 1/3] drm/xe: Undo pinned BO eviction on suspend failure Date: Thu, 3 Dec 2026 11:47:13 +0100 Message-ID: <20261203104715.270111-2-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203104715.270111-1-thomas.hellstrom@linux.intel.com> References: <20261203104715.270111-1-thomas.hellstrom@linux.intel.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Pinned VRAM BOs are evicted at suspend by copying their contents to a backup object, while the BOs themselves remain in VRAM. Pinned kernel BOs are additionally moved to the evicted lists. If suspend fails after some or all pinned BOs have been evicted, either in xe_bo_evict_all() itself, for example due to -ENOMEM when allocating a backup object, or in a later suspend step, nothing undoes this, and the device continues operating with the stale backups. That causes: - A subsequent suspend skipping the BOs on the evicted lists, and the following resume overwriting their VRAM contents with stale data. - The backup objects of pinned external BOs being leaked through a reference cycle when the BOs are later unpinned. - A subsequent PM notifier prepare step hitting the xe_assert(xe, !bo->backup_obj) in xe_bo_notifier_prepare_pinned(). This has been an issue since the initial driver. Before commit 86f69c26113c ("drm/xe: use backup object for pinned save/restore"), pinned BOs were instead moved out of VRAM, and with a failed suspend, the GuC would continue to access the freed VRAM through the GGTT while the CPU would access the moved copy. This patch only addresses the backup object scheme. Add xe_bo_evict_all_undo() that drops the backup objects created by the eviction and moves the pinned kernel BOs back to the present lists, and call it on failure in xe_bo_evict_all() and on failures after xe_bo_evict_all() in the system- and runtime suspend paths. Backup objects pre-allocated by the PM notifier are kept and released as usual by the notifier. v3: - Rebase onto latest drm-tip Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs") Fixes: 86f69c26113c ("drm/xe: use backup object for pinned save/restore") Cc: Matthew Auld Cc: Satyanarayana K V P Cc: Matthew Brost Cc: Rodrigo Vivi Cc: intel-xe@lists.freedesktop.org Cc: # v6.16+ Signed-off-by: Thomas Hellström --- drivers/gpu/drm/xe/xe_bo.c | 26 +++++++++++++++++++++ drivers/gpu/drm/xe/xe_bo.h | 1 + drivers/gpu/drm/xe/xe_bo_evict.c | 39 ++++++++++++++++++++++++++++---- drivers/gpu/drm/xe/xe_bo_evict.h | 1 + drivers/gpu/drm/xe/xe_device.c | 5 +++- drivers/gpu/drm/xe/xe_pm.c | 5 +++- 6 files changed, 71 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index c89b39b503fe..af7365581f09 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -1786,6 +1786,32 @@ int xe_bo_evict_pinned(struct xe_bo *bo) return ret; } +/** + * xe_bo_evict_pinned_undo() - Undo a pinned VRAM object eviction + * @bo: The buffer object for which to undo the eviction. + * + * Drop the backup object created by xe_bo_evict_pinned(), if any. Backup + * objects pre-allocated by xe_bo_notifier_prepare_pinned() are kept and + * released by xe_bo_notifier_unprepare_pinned(). Only valid if the VRAM + * contents of @bo were preserved since the eviction. + * + * Return: Always returns 0. + */ +int xe_bo_evict_pinned_undo(struct xe_bo *bo) +{ + struct xe_bo *backup; + + xe_bo_lock(bo, false); + backup = bo->backup_obj; + if (backup && !xe_bo_is_pinned(backup)) { + bo->backup_obj = NULL; + xe_bo_put(backup); + } + xe_bo_unlock(bo); + + return 0; +} + /** * xe_bo_restore_pinned() - Restore a pinned VRAM object * @bo: The buffer object to move. diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h index 6a1ae07d2904..bb3cb90cbfc4 100644 --- a/drivers/gpu/drm/xe/xe_bo.h +++ b/drivers/gpu/drm/xe/xe_bo.h @@ -440,6 +440,7 @@ int xe_bo_migrate(struct xe_bo *bo, u32 mem_type, struct ttm_operation_ctx *ctc, int xe_bo_evict(struct xe_bo *bo, struct drm_exec *exec); int xe_bo_evict_pinned(struct xe_bo *bo); +int xe_bo_evict_pinned_undo(struct xe_bo *bo); int xe_bo_notifier_prepare_pinned(struct xe_bo *bo); int xe_bo_notifier_unprepare_pinned(struct xe_bo *bo); int xe_bo_restore_pinned(struct xe_bo *bo); diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c index ab7cba57fb3c..61986422772c 100644 --- a/drivers/gpu/drm/xe/xe_bo_evict.c +++ b/drivers/gpu/drm/xe/xe_bo_evict.c @@ -227,12 +227,43 @@ int xe_bo_evict_all(struct xe_device *xe) for_each_tile(tile, xe, id) xe_tile_migrate_wait(tile); + if (!ret) + ret = xe_bo_apply_to_pinned(xe, &xe->pinned.early.kernel_bo_present, + &xe->pinned.early.evicted, + xe_bo_evict_pinned); + if (ret) - return ret; + xe_bo_evict_all_undo(xe); + + return ret; +} + +/** + * xe_bo_evict_all_undo - undo the pinned BO eviction of xe_bo_evict_all() + * @xe: xe device + * + * Drop the backups of pinned BOs created by xe_bo_evict_all() and move + * evicted pinned kernel BOs back to the present lists, without restoring + * their contents. Non-pinned user BOs are left evicted. + * + * This function should be called if suspend fails after xe_bo_evict_all() + * while VRAM contents are still preserved, so that a subsequent suspend + * doesn't skip the BOs, and a subsequent resume doesn't restore stale + * contents. + */ +void xe_bo_evict_all_undo(struct xe_device *xe) +{ + (void)xe_bo_apply_to_pinned(xe, &xe->pinned.late.external, + &xe->pinned.late.external, + xe_bo_evict_pinned_undo); + + (void)xe_bo_apply_to_pinned(xe, &xe->pinned.late.evicted, + &xe->pinned.late.kernel_bo_present, + xe_bo_evict_pinned_undo); - return xe_bo_apply_to_pinned(xe, &xe->pinned.early.kernel_bo_present, - &xe->pinned.early.evicted, - xe_bo_evict_pinned); + (void)xe_bo_apply_to_pinned(xe, &xe->pinned.early.evicted, + &xe->pinned.early.kernel_bo_present, + xe_bo_evict_pinned_undo); } static int xe_bo_map_ggtt(struct xe_bo *bo) diff --git a/drivers/gpu/drm/xe/xe_bo_evict.h b/drivers/gpu/drm/xe/xe_bo_evict.h index aabba06f0abf..6dbdab3ebb66 100644 --- a/drivers/gpu/drm/xe/xe_bo_evict.h +++ b/drivers/gpu/drm/xe/xe_bo_evict.h @@ -9,6 +9,7 @@ struct xe_device; int xe_bo_evict_all(struct xe_device *xe); +void xe_bo_evict_all_undo(struct xe_device *xe); int xe_bo_evict_all_user(struct xe_device *xe); int xe_bo_notifier_prepare_all_pinned(struct xe_device *xe); void xe_bo_notifier_unprepare_all_pinned(struct xe_device *xe); diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c index af96394b4b31..aae30237d86c 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -1455,7 +1455,7 @@ int xe_device_suspend(struct xe_device *xe, bool hibernate, bool flr) for_each_gt(gt, xe, id) { err = xe_gt_suspend(gt); if (err) - goto err_display; + goto err_evict; } } @@ -1474,6 +1474,9 @@ int xe_device_suspend(struct xe_device *xe, bool hibernate, bool flr) return 0; +err_evict: + if (xe_pm_needs_bo_evict(xe, hibernate)) + xe_bo_evict_all_undo(xe); err_display: xe_display_pm_resume(xe); xe_pxp_pm_resume(xe->pxp); diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c index e3eb4118d461..00d321a7d646 100644 --- a/drivers/gpu/drm/xe/xe_pm.c +++ b/drivers/gpu/drm/xe/xe_pm.c @@ -589,7 +589,7 @@ int xe_pm_runtime_suspend(struct xe_device *xe) for_each_gt(gt, xe, id) { err = xe->d3cold.allowed ? xe_gt_suspend(gt) : xe_gt_runtime_suspend(gt); if (err) - goto out_resume; + goto out_evict; } for_each_gt(gt, xe, id) @@ -605,6 +605,9 @@ int xe_pm_runtime_suspend(struct xe_device *xe) xe_pm_write_callback_task(xe, NULL); return 0; +out_evict: + if (xe->d3cold.allowed) + xe_bo_evict_all_undo(xe); out_resume: xe_pm_update_pme_enabled(xe, false); xe_display_pm_runtime_resume(xe); -- 2.56.1