* [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer
@ 2026-11-17 11:14 Renyong Wan
2026-11-17 11:14 ` [PATCH v4 2/3] net/xsc: fix leak and missing null check Renyong Wan
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Renyong Wan @ 2026-11-17 11:14 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, nana, qianr, zhangxx, xudw
v4:
- free the jumbo buffer only when the last representor stops the device, it
is shared by every port and their Rx queues still point at it
v3:
- free the jumbo buffer in xsc_dev_close(), the device removal path does not
go through xsc_dev_uninit()
- drop the redundant parentheses reported by checkpatch, no functional
change
v2:
- address the AI review of v1: allocate the jumbo buffer once per device,
fail the queue setup when there is no IOVA, and free it on device close
- fix the leak in xsc_dev_init() and the unchecked rte_malloc_socket()
- rename the jumbo buffer fields, they held the opposite of what their
names say
Renyong Wan (3):
net/xsc: fix jumbo buffer allocation and leak
net/xsc: fix leak and missing null check
net/xsc: rename jumbo buffer fields
drivers/net/xsc/xsc_dev.c | 17 ++++++++++--
drivers/net/xsc/xsc_dev.h | 4 +--
drivers/net/xsc/xsc_ethdev.c | 6 ++++
drivers/net/xsc/xsc_rx.c | 53 ++++++++++++++++++++----------------
4 files changed, 51 insertions(+), 29 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/3] net/xsc: fix jumbo buffer allocation and leak
2026-11-17 11:14 [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
2026-11-17 11:14 ` [PATCH v4 2/3] net/xsc: fix leak and missing null check Renyong Wan
2026-11-17 11:14 ` [PATCH v4 3/3] net/xsc: rename jumbo buffer fields Renyong Wan
@ 2026-11-17 11:14 ` Renyong Wan
2026-11-17 17:04 ` [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Stephen Hemminger
3 siblings, 0 replies; 5+ messages in thread
From: Renyong Wan @ 2026-11-17 11:14 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, nana, qianr, zhangxx, xudw, stable
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,
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 2/3] net/xsc: fix leak and missing null check
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
2026-11-17 11:14 ` [PATCH v4 3/3] net/xsc: rename jumbo buffer fields Renyong Wan
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Renyong Wan @ 2026-11-17 11:14 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, nana, qianr, zhangxx, xudw, stable
xsc_dev_init() leaks the structure when the dev_ops lookup fails. Free
it there: xsc_dev_uninit() cannot be used, as xsc_dev_close()
dereferences xdev->dev_ops.
xsc_ethdev_tx_queue_setup() misses the NULL check on the
rte_malloc_socket() result. Return -ENOMEM, as the Rx path does.
Fixes: fb7d4f7ae39a ("net/xsc: add device initialization")
Fixes: 488262986eee ("net/xsc: support Rx and Tx queue setup")
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 | 1 +
drivers/net/xsc/xsc_ethdev.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 953409a9..f048efd7 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -375,6 +375,7 @@ xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **xdev)
d->dev_ops = xsc_dev_ops_get(pci_dev->kdrv);
if (d->dev_ops == NULL) {
PMD_DRV_LOG(ERR, "Could not get dev_ops, kdrv=%d", pci_dev->kdrv);
+ rte_free(d);
return -ENODEV;
}
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 20d6f58f..a5c3e4a6 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -545,6 +545,12 @@ xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
txq = rte_malloc_socket(NULL, sizeof(*txq) + desc_n * sizeof(struct rte_mbuf *),
RTE_CACHE_LINE_SIZE, socket);
+ if (txq == NULL) {
+ PMD_DRV_LOG(ERR, "Port %u create txq idx %d failure",
+ dev->data->port_id, idx);
+ rte_errno = ENOMEM;
+ return -rte_errno;
+ }
txq->offloads = conf->offloads | dev->data->dev_conf.txmode.offloads;
txq->priv = priv;
txq->socket = socket;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4 3/3] net/xsc: rename jumbo buffer fields
2026-11-17 11:14 [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
2026-11-17 11:14 ` [PATCH v4 2/3] net/xsc: fix leak and missing null check Renyong Wan
@ 2026-11-17 11:14 ` Renyong Wan
2026-11-17 11:14 ` [PATCH v4 1/3] net/xsc: fix jumbo buffer allocation and leak Renyong Wan
2026-11-17 17:04 ` [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Stephen Hemminger
3 siblings, 0 replies; 5+ messages in thread
From: Renyong Wan @ 2026-11-17 11:14 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, nana, qianr, zhangxx, xudw
The names are the other way round: jumbo_buffer_pa holds the virtual
address and jumbo_buffer_va holds the IOVA, which is why the bug went
unnoticed.
Rename them to jumbo_buf and jumbo_iova with matching types, which also
removes the casts.
Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Renyong Wan <wanry@yunsilicon.com>
---
drivers/net/xsc/xsc_dev.c | 4 ++--
drivers/net/xsc/xsc_dev.h | 4 ++--
drivers/net/xsc/xsc_rx.c | 22 +++++++++++-----------
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index f048efd7..f1abe560 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -151,8 +151,8 @@ xsc_dev_close(struct xsc_dev *xdev, int repr_id)
* 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;
+ rte_free(xdev->jumbo_buf);
+ xdev->jumbo_buf = NULL;
}
return ret;
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index d4a7d90b..3473333c 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -189,8 +189,8 @@ struct xsc_dev {
void *dev_priv;
char name[PCI_PRI_STR_SIZE];
void *bar_addr;
- void *jumbo_buffer_pa;
- void *jumbo_buffer_va;
+ void *jumbo_buf;
+ rte_iova_t jumbo_iova;
uint64_t bar_len;
int ctrl_fd;
rte_intr_callback_fn intr_cb;
diff --git a/drivers/net/xsc/xsc_rx.c b/drivers/net/xsc/xsc_rx.c
index 30b40df3..f7529371 100644
--- a/drivers/net/xsc/xsc_rx.c
+++ b/drivers/net/xsc/xsc_rx.c
@@ -206,27 +206,27 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
uint32_t log2ds = rte_log2_u32(rx_ds_num);
uintptr_t addr;
struct rte_mbuf *mbuf;
- void *jumbo_buffer_pa = xdev->jumbo_buffer_pa;
- void *jumbo_buffer_va = xdev->jumbo_buffer_va;
+ void *jumbo_buf = xdev->jumbo_buf;
+ rte_iova_t jumbo_iova = xdev->jumbo_iova;
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) {
+ if (rx_ds_num != 1 && jumbo_buf == NULL) {
+ jumbo_buf = rte_malloc(NULL, XSC_MAX_RECV_LEN, 0);
+ if (jumbo_buf == 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) {
+ jumbo_iova = rte_malloc_virt2iova(jumbo_buf);
+ if (jumbo_iova == RTE_BAD_IOVA) {
PMD_DRV_LOG(ERR, "Failed to get IOVA of jumbo_buffer");
- rte_free(jumbo_buffer_pa);
+ rte_free(jumbo_buf);
return -EFAULT;
}
- xdev->jumbo_buffer_pa = jumbo_buffer_pa;
- xdev->jumbo_buffer_va = jumbo_buffer_va;
+ xdev->jumbo_buf = jumbo_buf;
+ xdev->jumbo_iova = jumbo_iova;
}
for (i = 0; (i != wqe_n); ++i) {
@@ -246,7 +246,7 @@ xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
if (rx_ds_num != 1) {
seg_next = seg + 1;
*seg_next = (struct xsc_wqe_data_seg){
- .va = rte_cpu_to_le_64((uint64_t)jumbo_buffer_va),
+ .va = rte_cpu_to_le_64(jumbo_iova),
.seg_len = rte_cpu_to_le_32(XSC_MAX_RECV_LEN - seg_len),
.lkey = 0,
};
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer
2026-11-17 11:14 [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
` (2 preceding siblings ...)
2026-11-17 11:14 ` [PATCH v4 1/3] net/xsc: fix jumbo buffer allocation and leak Renyong Wan
@ 2026-11-17 17:04 ` Stephen Hemminger
3 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2026-11-17 17:04 UTC (permalink / raw)
To: Renyong Wan; +Cc: dev, nana, qianr, zhangxx, xudw
On Tue, 17 Nov 2026 19:14:20 +0800
"Renyong Wan" <wanry@yunsilicon.com> wrote:
> v4:
> - free the jumbo buffer only when the last representor stops the device, it
> is shared by every port and their Rx queues still point at it
>
> v3:
> - free the jumbo buffer in xsc_dev_close(), the device removal path does not
> go through xsc_dev_uninit()
> - drop the redundant parentheses reported by checkpatch, no functional
> change
>
> v2:
> - address the AI review of v1: allocate the jumbo buffer once per device,
> fail the queue setup when there is no IOVA, and free it on device close
> - fix the leak in xsc_dev_init() and the unchecked rte_malloc_socket()
> - rename the jumbo buffer fields, they held the opposite of what their
> names say
>
> Renyong Wan (3):
> net/xsc: fix jumbo buffer allocation and leak
> net/xsc: fix leak and missing null check
> net/xsc: rename jumbo buffer fields
>
> drivers/net/xsc/xsc_dev.c | 17 ++++++++++--
> drivers/net/xsc/xsc_dev.h | 4 +--
> drivers/net/xsc/xsc_ethdev.c | 6 ++++
> drivers/net/xsc/xsc_rx.c | 53 ++++++++++++++++++++----------------
> 4 files changed, 51 insertions(+), 29 deletions(-)
Too late for 26.11 but added to next-net to be picked up in 27.03
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-17 17:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 11:14 [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Renyong Wan
2026-11-17 11:14 ` [PATCH v4 2/3] net/xsc: fix leak and missing null check Renyong Wan
2026-11-17 11:14 ` [PATCH v4 3/3] net/xsc: rename jumbo buffer fields Renyong Wan
2026-11-17 11:14 ` [PATCH v4 1/3] net/xsc: fix jumbo buffer allocation and leak Renyong Wan
2026-11-17 17:04 ` [PATCH v4 0/3] net/xsc: fix issues reported by GCC analyzer Stephen Hemminger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.