* [PATCH net-next v2] eth: fbnic: Support XDP redirect
@ 2026-12-03 18:09 Björn Töpel
2026-12-04 18:11 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Björn Töpel @ 2026-12-03 18:09 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, Andrew Lunn, David S. Miller,
Eric Dumazet, Paolo Abeni, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Willem de Bruijn, netdev,
bpf
Cc: Björn Töpel, kernel-team, Stanislav Fomichev,
Simon Horman, Dimitri Daskalakis, Bobby Eshleman, Daniel Zahka,
Mike Marciniszyn (Meta), Mohsin Bashir, Breno Leitao
fbnic treats XDP_REDIRECT as an invalid action: it warns and drops the
packet, so programs on fbnic cannot redirect to devmap, cpumap or
AF_XDP sockets.
Support the verdict and advertise NETDEV_XDP_ACT_REDIRECT. The buffers
of a redirected packet go to the target, and a failed redirect drops
the packet as XDP_ABORTED does. Each RX queue flushes its redirects
once per poll.
The NAPI vector, not a variable of the RX loop, notes that a flush is
due, as one more live variable in that loop costs XDP_DROP six
instructions per packet.
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
Changes in v2:
- Make xdp_flush a u8, not a bool (Alexander)
- Drop the comment on xdp_flush
- Rebase on net-next
v1: https://lore.kernel.org/netdev/20261127055334.3156389-1-bjorn@kernel.org/
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 3 ++-
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 13 +++++++++++++
drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 1 +
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
index 52244219d166..9f0d8c070d1c 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c
@@ -822,7 +822,8 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd)
netdev->hw_enc_features |= netdev->features;
netdev->features |= NETIF_F_NTUPLE;
- netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_RX_SG;
+ netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
+ NETDEV_XDP_ACT_RX_SG;
netdev->min_mtu = IPV6_MIN_MTU;
netdev->max_mtu = FBNIC_MAX_JUMBO_FRAME_SIZE - ETH_HLEN;
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
index 381831b7e108..9525ad2f7e14 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
@@ -22,6 +22,7 @@ enum {
FBNIC_XDP_PASS = 0,
FBNIC_XDP_CONSUME,
FBNIC_XDP_TX,
+ FBNIC_XDP_REDIRECT,
FBNIC_XDP_LEN_ERR,
};
@@ -1211,10 +1212,15 @@ static struct sk_buff *fbnic_run_xdp(struct fbnic_napi_vector *nv,
return fbnic_build_skb(nv, pkt);
case XDP_TX:
return ERR_PTR(fbnic_pkt_tx(nv, pkt));
+ case XDP_REDIRECT:
+ if (xdp_do_redirect(nv->napi.dev, &pkt->buff, xdp_prog))
+ goto xdp_exception;
+ return ERR_PTR(-FBNIC_XDP_REDIRECT);
default:
bpf_warn_invalid_xdp_action(nv->napi.dev, xdp_prog, act);
fallthrough;
case XDP_ABORTED:
+xdp_exception:
trace_xdp_exception(nv->napi.dev, xdp_prog, act);
fallthrough;
case XDP_DROP:
@@ -1334,6 +1340,8 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
napi_gro_receive(&nv->napi, skb);
} else if (skb == ERR_PTR(-FBNIC_XDP_TX)) {
pkt_tail = nv->qt[0].sub1.tail;
+ } else if (skb == ERR_PTR(-FBNIC_XDP_REDIRECT)) {
+ nv->xdp_flush = true;
} else if (PTR_ERR(skb) == -FBNIC_XDP_CONSUME) {
fbnic_put_pkt_buff(qt, pkt, 1);
} else {
@@ -1387,6 +1395,11 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *nv,
fbnic_clean_bdq(&qt->sub1, head1, budget);
fbnic_fill_bdq(&qt->sub1);
+ if (nv->xdp_flush) {
+ nv->xdp_flush = false;
+ xdp_do_flush();
+ }
+
/* Record the current head/tail of the queue */
if (rcq->head != head) {
rcq->head = head;
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h
index 6ee3cce3d942..a61ac2df7c03 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h
@@ -173,6 +173,7 @@ struct fbnic_napi_vector {
u16 v_idx;
u8 txt_count;
u8 rxt_count;
+ u8 xdp_flush;
struct fbnic_q_triad qt[];
};
base-commit: c1165beb053a652299b1503b2dd7674ced0b1596
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next v2] eth: fbnic: Support XDP redirect
2026-12-03 18:09 [PATCH net-next v2] eth: fbnic: Support XDP redirect Björn Töpel
@ 2026-12-04 18:11 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 18:11 UTC (permalink / raw)
To: bjorn
Cc: alexanderduyck, kuba, andrew+netdev, davem, edumazet, pabeni, ast,
daniel, hawk, john.fastabend, willemb, netdev, bpf, kernel-team,
sdf, horms, dimitri.daskalakis1, bobbyeshleman, daniel.zahka,
mike.marciniszyn, hmohsin, leitao
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] This patch lets fbnic hand multi-buffer XDP frames to redirect
targets.
--
eth: fbnic: Support XDP redirect
This commit adds the XDP_REDIRECT verdict to fbnic_run_xdp() and
advertises NETDEV_XDP_ACT_REDIRECT. Each RX queue flushes its pending
redirects once per poll, and a flag in the NAPI vector records when a
flush is needed.
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
> index 381831b7e1080..9525ad2f7e14d 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
[ ... ]
> @@ -1211,10 +1212,15 @@ static struct sk_buff *fbnic_run_xdp(struct fbnic_napi_vector *nv,
> return fbnic_build_skb(nv, pkt);
> case XDP_TX:
> return ERR_PTR(fbnic_pkt_tx(nv, pkt));
> + case XDP_REDIRECT:
> + if (xdp_do_redirect(nv->napi.dev, &pkt->buff, xdp_prog))
> + goto xdp_exception;
> + return ERR_PTR(-FBNIC_XDP_REDIRECT);
[Severity: High]
Can multi-buffer frames redirected from fbnic end up as skbs whose
truesize is much smaller than the memory they hold?
REDIRECT is now advertised together with NETDEV_XDP_ACT_RX_SG. That means
a header-split frame with payload frags can reach a cpumap (or veth).
There, cpu_map_kthread_run() builds the skb with
__xdp_build_skb_from_frame(), which ignores sinfo->xdp_frags_truesize:
net/core/xdp.c:__xdp_build_skb_from_frame() {
...
if (unlikely(xdp_frame_has_frags(xdpf)))
xdp_update_skb_frags_info(skb, nr_frags, sinfo->xdp_frags_size,
nr_frags * xdpf->frame_sz,
xdp_frame_get_skb_flags(xdpf));
...
}
In fbnic, frame_sz only covers the header chunk:
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c:fbnic_pkt_prepare() {
...
frame_sz = hdr_pg_end - hdr_pg_start;
xdp_init_buff(&pkt->buff, frame_sz, &qt->xdp_rxq);
...
}
With FBNIC_RX_HROOM and FBNIC_RX_TROOM, that comes to roughly 704 bytes
for a split TCP header.
The payload frags are added in fbnic_add_rx_frag() with their real
truesize, which can be up to FBNIC_BD_PAGE_SIZE - pg_off:
added = xdp_buff_add_frag(&pkt->buff, netmem, pg_off, len, truesize);
xdp_buff_add_frag() can also coalesce adjacent device pages into one
frag. So a 9000-byte jumbo payload could end up as nr_frags == 1 with
about 9 KiB of real truesize, yet it would be charged only frame_sz.
The XDP_PASS path avoids this, because xdp_build_skb_from_buff() prefers
sinfo->xdp_frags_truesize. The redirect-to-cpumap path does not.
If skb->truesize ends up below skb->len, socket rcvbuf and tcp_mem
accounting would be under-charged by a large factor. A remote sender
could exploit that to pin far more memory than the limits allow.
It would also trigger this warning when TCP coalesces into the
receive-queue tail via tcp_queue_rcv()->tcp_try_coalesce()->
skb_try_coalesce():
if (WARN_ON_ONCE(delta < 0 || delta < len))
return false;
Would it make sense to have __xdp_build_skb_from_frame() use
sinfo->xdp_frags_truesize? That field should still be valid, since
xdp_convert_buff_to_frame() does not touch it.
Alternatively, could frames with frags be kept off the redirect path
until the core accounts for them correctly?
> default:
> bpf_warn_invalid_xdp_action(nv->napi.dev, xdp_prog, act);
> fallthrough;
> case XDP_ABORTED:
> +xdp_exception:
> trace_xdp_exception(nv->napi.dev, xdp_prog, act);
> fallthrough;
> case XDP_DROP:
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203180924.3862144-1-bjorn%40kernel.org
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 18:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 18:09 [PATCH net-next v2] eth: fbnic: Support XDP redirect Björn Töpel
2026-12-04 18:11 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox