On Fri, 13 Nov 2026 11:10:25 +0800
"Renyong Wan" <[email protected]> wrote:

> >From 0fe3f49419330852df7d2a82fcf179fa6f80a9a0 Mon Sep 17 00:00:00 2001  
> From: Renyong Wan <[email protected]>
> Date: Fri, 13 Nov 2026 10:44:51 +0800
> Subject: [PATCH 0/2] net/xsc: fix two issues reported by GCC analyzer
> 
> Two fixes for net/xsc coming out of the GCC -fanalyzer report.
> 
> 45: when rte_malloc_virt2iova() fails, the jumbo buffer is leaked and
> RTE_BAD_IOVA ends up in the WQE.
> 
> 46: xsc_dev_init() leaks a structure on the dev_ops failure path, and
> the Tx queue allocation is dereferenced without a NULL check.
> 
> The two patches are independent.
> 
> Renyong Wan (2):
>   net/xsc: fix jumbo buffer on IOVA conversion failure
>   net/xsc: fix leak and missing NULL check
> 
>  drivers/net/xsc/xsc_dev.c    | 1 +
>  drivers/net/xsc/xsc_ethdev.c | 6 ++++++
>  drivers/net/xsc/xsc_rx.c     | 5 ++++-
>  3 files changed, 11 insertions(+), 1 deletion(-)

AI review picked up some possible issues:

Subject: Re: [PATCH 1/2] net/xsc: fix jumbo buffer on IOVA conversion failure

Both patches apply to main and build with -Dwerror=true. Fixes tags
resolve and point at 25.03 commits, so Cc: stable is correct.

Patch 2/2 has no findings.

[PATCH 1/2] net/xsc: fix jumbo buffer on IOVA conversion failure

Warning: the fix stops the use of RTE_BAD_IOVA, but the fallback path
it lands in is still unsafe.

When rte_malloc_virt2iova() fails it will fail the same way on every
retry (e.g. IOVA as PA without access to physical addresses). With
this patch every WQE of every Rx queue now does rte_malloc(),
virt2iova, rte_free() and logs at ERR level: up to 1024 log lines per
queue on each start.

Worse, the fallback sets seg->seg_len = XSC_MAX_RECV_LEN (9800) on a
segment that points at an mbuf whose data room is only
rte_pktmbuf_data_len(mbuf). The second segment exists so oversized
frames land in the jumbo buffer; without it, a frame larger than the
mbuf is DMA'd past the end of the mbuf. "Rely on mtu" only holds if
the MTU fits in the mbuf, which nothing here checks.

Allocate the buffer once before the loop and fail queue start on
error instead of degrading per WQE:

static int
xsc_rxq_initialize(struct xsc_dev *xdev, struct xsc_rxq_data *rxq_data)
{
        ...
        if (rx_ds_num != 1 && xdev->jumbo_buffer_va == NULL) {
                void *buf = rte_malloc(NULL, XSC_MAX_RECV_LEN, 0);
                rte_iova_t iova;

                if (buf == NULL) {
                        PMD_DRV_LOG(ERR, "Failed to alloc jumbo buffer");
                        return -ENOMEM;
                }
                iova = rte_malloc_virt2iova(buf);
                if (iova == RTE_BAD_IOVA) {
                        PMD_DRV_LOG(ERR, "Failed to get IOVA of jumbo buffer");
                        rte_free(buf);
                        return -EFAULT;
                }
                xdev->jumbo_buffer_pa = buf;
                xdev->jumbo_buffer_va = (void *)iova;
        }

        for (i = 0; i != wqe_n; ++i) {
                /* fill seg and seg_next, no allocation here */
        }
        ...
        return 0;
}

and in the caller:

        ret = xsc_rxq_initialize(xdev, rxq_data);
        if (ret != 0) {
                rte_errno = -ret;
                goto set_qp_fail;
        }

Info: xdev->jumbo_buffer_pa is never freed. There is no rte_free() of
it anywhere in the driver, so it leaks on device close. Free it in
the close/uninit path (separate patch is fine).

Info: the names are swapped relative to content: jumbo_buffer_pa holds
the virtual address and jumbo_buffer_va holds the IOVA (as a void *).
That is how the original bug went unnoticed. Consider
"void *jumbo_buf; rte_iova_t jumbo_iova;" in struct xsc_dev, which
also removes the casts.

Reply via email to