public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: pvalerio@redhat.com
Cc: Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, nicolas.ferre@microchip.com,
	claudiu.beznea@tuxon.dev, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	lorenzo@kernel.org, theo.lebrun@bootlin.com, nb@tipi-net.de
Subject: Re: [PATCH net-next v6 6/7] net: macb: add XDP support for gem
Date: Sun, 29 Mar 2026 12:47:49 -0700	[thread overview]
Message-ID: <20260329194749.2781535-1-kuba@kernel.org> (raw)
In-Reply-To: <20260323221047.2749577-7-pvalerio@redhat.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: macb: add XDP support for gem

This commit introduces basic XDP support for macb/gem with the XDP_TX,
XDP_PASS, XDP_DROP, and XDP_REDIRECT verdict support.

> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 4c5dd70f003b..537d02264851 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
[ ... ]
> @@ -1197,6 +1198,18 @@ static int macb_halt_tx(struct macb *bp)
>  					bp, TSR);
>  }
>  
> +static void macb_tx_release_buff(void *buff, enum macb_tx_buff_type type, int budget)
> +{
> +	if (type == MACB_TYPE_SKB) {
> +		napi_consume_skb(buff, budget);
> +	} else {
> +		if (!budget)
> +			xdp_return_frame(buff);
> +		else
> +			xdp_return_frame_rx_napi(buff);
> +	}
> +}

Does this code cause memory corruption in the page pool lockless cache?
This function is called from macb_tx_complete(), which executes in the
context of the TX NAPI poll routine (queue->napi_tx).

However, the page pool was created and bound to the RX NAPI context
(queue->napi_rx). Since xdp_return_frame_rx_napi() bypasses safety checks
and places the page directly into the pool's lockless cache, and these are
independent NAPI instances that can be scheduled concurrently on different
CPUs, shouldn't this use xdp_return_frame() to safely handle cross-CPU
synchronization?

[ ... ]
> +static int macb_xdp_submit_frame(struct macb *bp, struct xdp_frame *xdpf,
> +				 struct net_device *dev, dma_addr_t addr)
> +{
[ ... ]
> +	tx_buff->ptr = xdpf;
> +	tx_buff->type = MACB_TYPE_XDP_TX;
> +	tx_buff->mapping = 0;
> +	tx_buff->size = xdpf->len;
> +	tx_buff->mapped_as_page = false;
> +
> +	ctrl = (u32)tx_buff->size;
> +	ctrl |= MACB_BIT(TX_LAST);

Could this write overwrite control bits in the descriptor if the XDP frame
length exceeds the hardware's maximum limit?

The hardware uses a 14-bit field for the frame length, with higher bits
reserved for control flags like TX_LAST and TX_WRAP. On architectures with
a PAGE_SIZE larger than 16KB (e.g., ARM64 ZynqMP with 64KB pages), an XDP
program can use bpf_xdp_adjust_tail() to legitimately increase the frame
length beyond this boundary.

Does this need a bounds check against the hardware's maximum supported
transmit size to prevent corrupted DMA operations?

[ ... ]
> @@ -1683,6 +1878,18 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi,
>  				queue->stats.rx_dropped++;
>  			}
>  
> +			headroom = bp->rx_headroom;
> +
> +			if (last_frame) {
> +				ret = gem_xdp_run(queue, buff_head, &data_len,
> +						  &headroom, addr - gem_rx_pad(bp));
> +				if (ret == XDP_REDIRECT)
> +					xdp_flush = true;
> +
> +				if (ret != XDP_PASS)
> +					goto next_frame;
> +			}
> +
>  			queue->skb = napi_build_skb(buff_head, gem_total_rx_buffer_size(bp));

Will this sequence allow multi-descriptor RX packets to silently bypass the
XDP program?

If a received packet spans multiple hardware descriptors (first_frame is true
but last_frame is false), the code skips gem_xdp_run() completely. It then
proceeds to allocate an sk_buff using napi_build_skb(), append subsequent
fragments on following loop iterations, and pass the assembled packet to the
network stack.

Shouldn't the driver explicitly drop packets that span multiple descriptors
when an XDP program is attached?

  parent reply	other threads:[~2026-03-29 19:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 22:10 [PATCH net-next v6 0/7] net: macb: Add XDP support and page pool integration Paolo Valerio
2026-03-23 22:10 ` [PATCH net-next v6 1/7] net: macb: move Rx buffers alloc from link up to open Paolo Valerio
2026-03-29 19:47   ` Jakub Kicinski
2026-03-23 22:10 ` [PATCH net-next v6 2/7] net: macb: rename rx_skbuff into rx_buff Paolo Valerio
2026-03-29 19:47   ` Jakub Kicinski
2026-03-23 22:10 ` [PATCH net-next v6 3/7] net: macb: Add page pool support handle multi-descriptor frame rx Paolo Valerio
2026-03-25 17:45   ` Simon Horman
2026-03-29 19:47   ` Jakub Kicinski
2026-03-23 22:10 ` [PATCH net-next v6 4/7] net: macb: make macb_tx_skb generic Paolo Valerio
2026-03-29 19:47   ` Jakub Kicinski
2026-03-23 22:10 ` [PATCH net-next v6 5/7] net: macb: generalize tx buffer handling Paolo Valerio
2026-03-29 19:47   ` Jakub Kicinski
2026-03-23 22:10 ` [PATCH net-next v6 6/7] net: macb: add XDP support for gem Paolo Valerio
2026-03-24  4:57   ` Mohsin Bashir
2026-03-29 19:47   ` Jakub Kicinski [this message]
2026-03-29 19:50   ` Jakub Kicinski
2026-03-23 22:10 ` [PATCH net-next v6 7/7] net: macb: introduce ndo_xdp_xmit support Paolo Valerio
2026-03-29 19:47   ` Jakub Kicinski

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=20260329194749.2781535-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=lorenzo@kernel.org \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=pabeni@redhat.com \
    --cc=pvalerio@redhat.com \
    --cc=theo.lebrun@bootlin.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