From: netdev-bot+sashiko@kernel.org
To: tianx@yunsilicon.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, jgg@ziepe.ca,
leon@kernel.org, huangjunxian6@hisilicon.com,
weihg@yunsilicon.com, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
kerneljasonxing@gmail.com
Subject: Re: [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function
Date: Fri, 27 Nov 2026 15:57:53 +0000 [thread overview]
Message-ID: <179579507336.3135.5729346813922191216@kernel.org> (raw)
In-Reply-To: <20261126145721.70868-5-tianx@yunsilicon.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] In xsc_pci_init()
(drivers/net/ethernet/yunsilicon/xsc/pci/main.c), the new…
- [Medium] net/xsc: missing in.hdr.ver initialization in
xsc_cmd_query_hca_cap()
- [Low] xsc_cmd_query_hca_cap() in
drivers/net/ethernet/yunsilicon/xsc/pci/main.c computes…
- [Low] The subject line is split across two lines.
- [Low] xsc_cmd_query_hca_cap()
(drivers/net/ethernet/yunsilicon/xsc/pci/main.c) takes an unneeded…
--
net/xsc: query HCA capabilities and reset function
During probe, this commit queries the firmware HCA capabilities (CQ size,
segment counts, MSI-X range, port and PF identifiers). It stores them in
struct xsc_caps and struct xsc_core_device, then sends the firmware
FUNCTION_RESET command to reset the function's resources.
> net/xsc: query HCA capabilities and reset function
>
> resources
[Severity: Low]
This isn't a bug, but the subject line looks like it was wrapped onto two
lines. Git will use "net/xsc: query HCA capabilities and reset function"
as the subject, and "resources" will become the first paragraph of the
body.
The cut-off shortlog also reads like a PCI function-level reset. The patch
actually sends the firmware XSC_CMD_OP_FUNCTION_RESET command.
Could the subject be joined back into a single line?
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
> index 9b08580f52f38..42c5a1baed23b 100644
> --- a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
> @@ -29,6 +29,63 @@ static int xsc_set_dma_caps(struct pci_dev *pdev)
> return err;
> }
>
> +static int xsc_cmd_query_hca_cap(struct xsc_core_device *xdev,
> + struct xsc_caps *caps)
> +{
[ ... ]
> + xdev->glb_func_id = be32_to_cpu(out->hca_cap.glb_func_id);
> +
> + caps->max_cqes = 1 << out->hca_cap.log_max_cq_sz;
[Severity: Low]
log_max_cq_sz is a u8 that comes straight from firmware, and nothing
checks its range. The 1 here is a signed int, so a value of 31 shifts into
the sign bit, and a value of 32 or more is undefined behaviour.
Later in the series, xsc_eth_build_queue_param() does:
min_t(int, XSC_RQCQ_ELE_NUM, xdev->caps.max_cqes)
A max_cqes of 0x80000000 would become INT_MIN there and give a negative
queue size. log_max_qp_depth is also stored unchecked, and the same
function uses it in BIT(xdev->caps.log_max_qp_depth) for rq_size with no
upper clamp.
Would it make sense to use 1U << n (or BIT()) here, and reject or clamp
out-of-range exponents?
> + caps->send_ds_num = out->hca_cap.send_seg_num;
> + caps->recv_ds_num = out->hca_cap.recv_seg_num;
> +
> + caps->nic_caps = (caps->nic_caps & ~XSC_CAP_MAC_PORT_MASK) |
> + FIELD_PREP(XSC_CAP_MAC_PORT_MASK,
> + out->hca_cap.mac_port & 0xff);
> + xdev->mac_port = FIELD_GET(XSC_CAP_MAC_PORT_MASK, caps->nic_caps);
[Severity: Low]
This isn't a bug, but is the round trip through caps->nic_caps needed?
Packing mac_port with FIELD_PREP() and then unpacking it with FIELD_GET()
gives the same result as:
xdev->mac_port = out->hca_cap.mac_port;
As far as I can tell, nothing else in the series reads caps->nic_caps. That
leaves the nic_caps field and XSC_CAP_MAC_PORT_MASK otherwise unused. The
other capability fields are read by later patches, so this applies only to
nic_caps.
The & 0xff masks on the u8 fields mac_port and log_max_qp_depth also have
no effect.
[ ... ]
> @@ -90,6 +147,19 @@ static int xsc_pci_init(struct xsc_core_device *xdev,
> goto err_cmd_cleanup;
> }
>
> + err = xsc_cmd_query_hca_cap(xdev, &xdev->caps);
> + if (err) {
> + pci_err(pdev, "failed to query hca caps: err=%d\n", err);
> + goto err_cmd_cleanup;
> + }
> +
> + err = xsc_reset_function_resource(xdev);
> + if (err) {
> + pci_err(pdev, "failed to reset function resource: err=%d\n",
> + err);
> + goto err_cmd_cleanup;
> + }
[Severity: High]
What happens to the device's DMA if one of these commands times out and
probe takes the err_cmd_cleanup path?
On a timeout, xsc_cmd_invoke() leaves the entry registered, and
_xsc_cmd_exec() leaves both mailboxes owned by the device:
drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c:xsc_cmd_invoke() {
...
if (!wait_for_completion_timeout(&ent->done, timeout)) {
cmd->cmd_status = XSC_CMD_STATUS_TIMEDOUT;
...
/* the entry stays registered for the completion handler */
return -ETIMEDOUT;
}
...
}
drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c:_xsc_cmd_exec() {
...
err = xsc_cmd_invoke(xdev, inb, outb, &status);
if (err == -ETIMEDOUT)
/* the command owns both mailboxes now */
return err;
...
}
The device still holds out->next->dma through lay->out_ptr. It also still
has cq_buf and cmd_buf programmed as DMA targets.
xsc_cmd_cleanup() then stops only the polling kthread. It frees all of
that memory while bus mastering is still enabled:
drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c:xsc_cmd_cleanup() {
...
xsc_free_msg(xdev, cmd->ent_arr[i]->in);
xsc_free_msg(xdev, cmd->ent_arr[i]->out);
...
dma_free_coherent(&xdev->pdev->dev, PAGE_SIZE, cmd->cq_buf, cmd->cq_dma);
dma_free_coherent(&xdev->pdev->dev, PAGE_SIZE, cmd->cmd_buf, cmd->dma);
dma_pool_destroy(cmd->pool);
...
}
pci_clear_master() only runs later, at err_clr_master, after
pci_iounmap(). If the firmware finishes the timed-out command late, can it
DMA the response and completion entry into memory that has already gone
back to the page allocator or the dma_pool?
The comment in xsc_cmd_cleanup() describes a response that "may never
come", which suggests the driver expects a late response is possible.
This ordering comes from the earlier "net/xsc: add the command queue"
patch in this series. The xsc_cmd_version_check() error path can already
reach it, and xsc_pci_fini() also calls xsc_cmd_cleanup() before
pci_clear_master(). This patch adds two more probe paths into it.
FUNCTION_RESET is a firmware resource teardown, so it seems likely to run
long and time out.
Should the device's cmdq be quiesced, or bus mastering cleared, before
the mailboxes and rings are freed?
[ ... ]
> @@ -29,6 +29,63 @@ static int xsc_set_dma_caps(struct pci_dev *pdev)
> return err;
> }
>
> +static int xsc_cmd_query_hca_cap(struct xsc_core_device *xdev,
> + struct xsc_caps *caps)
> +{
> + struct xsc_cmd_query_hca_cap_mbox_out *out;
> + struct xsc_cmd_query_hca_cap_mbox_in in;
> + int err;
> +
> + out = kzalloc_obj(*out, GFP_KERNEL);
> + if (!out)
> + return -ENOMEM;
> +
> + memset(&in, 0, sizeof(in));
> + in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_QUERY_HCA_CAP);
> + in.cpu_num = cpu_to_be16(num_online_cpus());
> +
> + err = xsc_cmd_exec(xdev, &in, sizeof(in), out, sizeof(*out));
> + if (err)
> + goto err_free;
> +
> + xdev->glb_func_id = be32_to_cpu(out->hca_cap.glb_func_id);
> +
> + caps->max_cqes = 1 << out->hca_cap.log_max_cq_sz;
> + caps->send_ds_num = out->hca_cap.send_seg_num;
> + caps->recv_ds_num = out->hca_cap.recv_seg_num;
> +
> + caps->nic_caps = (caps->nic_caps & ~XSC_CAP_MAC_PORT_MASK) |
> + FIELD_PREP(XSC_CAP_MAC_PORT_MASK,
> + out->hca_cap.mac_port & 0xff);
> + xdev->mac_port = FIELD_GET(XSC_CAP_MAC_PORT_MASK, caps->nic_caps);
> +
> + caps->msix_base = be16_to_cpu(out->hca_cap.msix_base);
> + caps->msix_num = be16_to_cpu(out->hca_cap.msix_num);
> +
> + caps->log_max_qp_depth = out->hca_cap.log_max_qp_depth & 0xff;
> +
> + xdev->pcie_no = out->hca_cap.pcie_no;
> + xdev->pf_id = out->hca_cap.pf_id;
> +
> + kfree(out);
> + return 0;
> +err_free:
> + kfree(out);
> + return err;
> +}
> +
> +static int xsc_reset_function_resource(struct xsc_core_device *xdev)
> +{
> + struct xsc_function_reset_mbox_out out;
> + struct xsc_function_reset_mbox_in in;
> +
> + memset(&in, 0, sizeof(in));
> + in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_FUNCTION_RESET);
> + in.glb_func_id = cpu_to_be16(xdev->glb_func_id);
> +
> + return xsc_cmd_exec(xdev, &in, sizeof(in), &out, sizeof(out));
> +}
> +
> static int xsc_pci_init(struct xsc_core_device *xdev,
> const struct pci_device_id *id)
> {
[Severity: Medium]
The input mailbox is zeroed by memset(), and only in.hdr.opcode and
in.cpu_num are filled in, so in.hdr.ver goes to the firmware as 0.
xsc_cmd.h defines XSC_CMD_QUERY_HCA_CAP_V1 as the hca_cap mbox
version, but nothing in the driver uses it.
This matters because the function then reads out->hca_cap.pcie_no and
out->hca_cap.pf_id without any check. Those fields are part of the
versioned extension of struct xsc_hca_cap, and later in the series
xsc_core_eth_modify_raw_qp() uses them to set up raw QP port routing.
The firmware might validate hdr.ver, or fill in the extended fields
only for a V1 request. In that case a version 0 request could fail
the query and abort probe. It could also leave pcie_no and pf_id at
zero from the kzalloc. In that second case probe succeeds and the raw
QPs are set up with the wrong port routing, and nothing is logged.
Should this set in.hdr.ver = cpu_to_be16(XSC_CMD_QUERY_HCA_CAP_V1)?
If the firmware is meant to return the full structure for version 0,
could the commit message say so, and the unused define be dropped?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126145711.70868-1-tianx%40yunsilicon.com
next prev parent reply other threads:[~2026-11-27 15:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 14:57 [PATCH v2 00/11] net/xsc: add the Yunsilicon XSC ethernet driver Xin Tian
2026-11-26 14:57 ` [PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 03/11] net/xsc: add the command queue Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko [this message]
2026-11-26 14:57 ` [PATCH v2 05/11] net/xsc: add event queues and MSI-X Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 06/11] net/xsc: add CQ and QP helpers Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 07/11] net/xsc: add the ethernet netdev Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 08/11] net/xsc: add the single TX/RX channel Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 09/11] net/xsc: report link state changes Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 10/11] net/xsc: add the transmit path Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 11/11] net/xsc: add the receive path Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179579507336.3135.5729346813922191216@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=huangjunxian6@hisilicon.com \
--cc=jgg@ziepe.ca \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tianx@yunsilicon.com \
--cc=weihg@yunsilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox