[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <2ffe99be4545b01436f23405177c618916d84a19.1617885385.git.lorenzo@kernel.org>
Date: Thu, 8 Apr 2021 14:50:59 +0200
From: Lorenzo Bianconi <lorenzo@...nel.org>
To: bpf@...r.kernel.org, netdev@...r.kernel.org
Cc: lorenzo.bianconi@...hat.com, davem@...emloft.net, kuba@...nel.org,
ast@...nel.org, daniel@...earbox.net, shayagr@...zon.com,
sameehj@...zon.com, john.fastabend@...il.com, dsahern@...nel.org,
brouer@...hat.com, echaudro@...hat.com, jasowang@...hat.com,
alexander.duyck@...il.com, saeed@...nel.org,
maciej.fijalkowski@...el.com
Subject: [PATCH v8 bpf-next 07/14] net: xdp: add multi-buff support to xdp_build_skb_from_fram
Introduce xdp multi-buff support to
__xdp_build_skb_from_frame/xdp_build_skb_from_fram utility
routines.
Signed-off-by: Lorenzo Bianconi <lorenzo@...nel.org>
---
net/core/xdp.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 430f516259d9..7388bc6d680b 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -603,9 +603,21 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
struct sk_buff *skb,
struct net_device *dev)
{
+ skb_frag_t frag_list[MAX_SKB_FRAGS];
unsigned int headroom, frame_size;
+ int i, num_frags = 0;
void *hard_start;
+ /* XDP multi-buff frame */
+ if (unlikely(xdpf->mb)) {
+ struct xdp_shared_info *xdp_sinfo;
+
+ xdp_sinfo = xdp_get_shared_info_from_frame(xdpf);
+ num_frags = xdp_sinfo->nr_frags;
+ memcpy(frag_list, xdp_sinfo->frags,
+ sizeof(skb_frag_t) * num_frags);
+ }
+
/* Part of headroom was reserved to xdpf */
headroom = sizeof(*xdpf) + xdpf->headroom;
@@ -624,6 +636,20 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
if (xdpf->metasize)
skb_metadata_set(skb, xdpf->metasize);
+ /* Single-buff XDP frame */
+ if (likely(!num_frags))
+ goto out;
+
+ for (i = 0; i < num_frags; i++) {
+ struct page *page = xdp_get_frag_page(&frag_list[i]);
+
+ skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
+ page, xdp_get_frag_offset(&frag_list[i]),
+ xdp_get_frag_size(&frag_list[i]),
+ xdpf->frame_sz);
+ }
+
+out:
/* Essential SKB info: protocol and skb->dev */
skb->protocol = eth_type_trans(skb, dev);
--
2.30.2
Powered by blists - more mailing lists