DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Renyong Wan" <wanry@yunsilicon.com>
To: <dev@dpdk.org>
Cc: "Stephen Hemminger" <stephen@networkplumber.org>,
	<nana@yunsilicon.com>,  <qianr@yunsilicon.com>,
	<zhangxx@yunsilicon.com>, <xudw@yunsilicon.com>,
	 <stable@dpdk.org>
Subject: [PATCH v4 1/3] net/xsc: fix jumbo buffer allocation and leak
Date: Tue, 17 Nov 2026 19:14:20 +0800	[thread overview]
Message-ID: <1794914060.966424@yunsilicon.com> (raw)
In-Reply-To: <1794914060.606144@yunsilicon.com>

The jumbo buffer is allocated inside the WQE loop, so a device without
IOVA retries it on every WQE and logs an error each time. The fallback
also hands XSC_MAX_RECV_LEN bytes to a segment that points into an
mbuf, which is a DMA overrun.

Allocate it once before the loop and fail the queue start on error.
Nothing frees it on removal either, so free it in xsc_dev_close() once
the last port stops the hardware.

Fixes: 0ff4b93c318f ("net/xsc: support device start")
Cc: stable@dpdk.org
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Renyong Wan <wanry@yunsilicon.com>
---
 drivers/net/xsc/xsc_dev.c | 16 ++++++++++---
 drivers/net/xsc/xsc_rx.c  | 47 ++++++++++++++++++++++-----------------
 2 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 478f4895..953409a9 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -141,11 +141,21 @@ xsc_dev_tx_qp_create(struct xsc_dev *xdev, struct xsc_tx_qp_params *qp_params,
 int
 xsc_dev_close(struct xsc_dev *xdev, int repr_id)
 {
+	int ret = 0;
+
 	xsc_dev_clear_pct(xdev, repr_id);
 
-	if (repr_id == xdev->num_repr_ports - 1)
-		return xdev->dev_ops->dev_close(xdev);
-	return 0;
+	if (repr_id == xdev->num_repr_ports - 1) {
+		ret = xdev->dev_ops->dev_close(xdev);
+		/*
+		 * The buffer is shared by all the ports, the other Rx
+		 * queues hold its IOVA until the device is stopped.
+		 */
+		rte_free(xdev->jumbo_buffer_pa);
+		xdev->jumbo_buffer_pa = NULL;
+	}
+
+	return ret;
 }
 
 int
diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c
index 13b2e269..30b40df3 100644
--- a/drivers/net/xsc/xsc_rx.c
+++ b/drivers/net/xsc/xsc_rx.c
@@ -195,7 +195,7 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 	return nb_pkts;
 }
 
-static void
+static int
 xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
 {
 	const uint32_t wqe_n = rxq_data->wqe_s;
@@ -211,6 +211,24 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
 	volatile struct xsc_wqe_data_seg *seg;
 	volatile struct xsc_wqe_data_seg *seg_next;
 
+	if (rx_ds_num != 1 && jumbo_buffer_pa == NULL) {
+		jumbo_buffer_pa = rte_malloc(NULL, XSC_MAX_RECV_LEN, 0);
+		if (jumbo_buffer_pa == NULL) {
+			PMD_DRV_LOG(ERR, "Failed to malloc jumbo_buffer");
+			return -ENOMEM;
+		}
+
+		jumbo_buffer_va = (void *)rte_malloc_virt2iova(jumbo_buffer_pa);
+		if ((rte_iova_t)jumbo_buffer_va == RTE_BAD_IOVA) {
+			PMD_DRV_LOG(ERR, "Failed to get IOVA of jumbo_buffer");
+			rte_free(jumbo_buffer_pa);
+			return -EFAULT;
+		}
+
+		xdev->jumbo_buffer_pa = jumbo_buffer_pa;
+		xdev->jumbo_buffer_va = jumbo_buffer_va;
+	}
+
 	for (i = 0; (i != wqe_n); ++i) {
 		mbuf = (*rxq_data->elts)[i];
 		seg = &((volatile struct xsc_wqe_data_seg *)rxq_data->wqes)[i * rx_ds_num];
@@ -227,25 +245,6 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
 
 		if (rx_ds_num != 1) {
 			seg_next = seg + 1;
-			if (jumbo_buffer_va == NULL) {
-				jumbo_buffer_pa = rte_malloc(NULL, XSC_MAX_RECV_LEN, 0);
-				if (jumbo_buffer_pa == NULL) {
-					/* Rely on mtu */
-					seg->seg_len = XSC_MAX_RECV_LEN;
-					PMD_DRV_LOG(ERR, "Failed to malloc jumbo_buffer");
-					continue;
-				} else {
-					jumbo_buffer_va =
-						(void *)rte_malloc_virt2iova(jumbo_buffer_pa);
-					if ((rte_iova_t)jumbo_buffer_va == RTE_BAD_IOVA) {
-						seg->seg_len = XSC_MAX_RECV_LEN;
-						PMD_DRV_LOG(ERR, "Failed to turn jumbo_buffer");
-						continue;
-					}
-				}
-				xdev->jumbo_buffer_pa = jumbo_buffer_pa;
-				xdev->jumbo_buffer_va = jumbo_buffer_va;
-			}
 			*seg_next = (struct xsc_wqe_data_seg){
 				.va = rte_cpu_to_le_64((uint64_t)jumbo_buffer_va),
 				.seg_len = rte_cpu_to_le_32(XSC_MAX_RECV_LEN - seg_len),
@@ -264,6 +263,8 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
 	recv_db.next_pid = wqe_n << log2ds;
 	recv_db.qp_num = rxq_data->qpn;
 	rte_write32(rte_cpu_to_le_32(recv_db.recv_data), rxq_data->rq_db);
+
+	return 0;
 }
 
 static int
@@ -484,7 +485,11 @@ xsc_rss_qp_create(struct xsc_ethdev_priv *priv, int port_id)
 
 		rxq_data->qpn = rqn_base + i;
 		xsc_dev_modify_qp_status(xdev, rxq_data->qpn, 1, XSC_CMD_OP_RTR2RTS_QP);
-		xsc_rxq_initialize(xdev, rxq_data);
+		ret = xsc_rxq_initialize(xdev, rxq_data);
+		if (ret != 0) {
+			rte_errno = -ret;
+			goto set_qp_fail;
+		}
 		rxq_data->cq_ci = 0;
 		PMD_DRV_LOG(INFO, "Port %d create rx qp, wqe_s:%d, wqe_n:%d, qp_db=%p, qpn:%u",
 			    port_id,

  reply	other threads:[~2026-11-17 11:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 11:14 [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
2026-11-17 11:14 ` Renyong Wan [this message]
2026-11-17 11:14 ` [PATCH v4 3/3] net/xsc: rename jumbo buffer fields Renyong Wan
2026-11-17 11:14 ` [PATCH v4 2/3] net/xsc: fix leak and missing null check Renyong Wan
2026-11-17 17:04 ` [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Stephen Hemminger

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=1794914060.966424@yunsilicon.com \
    --to=wanry@yunsilicon.com \
    --cc=dev@dpdk.org \
    --cc=nana@yunsilicon.com \
    --cc=qianr@yunsilicon.com \
    --cc=stable@dpdk.org \
    --cc=stephen@networkplumber.org \
    --cc=xudw@yunsilicon.com \
    --cc=zhangxx@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