From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, daniel@iogearbox.net,
hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me,
michael.chan@broadcom.com, anthony.l.nguyen@intel.com,
marcin.s.wojtas@gmail.com, tariqt@nvidia.com, mbloch@nvidia.com,
jasowang@redhat.com, bpf@vger.kernel.org,
aleksander.lobakin@intel.com, pavan.chebbi@broadcom.com,
przemyslaw.kitszel@intel.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 2/2] net: xdp: handle frags with unreadable memory
Date: Fri, 5 Sep 2025 15:15:39 -0700 [thread overview]
Message-ID: <20250905221539.2930285-3-kuba@kernel.org> (raw)
In-Reply-To: <20250905221539.2930285-1-kuba@kernel.org>
We don't expect frags with unreadable memory to be presented
to XDP programs today, but the XDP helpers are designed to be
usable whether XDP is enabled or not. Support handling frags
with unreadable memory.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
include/net/xdp.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 57189fc21168..98f984d8f2c6 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -76,6 +76,11 @@ enum xdp_buff_flags {
XDP_FLAGS_FRAGS_PF_MEMALLOC = BIT(1), /* xdp paged memory is under
* pressure
*/
+ /* frags have unreadable mem, this can't be true for real XDP packets,
+ * but drivers may use XDP helpers to construct Rx pkt state even when
+ * XDP program is not attached.
+ */
+ XDP_FLAGS_FRAGS_UNREADABLE = BIT(2),
};
struct xdp_buff {
@@ -109,6 +114,11 @@ static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
}
+static __always_inline void xdp_buff_set_frag_unreadable(struct xdp_buff *xdp)
+{
+ xdp->flags |= XDP_FLAGS_FRAGS_UNREADABLE;
+}
+
static __always_inline u32 xdp_buff_get_skb_flags(const struct xdp_buff *xdp)
{
return xdp->flags;
@@ -248,6 +258,8 @@ static inline bool xdp_buff_add_frag(struct xdp_buff *xdp, netmem_ref netmem,
if (unlikely(netmem_is_pfmemalloc(netmem)))
xdp_buff_set_frag_pfmemalloc(xdp);
+ if (unlikely(netmem_is_net_iov(netmem)))
+ xdp_buff_set_frag_unreadable(xdp);
return true;
}
@@ -328,6 +340,7 @@ xdp_update_skb_frags_info(struct sk_buff *skb, u8 nr_frags,
skb->data_len += size;
skb->truesize += truesize;
skb->pfmemalloc |= !!(xdp_flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
+ skb->unreadable |= !!(xdp_flags & XDP_FLAGS_FRAGS_UNREADABLE);
}
/* Avoids inlining WARN macro in fast-path */
--
2.51.0
next prev parent reply other threads:[~2025-09-05 22:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 22:15 [PATCH net-next 0/2] net: xdp: handle frags with unreadable memory Jakub Kicinski
2025-09-05 22:15 ` [PATCH net-next 1/2] net: xdp: pass full flags to xdp_update_skb_shared_info() Jakub Kicinski
2025-09-09 13:30 ` Jesper Dangaard Brouer
2025-09-09 23:24 ` Jakub Kicinski
2025-09-05 22:15 ` Jakub Kicinski [this message]
2025-09-05 22:55 ` [PATCH net-next 0/2] net: xdp: handle frags with unreadable memory Stanislav Fomichev
2025-09-08 12:02 ` Alexander Lobakin
2025-09-11 10:10 ` patchwork-bot+netdevbpf
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=20250905221539.2930285-3-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=marcin.s.wojtas@gmail.com \
--cc=mbloch@nvidia.com \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=sdf@fomichev.me \
--cc=tariqt@nvidia.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;
as well as URLs for NNTP newsgroup(s).