Skip to contentSkip to conversation

pds_core: error handling fixes

PATCH Applied Shannon Nelson 3 participants 8 messages Aug 24, 2023 – Aug 26, 2023

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

cover pds_core: error handling fixes

Some fixes for better handling of broken states.

Shannon Nelson (5):
pds_core: protect devlink callbacks from fw_down state
pds_core: no health reporter in VF
pds_core: no reset command for VF
pds_core: check for work queue before use
pds_core: pass opcode to devcmd_wait

 drivers/net/ethernet/amd/pds_core/core.c    | 11 +++++++----
 drivers/net/ethernet/amd/pds_core/dev.c     |  9 +++------
 drivers/net/ethernet/amd/pds_core/devlink.c |  3 +++
 3 files changed, 13 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/5 pds_core: protect devlink callbacks from fw_down state

Don't access structs that have been cleared when in the fw_down state and the various structs have been cleaned and are waiting to recover. This caused a panic on rmmod when already in fw_down and devlink_param_unregister() tried to check the parameters.

Fixes 40ced8944536 ("pds_core: devlink params for enabling VIF support")
---
 drivers/net/ethernet/amd/pds_core/devlink.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/amd/pds_core/devlink.c +3 -0
index 9c6b3653c1c7..d9607033bbf2 100644
@@ -10,6 +10,9 @@ pdsc_viftype *pdsc_dl_find_viftype_by_id(struct pdsc *pdsc,
 {
 	int vt;
 
+	if (!pdsc->viftype_status)
+		return NULL;
+
 	for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) {
 		if (pdsc->viftype_status[vt].dl_id == dl_id)
 			return &pdsc->viftype_status[vt];
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/5 pds_core: no health reporter in VF

In reply to Shannon Nelson

Make sure the health reporter is set up before we use it in our devlink health updates, especially since the VF doesn't set up the health reporter.

Fixes 25b450c05a49 ("pds_core: add devlink health facilities")
---
 drivers/net/ethernet/amd/pds_core/core.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +5 -3
index f2c79456d745..383e3311a52c 100644
@@ -524,7 +524,8 @@ static void pdsc_fw_down(struct pdsc *pdsc)
 	}
 
 	/* Notify clients of fw_down */
-	devlink_health_report(pdsc->fw_reporter, "FW down reported", pdsc);
+	if (pdsc->fw_reporter)
+		devlink_health_report(pdsc->fw_reporter, "FW down reported", pdsc);
 	pdsc_notify(PDS_EVENT_RESET, &reset_event);
 
 	pdsc_stop(pdsc);
@@ -554,8 +555,9 @@ static void pdsc_fw_up(struct pdsc *pdsc)
 
 	/* Notify clients of fw_up */
 	pdsc->fw_recoveries++;
-	devlink_health_reporter_state_update(pdsc->fw_reporter,
-					     DEVLINK_HEALTH_REPORTER_STATE_HEALTHY);
+	if (pdsc->fw_reporter)
+		devlink_health_reporter_state_update(pdsc->fw_reporter,
+						     DEVLINK_HEALTH_REPORTER_STATE_HEALTHY);
 	pdsc_notify(PDS_EVENT_RESET, &reset_event);
 
 	return;
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/5 pds_core: no reset command for VF

In reply to Shannon Nelson

The VF doesn't need to send a reset command, and in a PCI reset scenario it might not have a valid IO space to write to anyway.

Fixes 523847df1b37 ("pds_core: add devcmd device interfaces")
---
 drivers/net/ethernet/amd/pds_core/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/amd/pds_core/core.c +2 -1
index 383e3311a52c..36f9b932b9e2 100644
@@ -464,7 +464,8 @@ void pdsc_teardown(struct pdsc *pdsc, bool removing)
 {
 	int i;
 
-	pdsc_devcmd_reset(pdsc);
+	if (!pdsc->pdev->is_virtfn)
+		pdsc_devcmd_reset(pdsc);
 	pdsc_qcq_free(pdsc, &pdsc->notifyqcq);
 	pdsc_qcq_free(pdsc, &pdsc->adminqcq);
 
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/5 pds_core: check for work queue before use

In reply to Shannon Nelson

Add a check that the wq exists before queuing up work for a failed devcmd, as the PF is responsible for health and the VF doesn't have a wq.

Fixes c2dbb0904310 ("pds_core: health timer and workqueue")
---
 drivers/net/ethernet/amd/pds_core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amd/pds_core/dev.c +1 -1
index debe5216fe29..524f422ee7ac 100644
@@ -183,7 +183,7 @@ int pdsc_devcmd_locked(struct pdsc *pdsc, union pds_core_dev_cmd *cmd,
 	err = pdsc_devcmd_wait(pdsc, max_seconds);
 	memcpy_fromio(comp, &pdsc->cmd_regs->comp, sizeof(*comp));
 
-	if (err == -ENXIO || err == -ETIMEDOUT)
+	if ((err == -ENXIO || err == -ETIMEDOUT) && pdsc->wq)
 		queue_work(pdsc->wq, &pdsc->health_work);
 
 	return err;
Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/5 pds_core: pass opcode to devcmd_wait

In reply to Shannon Nelson

Don't rely on the PCI memory for the devcmd opcode because we read a 0xff value if the PCI bus is broken, which can cause us to report a bogus dev_cmd opcode later.

Fixes 523847df1b37 ("pds_core: add devcmd device interfaces")
---
 drivers/net/ethernet/amd/pds_core/dev.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/amd/pds_core/dev.c +2 -5
index 524f422ee7ac..f77cd9f5a2fd 100644
@@ -121,7 +121,7 @@ static const char *pdsc_devcmd_str(int opcode)
 	}
 }
 
-static int pdsc_devcmd_wait(struct pdsc *pdsc, int max_seconds)
+static int pdsc_devcmd_wait(struct pdsc *pdsc, u8 opcode, int max_seconds)
 {
 	struct device *dev = pdsc->dev;
 	unsigned long start_time;
@@ -131,9 +131,6 @@ static int pdsc_devcmd_wait(struct pdsc *pdsc, int max_seconds)
 	int done = 0;
 	int err = 0;
 	int status;
-	int opcode;
-
-	opcode = ioread8(&pdsc->cmd_regs->cmd.opcode);
 
 	start_time = jiffies;
 	max_wait = start_time + (max_seconds * HZ);
@@ -180,7 +177,7 @@ int pdsc_devcmd_locked(struct pdsc *pdsc, union pds_core_dev_cmd *cmd,
 
 	memcpy_toio(&pdsc->cmd_regs->cmd, cmd, sizeof(*cmd));
 	pdsc_devcmd_dbell(pdsc);
-	err = pdsc_devcmd_wait(pdsc, max_seconds);
+	err = pdsc_devcmd_wait(pdsc, cmd->opcode, max_seconds);
 	memcpy_fromio(comp, &pdsc->cmd_regs->comp, sizeof(*comp));
 
 	if ((err == -ENXIO || err == -ETIMEDOUT) && pdsc->wq)
Signature · 1 line
2.17.1
reviewer Reviewed-by on the v1 series
#6 lore raw
In reply to Shannon Nelson
Quoted 9 lines · Shannon Nelson

Some fixes for better handling of broken states.

Shannon Nelson (5):
pds_core: protect devlink callbacks from fw_down state
pds_core: no health reporter in VF
pds_core: no reset command for VF
pds_core: check for work queue before use
pds_core: pass opcode to devcmd_wait

Quoted 4 lines
 drivers/net/ethernet/amd/pds_core/core.c    | 11 +++++++----
 drivers/net/ethernet/amd/pds_core/dev.c     |  9 +++------
 drivers/net/ethernet/amd/pds_core/devlink.c |  3 +++
 3 files changed, 13 insertions(+), 10 deletions(-)

For series,

#7 lore raw
In reply to Shannon Nelson
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Thu, 24 Aug 2023 09:17:49 -0700 you wrote:

Some fixes for better handling of broken states.

Shannon Nelson (5):
pds_core: protect devlink callbacks from fw_down state
pds_core: no health reporter in VF
pds_core: no reset command for VF
pds_core: check for work queue before use
pds_core: pass opcode to devcmd_wait

[...]

Here is the summary with links:
- [net,1/5] pds_core: protect devlink callbacks from fw_down state

    https://git.kernel.org/netdev/net/c/91202ce78fcd
  - [net,2/5] pds_core: no health reporter in VF
    https://git.kernel.org/netdev/net/c/e48b894a1db7
  - [net,3/5] pds_core: no reset command for VF
    https://git.kernel.org/netdev/net/c/95e383226d6f
  - [net,4/5] pds_core: check for work queue before use
    https://git.kernel.org/netdev/net/c/969cfd4c8ca5
  - [net,5/5] pds_core: pass opcode to devcmd_wait
    https://git.kernel.org/netdev/net/c/0ea064e74bc8

You are awesome, thank you!

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