BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Meghana Malladi" <m-malladi@ti.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI
Date: Thu, 19 Nov 2026 18:50:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-223805@kernel.org> (raw)
In-Reply-To: <20261118184729.2302130-2-m-malladi@ti.com>

Thank you for your contribution! Sashiko AI review found 10 potential
issues to consider:
- [High] net: ti: icssg: shared FDQ overflow and broken per-flow reset
  on AM654
- [High] net: ti: icssg: NAPI double-disable hang and leaks in XSK pool
  enable/disable
- [High] net: ti: icssg: OOB flow index and uninitialized NAPI in SR1
  emac_ndo_open()
- [High] net: ti: icssg: broken DMA mapping, reset, and cleanup for SR1
  rx_mgm_chn
- [Medium] net: ti: icssg: uncapped desc_pool avail in
  emac_rx_packet_zc() overflows FDQ
- [Medium] net: ti: icssg: XSK pool state lost in prueth_init_rx_chns()
  and channel change
- [Medium] net: ti: icssg: invalid SR1 max_rx and uninitialized
  rx_flow_num in ethtool
- [Medium] net: ti: icssg: enable_irq() before RXCQ drain in
  prueth_destroy_rxq()
- [Low] net: ti: icssg: emac_set_coalesce() leaves inactive RX flows
  unconfigured
- [Low] net: ti: icssg: missing skb_record_rx_queue() in RX packet paths
It also noticed 2 related pre-existing issues this patch does not
introduce:
- [Critical] net: ti: icssg-prueth: dangling pointers in
  prueth_cleanup_rx_chns() [1]
- [Critical] net: ti: icssg-prueth: invalid dma_unmap_single() in
  prueth_process_rx_mgm() [2]
--

commit 7f9ba334666f2704f197c0021554819e2e901c62
Author: Meghana Malladi <m-malladi@ti.com>

net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI

