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 08/11] net/xsc: add the single TX/RX channel
Date: Fri, 27 Nov 2026 14:58:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-237641@kernel.org> (raw)
In-Reply-To: <20261126145733.70868-9-tianx@yunsilicon.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] net/xsc: return -ENOMEM on di alloc failure in
  xsc_eth_alloc_rq()
- [Medium] net/xsc: disable NIC HCA and port before queue teardown in
  xsc_eth_close()
- [Medium] net/xsc: WQ DMA buffers freed on xsc_core_eth_destroy_qp()
  rollback failure
- [Medium] net/xsc: unsafe CQ teardown and memset on failure in
  xsc_eth_close_channel()
- [Medium] net/xsc: unsynchronized set_dev_node() in
  xsc_dma_zalloc_coherent_node()
--

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

net/xsc: add the single TX/RX channel

This commit brings up a single TX/RX channel on the netdev by building queue
parameters, creating the CQs, SQ, and RQ, enabling the NIC HCA, and adding
the queue ring and fragmented DMA buffer helpers.

> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> index b9e75d7e14e78..1c7bbc27d8c4f 100644
> --- a/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> @@ -25,6 +25,774 @@ static void xsc_eth_netdev_init(struct xsc_adapter *adapter)

[ ... ]

> +static int xsc_eth_open_qp_sq(struct xsc_channel *c,
> +			      struct xsc_sq *psq,
> +			      struct xsc_sq_param *psq_param)
> +{

[ ... ]

> +err_sq_modify_in_destroy:
> +	kvfree(modify_in);
> +
> +err_sq_common_destroy:
> +	xsc_free_qp_sq_db(psq);
> +
> +	xsc_core_destroy_resource_common(xdev, &psq->cqp);
> +
> +err_sq_destroy:
> +	xsc_core_eth_destroy_qp(xdev, psq->cqp.qpn);
> +
> +err_sq_in_destroy:
> +	kvfree(in);
> +
> +err_sq_wq_destroy:
> +	xsc_eth_wq_destroy(&psq->wq_ctrl);
> +	return ret;
> +}

[Severity: Medium]
Can this free psq->wq_ctrl while the SQ is still live in firmware if
xsc_core_eth_destroy_qp() fails during error rollback?  Unlike
xsc_eth_close_qp_sq() and xsc_eth_close_qp_rq(), which leak the WQ buffer
when DESTROY_QP fails so the device cannot DMA into freed pages,
err_sq_destroy here and err_destroy_qp in xsc_eth_open_qp_rq() ignore the
return value of xsc_core_eth_destroy_qp() and unconditionally free the WQ
DMA buffers (and prq->page_pool in the RQ case).

[ ... ]

> +static int xsc_eth_alloc_rq(struct xsc_channel *c,
> +			    struct xsc_rq *prq,
> +			    struct xsc_rq_param *prq_param)
> +{
> +	u8 ele_log_size = prq_param->rq_attr.ele_log_size;
> +	struct page_pool_params pagepool_params = {0};
> +	u8 q_log_size = prq_param->rq_attr.q_log_size;
> +	u32 wq_sz;
> +	int ret = 0;
> +	int i;
> +
> +	prq_param->wq.db_numa_node = cpu_to_node(c->cpu);
> +
> +	ret = xsc_eth_wq_cyc_create(c->adapter->xdev, &prq_param->wq,
> +				    q_log_size, ele_log_size, &prq->wqe.wq,
> +				    &prq->wq_ctrl);
> +	if (ret)
> +		return ret;
> +
> +	wq_sz = xsc_wq_cyc_get_size(&prq->wqe.wq);
> +	prq->wqe.di = kvzalloc_node(array_size(wq_sz, sizeof(*prq->wqe.di)),
> +				    GFP_KERNEL, cpu_to_node(c->cpu));
> +	if (!prq->wqe.di)
> +		goto err_destroy_wq;

[ ... ]

> +err_free_di:
> +	kvfree(prq->wqe.di);
> +err_destroy_wq:
> +	xsc_eth_wq_destroy(&prq->wq_ctrl);
> +	return ret;
> +}

[Severity: Medium]
Does xsc_eth_alloc_rq() return 0 when kvzalloc_node() fails to allocate
prq->wqe.di?  Because ret is still 0 from xsc_eth_wq_cyc_create(), jumping
to err_destroy_wq frees prq->wq_ctrl.buf and returns success to
xsc_eth_open_qp_rq(), which then reads the freed prq->wq_ctrl.buf.frags in
xsc_core_fill_page_frag_array() and double frees prq->wq_ctrl on teardown.

[ ... ]

