Skip to content

Commit 6bffdc0

Browse files
kuba-mooPaolo Abeni
authored andcommitted
net: xdp: handle frags with unreadable memory
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Acked-by: Stanislav Fomichev <[email protected]> Reviewed-by: Alexander Lobakin <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 1827f77 commit 6bffdc0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/net/xdp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ enum xdp_buff_flags {
7676
XDP_FLAGS_FRAGS_PF_MEMALLOC = BIT(1), /* xdp paged memory is under
7777
* pressure
7878
*/
79+
/* frags have unreadable mem, this can't be true for real XDP packets,
80+
* but drivers may use XDP helpers to construct Rx pkt state even when
81+
* XDP program is not attached.
82+
*/
83+
XDP_FLAGS_FRAGS_UNREADABLE = BIT(2),
7984
};
8085

8186
struct xdp_buff {
@@ -121,6 +126,11 @@ static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
121126
xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
122127
}
123128

129+
static __always_inline void xdp_buff_set_frag_unreadable(struct xdp_buff *xdp)
130+
{
131+
xdp->flags |= XDP_FLAGS_FRAGS_UNREADABLE;
132+
}
133+
124134
static __always_inline u32 xdp_buff_get_skb_flags(const struct xdp_buff *xdp)
125135
{
126136
return xdp->flags;
@@ -270,6 +280,8 @@ static inline bool xdp_buff_add_frag(struct xdp_buff *xdp, netmem_ref netmem,
270280

271281
if (unlikely(netmem_is_pfmemalloc(netmem)))
272282
xdp_buff_set_frag_pfmemalloc(xdp);
283+
if (unlikely(netmem_is_net_iov(netmem)))
284+
xdp_buff_set_frag_unreadable(xdp);
273285

274286
return true;
275287
}
@@ -350,6 +362,7 @@ xdp_update_skb_frags_info(struct sk_buff *skb, u8 nr_frags,
350362
skb->data_len += size;
351363
skb->truesize += truesize;
352364
skb->pfmemalloc |= !!(xdp_flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
365+
skb->unreadable |= !!(xdp_flags & XDP_FLAGS_FRAGS_UNREADABLE);
353366
}
354367

355368
/* Avoids inlining WARN macro in fast-path */

0 commit comments

Comments
 (0)