All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: skip PCI slot reset and resume if the device was not prepared
@ 2026-12-02  9:14 Yifan Zhang
  2026-12-02  9:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Yifan Zhang @ 2026-12-02  9:14 UTC (permalink / raw)
  To: amd-gfx
  Cc: Alexander.Deucher, Christian.Koenig, Perry.Yuan, Lejun Zhu,
	Yifan Zhang

From: Lejun Zhu <lejun.zhu@amd.com>

amdgpu_pci_error_detected() takes the reset domain lock and halts the
device only when it votes PCI_ERS_RESULT_NEED_RESET. For a frozen error
on an XGMI hive member without link reset support it logs "No support
for XGMI hive yet..." and returns PCI_ERS_RESULT_DISCONNECT without doing
either.

The PCI core merges a DISCONNECT and a NEED_RESET vote into NEED_RESET
and then calls slot_reset() on every device below the port, including
the one that voted DISCONNECT:

  amdgpu 0000:90:00.0: amdgpu: PCI error: detected callback!!
  amdgpu 0000:90:00.0: amdgpu: pci_channel_io_frozen: state(2)!!
  amdgpu 0000:90:00.0: amdgpu: No support for XGMI hive yet...
  amdgpu 0000:90:00.0: amdgpu: PCI error: slot reset callback!!
  amdgpu 0000:90:00.0: amdgpu: PCIe error recovery failed, err:-62

amdgpu_pci_slot_reset() tries to recover the hive although nothing was
halted. When that fails it calls amdgpu_device_recovery_put_reset_lock(),
which is an up_write() on a reset domain rwsem that nobody holds. This
corrupts the rwsem count, and every later down_read() or down_write() on
the reset domain blocks forever. That affects GPU recovery after a job
timeout, AMDGPU_INFO_READ_MMR_REG, RAS EEPROM access and other users, on
all devices of the hive. amdgpu_pci_resume() releases the lock in the
same unconditional way.

Record in the PCIe reset context that error_detected() prepared the
device, which means the PCI error path holds the reset lock for it.
Without that, slot_reset() returns PCI_ERS_RESULT_DISCONNECT before it
touches the device or the lock, and resume() does nothing.

Devices which vote NEED_RESET take the lock as before, their flow is
unchanged.

Fixes: 785c536c31c0 ("drm/amdgpu: Release reset locks during failures")
Co-authored-by: Yifan Zhang <yifan1.zhang@amd.com>
Signed-off-by: Yifan Zhang <yifan1.zhang@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 24 ++++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index d6caf06c61e6..0c1f6b96b42b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -589,6 +589,11 @@ struct amdgpu_pcie_reset_ctx {
 	bool in_link_reset;
 	bool occurs_dpc;
 	bool audio_suspended;
+	/*
+	 * Set when error_detected() took the reset lock and halted the device,
+	 * cleared when slot_reset() or resume() release the lock again.
+	 */
+	bool reset_prepared;
 	struct pci_dev *swus;
 	struct pci_saved_state *swus_pcistate;
 	struct pci_saved_state *swds_pcistate;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index ed632757e78d..5bb18065a471 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -6336,6 +6336,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_sta
 		amdgpu_device_recovery_get_reset_lock(adev, &device_list);
 		amdgpu_device_halt_activities(adev, NULL, &reset_context, &device_list,
 					      hive, false);
+		adev->pcie_reset_ctx.reset_prepared = true;
 		if (hive)
 			mutex_unlock(&hive->hive_lock);
 		return PCI_ERS_RESULT_NEED_RESET;
@@ -6392,6 +6393,19 @@ pci_ers_result_t amdgpu_pci_slot_reset(struct pci_dev *pdev)
 
 	dev_info(adev->dev, "PCI error: slot reset callback!!\n");
 
+	/*
+	 * The PCI core calls slot_reset() on every device below the port as
+	 * soon as one of them voted NEED_RESET, also on devices which did not
+	 * vote NEED_RESET in error_detected(). Such a device was not halted
+	 * and does not hold the reset lock, so do not try to recover it and
+	 * do not release the lock.
+	 */
+	if (!adev->pcie_reset_ctx.reset_prepared) {
+		dev_warn(adev->dev,
+			 "PCI error: device not prepared for reset, skip slot reset\n");
+		return PCI_ERS_RESULT_DISCONNECT;
+	}
+
 	memset(&reset_context, 0, sizeof(reset_context));
 	INIT_LIST_HEAD(&device_list);
 	hive = amdgpu_get_xgmi_hive(adev);
@@ -6465,6 +6479,7 @@ pci_ers_result_t amdgpu_pci_slot_reset(struct pci_dev *pdev)
 				amdgpu_device_unset_mp1_state(tmp_adev);
 		}
 		amdgpu_device_recovery_put_reset_lock(adev, &device_list);
