Skip to contentSkip to conversation

pds_core: AER handling

PATCH Applied Shannon Nelson 5 participants 10 messages Feb 16, 2024 – Aug 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover pds_core: AER handling

Add simple handlers for the PCI AER callbacks, and improve the reset handling.

Shannon Nelson (3):
pds_core: add simple AER handler
pds_core: delete VF dev on reset
pds_core: use pci_reset_function for health reset

 drivers/net/ethernet/amd/pds_core/auxbus.c | 18 ++++++++-
 drivers/net/ethernet/amd/pds_core/core.c   |  3 +-
 drivers/net/ethernet/amd/pds_core/core.h   |  3 --
 drivers/net/ethernet/amd/pds_core/main.c   | 47 ++++++++++++++++++++--
 4 files changed, 62 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 pds_core: add simple AER handler

Set up the pci_error_handlers error_detected and resume to be useful in handling AER events.

---
 drivers/net/ethernet/amd/pds_core/main.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/net/ethernet/amd/pds_core/main.c +24 -0
index 0050c5894563..e10451a5a89b 100644
@@ -45,6 +45,7 @@ static void pdsc_unmap_bars(struct pdsc *pdsc)
 	for (i = 0; i < PDS_CORE_BARS_MAX; i++) {
 		if (bars[i].vaddr)
 			pci_iounmap(pdsc->pdev, bars[i].vaddr);
+		bars[i].vaddr = NULL;
 	}
 }
 
@@ -512,10 +513,33 @@ void pdsc_reset_done(struct pci_dev *pdev)
 	pdsc_restart_health_thread(pdsc);
 }
 
+static pci_ers_result_t pdsc_pci_error_detected(struct pci_dev *pdev,
+						pci_channel_state_t error)
+{
+	if (error == pci_channel_io_frozen) {
+		pdsc_reset_prepare(pdev);
+		return PCI_ERS_RESULT_NEED_RESET;
+	}
+
+	return PCI_ERS_RESULT_NONE;
+}
+
+static void pdsc_pci_error_resume(struct pci_dev *pdev)
+{
+	struct pdsc *pdsc = pci_get_drvdata(pdev);
+
+	if (test_bit(PDSC_S_FW_DEAD, &pdsc->state))
+		pci_reset_function_locked(pdev);
+}
+
 static const struct pci_error_handlers pdsc_err_handler = {
 	/* FLR handling */
 	.reset_prepare      = pdsc_reset_prepare,
 	.reset_done         = pdsc_reset_done,
+
+	/* AER handling */
+	.error_detected     = pdsc_pci_error_detected,
+	.resume             = pdsc_pci_error_resume,
 };
 
 static struct pci_driver pdsc_driver = {
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH net-next 1/3] pds_core: add simple AER handler

Quoted 2 lines · Shannon Nelson

Set up the pci_error_handlers error_detected and resume to be useful in handling AER events.

The above was committed as d740f4be7cf0 ("pds_core: add simple AER handler").

Just noticed the following while inspecting the pci_error_handlers of this driver:

drivers/net/ethernet/amd/pds_core/main.c void pdsc_reset_done(struct pci_dev *pdev) · line 525

Quoted 10 lines
drivers/net/ethernet/amd/pds_core/main.c +10 -0
+static pci_ers_result_t pdsc_pci_error_detected(struct pci_dev *pdev,
+						pci_channel_state_t error)
+{
+	if (error == pci_channel_io_frozen) {
+		pdsc_reset_prepare(pdev);
+		return PCI_ERS_RESULT_NEED_RESET;
+	}
+
+	return PCI_ERS_RESULT_NONE;
+}

The ->error_detected() callback of this driver invokes pdsc_reset_prepare(), which unmaps BARs and calls pci_disable_device(), but there is no corresponding ->slot_reset() callback which would invoke pdsc_reset_done() to re-enable the device after reset recovery.

I don't have this hardware available for testing, hence do not feel comfortable submitting a fix. But this definitely looks broken.

Thanks,

Lukas

#3 lore raw

Re: [PATCH net-next 1/3] pds_core: add simple AER handler

Quoted 29 lines · Lukas Wunner

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 2 lines · Shannon Nelson

Set up the pci_error_handlers error_detected and resume to be useful in handling AER events.

The above was committed as d740f4be7cf0 ("pds_core: add simple AER handler").

Just noticed the following while inspecting the pci_error_handlers of this driver:

drivers/net/ethernet/amd/pds_core/main.c void pdsc_reset_done(struct pci_dev *pdev) · line 525

Quoted 10 lines
drivers/net/ethernet/amd/pds_core/main.c +10 -0
+static pci_ers_result_t pdsc_pci_error_detected(struct pci_dev *pdev,
+                                             pci_channel_state_t error)
+{
+     if (error == pci_channel_io_frozen) {
+             pdsc_reset_prepare(pdev);
+             return PCI_ERS_RESULT_NEED_RESET;
+     }
+
+     return PCI_ERS_RESULT_NONE;
+}