This commit extends the ICSSG driver to support up to 8 RX flows per EMAC
with per-flow NAPI, hrtimer, page pool, XDP rxq, AF_XDP pool, and IRQ
state.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_common.c b/drivers/net/ethernet/ti/icssg/icssg_common.c
> index 4a7d1a6f470b1..6cd2a77c491ac 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_common.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_common.c
> @@ -39,16 +39,10 @@
>  				 NETIF_MSG_HW | \
>  				 NETIF_MSG_WOL)
>  
> -#define prueth_napi_to_emac(napi) container_of(napi, struct prueth_emac, napi_rx)
>  
> -void prueth_cleanup_rx_chns(struct prueth_emac *emac,
> -			    struct prueth_rx_chn *rx_chn,
> -			    int max_rflows)
> +void prueth_cleanup_rx_chns(struct prueth_emac *emac)
>  {
> -	if (rx_chn->pg_pool) {
> -		page_pool_destroy(rx_chn->pg_pool);
> -		rx_chn->pg_pool = NULL;
> -	}
> +	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
>  
>  	if (rx_chn->desc_pool)
>  		k3_cppi_desc_pool_destroy(rx_chn->desc_pool);

[Severity: Critical]
This problem wasn't introduced by this patch, but prueth_cleanup_rx_chns()
destroys rx_chn->desc_pool and releases rx_chn->rx_chn without clearing their
pointers [1].

If a subsequent emac_ndo_open() calls prueth_init_rx_chns() and
k3_udma_glue_request_rx_chn() fails before rx_chn->desc_pool is overwritten,
the fail path calls prueth_cleanup_rx_chns() again with the stale
rx_chn->desc_pool pointer and triggers a double free in
k3_cppi_desc_pool_destroy().

[ ... ]

> @@ -548,22 +594,14 @@ int prueth_init_rx_chns(struct prueth_emac *emac,
>  		goto fail;
>  	}
>  
> -	pool = prueth_create_page_pool(emac, rx_chn->dma_dev, rx_chn->descs_num);
> -	if (IS_ERR(pool)) {
> -		ret = PTR_ERR(pool);
> -		goto fail;
> +	for (i = 0; i < rx_cfg.flow_id_num; i++) {
> +		flow = &rx_chn->flows[i];
> +		flow->pg_pool = NULL;
> +		flow->xsk_pool = NULL;
>  	}

[Severity: Medium]
Does clearing flow->xsk_pool here lose active AF_XDP pools across an
interface down/up cycle or system suspend/resume?

On stop, prueth_cleanup_tx_chns() zeroes tx_chn->xsk_pool, and on open this
loop zeroes flow->xsk_pool while emac->xsk_queues keeps the registered queue
bits set.  Because emac_ndo_open() never calls prueth_set_xsk_pool() before
prueth_create_rxqs(), prueth_create_rxq() falls back to creating a regular
page_pool and prueth_xsk_wakeup() fails with -EINVAL on the NULL xsk_pool
pointers.

In addition, if emac_set_channels() reduces rx_flow_num or tx_ch_num while
the interface is down, prueth_xsk_pool_disable() rejects queue_id >=
emac->rx_flow_num or queue_id >= emac->tx_ch_num with -EINVAL, leaving no way
to unmap and unregister the pool on that queue.

> -
> -	rx_chn->pg_pool = pool;
> -
> -	flow_id_base = k3_udma_glue_rx_get_flow_id_base(rx_chn->rx_chn);
> -	if (emac->is_sr1 && !strcmp(name, "rxmgm")) {
> -		emac->rx_mgm_flow_id_base = flow_id_base;
> -		netdev_dbg(ndev, "mgm flow id base = %d\n", flow_id_base);
> -	} else {
> -		emac->rx_flow_id_base = flow_id_base;
> -		netdev_dbg(ndev, "flow id base = %d\n", flow_id_base);
> -	}
> +	emac->rx_flow_id_base = k3_udma_glue_rx_get_flow_id_base(rx_chn->rx_chn);
> +	netdev_dbg(ndev, "flow id base = %d\n", emac->rx_flow_id_base);
>  
>  	fdqring_id = K3_RINGACC_RING_ID_ANY;
>  	for (i = 0; i < rx_cfg.flow_id_num; i++) {
> @@ -584,9 +622,14 @@ int prueth_init_rx_chns(struct prueth_emac *emac,
>  				K3_UDMA_GLUE_SRC_TAG_LO_USE_REMOTE_SRC_TAG,
>  		};
>  
> +		flow = &rx_chn->flows[i];
> +		flow->emac = emac;
> +		flow->id = i;
> +		flow->irq = -EINVAL;
> +
>  		rx_flow_cfg.ring_rxfdq0_id = fdqring_id;
> -		rx_flow_cfg.rx_cfg.size = max_desc_num;
> -		rx_flow_cfg.rxfdq_cfg.size = max_desc_num;
> +		rx_flow_cfg.rx_cfg.size = PRUETH_MAX_RX_DESC;
> +		rx_flow_cfg.rxfdq_cfg.size = PRUETH_MAX_RX_DESC;

[Severity: High]
Does configuring rx_flow_cfg.rxfdq_cfg.size to PRUETH_MAX_RX_DESC break
multi-flow RX on AM654 SR2.0 (ti,am654-icssg-prueth)?

Unlike AM642 PKTDMA, AM654 SR2.0 uses NavSS UDMAP where rx_chn->single_fdq is
true and all flows share flow 0's FDQ ring (via fdqring_id and
K3_RINGACC_RING_SHARED).  Because the shared FDQ ring is sized to
PRUETH_MAX_RX_DESC (512) instead of rx_chn->descs_num (512 * flow_id_num),
flow 0 fills all 512 slots in prueth_prepare_rx_flow() and flow 1
immediately fails with -ENOMEM in k3_udma_glue_push_rx_chn().

Because k3_udma_glue_reset_rx_chn() only drains a shared FDQ when
flow_num == 0:

drivers/dma/ti/k3-udma-glue.c:k3_udma_glue_reset_rx_chn() {
    ...
	if (rx_chn->single_fdq && flow_num)
		goto do_reset;
    ...
}

per-flow resets on AM654 SR2.0 also break:
- prueth_create_rxqs() unwinds in reverse order (i > 0 before 0), destroying
  flows[i].pg_pool before flow 0 drains the shared FDQ, so
  prueth_rx_cleanup() sees pg_pool == NULL and leaks the pages.
- prueth_destroy_rxqs() destroys flow 0 first, draining the shared FDQ and
  destroying flows[0].pg_pool while flows 1..N still have NAPI enabled and
  undrained completion rings.
- Single-flow teardown in prueth_xsk_pool_enable() and
  prueth_xsk_pool_disable() either drains the shared FDQ for all flows (when
  queue_id == 0) or leaves queue_id's descriptors in the shared FDQ (when
  queue_id > 0).
- On RX, UDMAP pops descriptors from the shared FDQ in FIFO order regardless
  of which flow pushed them, while emac_rx_packet() syncs and recycles pages
  against rx_flow->pg_pool instead of rx_chn->flows[swdata->flow_id].pg_pool.

[ ... ]

> @@ -1022,13 +1081,13 @@ static int emac_rx_packet_zc(struct prueth_emac *emac, u32 flow_id,
>  	avail_desc = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
>  	alloc_budget = min_t(int, budget, avail_desc);
>  
> -	ret = prueth_rx_alloc_zc(emac, alloc_budget);
> +	ret = prueth_rx_alloc_zc(emac, flow_id, alloc_budget);
>  
> -	if (xsk_uses_need_wakeup(rx_chn->xsk_pool)) {
> +	if (xsk_uses_need_wakeup(rx_flow->xsk_pool)) {
>  		if (ret < alloc_budget)
> -			xsk_set_rx_need_wakeup(rx_chn->xsk_pool);
> +			xsk_set_rx_need_wakeup(rx_flow->xsk_pool);
>  		else
> -			xsk_clear_rx_need_wakeup(rx_chn->xsk_pool);
> +			xsk_clear_rx_need_wakeup(rx_flow->xsk_pool);
>  	}

[Severity: Medium]
Can deriving alloc_budget from k3_cppi_desc_pool_avail(rx_chn->desc_pool)
overflow flow_id's 512-entry FDQ ring or starve other RX flows?

rx_chn->desc_pool is shared across all flows (PRUETH_MAX_RX_DESC *
rx_flow_num descriptors), whereas each flow's FDQ ring holds at most
PRUETH_MAX_RX_DESC (512) descriptors.  If another flow has not allocated all
of its descriptors from rx_chn->desc_pool (for example, another XSK flow
whose fill ring had fewer than 512 buffers), avail_desc exceeds the free
slots in flow_id's FDQ ring.  When emac_rx_packet_zc() pops fewer than budget
packets, prueth_rx_alloc_zc() tries to push more descriptors than flow_id's
FDQ ring can hold, failing in k3_udma_glue_push_rx_chn() with -ENOMEM,
freeing the popped xdp_buff, and falsely setting xsk_set_rx_need_wakeup().

[ ... ]

> @@ -1132,15 +1192,15 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id, u32 *xdp_state)
>  	skb->protocol = eth_type_trans(skb, ndev);
>  
>  	skb_mark_for_recycle(skb);
> -	napi_gro_receive(&emac->napi_rx, skb);
> +	napi_gro_receive(&emac->rx_chns.flows[flow_id].napi_rx, skb);

[Severity: Low]
Should emac_rx_packet() and emac_dispatch_skb_zc() call
skb_record_rx_queue(skb, flow_id) before napi_gro_receive() so the stack
knows which RX queue received the packet?

[ ... ]

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index b715af21d23ac..68646cb7df442 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> @@ -159,7 +160,7 @@ static void emac_get_channels(struct net_device *ndev,
>  {
>  	struct prueth_emac *emac = netdev_priv(ndev);
>  
> -	ch->max_rx = 1;
> +	ch->max_rx = ICSSG_MAX_RFLOWS;
>  	ch->max_tx = PRUETH_MAX_TX_QUEUES;
>  
>  	/* Disable multiple TX channels due to timeouts
> @@ -167,7 +168,7 @@ static void emac_get_channels(struct net_device *ndev,
>  	if (emac->is_sr1)
>  		ch->max_tx = 1;
>  
> -	ch->rx_count = 1;
> +	ch->rx_count = emac->rx_flow_num;

[Severity: Medium]
On SR1.0, doesn't emac_get_channels() report ch->rx_count == 0 before the
interface is opened and allow setting up to 8 RX channels even though SR1.0
only supports 1 RX queue?

In icssg_prueth_sr1.c, prueth_netdev_init() allocates ndev with a single RX
queue via alloc_etherdev_mq() and never initializes emac->rx_flow_num (which
is only set to 1 in emac_ndo_open()).  Capping ch->max_rx = 1 when
emac->is_sr1 is true and initializing emac->rx_flow_num = 1 in SR1.0's
prueth_netdev_init() would avoid this.  Also, struct prueth_emac in
icssg_prueth.h still retains the unused int xsk_qid field.

[ ... ]

> @@ -264,7 +269,8 @@ static int emac_set_coalesce(struct net_device *ndev,
>  		coal->tx_coalesce_usecs = ICSSG_MIN_COALESCE_USECS;
>  	}
>  
> -	emac->rx_pace_timeout_ns = coal->rx_coalesce_usecs * 1000;
> +	for (i = 0; i < emac->rx_flow_num; i++)
> +		rx_chn->flows[i].rx_pace_timeout_ns = coal->rx_coalesce_usecs * 1000;

[Severity: Low]
If a user configures RX coalescing via emac_set_coalesce() and later
increases the number of RX flows via emac_set_channels(), won't the newly
enabled flows remain at rx_pace_timeout_ns == 0 while emac_get_coalesce()
reports flow 0's timeout?  Looping over PRUETH_MAX_RX_FLOWS would keep all
flows consistent.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 9bb67e185a3ea..716f1b9195d67 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c

[ ... ]

> @@ -921,7 +866,43 @@ static void prueth_destroy_txq(struct prueth_emac *emac)
>  	}
>  }
>  
> -static void prueth_destroy_rxq(struct prueth_emac *emac)
> +static void prueth_destroy_rxq(struct prueth_emac *emac, int qid)
> +{
> +	struct prueth_rx_chn *rx_chn = &emac->rx_chns;
> +	struct prueth_rx_flow *flow = &rx_chn->flows[qid];
> +	dma_addr_t desc_dma;
> +
> +	napi_disable(&flow->napi_rx);
> +	hrtimer_cancel(&flow->rx_hrtimer);
> +	if (flow->irq_disabled) {
> +		enable_irq(flow->irq);
> +		flow->irq_disabled = false;
> +	}
> +
> +	/* k3_udma_glue_reset_rx_chn() only drains the FDQ; it resets the
> +	 * completion ring (RXCQ) without freeing descriptors still in it.
> +	 * Teardown posts TDCM only to flow 0's RXCQ; flows 1..N have no
> +	 * NAPI trigger to drain their RXCQs. Drain each flow's RXCQ here
> +	 * so page_pool_destroy() finds no inflight pages.
> +	 */
> +	while (!k3_udma_glue_pop_rx_chn(rx_chn->rx_chn, qid, &desc_dma)) {
> +		if (!cppi5_desc_is_tdcm(desc_dma))
> +			prueth_rx_cleanup(rx_chn, desc_dma);
> +	}
> +
> +	k3_udma_glue_reset_rx_chn(rx_chn->rx_chn, flow->id, rx_chn,
> +				  prueth_rx_cleanup);

[Severity: Medium]
Can calling enable_irq(flow->irq) before draining and resetting the RXCQ
leave flow->irq permanently disabled when a queue is recreated?

flow->irq is registered with IRQF_TRIGGER_HIGH and stays asserted while
descriptors remain in the RXCQ:

prueth_destroy_rxq()
  napi_disable(&flow->napi_rx)
  if (flow->irq_disabled)
    enable_irq(flow->irq)
      <hardirq>
        prueth_rx_irq()
          flow->irq_disabled = true
          disable_irq_nosync(flow->irq)
          napi_schedule(&flow->napi_rx)  <-- no-op (NAPIF_STATE_SCHED set)
    flow->irq_disabled = false           <-- clobbers true while IRQ is disabled

The same sequence also exists in the err path of prueth_create_rxq(), and if
flow->irq was still enabled when napi_disable() returned, an IRQ arriving
before the RXCQ is drained will likewise disable flow->irq after the
flow->irq_disabled check has already run.  Draining and resetting the queue
before re-enabling the IRQ (and clearing flow->irq_disabled before
enable_irq()) would prevent this.

[ ... ]

> @@ -1492,21 +1512,24 @@ static int prueth_xsk_pool_enable(struct prueth_emac *emac,
>  		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
>  		if (ret)
>  			return ret;
> -		prueth_destroy_rxq(emac);
> +		prueth_destroy_rxq(emac, queue_id);
>  	}
>  
> -	emac->xsk_qid = queue_id;
> +	set_bit(queue_id, emac->xsk_queues);
>  	prueth_set_xsk_pool(emac, queue_id);
>  
>  	if (netif_running(emac->ndev)) {
> -		ret = prueth_create_rxq(emac, queue_id);
> +		ret = prueth_create_rxq(emac, queue_id);
>  		if (ret) {
>  			netdev_err(emac->ndev, "Failed to create RX queue: %d\n", ret);
> +			clear_bit(queue_id, emac->xsk_queues);
> +			prueth_set_xsk_pool(emac, queue_id);
> +			xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);
>  			return ret;
>  		}
>  		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
>  		if (ret) {
> -			prueth_destroy_rxq(emac);
> +			prueth_destroy_rxq(emac, queue_id);
>  			return ret;
>  		}
>  		ret = prueth_xsk_wakeup(emac->ndev, queue_id, XDP_WAKEUP_RX);
> @@ -1523,12 +1546,13 @@ static int prueth_xsk_pool_disable(struct prueth_emac *emac, u16 queue_id)
>  	int ret;
>  
>  	if (queue_id >= PRUETH_MAX_RX_FLOWS ||
> +	    queue_id >= emac->rx_flow_num ||
>  	    queue_id >= emac->tx_ch_num) {
>  		netdev_err(emac->ndev, "Invalid XSK queue ID %d\n", queue_id);
>  		return -EINVAL;
>  	}
>  
> -	if (emac->xsk_qid != queue_id) {
> +	if (!test_bit(queue_id, emac->xsk_queues)) {
>  		netdev_err(emac->ndev, "XSK queue ID %d not registered\n", queue_id);
>  		return -EINVAL;
>  	}
> @@ -1544,27 +1568,28 @@ static int prueth_xsk_pool_disable(struct prueth_emac *emac, u16 queue_id)
>  		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_DISABLE);
>  		if (ret)
>  			return ret;
> -		prueth_destroy_rxq(emac);
> +		prueth_destroy_rxq(emac, queue_id);
>  	}
>  
>  	xsk_pool_dma_unmap(pool, PRUETH_RX_DMA_ATTR);
> -	emac->xsk_qid = -EINVAL;
> +	clear_bit(queue_id, emac->xsk_queues);
>  	prueth_set_xsk_pool(emac, queue_id);
>  
>  	if (netif_running(emac->ndev)) {
> -		ret = prueth_create_rxq(emac);
> -		if (ret) {
> -			netdev_err(emac->ndev, "Failed to create RX queue: %d\n", ret);
> -			return ret;
> -		}
> -		ret = icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
> -		if (ret) {
> -			prueth_destroy_rxq(emac);
> -			return ret;
> -		}
> +		ret = prueth_create_rxq(emac, queue_id);
> +		if (ret)
> +			netdev_err(emac->ndev, "Failed to recreate RX queue after XSK disable: %d\n",
> +				   ret);
> +
> +		/* Always re-enable port forwarding so the interface is not left
> +		 * permanently disabled if prueth_create_rxq() failed due to a
> +		 * transient descriptor shortage (inflight pages not yet returned
> +		 * by the network stack).
> +		 */
> +		icssg_set_port_state(emac, ICSSG_EMAC_PORT_FORWARD);
>  	}
>  
> -	return 0;
> +	return ret;
>  }

[Severity: High]
If prueth_create_rxq() fails in prueth_xsk_pool_enable() or
prueth_xsk_pool_disable(), won't the next emac_ndo_stop() hang forever in
napi_disable()?

When the interface is running, prueth_destroy_rxq() calls
napi_disable(&flow->napi_rx), which sets NAPIF_STATE_SCHED.  If
prueth_create_rxq() then fails (for instance with -ENOSPC when inflight pages
from the previous queue have not yet returned to rx_chn->desc_pool), it jumps
to err before calling napi_enable(&flow->napi_rx).  The interface stays up
with flow->napi_rx disabled, so when emac_ndo_stop() -> prueth_destroy_rxqs()
later calls prueth_destroy_rxq() on that flow, napi_disable() is called a
second time and busy-waits forever for NAPIF_STATE_SCHED to clear.

In prueth_xsk_pool_enable(), the error paths also leave the port in
ICSSG_EMAC_PORT_DISABLE when prueth_create_rxq() fails, leak the
xsk_pool_dma_map() mapping if icssg_set_port_state(ICSSG_EMAC_PORT_DISABLE)
fails, and leave queue_id set in emac->xsk_queues with dangling xsk_pool
pointers and a leaked DMA mapping if
icssg_set_port_state(ICSSG_EMAC_PORT_FORWARD) fails.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> index 21a14b3bc889b..589b73be3ac60 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c
> @@ -306,7 +306,7 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,
>  	dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE);
>  	k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
>  
> -	new_page = page_pool_dev_alloc_pages(rx_chn->pg_pool);
> +	new_page = page_pool_dev_alloc_pages(rx_chn->flows[flow_id].pg_pool);

[Severity: Critical]
This problem wasn't introduced by this patch, but prueth_process_rx_mgm()
calls dma_unmap_single() on pages allocated from a page_pool [2].

The buffer was never mapped with dma_map_single() (and buf_dma is offset by
PRUETH_HEADROOM), so dma_unmap_single() corrupts DMA state; if
page_pool_dev_alloc_pages() fails, the unmapped page is pushed back to the RX
ring for hardware DMA.

>  	/* if allocation fails we drop the packet but push the
>  	 * descriptor back to the ring with old skb to prevent a stall
>  	 */
> @@ -319,14 +319,104 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,
>  	}
>  
>  	/* queue another DMA */
> -	ret = prueth_dma_rx_push_mapped(emac, &emac->rx_chns, new_page,
> -					PRUETH_MAX_PKT_SIZE);
> +	ret = prueth_dma_rx_push_mapped(emac, rx_chn, new_page,
> +					PRUETH_MAX_PKT_SIZE, flow_id);
>  	if (WARN_ON(ret < 0))
> -		page_pool_recycle_direct(rx_chn->pg_pool, new_page);
> +		page_pool_recycle_direct(rx_chn->flows[flow_id].pg_pool, new_page);
>  
>  	return page;
>  }
>  
> +/* SR1-specific helpers for rx_mgm_chn */
> +
> +static int prueth_sr1_prepare_rx_mgm_flow(struct prueth_emac *emac, int flow, u32 buf_len)
> +{
> +	struct prueth_rx_flow *rx_flow;
> +	struct prueth_rx_chn *rx_chn;
> +	struct page_pool *pool;
> +	struct page *page;
> +	int desc_avail;
> +	int i, ret;
> +
> +	rx_chn = &emac->rx_mgm_chn;
> +	rx_flow = &rx_chn->flows[flow];
> +
> +	/* Initialize page pool for this flow - using simple page pool */
> +	pool = page_pool_create(&(struct page_pool_params){
> +		.order = 0,
> +		.pool_size = rx_chn->descs_num,
> +		.nid = NUMA_NO_NODE,
> +		.dev = rx_chn->dma_dev,
> +		.dma_dir = DMA_FROM_DEVICE,
> +		.max_len = PRUETH_MAX_PKT_SIZE,
> +	});
> +
> +	if (IS_ERR(pool))
> +		return PTR_ERR(pool);
> +
> +	rx_flow->pg_pool = pool;
> +
> +	desc_avail = k3_cppi_desc_pool_avail(rx_chn->desc_pool);
> +	if (desc_avail < PRUETH_MAX_RX_DESC)
> +		netdev_warn(emac->ndev,
> +			    "not enough RX descriptors available %d < %d\n",
> +			    desc_avail, PRUETH_MAX_RX_DESC);
> +
> +	for (i = 0; i < desc_avail; i++) {
> +		page = page_pool_dev_alloc_pages(rx_flow->pg_pool);
> +		if (!page)
> +			break;
> +
> +		ret = prueth_dma_rx_push_mapped(emac, rx_chn, page, buf_len, flow);
> +		if (ret < 0) {
> +			page_pool_recycle_direct(rx_flow->pg_pool, page);
> +			netdev_err(emac->ndev, "failed to push rx mgm buf %d\n", ret);
> +			break;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static void prueth_sr1_cleanup_rx_mgm_chn(struct prueth_emac *emac)
> +{
> +	struct prueth_rx_flow *flow;
> +	int i;
> +
> +	for (i = 0; i < PRUETH_MAX_RX_MGM_FLOWS_SR1; i++) {
> +		flow = &emac->rx_mgm_chn.flows[i];
> +		if (flow->pg_pool) {
> +			page_pool_destroy(flow->pg_pool);
> +			flow->pg_pool = NULL;
> +		}
> +	}
> +
> +	if (emac->rx_mgm_chn.rx_chn) {
> +		k3_udma_glue_release_rx_chn(emac->rx_mgm_chn.rx_chn);
> +		emac->rx_mgm_chn.rx_chn = NULL;
> +	}
> +}
> +
> +static void prueth_sr1_reset_rx_mgm_chn(struct prueth_emac *emac, bool disable)
> +{
> +	struct prueth_rx_flow *flow;
> +	int i;
> +
> +	for (i = 0; i < PRUETH_MAX_RX_MGM_FLOWS_SR1; i++) {
> +		flow = &emac->rx_mgm_chn.flows[i];
> +		if (flow->irq <= 0)
> +			continue;
> +
> +		if (disable) {
> +			disable_irq(flow->irq);
> +			flow->irq_disabled = true;
> +		} else if (flow->irq_disabled) {
> +			enable_irq(flow->irq);
> +			flow->irq_disabled = false;
> +		}
> +	}
> +}

[Severity: High]
Does prueth_sr1_prepare_rx_mgm_flow() push unmapped DMA address 0x40 to the
hardware descriptors?

page_pool_create() is called without PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
so page_pool_get_dma_addr(page) returns 0 and prueth_dma_rx_push_mapped()
attaches buf_dma = 0 + PRUETH_HEADROOM (0x40) to the descriptor.

There are several additional regressions in the SR1 management channel
handling:
- prueth_sr1_prepare_rx_mgm_flow() checks desc_avail < PRUETH_MAX_RX_DESC
  (16 < 512, which always warns) and loops i < desc_avail (16) instead of
  PRUETH_MAX_RX_MGM_DESC_SR1 (8), overflowing flow 0's 8-entry ring and
  leaving no descriptors for flow 1.
- In emac_ndo_open(), rx_flow_cfg.ring_rxfdq0_id is hardcoded to
  K3_RINGACC_RING_ID_ANY for every management flow instead of passing flow
  0's FDQ ring ID to flow 1 on UDMAP.
- In emac_ndo_open(), flow->irq is a signed int, so
  if (flow->irq == 0 || flow->irq > INT_MAX) misses negative error codes from
  k3_udma_glue_rx_get_irq() and sets ret = 0 when flow->irq == 0.
- prueth_sr1_reset_rx_mgm_chn() only toggles IRQs instead of calling
  k3_udma_glue_reset_rx_chn(..., prueth_rx_cleanup) and
  k3_udma_glue_disable_rx_chn(), so management descriptors and pages are
  never drained before page_pool_destroy().
- prueth_sr1_cleanup_rx_mgm_chn() never calls
  k3_cppi_desc_pool_destroy(emac->rx_mgm_chn.desc_pool), leaking the
  management descriptor pool.
- In emac_ndo_open(), cleanup_rx_mgm_init is placed above stop:, so failures
  during rx_mgm_chn setup call prueth_emac_stop(), free_irq(), and
  prueth_ndev_del_rx_napi() / prueth_ndev_del_tx_napi() before those
  resources are initialized, and call prueth_sr1_cleanup_rx_mgm_chn() twice.

[ ... ]

> @@ -514,37 +610,116 @@ static int emac_ndo_open(struct net_device *ndev)
>  		return ret;
>  	}
>  
> -	max_rx_flows = PRUETH_MAX_RX_FLOWS_SR1;
> -	ret = prueth_init_rx_chns(emac, &emac->rx_chns, "rx",
> -				  max_rx_flows, PRUETH_MAX_RX_DESC);
> +	emac->rx_flow_num = 1;
> +	ret = prueth_init_rx_chns(emac);

[ ... ]

> @@ -570,11 +745,15 @@ static int emac_ndo_open(struct net_device *ndev)
>  	icssg_mii_update_mtu(prueth->mii_rt, slice, ndev->max_mtu);
>  
>  	/* Prepare RX */
> -	ret = prueth_prepare_rx_chan(emac, &emac->rx_chns, PRUETH_MAX_PKT_SIZE);
> +	ret = prueth_prepare_rx_flow(emac, PRUETH_RX_FLOW_DATA_SR1);
>  	if (ret)
>  		goto stop;
>  
> -	ret = prueth_prepare_rx_chan(emac, &emac->rx_mgm_chn, 64);
> +	ret = prueth_sr1_prepare_rx_mgm_flow(emac, PRUETH_RX_MGM_FLOW_RESPONSE_SR1, 64);
> +	if (ret)
> +		goto reset_rx_chn;
> +
> +	ret = prueth_sr1_prepare_rx_mgm_flow(emac, PRUETH_RX_MGM_FLOW_TIMESTAMP_SR1, 64);
>  	if (ret)
>  		goto reset_rx_chn;
>  
> @@ -595,7 +774,7 @@ static int emac_ndo_open(struct net_device *ndev)
>  	/* Enable NAPI in Tx and Rx direction */
>  	for (i = 0; i < emac->tx_ch_num; i++)
>  		napi_enable(&emac->tx_chns[i].napi_tx);
> -	napi_enable(&emac->napi_rx);
> +	napi_enable(&emac->rx_chns.flows[PRUETH_RX_FLOW_DATA_SR1].napi_rx);

[Severity: High]
Doesn't passing PRUETH_RX_FLOW_DATA_SR1 (3) here access out of bounds in
k3_udma_glue_push_rx_chn() and call napi_enable() on an uninitialized
napi_struct?

emac_ndo_open() sets emac->rx_flow_num = 1, so prueth_init_rx_chns() only
allocates 1 flow (index 0) in rx_chn->rx_chn->flows and
prueth_ndev_add_rx_napi() only initializes emac->rx_chns.flows[0].napi_rx.
Calling prueth_prepare_rx_flow(emac, PRUETH_RX_FLOW_DATA_SR1) then indexes
flow 3 in the 1-element UDMA channel flow array, and napi_enable() /
napi_disable() operate on flows[3].napi_rx (where dev is NULL), crashing on
open while flows[0].napi_rx stays disabled.

Also, because page_pool_destroy() was removed from prueth_cleanup_rx_chns(),
neither emac_ndo_stop() nor the open error path in icssg_prueth_sr1.c
destroys emac->rx_chns.flows[].pg_pool, leaking the data RX page pool.

[1] https://sashiko.dev/#/bug/linux-c1c04236-d320-4b5d-9640-11b78b923fbc
[2] https://sashiko.dev/#/bug/linux-925eaf98-fa4b-478a-8a96-afcb47316f81

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118184729.2302130-1-m-malladi@ti.com?part=1

  reply	other threads:[~2026-11-19 18:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 18:47 [PATCH net-next 0/2] net: ti: icssg: Multi-flow RX and ethtool RX flow classification Meghana Malladi
2026-11-18 18:47 ` [PATCH net-next 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI Meghana Malladi
2026-11-19 18:50   ` sashiko-bot [this message]
2026-11-18 18:47 ` [PATCH net-next 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support Meghana Malladi
2026-11-19  9:19   ` Marco Crivellari
2026-11-19 18:50   ` 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-223805@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=m-malladi@ti.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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