Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xin Tian" <tianx@yunsilicon.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH v2 10/11] net/xsc: add the transmit path
Date: Fri, 27 Nov 2026 14:58:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-237643@kernel.org> (raw)
In-Reply-To: <20261126145740.70868-11-tianx@yunsilicon.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] net/xsc: lockless TX queue stop/wake race in xsc_eth_xmit()
- [Medium] net/xsc: xsc_eth_xmit() returns NETDEV_TX_BUSY without
  stopping TX queue
- [Medium] net/xsc: xsc_poll_tx_cq() frees completed TX skbs with
  dev_kfree_skb_any()
- [Medium] net/xsc: unconditional CQ doorbell MMIO write in
  xsc_poll_tx_cq()
--

commit a6c0dbbfbb297d8daa2d0367ab92f524118727e6
Author: Xin Tian <tianx@yunsilicon.com>

net/xsc: add the transmit path

This commit adds the transmit path for the xsc Ethernet driver, including
posting linear skbs to the send queue, ringing the TX doorbell, and
polling the TX completion queue.

> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c
> new file mode 100644
> index 0000000000000..580af1f231056
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c
> @@ -0,0 +1,87 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
> + * All rights reserved.
> + */
> +
> +#include "xsc_eth.h"
> +#include "xsc_eth_txrx.h"
> +
> +#define XSC_OPCODE_RAW			7
> +
> +netdev_tx_t xsc_eth_xmit(struct sk_buff *skb, struct net_device *netdev)
> +{
> +	struct xsc_adapter *adapter = netdev_priv(netdev);
> +	struct xsc_core_device *xdev = adapter->xdev;
> +	struct xsc_send_wqe_ctrl_seg *cseg;
> +	struct xsc_tx_wqe_info *wi;
> +	struct xsc_sq *sq = &adapter->channel.qp.sq;
> +	struct xsc_tx_wqe *wqe;
> +	u32 ds_num_log = ilog2(xdev->caps.send_ds_num);
> +	dma_addr_t dma_addr;
> +	u16 pi;
> +
> +	if (!adapter->opened)
> +		return NETDEV_TX_BUSY;

[Severity: Medium]
Does returning NETDEV_TX_BUSY here without stopping sq->txq cause a
busy-requeue loop in sch_direct_xmit()?

In xsc_eth_open(), xsc_eth_sw_init() starts sq->txq and
netif_carrier_on() runs before adapter->opened is set to true, and in
xsc_eth_close(), adapter->opened is cleared before xsc_eth_sw_deinit()
disables the TX queue:

drivers/net/ethernet/yunsilicon/xsc/net/main.c:xsc_eth_close() {
	adapter->opened = false;

	netif_carrier_off(adapter->netdev);

	xsc_eth_sw_deinit(adapter);
    ...
}

While sq->txq is running and adapter->opened is false, returning
NETDEV_TX_BUSY causes sch_direct_xmit() to requeue skb and immediately
reschedule the qdisc via __netif_schedule().  Also, if earlier packets in
a batch were posted with netdev_xmit_more() true and adapter->opened
becomes false before the last packet of the batch, returning early here
skips xsc_update_tx_db() for the already-posted WQEs.

> +
> +	if (unlikely(skb_is_nonlinear(skb) || skb->len == 0 ||
> +		     skb->len > sq->hw_mtu))
> +		goto err_drop;
> +
> +	pi = xsc_wq_cyc_ctr2ix(&sq->wq, sq->pc);
> +	wqe = xsc_wq_cyc_get_wqe(&sq->wq, pi);
> +	memset(wqe, 0, xdev->caps.send_ds_num * XSC_SEND_WQE_DS);
> +
> +	dma_addr = dma_map_single(sq->channel->adapter->dev, skb->data,
> +				  skb->len, DMA_TO_DEVICE);
> +	if (unlikely(dma_mapping_error(sq->channel->adapter->dev, dma_addr)))
> +		goto err_drop;
> +
> +	wi = &sq->wqe_info[pi];
> +	wi->skb = skb;
> +	wi->dma_addr = dma_addr;
> +
> +	cseg = &wqe->ctrl;
> +	cseg->data0 = cpu_to_le32(FIELD_PREP(XSC_WQE_CTRL_SEG_DATA0_MSG_OPCODE_MASK,
> +					     XSC_OPCODE_RAW) |
> +				  FIELD_PREP(XSC_WQE_CTRL_SEG_DATA0_DS_DATA_NUM_MASK,
> +					     1) |
> +				  FIELD_PREP(XSC_WQE_CTRL_SEG_DATA0_WQE_ID_MASK,
> +					     sq->pc << ds_num_log));
> +	cseg->msg_len = cpu_to_le32(skb->len);
> +	cseg->data3 = cpu_to_le32(XSC_WQE_CTRL_SEG_DATA3_CE);
> +	wqe->data[0].data0 =
> +		cpu_to_le32(FIELD_PREP(XSC_WQE_DATA_SEG_DATA0_SEG_LEN_MASK,
> +				       skb->len));
> +	wqe->data[0].va = cpu_to_le64(dma_addr);
> +
> +	sq->pc++;
> +	if (unlikely(!xsc_wqc_has_room_for(&sq->wq, sq->cc, sq->pc,
> +					   sq->stop_room)))
> +		netif_tx_stop_queue(sq->txq);

[Severity: High]
Can the lockless stop/wake protocol between xsc_eth_xmit() and
xsc_poll_tx_cq() race to either wake a full ring or leave sq->txq
permanently stopped?

xsc_eth_xmit() does not barrier and re-check xsc_wqc_has_room_for() after
netif_tx_stop_queue(), and xsc_poll_tx_cq() updates sq->cc and checks
netif_tx_queue_stopped(sq->txq) and sq->pc without memory barriers (even
when 0 CQEs were reaped):

CPU0 (xsc_eth_xmit)               CPU1 (xsc_poll_tx_cq)
-------------------               ---------------------
/* 1 slot left:
 * pc - cc == sz - 1
 */
                                  /* 0 CQEs reaped; loads old
                                   * sq->pc before CPU0's store
                                   * is visible
                                   */
sq->pc++;
/* pc - cc == sz (full) */
netif_tx_stop_queue(sq->txq);
                                  if (netif_tx_queue_stopped(sq->txq) &&
                                      xsc_wqc_has_room_for(..., old_pc, ...))
                                    netif_tx_wake_queue(sq->txq);
                                      <-- wakes full SQ

Because xsc_eth_xmit() does not check xsc_wqc_has_room_for() at entry,
the next xsc_eth_xmit() call indexes pi at sq->cc, overwriting the
in-flight WQE and sq->wqe_info[pi] (leaking wi->skb and wi->dma_addr) and
wrapping sq->pc past sq->cc + sz so the queue stays awake.

Conversely, when CPU1 reaps completions and writes sq->cc = sqcc while
CPU0 reads the old sq->cc and stops the queue, the lack of a store-load
barrier after sq->cc = sqcc on CPU1 and after netif_tx_stop_queue() on
CPU0 allows CPU1 to observe netif_tx_queue_stopped(sq->txq) == false and
skip waking the queue, leaving sq->txq stopped with free descriptors.
Using netif_txq_maybe_stop() in xsc_eth_xmit() and only checking for wake
when i > 0 after smp_mb() in xsc_poll_tx_cq() would close both races.

[ ... ]

> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.c b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.c
> new file mode 100644
> index 0000000000000..ee6554ed80040
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.c
> @@ -0,0 +1,70 @@

[ ... ]

> +int xsc_poll_tx_cq(struct xsc_cq *cq, int budget)
> +{
> +	struct xsc_cqe *cqe;
> +	struct device *dev;
> +	struct xsc_sq *sq;
> +	u16 sqcc;
> +	int i = 0;
> +
> +	sq = container_of(cq, struct xsc_sq, cq);
> +	if (!test_bit(XSC_ETH_SQ_STATE_ENABLED, &sq->state))
> +		return 0;
> +
> +	dev = sq->channel->adapter->dev;
> +	sqcc = sq->cc;
> +
> +	while (i < budget) {
> +		struct xsc_tx_wqe_info *wi;
> +		struct sk_buff *skb;
> +
> +		cqe = xsc_cqwq_get_cqe(&cq->wq);
> +		if (!cqe)
> +			break;
> +		/* ensure cqe content is read after cqe ownership bit */
> +		dma_rmb();
> +
> +		xsc_cqwq_pop(&cq->wq);
> +		wi = &sq->wqe_info[xsc_wq_cyc_ctr2ix(&sq->wq, sqcc)];
> +
> +		skb = wi->skb;
> +		wi->skb = NULL;
> +		if (skb) {
> +			dma_unmap_single(dev, wi->dma_addr, skb->len,
> +					 DMA_TO_DEVICE);
> +			dev_kfree_skb_any(skb);
> +		}

[Severity: Medium]
Should xsc_poll_tx_cq() free completed TX packets with
napi_consume_skb(skb, budget) instead of dev_kfree_skb_any(skb)?

dev_kfree_skb_any() records SKB_DROP_REASON_NOT_SPECIFIED instead of
SKB_CONSUMED, which reports every transmitted packet as a drop in
skb:kfree_skb tracepoints and drop_monitor, and bypasses NAPI bulk skb
freeing.

> +
> +		sqcc++;
> +		i++;
> +	}
> +
> +	xsc_update_cq_ci(cq->xdev, cq->xcq.cqn, cq->wq.cc);
> +
> +	sq->cc = sqcc;

[Severity: Medium]
When no TX completions are reaped (i == 0), does xsc_poll_tx_cq() still
issue an unconditional doorbell MMIO write?

xsc_update_cq_ci() executes a wmb() and a writel() to the PCIe BAR, and
sq->cc = sqcc dirties the sq->cc cacheline on every NAPI poll even when
the TX completion queue was empty.  Guarding the doorbell update, sq->cc
write, and wake check on i > 0 avoids the barrier and MMIO write on
idle-TX polls.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126145711.70868-1-tianx@yunsilicon.com?part=10

  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 [this message]
2026-11-26 14:57 ` [PATCH v2 11/11] net/xsc: add the receive path Xin Tian
2026-11-27 14:58   ` sashiko-bot
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-237643@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