The ->error_detected() callback of this driver invokes pdsc_reset_prepare(), which unmaps BARs and calls pci_disable_device(), but there is no corresponding ->slot_reset() callback which would invoke pdsc_reset_done() to re-enable the device after reset recovery.

Quoted 2 lines

I don't have this hardware available for testing, hence do not feel comfortable submitting a fix. But this definitely looks broken.

Hi Lukas,

Thanks for the note. It's been a bit since I have looked at this, but I believe that it's working in the following way:

1. pds_core's pci_error_handlers.error_detected callback returns PCI_ERS_RESULT_NEED_RESET
2. status is initialized to PCI_ERS_RESULT_RECOVERED in the pci core and since pds_core doesn't have a slot_reset callback then status remains PCI_ERS_RESULT_RECOVERED
3. pds_core's pci_error_handlers.resume callback is called, which will attempt reset/recover the device to a functional state

I also know that, at the very least, Shannon tested this when adding it to the driver.

Let me know if you still think otherwise.

Thanks again for the feedback,

Brett

#4 lore raw

Re: [PATCH net-next 1/3] pds_core: add simple AER handler

Quoted 33 lines · Brett Creeley
Quoted 29 lines · Lukas Wunner

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 2 lines · Shannon Nelson

Set up the pci_error_handlers error_detected and resume to be useful in handling AER events.

The above was committed as d740f4be7cf0 ("pds_core: add simple AER handler").

Just noticed the following while inspecting the pci_error_handlers of this driver:

drivers/net/ethernet/amd/pds_core/main.c void pdsc_reset_done(struct pci_dev *pdev) · line 525

Quoted 10 lines
drivers/net/ethernet/amd/pds_core/main.c +10 -0
+static pci_ers_result_t pdsc_pci_error_detected(struct pci_dev *pdev,
+ pci_channel_state_t error)
+{
+     if (error == pci_channel_io_frozen) {
+             pdsc_reset_prepare(pdev);
+             return PCI_ERS_RESULT_NEED_RESET;
+     }
+
+     return PCI_ERS_RESULT_NONE;
+}

The ->error_detected() callback of this driver invokes pdsc_reset_prepare(), which unmaps BARs and calls pci_disable_device(), but there is no corresponding ->slot_reset() callback which would invoke pdsc_reset_done() to re-enable the device after reset recovery.

Quoted 2 lines

I don't have this hardware available for testing, hence do not feel comfortable submitting a fix.  But this definitely looks broken.

Quoted 7 lines

Hi Lukas,

Thanks for the note. It's been a bit since I have looked at this, but I believe that it's working in the following way:

1. pds_core's pci_error_handlers.error_detected callback returns PCI_ERS_RESULT_NEED_RESET
2. status is initialized to PCI_ERS_RESULT_RECOVERED in the pci core and since pds_core doesn't have a slot_reset callback then status remains PCI_ERS_RESULT_RECOVERED
3. pds_core's pci_error_handlers.resume callback is called, which will attempt reset/recover the device to a functional state

Thanks, Brett - yes this sounds about right by my memory.  The resume callback takes care of getting the device reset and re -enabled.

Quoted 2 lines

I also know that, at the very least, Shannon tested this when adding it to the driver.

Yep, several cycles, several scenarios.

Cheers,
sln

Quoted 8 lines

Let me know if you still think otherwise.

Thanks again for the feedback,

Brett

#5 lore raw

Re: [PATCH net-next 1/3] pds_core: add simple AER handler

In reply to Brett Creeley
Quoted 30 lines · Brett Creeley
Quoted 10 lines · Lukas Wunner
Quoted 2 lines · Shannon Nelson

Set up the pci_error_handlers error_detected and resume to be useful in handling AER events.

The above was committed as d740f4be7cf0 ("pds_core: add simple AER handler").

Just noticed the following while inspecting the pci_error_handlers of this driver:

Quoted 15 lines

drivers/net/ethernet/amd/pds_core/main.c void pdsc_reset_done(struct pci_dev *pdev) · line 525

Quoted 10 lines
drivers/net/ethernet/amd/pds_core/main.c +10 -0
+static pci_ers_result_t pdsc_pci_error_detected(struct pci_dev *pdev,
+                                             pci_channel_state_t error)
+{
+     if (error == pci_channel_io_frozen) {
+             pdsc_reset_prepare(pdev);
+             return PCI_ERS_RESULT_NEED_RESET;
+     }
+
+     return PCI_ERS_RESULT_NONE;
+}

The ->error_detected() callback of this driver invokes pdsc_reset_prepare(), which unmaps BARs and calls pci_disable_device(), but there is no corresponding ->slot_reset() callback which would invoke pdsc_reset_done() to re-enable the device after reset recovery.

