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 05/11] net/xsc: add event queues and MSI-X
Date: Fri, 27 Nov 2026 15:57:55 +0000 [thread overview]
Message-ID: <179579507511.3135.1874125473034318876@kernel.org> (raw)
In-Reply-To: <20261126145724.70868-6-tianx@yunsilicon.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 5
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).
- [Medium] xsc_buf_alloc()
(drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c) handles buffers…
- [Medium] xsc_create_map_eq()
(drivers/net/ethernet/yunsilicon/xsc/pci/eq.c) frees the EQ ring for…
- [Low] In xsc_destroy_unmap_eq() (eq.c), the u32 eq->eqn is printed with
"%d", a signed specifier.
- [Low] struct xsc_eq::index gets two different meanings.
- [Low] The exported link-event callback API publishes the handler with a
plain WRITE_ONCE() in xsc_irq_event_register().
- [Low] The EQ consumer-index doorbell field is only 11 bits wide
(XSC_EQ_DB_DATA0_NEXT_CID_MASK = GENMASK(10, 0), with eqn in…
- [Low] xsc_irq_eq_destroy() tears down the async EQ (xsc_stop_eqs)
before the completion EQs (free_comp_eqs).
--
net/xsc: add event queues and MSI-X
This commit creates the asynchronous and completion event queues,
allocates MSI-X vectors, and dispatches link events from a dedicated
workqueue. The command queue remains polling-only.
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
> new file mode 100644
> index 0000000000000..46eb0b031511d
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
> @@ -0,0 +1,123 @@
[ ... ]
> + for (i = 0; i < buf->nbufs; i++) {
> + buf->page_list[i].buf =
> + dma_alloc_coherent(&xdev->pdev->dev, PAGE_SIZE,
> + &t, GFP_KERNEL);
[ ... ]
> + for (i = 0; i < buf->nbufs; i++) {
> + void *addr = buf->page_list[i].buf;
> +
> + if (is_vmalloc_addr(addr))
> + pages[i] = vmalloc_to_page(addr);
> + else
> + pages[i] = virt_to_page(addr);
> + }
> + buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL);
[Severity: Medium]
Is it valid to call virt_to_page()/vmalloc_to_page() on memory returned by
dma_alloc_coherent() and then vmap() it with PAGE_KERNEL?
The DMA API doesn't guarantee that a coherent allocation sits behind a
linear-map address with a valid struct page. It can be an uncached remap,
memory from a memremap'd per-device or restricted pool, or a decrypted page
on SEV/TDX guests. In those cases the derived struct page is wrong, or the
new cacheable alias has attributes that don't match. vmap() can also fail,
and then EQ creation fails.
On 4K-page systems this path runs on every probe. Each completion EQ has
nent = roundup_pow_of_two(1024 + 0x80) = 2048 entries of 8 bytes. That is
16 KiB, which is more than the max_direct = PAGE_SIZE passed by
xsc_create_map_eq().
The vmap'd buffer also seems to be unused. xsc_buf_offset() in xsc_core.h
never reads direct.buf when nbufs != 1:
if (likely(buf->nbufs == 1))
return buf->direct.buf + offset;
else
return buf->page_list[offset >> PAGE_SHIFT].buf +
(offset & (PAGE_SIZE - 1));
So direct.buf is only ever passed to vunmap().
Upstream removed the same pattern from mlx4_buf_alloc(). The current mlx4
alloc.c uses per-page dma_alloc_coherent() fragments and no vmap.
Could the vmap() step be dropped here too?
[ ... ]
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/eq.c b/drivers/net/ethernet/yunsilicon/xsc/pci/eq.c
> new file mode 100644
> index 0000000000000..875a277a83cb8
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/eq.c
> @@ -0,0 +1,217 @@
[ ... ]
> +int xsc_create_map_eq(struct xsc_core_device *xdev,
> + struct xsc_eq *eq, u16 vecidx,
> + u32 nent, const char *name)
> +{
[ ... ]
> + eq->nent = roundup_pow_of_two(nent + XSC_NUM_SPARE_EQE);
> + err = xsc_buf_alloc(xdev, eq->nent * XSC_EQE_SIZE, PAGE_SIZE, &eq->buf);
[ ... ]
> + in->hdr.opcode = cpu_to_be16(XSC_CMD_OP_CREATE_EQ);
> + in->ctx.log_eq_sz = ilog2(eq->nent);
[Severity: Low]
Can the consumer index doorbell describe a 2048-entry EQ? The CID field in
doorbell.c is only 11 bits wide:
#define XSC_EQ_DB_DATA0_NEXT_CID_MASK GENMASK(10, 0)
#define XSC_EQ_DB_DATA0_EQ_ID_MASK GENMASK(21, 11)
xsc_update_eq_ci() fills that field from the free-running eq->cons_index
using FIELD_PREP(), which silently masks non-constant values.
The comp EQs have nent = 2048 (log_eq_sz = 11), so their doorbell carries
only the slot index. Bit 11, the wrap/phase bit that next_eqe_sw() uses
for ownership, is lost. The 512-entry async EQ keeps its index bits plus
two wrap bits.
Whether this matters depends on how the hardware reads CID, which the
source doesn't show, and EQ occupancy is small today.
Should the driver check the firmware-reported log_max_eq_sz before asking
for a 2^11 EQ? The field is in the hca_cap layout in xsc_cmd.h, but it is
not stored in xsc_caps.
> + in->ctx.vecidx = cpu_to_be16(msix_vec_offset);
> + in->ctx.pa_num = cpu_to_be16(hw_npages);
> + in->ctx.glb_func_id = cpu_to_be16(xdev->glb_func_id);
> + in->ctx.is_async_eq = (vecidx == XSC_EQ_VEC_ASYNC ? 1 : 0);
> +
> + err = xsc_cmd_exec(xdev, in, inlen, &out, sizeof(out));
> + if (err)
> + goto err_free_in;
[Severity: Medium]
What happens to the EQ ring when xsc_cmd_exec() returns -ETIMEDOUT here?
The command layer treats a timeout as a command that is still in flight.
In 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;
}
and _xsc_cmd_exec() keeps the mailboxes alive on a timeout:
if (err == -ETIMEDOUT)
/* the command owns both mailboxes now */
return err;
Here the error path goes to err_free_in and then err_free_eq_buf, so
xsc_buf_free() returns the ring pages with dma_free_coherent(). Their bus
addresses were already passed to firmware in in->pas[].
If the firmware completes the late CREATE_EQ, can it end up with an armed
EQ that DMAs into freed pages? Once cmd_status is TIMEDOUT, every later
xsc_cmd_exec() returns -ETIMEDOUT at once, so a DESTROY_EQ can never be
sent to recover.
The err_destroy_eq path and xsc_destroy_unmap_eq() already leak the buffer
for this reason when DESTROY_EQ fails. Should a CREATE_EQ timeout leak
eq->buf as well, instead of freeing it?
[ ... ]
> + eq->index = vecidx;
[ ... ]
> +int xsc_destroy_unmap_eq(struct xsc_core_device *xdev, struct xsc_eq *eq)
> +{
> + int err;
> +
> + free_irq(eq->irqn, eq);
> + err = xsc_cmd_destroy_eq(xdev, eq->eqn);
> + if (err) {
> + pci_err(xdev->pdev, "failed to destroy a previously created eq: eqn %d\n",
> + eq->eqn);
[Severity: Low]
This isn't a bug, but eq->eqn is a u32 and is printed with %d. The caller
free_comp_eqs() logs the same failure again as "failed to destroy EQ
0x%x". A single DESTROY_EQ failure therefore produces two error lines,
with the same EQ number shown once in decimal and once in hex.
Could one of the messages be dropped, or both use the same format?
[ ... ]
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.c b/drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.c
> new file mode 100644
> index 0000000000000..accc3e56ba46c
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.c
> @@ -0,0 +1,345 @@
[ ... ]
> +int xsc_core_vector2eqn(struct xsc_core_device *xdev, int vector, u32 *eqn,
> + unsigned int *irqn)
> +{
[ ... ]
> + list_for_each_entry_safe(eq, n, &table->comp_eqs_list, list) {
> + if (eq->index == vector) {
[ ... ]
> + snprintf(name, XSC_MAX_IRQ_NAME, "xsc_comp%d", i);
> + err = xsc_create_map_eq(xdev, eq,
> + i + table->eq_vec_comp_base,
> + nent, name);
> + if (err) {
> + kfree(eq);
> + goto err_free;
> + }
> +
> + eq->index = i;
[Severity: Low]
This isn't a bug, but struct xsc_eq::index ends up with two meanings.
xsc_create_map_eq() sets eq->index = vecidx, which is the absolute MSI-X
table entry: 0 for async, and comp EQs starting at
XSC_EQ_VEC_COMP_BASE = 4. This line then immediately overwrites it with
the comp-relative i.
The exported xsc_core_vector2eqn() compares vector against this field.
That makes the store in xsc_create_map_eq() dead for comp EQs, and the API
does not say that vector is comp-relative.
The in-tree callers added later in the series, xsc_eth_open_channel() and
xsc_eth_set_cq(), pass comp-relative indices and work today.
Could the field or the vector argument of xsc_core_vector2eqn() be
documented, or split into two fields, so that a caller expecting MSI-X
numbering is not misled?
[ ... ]
> +static void xsc_event_work(struct work_struct *work)
> +{
[ ... ]
> + handler = READ_ONCE(xdev->link_event_handler);
> + if (handler)
> + handler(xdev);
[ ... ]
> +void xsc_irq_event_register(struct xsc_core_device *xdev,
> + void (*handler)(void *xdev))
> +{
> + WRITE_ONCE(xdev->link_event_handler, handler);
> +}
[Severity: Low]
Is there enough ordering between xsc_irq_event_register() and
xsc_event_work()?
The handler is published with a plain WRITE_ONCE(), read with a plain
READ_ONCE(), and called right away. It reaches the registrant's state
through xdev (for example xdev->eth_priv), and that access has no address
dependency on the function pointer.
There is no smp_store_release()/smp_load_acquire() pair, lock, or RCU
here. A worker on another CPU could therefore see the new handler together
with state written before the register call that is still stale.
The in-tree user in xsc_eth_probe() happens to get a wmb() on the writer
side from the xsc_cmd_exec() calls in between. Also,
xsc_eth_link_event_handler() returns early when !adapter ||
!adapter->opened, so at worst a link event is ignored today.
The header comment describes a register/unregister contract, but nothing
in the code orders it. Would release/acquire semantics be worth using
here?
[ ... ]
> +void xsc_irq_eq_destroy(struct xsc_core_device *xdev)
> +{
> + xsc_stop_eqs(xdev);
> + free_comp_eqs(xdev);
[Severity: Low]
Should this teardown run in reverse creation order?
xsc_irq_eq_create() creates the async EQ first and the comp EQs after it.
Its own error unwind gets the order right:
err_free_comp_eqs:
free_comp_eqs(xdev);
err_stop_eqs:
xsc_stop_eqs(xdev);
Here, the async EQ (is_async_eq = 1, where firmware reports CQ/QP error
events) is destroyed while the comp EQs are still live in firmware.
Later in the series xsc_pci_fini() calls xsc_adev_uninit() before this, so
no concrete failure is known. The normal teardown and the error unwind
still disagree.
[ ... ]
--
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
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 [this message]
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=179579507511.3135.1874125473034318876@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