+		adev->pcie_reset_ctx.reset_prepared = false;
 	}
 
 	if (hive) {
@@ -6492,8 +6507,12 @@ void amdgpu_pci_resume(struct pci_dev *pdev)
 
 	dev_info(adev->dev, "PCI error: resume callback!!\n");
 
-	/* Only continue execution for the case of pci_channel_io_frozen */
-	if (adev->pci_channel_state != pci_channel_io_frozen)
+	/*
+	 * Only continue execution for the case of pci_channel_io_frozen, and
+	 * only if error_detected() prepared the device and took the reset lock
+	 */
+	if (adev->pci_channel_state != pci_channel_io_frozen ||
+	    !adev->pcie_reset_ctx.reset_prepared)
 		return;
 
 	INIT_LIST_HEAD(&device_list);
@@ -6512,6 +6531,7 @@ void amdgpu_pci_resume(struct pci_dev *pdev)
 	amdgpu_device_sched_resume(&device_list, NULL, NULL);
 	amdgpu_device_gpu_resume(adev, &device_list, false);
 	amdgpu_device_recovery_put_reset_lock(adev, &device_list);
+	adev->pcie_reset_ctx.reset_prepared = false;
 
 	if (hive) {
 		mutex_unlock(&hive->hive_lock);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdgpu: skip PCI slot reset and resume if the device was not prepared
  2026-12-02  9:14 [PATCH] drm/amdgpu: skip PCI slot reset and resume if the device was not prepared Yifan Zhang
@ 2026-12-02  9:26 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02  9:26 UTC (permalink / raw)
  To: Yifan Zhang, amd-gfx

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] drm/amdgpu: wrong device used for KFD init in
  amdgpu_device_gpu_resume() [1]
--

commit 117b3201e4109fecb8f7e0d137a2aaccfd1dfee9
Author: Lejun Zhu <lejun.zhu@amd.com>

drm/amdgpu: skip PCI slot reset and resume if the device was not prepared

This commit tracks whether amdgpu_pci_error_detected() halted the device
and acquired the reset domain lock so that amdgpu_pci_slot_reset() and
amdgpu_pci_resume() do not attempt recovery or unlock a reset domain lock
they do not hold.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 7cf3a4cbac27c..b2889f59be291 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

[ ... ]

> @@ -6467,6 +6486,7 @@ void amdgpu_pci_resume(struct pci_dev *pdev)
>  	amdgpu_device_sched_resume(&device_list, NULL, NULL);
>  	amdgpu_device_gpu_resume(adev, &device_list, false);
>  	amdgpu_device_recovery_put_reset_lock(adev, &device_list);
> +	adev->pcie_reset_ctx.reset_prepared = false;

[Severity: High]
This problem wasn't introduced by this patch, but in
amdgpu_device_gpu_resume() [1], should the KFD initialization check
and amdgpu_amdkfd_device_init() call use the loop iterator tmp_adev instead
of adev?

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:amdgpu_device_gpu_resume() {
	...
	list_for_each_entry(tmp_adev, device_list, reset_list) {
		if (!need_emergency_restart && !amdgpu_sriov_vf(tmp_adev))
			amdgpu_amdkfd_post_reset(tmp_adev);

		if (!adev->kfd.init_complete)
			amdgpu_amdkfd_device_init(adev);
	...
}

In a multi-GPU reset recovery, checking and initializing adev on each
iteration leaves KFD uninitialized on any other device in device_list
where kfd.init_complete is false.

[1] https://sashiko.dev/#/bug/linux-5cf51b39-dfd5-4eaf-89c5-a3b47f0fd56b

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202091435.3183770-1-yifan1.zhang@amd.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  9:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  9:14 [PATCH] drm/amdgpu: skip PCI slot reset and resume if the device was not prepared Yifan Zhang
2026-12-02  9:26 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.