Thanks for the note. It's been a bit since I have looked at this, but I believe that it's working in the following way:

Quoted 7 lines

1. pds_core's pci_error_handlers.error_detected callback returns PCI_ERS_RESULT_NEED_RESET
2. status is initialized to PCI_ERS_RESULT_RECOVERED in the pci core and since pds_core doesn't have a slot_reset callback then status remains PCI_ERS_RESULT_RECOVERED
3. pds_core's pci_error_handlers.resume callback is called, which will attempt reset/recover the device to a functional state

My point is, you're calling pdsc_reset_prepare() but you're never calling pdsc_reset_done(). The former performs various teardown steps and calls pci_disable_device(), which disables MMIO access to the device. Since you're never calling pdsc_reset_done(), you're not re-enabling MMIO access to the device and re-initializing the device. So I'd expect any subsequent device access to fail.

Normally you'd have a ->slot_reset() callback which would call pdsc_reset_done(). Then the code would look sane.

Moreover, the AER driver in the PCI core performs an unconditional Secondary Bus Reset on Fatal Errors (channel state pci_channel_io_frozen). You're performing an additional reset of the PCI Function in pdsc_pci_error_resume(). At least for Fatal Errors, this seems superfluous.

You're only resetting the PCI Function if the PDSC_S_FW_DEAD bit is set, irrespective whether you're dealing with a Fatal or Non-Fatal Error.

Normally I'd expect that you need to perform some re-initialization after resetting the PCI Function, so this also looks weird.

Thanks,

Lukas

#6 lore raw

Re: [PATCH net-next 1/3] pds_core: add simple AER handler

Quoted 7 lines · Lukas Wunner

My point is, you're calling pdsc_reset_prepare() but you're never calling pdsc_reset_done(). The former performs various teardown steps and calls pci_disable_device(), which disables MMIO access to the device. Since you're never calling pdsc_reset_done(), you're not re-enabling MMIO access to the device and re-initializing the device. So I'd expect any subsequent device access to fail.

Quoted 8 lines

Normally you'd have a ->slot_reset() callback which would call pdsc_reset_done(). Then the code would look sane.

Moreover, the AER driver in the PCI core performs an unconditional Secondary Bus Reset on Fatal Errors (channel state pci_channel_io_frozen). You're performing an additional reset of the PCI Function in pdsc_pci_error_resume(). At least for Fatal Errors, this seems superfluous.

I note that the pensando ionic driver uses the same weird pattern, see commit c3a910e1c47a ("ionic: fill out pci error handlers").

So I suppose it got copy-pasted from there to the pds_core driver.

Thanks,

Lukas

#7 lore raw

PATCH 2/3 pds_core: delete VF dev on reset

In reply to Shannon Nelson

When the VF is hit with a reset, remove the aux device in the prepare for reset and try to restore it after the reset. The userland mechanics will need to recover and rebuild whatever uses the device afterwards.

---
 drivers/net/ethernet/amd/pds_core/auxbus.c | 18 +++++++++++++++++-
 drivers/net/ethernet/amd/pds_core/main.c   | 16 ++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
drivers/net/ethernet/amd/pds_core/auxbus.c +17 -1
index 11c23a7f3172..a3c79848a69a 100644
@@ -184,6 +184,9 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
 	struct pds_auxiliary_dev *padev;
 	int err = 0;
 
+	if (!cf)
+		return -ENODEV;
+
 	mutex_lock(&pf->config_lock);
 
 	padev = pf->vfs[cf->vf_id].padev;
