pds_core: updates and fixes
Subsystems (3)
v4 cover pds_core: updates and fixes
This patchset has fixes for issues seen in recent internal testing of error conditions and stress handling.
Note that the first patch in this series is a leftover from an earlier patchset that was abandoned:
v4:
- use init/reinit_completion() rather than COMPLETION_INITIALIZER_ONSTACK()
- use completion_done() to protect from completing timed-out requests
v3:
https://lore.kernel.org/netdev/[email protected]/
- dropped the kdoc complaint fix, save for later net-next update
v2:
https://lore.kernel.org/netdev/[email protected]/
- dropped patch 5/6 "adminq poll interval", will send for net-next later
- updated commit comments and tags
v1:
https://lore.kernel.org/netdev/[email protected]/
Brett Creeley (3):
pds_core: Prevent possible adminq overflow/stuck condition
pds_core: handle unsupported PDS_CORE_CMD_FW_CONTROL result
pds_core: Remove unnecessary check in pds_client_adminq_cmd()
Shannon Nelson (1):
pds_core: make wait_context part of q_info
drivers/net/ethernet/amd/pds_core/adminq.c | 36 ++++++++------------- drivers/net/ethernet/amd/pds_core/auxbus.c | 3 -- drivers/net/ethernet/amd/pds_core/core.c | 9 +++--- drivers/net/ethernet/amd/pds_core/core.h | 4 +-- drivers/net/ethernet/amd/pds_core/devlink.c | 4 +-- 5 files changed, 21 insertions(+), 35 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/4 pds_core: Prevent possible adminq overflow/stuck condition
From: Brett Creeley <[email protected]>
The pds_core's adminq is protected by the adminq_lock, which prevents more than 1 command to be posted onto it at any one time. This makes it so the client drivers cannot simultaneously post adminq commands. However, the completions happen in a different context, which means multiple adminq commands can be posted sequentially and all waiting on completion.
On the FW side, the backing adminq request queue is only 16 entries long and the retry mechanism and/or overflow/stuck prevention is lacking. This can cause the adminq to get stuck, so commands are no longer processed and completions are no longer sent by the FW.
As an initial fix, prevent more than 16 outstanding adminq commands so there's no way to cause the adminq from getting stuck. This works because the backing adminq request queue will never have more than 16 pending adminq commands, so it will never overflow. This is done by reducing the adminq depth to 16.
--- drivers/net/ethernet/amd/pds_core/core.c | 5 +---- drivers/net/ethernet/amd/pds_core/core.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/amd/pds_core/core.c +1 -4
@@ -325,10 +325,7 @@ static int pdsc_core_init(struct pdsc *pdsc)size_t sz;int err; -/* Scale the descriptor ring length based on number of CPUs and VFs */ - numdescs =max_t (int,PDSC_ADMINQ_MIN_LENGTH ,num_online_cpus ()); - numdescs +=2 *pci_sriov_get_totalvfs (pdsc->pdev); - numdescs =roundup_pow_of_two (numdescs); + numdescs =PDSC_ADMINQ_MAX_LENGTH ; err = pdsc_qcq_alloc(pdsc, PDS_CORE_QTYPE_ADMINQ, 0, "adminq", PDS_CORE_QCQ_F_CORE | PDS_CORE_QCQ_F_INTR, numdescs,
drivers/net/ethernet/amd/pds_core/core.h +1 -1
@@ -16,7 +16,7 @@#define PDSC_WATCHDOG_SECS 5#define PDSC_QUEUE_NAME_MAX_SZ 16 -#define PDSC_ADMINQ_MIN_LENGTH 16/* must be a power of two */ +#define PDSC_ADMINQ_MAX_LENGTH 16/* must be a power of two */ #define PDSC_NOTIFYQ_LENGTH 64/* must be a power of two */ #define PDSC_TEARDOWN_RECOVERY false#define PDSC_TEARDOWN_REMOVING true
Signature · 1 line
2.17.1
PATCH v4 2/4 pds_core: handle unsupported PDS_CORE_CMD_FW_CONTROL result
In reply to Shannon NelsonFrom: Brett Creeley <[email protected]>
If the FW doesn't support the PDS_CORE_CMD_FW_CONTROL command the driver might at the least print garbage and at the worst crash when the user runs the "devlink dev info" devlink command.
This happens because the stack variable fw_list is not 0 initialized which results in fw_list.num_fw_slots being a garbage value from the stack. Then the driver tries to access fw_list.fw_names[i] with i >= ARRAY_SIZE and runs off the end of the array.
Fix this by initializing the fw_list and by not failing completely if the devcmd fails because other useful information is printed via devlink dev info even if the devcmd fails.
--- drivers/net/ethernet/amd/pds_core/devlink.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/amd/pds_core/devlink.c +1 -3
@@ -105,7 +105,7 @@ int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req, .fw_control.opcode = PDS_CORE_CMD_FW_CONTROL, .fw_control.oper = PDS_CORE_FW_GET_LIST, }; -struct pds_core_fw_list_info fw_list; +struct pds_core_fw_list_info fw_list = {};struct pdsc *pdsc =devlink_priv (dl);union pds_core_dev_comp comp;char buf[32 ];
@@ -118,8 +118,6 @@ int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req,if (!err)memcpy_fromio (&fw_list, pdsc->cmd_regs->data,sizeof (fw_list));mutex_unlock (&pdsc->devcmd_lock); -if (err && err != -EIO ) -return err; listlen =min (fw_list.num_fw_slots,ARRAY_SIZE (fw_list.fw_names));for (i =0 ; i < listlen; i++) {
Signature · 1 line
2.17.1
PATCH v4 3/4 pds_core: Remove unnecessary check in pds_client_adminq_cmd()
In reply to Shannon NelsonFrom: Brett Creeley <[email protected]>
When the pds_core driver was first created there were some race conditions around using the adminq, especially for client drivers. To reduce the possibility of a race condition there's a check against pf->state in pds_client_adminq_cmd(). This is problematic for a couple of reasons:
1. The PDSC_S_INITING_DRIVER bit is set during probe, but not cleared until after everything in probe is complete, which includes creating the auxiliary devices. For pds_fwctl this means it can't make any adminq commands until after pds_core's probe is complete even though the adminq is fully up by the time pds_fwctl's auxiliary device is created.
2. The race conditions around using the adminq have been fixed and this path is already protected against client drivers calling pds_client_adminq_cmd() if the adminq isn't ready, i.e. see pdsc_adminq_post() -> pdsc_adminq_inc_if_up().
Fix this by removing the pf->state check in pds_client_adminq_cmd() because invalid accesses to pds_core's adminq is already handled by pdsc_adminq_post()->pdsc_adminq_inc_if_up().
--- drivers/net/ethernet/amd/pds_core/auxbus.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/ethernet/amd/pds_core/auxbus.c +0 -3
@@ -107,9 +107,6 @@ int pds_client_adminq_cmd(struct pds_auxiliary_dev *padev,dev_dbg (pf->dev,"%s: %s opcode %d\n" , __func__,dev_name (&padev->aux_dev.dev), req->opcode); -if (pf->state) -return -ENXIO ; -/* Wrap the client's request */ cmd.client_request.opcode =PDS_AQ_CMD_CLIENT_CMD ; cmd.client_request.client_id =cpu_to_le16 (padev->client_id);
Signature · 1 line
2.17.1
PATCH v4 4/4 pds_core: make wait_context part of q_info
In reply to Shannon NelsonMake the wait_context a full part of the q_info struct rather than a stack variable that goes away after pdsc_adminq_post() is done so that the context is still available after the wait loop has given up.
There was a case where a slow development firmware caused the adminq request to time out, but then later the FW finally finished the request and sent the interrupt. The handler tried to complete_all() the completion context that had been created on the stack in pdsc_adminq_post() but no longer existed. This caused bad pointer usage, kernel crashes, and much wailing and gnashing of teeth.
--- drivers/net/ethernet/amd/pds_core/adminq.c | 36 +++++++++------------- drivers/net/ethernet/amd/pds_core/core.c | 4 ++- drivers/net/ethernet/amd/pds_core/core.h | 2 +- 3 files changed, 18 insertions(+), 24 deletions(-)
drivers/net/ethernet/amd/pds_core/adminq.c +14 -22
@@ -5,11 +5,6 @@#include "core.h" -struct pdsc_wait_context { -struct pdsc_qcq *qcq; -struct completion wait_completion; -}; -static int pdsc_process_notifyq (struct pdsc_qcq *qcq) {union pds_core_notifyq_comp *comp;
@@ -109,10 +104,10 @@ void pdsc_process_adminq(struct pdsc_qcq *qcq) q_info = &q->info[q->tail_idx]; q->tail_idx = (q->tail_idx +1 ) & (q->num_descs -1 ); -/* Copy out the completion data */ -memcpy (q_info->dest, comp,sizeof (*comp)); - -complete_all (&q_info->wc->wait_completion); +if (!completion_done (&q_info->completion)) { +memcpy (q_info->dest, comp,sizeof (*comp)); +complete (&q_info->completion); + }if (cq->tail_idx == cq->num_descs -1 ) cq->done_color = !cq->done_color;
@@ -162,8 +157,7 @@ irqreturn_t pdsc_adminq_isr(int irq, void *data)static int __pdsc_adminq_post (struct pdsc *pdsc,struct pdsc_qcq *qcq,union pds_core_adminq_cmd *cmd, -union pds_core_adminq_comp *comp, -struct pdsc_wait_context *wc) +union pds_core_adminq_comp *comp) {struct pdsc_queue *q = &qcq->q;struct pdsc_q_info *q_info;
@@ -205,9 +199,9 @@ static int __pdsc_adminq_post(struct pdsc *pdsc,/* Post the request */ index = q->head_idx; q_info = &q->info[index]; - q_info->wc = wc; q_info->dest = comp;memcpy (q_info->desc, cmd,sizeof (*cmd)); +reinit_completion (&q_info->completion);dev_dbg (pdsc->dev,"head_idx %d tail_idx %d\n" , q->head_idx, q->tail_idx);
@@ -231,16 +225,13 @@ int pdsc_adminq_post(struct pdsc *pdsc, union pds_core_adminq_comp *comp, bool fast_poll) { -struct pdsc_wait_context wc = { - .wait_completion = -COMPLETION_INITIALIZER_ONSTACK (wc.wait_completion), - };unsigned long poll_interval =1 ;unsigned long poll_jiffies;unsigned long time_limit;unsigned long time_start;unsigned long time_done;unsigned long remaining; +struct completion *wc;int err =0 ;int index;
@@ -250,20 +241,19 @@ int pdsc_adminq_post(struct pdsc *pdsc,return -ENXIO ; } - wc.qcq = &pdsc->adminqcq; - index =__pdsc_adminq_post (pdsc, &pdsc->adminqcq, cmd, comp, &wc); + index =__pdsc_adminq_post (pdsc, &pdsc->adminqcq, cmd, comp);if (index <0 ) { err = index; goto err_out; } + wc = &pdsc->adminqcq.q.info[index].completion; time_start = jiffies; time_limit = time_start +HZ * pdsc->devcmd_timeout; do { /* Timeslice the actual wait to catch IO errors etc early */ poll_jiffies = msecs_to_jiffies(poll_interval); - remaining = wait_for_completion_timeout(&wc.wait_completion, - poll_jiffies); + remaining = wait_for_completion_timeout(wc, poll_jiffies); if (remaining) break;
@@ -292,9 +282,11 @@ int pdsc_adminq_post(struct pdsc *pdsc,dev_dbg (pdsc->dev,"%s: elapsed %d msecs\n" , __func__,jiffies_to_msecs (time_done - time_start)); -/* Check the results */ -if (time_after_eq (time_done, time_limit)) +/* Check the results and clear an un-completed timeout */ +if (time_after_eq (time_done, time_limit) && !completion_done (wc)) { err = -ETIMEDOUT ; +complete (wc); + }dev_dbg (pdsc->dev,"read admin queue completion idx %d:\n" , index); dynamic_hex_dump("comp ", DUMP_PREFIX_OFFSET, 16, 1,
drivers/net/ethernet/amd/pds_core/core.c +3 -1
@@ -167,8 +167,10 @@ static void pdsc_q_map(struct pdsc_queue *q, void *base, dma_addr_t base_pa) q->base = base; q->base_pa = base_pa; -for (i =0 , cur = q->info; i < q->num_descs; i++, cur++) +for (i =0 , cur = q->info; i < q->num_descs; i++, cur++) { cur->desc = base + (i * q->desc_size); +init_completion (&cur->completion); + } }static void pdsc_cq_map (struct pdsc_cq *cq,void *base,dma_addr_t base_pa)
drivers/net/ethernet/amd/pds_core/core.h +1 -1
@@ -96,7 +96,7 @@ struct pdsc_q_info {unsigned int bytes;unsigned int nbufs;struct pdsc_buf_info bufs[PDS_CORE_MAX_FRAGS ]; -struct pdsc_wait_context *wc; +struct completion completion;void *dest; };
Signature · 1 line
2.17.1
Quoted 16 lines
-----Original Message-----
From: Shannon Nelson <[email protected]>
Sent: Monday, April 21, 2025 10:46 AM
To: [email protected]; [email protected]; [email protected]; Dumazet, Eric <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]
Cc: Shannon Nelson <[email protected]>
Subject: [PATCH v4 net 0/4]pds_core: updates and fixesThis patchset has fixes for issues seen in recent internal testing of error conditions and stress handling.
Quoted 9 lines
Note that the first patch in this series is a leftover from an earlier patchset that was abandoned:
v4:
- use init/reinit_completion() rather thanCOMPLETION_INITIALIZER_ONSTACK()
- usecompletion_done()to protect from completing timed-out requests
Just to confirm, everything looks good to me in this revision!
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 8 lines · On Mon, 21 Apr 2025 10:46:02 -0700 you wrote:
This patchset has fixes for issues seen in recent internal testing of error conditions and stress handling.
Note that the first patch in this series is a leftover from an earlier patchset that was abandoned:
[...]
Here is the summary with links:
- [v4,net,1/4] pds_core: Prevent possible adminq overflow/stuck condition
https://git.kernel.org/netdev/net/c/d9e2f070d8af - [v4,net,2/4] pds_core: handle unsupported PDS_CORE_CMD_FW_CONTROL result https://git.kernel.org/netdev/net/c/2567daad69cd - [v4,net,3/4] pds_core: Remove unnecessary check in pds_client_adminq_cmd() https://git.kernel.org/netdev/net/c/f9559d818205 - [v4,net,4/4] pds_core: make wait_context part of q_info https://git.kernel.org/netdev/net/c/3f77c3dfffc7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html