On 11/27/2026 11:57 PM, netd…@kernel.org wrote:
> 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?
Removed. nbufs > 1 never reads direct.buf so the vmap was dead code, and a
coherent allocation has no struct page to vmap. Matches what mlx4 does.
> [ ... ]
>
>> 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.
Fixed. EQ size is now roundup_pow2(roundup(nent, spare)) and the
completion EQ stays at 1024, so the index fits the 11-bit doorbell field
and the firmware EQ_SIZE_MAX.
>> + 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?
Agreed. On a CREATE_EQ timeout the ring is no longer freed: the device may
still own it, so we leak rather than hand it back.
> [ ... ]
>
>> + 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?
Changed to %u and dropped the duplicate log in free_comp_eqs().
> [ ... ]
>
>> 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?
Fixed: removed the dead eq->index store and documented that vector2eqn's
@vector is a completion EQ index, not an MSI-X table entry.
> [ ... ]
>
>> +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?
Declined, I don't see a reachable race: eth_priv is set in probe and two
commands complete before the handler is registered, the handler re-checks
opened under state_lock, and unregister flushes the workqueue. Worst case
a pre-open link event gets dropped, and open() samples the link itself.
> [ ... ]
>
>> +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.
>
> [ ... ]
Fixed: completion EQs are torn down first and the async EQ last, reverse
of creation.
Thanks,
Xin
>