From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.13 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796294869; b=zYaq2/avxSzomUH7cmmc7o2QDQgbRTvWwI30C7fcgMdkFMt5LPO9Z6psK2HkByQ14quQ +huV4lZCzSBRKAyu5eHHDrKpJUboshV78RT/9yJdVBzdIPOUUmn93Znz7XhltdVGEwMT4 NbmHkEqO4eTspruhLq3hBt9sxTwZKnQIcQFJ3BjutPaNvmJAUtUor0GMAgNfU5EfqQgRt BQl160e5LCcFLIuDyoXHEKokYfgUHOx6gTLdL5uhIgGQEtW66BJc727jjEyjSwVrulnYy kpibWkkapg/KD4b0ZlAZpkafq9umzEnXrDRxJ77yuTiRFEUxYvF+FFzs+qEDz4uqM8A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796294869; 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=EXwI4alRa9W+UW7D+GYBolrHPA1S0JthdFzwlJvWG24=; b=qPzVX4v4AHuMdxjRoa8ARVurRtaStRllMsQd6baQhV5PdWshBQC0DWeuJnxFIMJIQ6H2 J4FyVc/i2fr8husUttnlByqhV+h2EWW5lOOdKPKJ8+BSPEV/vElRup/jZo7vTXidINM6E ljpxuDSJm53HttErwyKhtakS1vBleamQj6/mi9pti8ZkH9SjJVFCUEQ89BqWCp0M6wDZh HHh+msnk9oQBsrsbxUNsGU+eF2uQdAmvxxrDFVp94sepkpXsJtVjoaYs8GZFVT4Z06ih7 K1N3oI6AtJ5KCmiKIeCvVfSoJsu0xTLs97Hls46IuDaAMuAT+C3cbhxVIVj+u7tiUWg== 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=g4kgw21U; arc=none smtp.remote-ip=198.175.65.13 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 6140D606A333 for ; Thu, 3 Dec 2026 10:47:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6140D606A333 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=g4kgw21U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796294869; x=1827830869; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EXwI4alRa9W+UW7D+GYBolrHPA1S0JthdFzwlJvWG24=; b=g4kgw21UIPrBd+gBztCsptBYLY6nJYwKSgkBFaEpbsyPR+CclhH2IIzh 0aiTd3KbXYELlYj2em+2qjGYKJpb/LU1dHHnX+qKwPv09YoIal047hm/S PNZFRMPcwPXEVbTlGsebdoqXugHMNyNP+7QkzGmkieyrHRZVvJp4hs04n p2q73BKEw/SXs6M7zxQOx1OMY5X2s7Yg+6WoZ1fMgSx78rfMA0RjDIsNO ivlUVQC+z4E8dTuZf8Nr8+IS7kOEZiiVkccp5nhO7QZFvm0rr3Yplp9LZ cbUKCqIyG2Z7KYQOz16qcgNf+HBTmtJrLsYMh7dovORQrUTc9nu3mbJ69 Q==; X-CSE-ConnectionGUID: xWNTNgZBSV6wsMQpmLKfyg== X-CSE-MsgGUID: BJwMbKshSaGfWIDQcuKljg== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5161229" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5161229" 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-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. 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