@@ -202,14 +205,27 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
 int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
 {
 	struct pds_auxiliary_dev *padev;
-	enum pds_core_vif_types vt;
 	char devname[PDS_DEVNAME_LEN];
+	enum pds_core_vif_types vt;
+	unsigned long mask;
 	u16 vt_support;
 	int client_id;
 	int err = 0;
 
+	if (!cf)
+		return -ENODEV;
+
 	mutex_lock(&pf->config_lock);
 
+	mask = BIT_ULL(PDSC_S_FW_DEAD) |
+	       BIT_ULL(PDSC_S_STOPPING_DRIVER);
+	if (cf->state & mask) {
+		dev_err(pf->dev, "%s: can't add dev, VF client in bad state %#lx\n",
+			__func__, cf->state);
+		err = -ENXIO;
+		goto out_unlock;
+	}
+
 	/* We only support vDPA so far, so it is the only one to
 	 * be verified that it is available in the Core device and
 	 * enabled in the devlink param.  In the future this might
drivers/net/ethernet/amd/pds_core/main.c +16 -0
index e10451a5a89b..82901a847306 100644
@@ -476,6 +476,14 @@ void pdsc_reset_prepare(struct pci_dev *pdev)
 	pdsc_stop_health_thread(pdsc);
 	pdsc_fw_down(pdsc);
 
+	if (pdev->is_virtfn) {
+		struct pdsc *pf;
+
+		pf = pdsc_get_pf_struct(pdsc->pdev);
+		if (!IS_ERR(pf))
+			pdsc_auxbus_dev_del(pdsc, pf);
+	}
+
 	pdsc_unmap_bars(pdsc);
 	pci_release_regions(pdev);
 	pci_disable_device(pdev);
@@ -511,6 +519,14 @@ void pdsc_reset_done(struct pci_dev *pdev)
 
 	pdsc_fw_up(pdsc);
 	pdsc_restart_health_thread(pdsc);
+
+	if (pdev->is_virtfn) {
+		struct pdsc *pf;
+
+		pf = pdsc_get_pf_struct(pdsc->pdev);
+		if (!IS_ERR(pf))
+			pdsc_auxbus_dev_add(pdsc, pf);
+	}
 }
 
 static pci_ers_result_t pdsc_pci_error_detected(struct pci_dev *pdev,
Signature · 1 line
2.17.1
#8 lore raw

PATCH 3/3 pds_core: use pci_reset_function for health reset

In reply to Shannon Nelson

We get the benefit of all the PCI reset locking and recovery if we use the existing pci_reset_function() that will call our local reset handlers.

---
 drivers/net/ethernet/amd/pds_core/core.c | 3 +--
 drivers/net/ethernet/amd/pds_core/core.h | 3 ---
 drivers/net/ethernet/amd/pds_core/main.c | 7 ++++---
 3 files changed, 5 insertions(+), 8 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +1 -2
index 1234a4a8a4ae..9662ee72814c 100644
@@ -607,8 +607,7 @@ static void pdsc_check_pci_health(struct pdsc *pdsc)
 	if (fw_status != PDS_RC_BAD_PCI)
 		return;
 
-	pdsc_reset_prepare(pdsc->pdev);
-	pdsc_reset_done(pdsc->pdev);
+	pci_reset_function(pdsc->pdev);
 }
 
 void pdsc_health_thread(struct work_struct *work)
drivers/net/ethernet/amd/pds_core/core.h +0 -3
index 3468a63f5ae9..92d7657dd614 100644
@@ -284,9 +284,6 @@ int pdsc_devcmd_reset(struct pdsc *pdsc);
 int pdsc_dev_init(struct pdsc *pdsc);
 void pdsc_dev_uninit(struct pdsc *pdsc);
 
-void pdsc_reset_prepare(struct pci_dev *pdev);
-void pdsc_reset_done(struct pci_dev *pdev);
-
 int pdsc_intr_alloc(struct pdsc *pdsc, char *name,
 		    irq_handler_t handler, void *data);
 void pdsc_intr_free(struct pdsc *pdsc, int index);
drivers/net/ethernet/amd/pds_core/main.c +4 -3
index 82901a847306..ab6133e7db42 100644
@@ -469,7 +469,7 @@ static void pdsc_restart_health_thread(struct pdsc *pdsc)
 	mod_timer(&pdsc->wdtimer, jiffies + 1);
 }
 
-void pdsc_reset_prepare(struct pci_dev *pdev)
+static void pdsc_reset_prepare(struct pci_dev *pdev)
 {
 	struct pdsc *pdsc = pci_get_drvdata(pdev);
 
@@ -486,10 +486,11 @@ void pdsc_reset_prepare(struct pci_dev *pdev)
 
 	pdsc_unmap_bars(pdsc);
 	pci_release_regions(pdev);
-	pci_disable_device(pdev);
+	if (pci_is_enabled(pdev))
+		pci_disable_device(pdev);
 }
 
-void pdsc_reset_done(struct pci_dev *pdev)
+static void pdsc_reset_done(struct pci_dev *pdev)
 {
 	struct pdsc *pdsc = pci_get_drvdata(pdev);
 	struct device *dev = pdsc->dev;
Signature · 1 line
2.17.1
#9 lore raw
In reply to Shannon Nelson
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 9 lines · On Fri, 16 Feb 2024 14:29:49 -0800 you wrote:

Add simple handlers for the PCI AER callbacks, and improve the reset handling.

Shannon Nelson (3):
pds_core: add simple AER handler
pds_core: delete VF dev on reset
pds_core: use pci_reset_function for health reset

[...]

Here is the summary with links:
- [net-next,1/3] pds_core: add simple AER handler

    https://git.kernel.org/netdev/net-next/c/d740f4be7cf0
  - [net-next,2/3] pds_core: delete VF dev on reset
    https://git.kernel.org/netdev/net-next/c/2dac60e06234
  - [net-next,3/3] pds_core: use pci_reset_function for health reset
    https://git.kernel.org/netdev/net-next/c/2cbab3c296f1

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html