> +static void xsc_eth_close_channel(struct xsc_channel *c, bool free_rq)
> +{
> +	if (free_rq)
> +		xsc_eth_close_qp_rq(c, &c->qp.rq);
> +	xsc_eth_close_cq(c, &c->qp.rq.cq);
> +	memset(&c->qp.rq, 0, sizeof(struct xsc_rq));
> +
> +	xsc_eth_close_qp_sq(c, &c->qp.sq);
> +	xsc_eth_close_cq(c, &c->qp.sq.cq);
> +	memset(&c->qp.sq, 0, sizeof(struct xsc_sq));
> +}

[Severity: Medium]
What happens in xsc_eth_close_channel() if xsc_core_eth_destroy_qp() or
xsc_core_eth_destroy_cq() fails?  When QP destruction fails in
xsc_eth_close_qp_rq() or xsc_eth_close_qp_sq(), the QP remains live in
firmware, yet xsc_eth_close_channel() still destroys and frees its bound CQ.
In addition, when xsc_core_eth_destroy_cq() fails, xsc_destroy_cq() returns
before waiting on xcq->free for in-flight event or completion handlers, and
the unconditional memset() zeroes xcq->free, xcq->refcount, and cq->xdev
while a handler can still be using them.

[ ... ]

> @@ -45,25 +813,46 @@ static void xsc_set_port_admin_status(struct xsc_adapter *adapter,
>  static int xsc_eth_open(struct net_device *netdev)
>  {
>  	struct xsc_adapter *adapter = netdev_priv(netdev);
> +	int ret;
> +
> +	ret = xsc_eth_sw_init(adapter);
> +	if (ret)
> +		return ret;
> +
> +	ret = xsc_eth_enable_nic_hca(adapter);
> +	if (ret)
> +		goto err_sw_deinit;
>  
>  	adapter->opened = true;
>  
>  	xsc_set_port_admin_status(adapter, XSC_PORT_UP);
>  
>  	return 0;
> +
> +err_sw_deinit:
> +	xsc_eth_sw_deinit(adapter);
> +	return ret;
>  }
>  
>  static int xsc_eth_close(struct net_device *netdev)
>  {
>  	struct xsc_adapter *adapter = netdev_priv(netdev);
> +	int ret;
>  
>  	adapter->opened = false;
>  
>  	netif_carrier_off(adapter->netdev);
>  
> +	xsc_eth_sw_deinit(adapter);
> +
> +	ret = xsc_eth_disable_nic_hca(adapter);
> +	if (ret)
> +		netdev_err(adapter->netdev, "failed to disable nic hca, err=%d\n",
> +			   ret);
> +
>  	xsc_set_port_admin_status(adapter, XSC_PORT_DOWN);
>  
> -	return 0;
> +	return ret;
>  }

[Severity: Medium]
Should xsc_eth_close() bring the port down and disable the NIC HCA before
calling xsc_eth_sw_deinit()?  Right now xsc_eth_sw_deinit() destroys the RQ,
SQ, and CQs and frees their DMA buffers and page_pool while the port is
still admin-up and the NIC HCA is still steering incoming packets to
adapter->channel.qp.rq.rqn.

> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
> index 46eb0b031511d..0b0478c64be3b 100644
> --- a/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
> @@ -121,3 +121,105 @@ void xsc_fill_page_array(struct xsc_buf *buf, __be64 *pas, unsigned int npages)

[ ... ]

> +static void *xsc_dma_zalloc_coherent_node(struct xsc_core_device *xdev,
> +					  size_t size, dma_addr_t *dma_handle,
> +					  int node)
> +{
> +	struct device *device = &xdev->pdev->dev;
> +	int original_node;
> +	void *cpu_handle;
> +
> +	/* WA for kernels that don't use numa_mem_id in alloc_pages_node */
> +	if (node == NUMA_NO_NODE)
> +		node = numa_mem_id();
> +
> +	original_node = dev_to_node(device);
> +	set_dev_node(device, node);
> +	cpu_handle = dma_alloc_coherent(device, size, dma_handle, GFP_KERNEL);
> +	set_dev_node(device, original_node);
> +
> +	return cpu_handle;
> +}

[Severity: Medium]
Can xsc_dma_zalloc_coherent_node() use dma_alloc_coherent_node() instead of
mutating xdev->pdev->dev.numa_node with set_dev_node()?  Overwriting the
shared device's NUMA node across a sleeping dma_alloc_coherent() call
without locking exposes the temporary node to concurrent readers of
dev_to_node(&xdev->pdev->dev), and two concurrent callers of
xsc_core_frag_buf_alloc_node() can save the overwritten value as
original_node and permanently corrupt the device's NUMA node.

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

  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 [this message]
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
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-237641@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