public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicolai Buchwitz <nb@tipi-net.de>
To: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org, Justin Chen <justin.chen@broadcom.com>,
	Simon Horman <horms@kernel.org>, Doug Berger <opendmb@gmail.com>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH net-next v5 3/6] net: bcmgenet: add basic XDP support (PASS/DROP)
Date: Thu, 02 Apr 2026 10:25:38 +0200	[thread overview]
Message-ID: <bc616b9914372a63c740c2f35f5dd8ef@tipi-net.de> (raw)
In-Reply-To: <20260401202702.0b0b6dec@kernel.org>

On 2.4.2026 05:27, Jakub Kicinski wrote:
> On Sun, 29 Mar 2026 00:05:06 +0100 Nicolai Buchwitz wrote:
>> @@ -2403,26 +2456,52 @@ static unsigned int bcmgenet_desc_rx(struct 
>> bcmgenet_rx_ring *ring,
>>  			goto next;
>>  		} /* error packet */
>> 
>> -		/* Build SKB from the page - data starts at hard_start,
>> -		 * frame begins after RSB(64) + pad(2) = 66 bytes.
>> -		 */
>> -		skb = napi_build_skb(hard_start, PAGE_SIZE - GENET_XDP_HEADROOM);
>> -		if (unlikely(!skb)) {
>> -			BCMGENET_STATS64_INC(stats, dropped);
>> -			page_pool_put_full_page(ring->page_pool, rx_page,
>> -						true);
>> -			goto next;
>> -		}
>> -
>> -		skb_mark_for_recycle(skb);
>> +		/* XDP: frame data starts after RSB + pad */
>> +		if (xdp_prog) {
>> +			struct xdp_buff xdp;
>> +			unsigned int xdp_act;
>> +			int pkt_len;
>> +
>> +			pkt_len = len - GENET_RSB_PAD;
>> +			if (priv->crc_fwd_en)
>> +				pkt_len -= ETH_FCS_LEN;
>> +
>> +			xdp_init_buff(&xdp, PAGE_SIZE, &ring->xdp_rxq);
>> +			xdp_prepare_buff(&xdp, page_address(rx_page),
>> +					 GENET_RX_HEADROOM, pkt_len, true);
>> +
>> +			xdp_act = bcmgenet_run_xdp(ring, xdp_prog, &xdp,
>> +						   rx_page);
>> +			if (xdp_act != XDP_PASS)
>> +				goto next;
>> +
>> +			/* XDP_PASS: build SKB from (possibly modified) xdp */
>> +			skb = bcmgenet_xdp_build_skb(ring, &xdp, rx_page);
>> +			if (unlikely(!skb)) {
>> +				BCMGENET_STATS64_INC(stats, dropped);
>> +				page_pool_put_full_page(ring->page_pool,
>> +							rx_page, true);
>> +				goto next;
>> +			}
>> +		} else {
>> +			/* Build SKB from the page - data starts at
>> +			 * hard_start, frame begins after RSB(64) + pad(2).
>> +			 */
>> +			skb = napi_build_skb(hard_start,
>> +					     PAGE_SIZE - GENET_XDP_HEADROOM);
>> +			if (unlikely(!skb)) {
>> +				BCMGENET_STATS64_INC(stats, dropped);
>> +				page_pool_put_full_page(ring->page_pool,
>> +							rx_page, true);
>> +				goto next;
>> +			}
> 
> The large branches here are quite unusual, normally drivers fully
> prepare the xdp_buff and if there's no xdp prog attached act as
> if there was one and it returned XDP_PASS. Saves LoC and therefore 
> bugs.

Agreed, will refactor to always prepare xdp_buff and use
bcmgenet_xdp_build_skb for both paths in v6.

> 
>> 
>> -		/* Reserve the RSB + pad, then set the data length */
>> -		skb_reserve(skb, GENET_RSB_PAD);
>> -		__skb_put(skb, len - GENET_RSB_PAD);
>> +			skb_mark_for_recycle(skb);
>> +			skb_reserve(skb, GENET_RSB_PAD);
>> +			__skb_put(skb, len - GENET_RSB_PAD);
>> 
>> -		if (priv->crc_fwd_en) {
>> -			skb_trim(skb, skb->len - ETH_FCS_LEN);
>> -			len -= ETH_FCS_LEN;
>> +			if (priv->crc_fwd_en)
>> +				skb_trim(skb, skb->len - ETH_FCS_LEN);
>>  		}
>> 
>>  		/* Set up checksum offload */
> 
> AI points out that :
> 
>   The status_64 structure is located at the start of the page
>   before the frame data. Since this resides inside the XDP headroom, if 
> an XDP
>   program expands the header backwards (e.g., via bpf_xdp_adjust_head() 
> or
>   metadata via bpf_xdp_adjust_meta()), could it physically overwrite
>   status->rx_csum?
> 
>   Since the driver reads status->rx_csum after executing the XDP 
> program, it
>   could risk reading garbage data if the headroom was used. Should the 
> driver
>   skip setting CHECKSUM_COMPLETE when an XDP program is loaded?

Makes sense, status->rx_csum is read after XDP runs and an
adjust_head could overwrite the RSB. I'll save rx_csum before
running the XDP program rather than skipping CHECKSUM_COMPLETE
entirely, so XDP_PASS packets that weren't modified still benefit
from HW checksum offload.

> 
>> @@ -3745,6 +3824,39 @@ static int bcmgenet_change_carrier(struct 
>> net_device *dev, bool new_carrier)
>>  	return 0;
>>  }
>> 
>> +static int bcmgenet_xdp_setup(struct net_device *dev,
>> +			      struct netdev_bpf *xdp)
>> +{
>> +	struct bcmgenet_priv *priv = netdev_priv(dev);
>> +	struct bpf_prog *old_prog;
>> +	struct bpf_prog *prog = xdp->prog;
>> +
>> +	if (prog && dev->mtu > PAGE_SIZE - GENET_RX_HEADROOM -
>> +	    SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) {
>> +		NL_SET_ERR_MSG_MOD(xdp->extack,
>> +				   "MTU too large for single-page XDP buffer");
>> +		return -EOPNOTSUPP;
>> +	}
>> +
>> +	old_prog = xchg(&priv->xdp_prog, prog);
>> +	if (old_prog) {
>> +		synchronize_net();
> 
> Why? BPF prog gets freed after a RCU grace period I think?

You're right, bpf_prog_put handles this via call_rcu. Will remove
the synchronize_net().

> 
>> +		bpf_prog_put(old_prog);

Thanks
Nicolai

  reply	other threads:[~2026-04-02  8:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-28 23:05 [PATCH net-next v5 0/6] net: bcmgenet: add XDP support Nicolai Buchwitz
2026-03-28 23:05 ` [PATCH net-next v5 1/6] net: bcmgenet: convert RX path to page_pool Nicolai Buchwitz
2026-03-28 23:05 ` [PATCH net-next v5 2/6] net: bcmgenet: register xdp_rxq_info for each RX ring Nicolai Buchwitz
2026-03-28 23:05 ` [PATCH net-next v5 3/6] net: bcmgenet: add basic XDP support (PASS/DROP) Nicolai Buchwitz
2026-04-02  3:27   ` Jakub Kicinski
2026-04-02  8:25     ` Nicolai Buchwitz [this message]
2026-03-28 23:05 ` [PATCH net-next v5 4/6] net: bcmgenet: add XDP_TX support Nicolai Buchwitz
2026-04-02  3:27   ` Jakub Kicinski
2026-04-02  8:19     ` Nicolai Buchwitz
2026-03-28 23:05 ` [PATCH net-next v5 5/6] net: bcmgenet: add XDP_REDIRECT and ndo_xdp_xmit support Nicolai Buchwitz
2026-03-28 23:05 ` [PATCH net-next v5 6/6] net: bcmgenet: add XDP statistics counters Nicolai Buchwitz

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=bc616b9914372a63c740c2f35f5dd8ef@tipi-net.de \
    --to=nb@tipi-net.de \
    --cc=andrew+netdev@lunn.ch \
    --cc=ast@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=justin.chen@broadcom.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=opendmb@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    /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