From: sashiko-bot@kernel.org
To: "Xin Tian" <tianx@yunsilicon.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH v2 11/11] net/xsc: add the receive path
Date: Fri, 27 Nov 2026 14:58:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-237644@kernel.org> (raw)
In-Reply-To: <20261126145742.70868-12-tianx@yunsilicon.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] net/xsc: missing RX doorbell on partial alloc in
xsc_eth_post_rx_wqes()
- [High] net/xsc: missing RQ state check in xsc_eth_post_rx_wqes() and
early NAPI enable
- [Medium] net/xsc: CQs armed before NAPI init in xsc_eth_open_cq() and
open_channel()
- [Medium] net/xsc: netif_napi_del() called before closing CQs in
xsc_eth_close_channel()
- [Medium] net/xsc: missing pagepool_params.napi assignment in
xsc_eth_alloc_rq()
- [Medium] net/xsc: wrong prefetch offset and DMA sync length in
xsc_skb_from_cqe()
- [Medium] net/xsc: unconditional TX CQ doorbell MMIO write in
xsc_poll_tx_cq()
--
commit 5c867b6dd2012f64299cb03411c3483a056f2b36
Author: Xin Tian <tianx@yunsilicon.com>
net/xsc: add the receive path
This commit adds the receive path for the xsc ethernet driver, building
linear skbs from page_pool buffers and polling both TX and RX completion
queues from a single NAPI instance.
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> index 8eda3c8b12f25..e7b0871c1ccb7 100644
> --- a/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> @@ -106,6 +106,13 @@ static void xsc_eth_cq_error_event(struct xsc_core_cq *xcq,
> "Eth catch CQ ERROR: %x, cqn: %d\n", event, xcq->cqn);
> }
>
> +static void xsc_eth_comp(struct xsc_core_cq *xcq)
> +{
> + struct xsc_cq *cq = container_of(xcq, struct xsc_cq, xcq);
> +
> + napi_schedule(cq->napi);
> +}
> +
> static int xsc_eth_alloc_cq(struct xsc_channel *c, struct xsc_cq *pcq,
> struct xsc_cq_param *pcq_param)
> {
> @@ -125,6 +132,7 @@ static int xsc_eth_alloc_cq(struct xsc_channel *c, struct xsc_cq *pcq,
> if (ret)
> return ret;
>
> + core_cq->comp = xsc_eth_comp;
> core_cq->event = xsc_eth_cq_error_event;
> core_cq->vector = 0;
>
> @@ -204,6 +212,7 @@ static int xsc_eth_open_cq(struct xsc_channel *c,
>
> xsc_arm_cq(pcq->xdev, pcq->xcq.cqn, pcq->wq.cc, 0);
>
> + pcq->napi = &c->napi;
> pcq->channel = c;
>
> return 0;
> @@ -448,6 +457,8 @@ static int xsc_eth_open_channel(struct xsc_adapter *adapter,
> if (ret)
> goto err_close_sq_cq;
>
> + netif_napi_add(adapter->netdev, &c->napi, xsc_eth_napi_poll);
> +
> netdev_dbg(adapter->netdev, "open channel ok\n");
> return 0;
[Severity: Medium]
Can an EQ completion interrupt reach xsc_eth_comp() before pcq->napi and
c->napi are initialized?
xsc_eth_open_cq() registers pcq->xcq in xdev->cq_table.tree via
xsc_eth_set_cq() and arms it with xsc_arm_cq() before assigning pcq->napi,
and xsc_eth_open_channel() opens both CQs before calling netif_napi_add():
CPU0 <hardirq>
xsc_eth_open_channel()
xsc_eth_open_cq(&c->qp.rq.cq)
xsc_eth_set_cq()
xsc_arm_cq()
xsc_eq_int()
xsc_cq_completion()
xsc_eth_comp()
napi_schedule(cq->napi)
<-- NULL or uninitialized napi
pcq->napi = &c->napi
...
netif_napi_add(&c->napi)
If an EQ event arrives in that window, napi_schedule() either dereferences
NULL or schedules a zeroed napi_struct whose NAPI_STATE_SCHED bit is clear
and poll callback is NULL. Calling netif_napi_add() before opening the
CQs and setting pcq->napi before xsc_eth_set_cq() would close this window.
[ ... ]
> @@ -625,11 +640,17 @@ static void xsc_eth_close_qp_rq(struct xsc_channel *c, struct xsc_rq *prq)
> return;
> }
>
> + /* return the pages still posted to hardware before the pool dies */
> + for (i = 0; i < wq_sz; i++)
> + xsc_eth_dealloc_rx_wqe(prq, i);
> +
> xsc_eth_free_qp_rq(prq);
> }
>
> static void xsc_eth_close_channel(struct xsc_channel *c, bool free_rq)
> {
> + netif_napi_del(&c->napi);
> +
> if (free_rq)
> xsc_eth_close_qp_rq(c, &c->qp.rq);
> xsc_eth_close_cq(c, &c->qp.rq.cq);
[Severity: Medium]
Should netif_napi_del(&c->napi) run after both CQs are closed in
xsc_eth_close_channel()?
While xsc_eth_close_qp_rq(), xsc_eth_close_qp_sq() and xsc_eth_close_cq()
are still running, the CQs remain in xdev->cq_table.tree and an arriving
EQ interrupt can invoke xsc_eth_comp() -> napi_schedule(&c->napi) on the
already deleted napi_struct.
> @@ -644,6 +665,7 @@ static int xsc_eth_open_channels(struct xsc_adapter *adapter)
> {
> struct xsc_channel_param *chl_param;
> bool free_rq = false;
> + bool napi_enabled = false;
> int ret = 0;
>
> chl_param = kvzalloc_obj(*chl_param, GFP_KERNEL);
> @@ -662,6 +684,9 @@ static int xsc_eth_open_channels(struct xsc_adapter *adapter)
> goto err_close_channel;
> free_rq = true;
>
> + napi_enable(&adapter->channel.napi);
> + napi_enabled = true;
> +
> ret = xsc_eth_modify_qps_channel(adapter, &adapter->channel);
> if (ret)
> goto err_close_channel;
> @@ -670,6 +695,8 @@ static int xsc_eth_open_channels(struct xsc_adapter *adapter)
> return 0;
>
> err_close_channel:
> + if (napi_enabled)
> + napi_disable(&adapter->channel.napi);
> xsc_eth_close_channel(&adapter->channel, free_rq);
> err_free_param:
> kvfree(chl_param);
> @@ -702,6 +729,9 @@ static void xsc_eth_deactivate_channel(struct xsc_channel *c)
> clear_bit(XSC_ETH_SQ_STATE_ENABLED, &c->qp.sq.state);
>
> synchronize_net();
> +
> + /* last doorbell out */
> + napi_disable(&c->napi);
> }
[Severity: High]
Can xsc_eth_napi_poll() race with xsc_eth_modify_qps_channel() or run
while XSC_ETH_RQ_STATE_ENABLED is clear?
xsc_eth_open_channels() calls napi_enable() while both CQs are already
armed, before xsc_eth_modify_qps_channel() posts the initial RX WQEs and
before xsc_eth_activate_channel() sets XSC_ETH_RQ_STATE_ENABLED and
XSC_ETH_SQ_STATE_ENABLED. Because xsc_eth_post_rx_wqes() does not check
XSC_ETH_RQ_STATE_ENABLED, an EQ interrupt during open can run
xsc_eth_post_rx_wqes() in NAPI concurrently with process context:
CPU0 (process) CPU1 (<softirq>)
xsc_eth_open_channels()
napi_enable(&c->napi)
xsc_eth_modify_qps_channel()
xsc_eth_post_rx_wqes(rq)
xsc_alloc_rx_wqes()
xsc_eth_napi_poll()
xsc_eth_post_rx_wqes(rq)
xsc_alloc_rx_wqes()
<-- concurrent page_pool alloc
and rq->wqe.wq corruption
This violates the single-consumer BH invariant of page_pool_dev_alloc_pages()
and corrupts rq->wqe.wq and rq->wqe.di[].
In addition, when xsc_eth_napi_poll() runs while the ENABLED bits are
clear (either before xsc_eth_activate_channel(), or in
xsc_eth_deactivate_channel() between clear_bit() and napi_disable()):
- xsc_eth_post_rx_wqes() still allocates pages and rings the RX doorbell,
and if xsc_alloc_rx_wqes() fails with -ENOMEM it returns true (busy),
preventing napi_complete_done() so napi_disable() hangs forever.
- xsc_poll_tx_cq() and xsc_poll_rx_cq() return 0 without draining pending
CQEs, yet xsc_eth_napi_poll() unconditionally rearms both CQs at the
unconsumed cq->wq.cc index, causing an immediate re-interrupt loop.
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_rx.c b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_rx.c
> new file mode 100644
> index 0000000000000..2c07f80928ea2
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_rx.c
> @@ -0,0 +1,210 @@
[ ... ]
> +static struct sk_buff *xsc_skb_from_cqe(struct xsc_rq *rq,
> + struct xsc_dma_info *di,
> + u32 cqe_bcnt)
> +{
> + struct sk_buff *skb;
> + void *va;
> + u32 frag_size;
> +
> + va = page_address(di->page);
> + frag_size = XSC_SKB_FRAG_SZ(cqe_bcnt);
> +
> + dma_sync_single_range_for_cpu(rq->cq.xdev->device, di->addr,
> + 0, frag_size, DMA_FROM_DEVICE);
> + net_prefetch(va + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
[Severity: Medium]
Does net_prefetch() prefetch past the packet headers here?
xsc_alloc_rx_wqes() programs wqe->data[0].va with di->addr (offset 0 of
di->page), and napi_build_skb(va, frag_size) places struct skb_shared_info
at the end of the buffer, not at the start. Prefetching
va + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) skips the first 320
bytes where the Ethernet, IP, and transport headers sit (and prefetches
past the end of frames <= 320 bytes), while dma_sync_single_range_for_cpu()
also syncs the trailing skb_shared_info region instead of cqe_bcnt bytes.
> +
> + skb = napi_build_skb(va, frag_size);
> + if (unlikely(!skb))
> + return NULL;
> +
> + skb_put(skb, cqe_bcnt);
> + skb_mark_for_recycle(skb);
> +
> + return skb;
> +}
[Severity: Medium]
Does skb_mark_for_recycle() ever use the lockless NAPI page_pool cache
without pagepool_params.napi set?
In xsc_eth_alloc_rq(), pagepool_params.napi is left NULL:
drivers/net/ethernet/yunsilicon/xsc/net/main.c:xsc_eth_alloc_rq() {
...
pagepool_params.dev = c->adapter->dev;
pagepool_params.dma_dir = DMA_FROM_DEVICE;
pagepool_params.max_len = PAGE_SIZE;
prq->page_pool = page_pool_create(&pagepool_params);
...
}
Because pool->p.napi is NULL, napi_pp_put_page() -> page_pool_napi_local()
always returns false when freeing recycled skbs, bypassing
pool->alloc.cache and forcing every recycled page through the locked
ptr_ring slow path.
[ ... ]
> +bool xsc_eth_post_rx_wqes(struct xsc_rq *rq)
> +{
> + struct xsc_wq_cyc *wq = &rq->wqe.wq;
> + int alloc;
> + u16 head;
> +
> + if (xsc_wq_cyc_missing(wq) < rq->wqe.wqe_bulk)
> + return false;
> +
> + do {
> + head = xsc_wq_cyc_get_head(wq);
> + alloc = min_t(int, rq->wqe.wqe_bulk, xsc_wq_cyc_missing(wq));
> +
> + if (xsc_alloc_rx_wqes(rq, head, alloc))
> + return true;
> +
> + xsc_wq_cyc_push_n(wq, alloc);
> + } while (xsc_wq_cyc_missing(wq) >= rq->wqe.wqe_bulk);
> +
> + dma_wmb();
> +
> + /* ensure wqes are visible to device before updating doorbell record */
> + xsc_rq_notify_hw(rq);
> +
> + return false;
> +}
[Severity: High]
If xsc_alloc_rx_wqes() fails after earlier loop iterations already pushed
WQEs, doesn't returning true immediately skip dma_wmb() and
xsc_rq_notify_hw(rq)?
Those earlier batches are already accounted for in wq->wqe_ctr and
wq->cur_sz via xsc_wq_cyc_push_n(), so skipping the doorbell leaves
hardware unaware of the posted descriptors. Furthermore,
xsc_eth_modify_qps_channel() ignores the return value of
xsc_eth_post_rx_wqes(&c->qp.rq) during initial fill; if any batch fails
during ndo_open, the RX doorbell is never rung at all and the RX queue
starts in RTS with 0 descriptors notified to hardware, stalling RX
permanently.
> +
> +int xsc_eth_napi_poll(struct napi_struct *napi, int budget)
> +{
> + struct xsc_channel *c = container_of(napi, struct xsc_channel, napi);
> + struct xsc_rq *rq = &c->qp.rq;
> + bool busy;
> + int work_done;
> +
> + busy = xsc_poll_tx_cq(&c->qp.sq.cq, xsc_cqwq_get_size(&c->qp.sq.cq.wq));
[Severity: Medium]
Does xsc_poll_tx_cq() ring the TX CQ consumer-index doorbell on every NAPI
poll even when no TX completions were processed?
Unlike xsc_poll_rx_cq(), which guards xsc_cq_notify_hw() with
if (work_done), xsc_poll_tx_cq() calls xsc_update_cq_ci() unconditionally
when i == 0, issuing an unnecessary wmb() and PCIe MMIO writel() on every
RX-only NAPI poll:
drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.c:xsc_poll_tx_cq() {
...
if (skb) {
dma_unmap_single(dev, wi->dma_addr, skb->len,
DMA_TO_DEVICE);
dev_kfree_skb_any(skb);
}
sqcc++;
i++;
}
xsc_update_cq_ci(cq->xdev, cq->xcq.cqn, cq->wq.cc);
...
}
Also, since xsc_poll_tx_cq() runs from NAPI poll context, using
napi_consume_skb(skb, budget) instead of dev_kfree_skb_any(skb) would
enable NAPI skb bulk freeing.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126145711.70868-1-tianx@yunsilicon.com?part=11
next prev parent reply other threads:[~2026-11-27 14:58 UTC|newest]
Thread overview: 22+ 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-26 14:57 ` [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors Xin Tian
2026-11-26 14:57 ` [PATCH v2 03/11] net/xsc: add the command queue Xin Tian
2026-11-27 14:58 ` sashiko-bot
2026-11-26 14:57 ` [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function Xin Tian
2026-11-27 14:58 ` sashiko-bot
2026-11-26 14:57 ` [PATCH v2 05/11] net/xsc: add event queues and MSI-X Xin Tian
2026-11-27 14:58 ` sashiko-bot
2026-11-26 14:57 ` [PATCH v2 06/11] net/xsc: add CQ and QP helpers Xin Tian
2026-11-27 14:58 ` sashiko-bot
2026-11-26 14:57 ` [PATCH v2 07/11] net/xsc: add the ethernet netdev Xin Tian
2026-11-27 14:58 ` sashiko-bot
2026-11-26 14:57 ` [PATCH v2 08/11] net/xsc: add the single TX/RX channel Xin Tian
2026-11-27 14:58 ` sashiko-bot
2026-11-26 14:57 ` [PATCH v2 09/11] net/xsc: report link state changes Xin Tian
2026-11-27 14:58 ` sashiko-bot
2026-11-26 14:57 ` [PATCH v2 10/11] net/xsc: add the transmit path Xin Tian
2026-11-27 14:58 ` sashiko-bot
2026-11-26 14:57 ` [PATCH v2 11/11] net/xsc: add the receive path Xin Tian
2026-11-27 14:58 ` sashiko-bot [this message]
2026-11-27 14:58 ` [PATCH v2 00/11] net/xsc: add the Yunsilicon XSC ethernet driver sashiko-bot
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=sashiko-outbox-237644@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tianx@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