From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796288034; b=cVw02DjAlI9SZLXyoPvsGATJClSjprm5bAqCJEKd4ZynwVWCsvCWYrrajhfCASK1CDIT +bQCZFWBCCXDXTFIFNPp8Kn9h68+y1pykw4IELrElvqXgNP9Xn/KUGV0vdkP3GE8htrt7 XkoW4AN971kay89qmsFoce6Ad0q5Xe9B0U0EP0PqdZovoO+CVThvpPxBASMErBvvxcTTA Dic9MF0msvgF434s5xlzH0ASkDYyqWCMuHiH6FV4ghgadd9bhSbt73O/IefxhzFvjkbjA 9+WyDMS2TyE97yyz1InDwdXfeW0Yhtivfw35F4sB2RIWsf627DZqmLW1XKYiFME3xQQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288034; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=+WAumLBHiCAohsukAQUtkH4gAvfM2yaYYCNmkkh1SqE=; b=4CyrpP2t/fSLfIbfLuSoh/UDlBZJrN2d9TCx8lR9uKWLbgABGQNPdoNJ1o6ZKdzJ8gZC LrXD8dzVg21RVp3FbJ712BjYuy6Imc+3J87KD2CQdm85zDkuPzykBZEE57dEnkG1/B+3v yebZdHlSqTqOB5nKMGMg2U+dcaFixnLh/c26cL9D1XXl8ZDMdCoWpzT1zxGhHS7IvtPti 1e8kMgyRTdOypfQDfGYgGEtTlq+3FOWSrmO65TppwhhTfniXBS7pCbecr0fAxaqhWPByv 0JcD+J0SQFnU/tebm1I/88hzjqeooAgzL4JWX/3BBdFX3cDdSfX0P+sZ8AjC/Q6vTDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Kzodjy+0; arc=none smtp.remote-ip=192.198.163.18 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B8ED606A322 for ; Thu, 3 Dec 2026 08:53:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4B8ED606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com 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=Kzodjy+0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796288033; x=1827824033; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+WAumLBHiCAohsukAQUtkH4gAvfM2yaYYCNmkkh1SqE=; b=Kzodjy+0/jWknH6sKBDBDtbvtAxK4KfIHl3o2EJc+Zp8lqzeJIm0K0UV gI209GNNODVnK6HZLfeap46g0I2AsK/M+MkLJPFWuK6+DIXOT+aUbyX6t npdkIMk7zkz+qZiWSy3zSzmgZB/VrN3Cw3eJlk7kBPoVPK+3tCQ4h9xlW QcEm8emkvQWCqamTudo7xHoxj0T7hd/z+PjSBZhjPHpbViA8umHJTKS9r NxE+BEUaQQTaDGPZDJqJPTD28p2JVwORfBnmpqUTiaMD+XN+nigk1pdrl NTzVI85E8Et9C7vECCJSw9ZIle9LHc3CXE3yAKSyWaIxQSfusdm9sJedT Q==; X-CSE-ConnectionGUID: vSmMhYULRqujXzOPxMu7Fg== X-CSE-MsgGUID: MdN95MccRlOf9wZYXpqO5g== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5248378" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5248378" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 00:53:52 -0800 X-CSE-ConnectionGUID: aIZ0eU/zSDqlrDgR3M2qhQ== X-CSE-MsgGUID: FBEbXF5DQoWPqTtYWwDr0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="14077757" Received: from kniemiec-mobl1.ger.corp.intel.com (HELO fedora) ([10.245.244.75]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 00:53:51 -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 v2 1/3] drm/xe: Undo pinned BO eviction on suspend failure Date: Thu, 3 Dec 2026 09:53:19 +0100 Message-ID: <20261203085321.235694-2-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203085321.235694-1-thomas.hellstrom@linux.intel.com> References: <20261203085321.235694-1-thomas.hellstrom@linux.intel.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. 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 86de5f183c0a..6d40ab29d59e 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -1444,7 +1444,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; } } @@ -1460,6 +1460,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 f73f68bd449b..103290fd6445 100644 --- a/drivers/gpu/drm/xe/xe_pm.c +++ b/drivers/gpu/drm/xe/xe_pm.c @@ -588,7 +588,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; } xe_irq_suspend(xe); @@ -601,6 +601,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