Netdev List
 help / color / mirror / Atom feed
From: Jon Kohler <jon@nutanix.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Jason Wang <jasowang@redhat.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, 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>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Cc: Jon Kohler <jon@nutanix.com>
Subject: [PATCH net-next] xdp: add xdp_skb_reserve_put helper
Date: Wed, 30 Apr 2025 11:29:20 -0700	[thread overview]
Message-ID: <20250430182921.1704021-1-jon@nutanix.com> (raw)

Add helper for calling skb_{put|reserve} to reduce repetitive pattern
across various drivers.

Plumb into tap and tun to start.

No functional change intended.

Signed-off-by: Jon Kohler <jon@nutanix.com>
---
 drivers/net/tap.c | 3 +--
 drivers/net/tun.c | 3 +--
 include/net/xdp.h | 8 ++++++++
 net/core/xdp.c    | 3 +--
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index d4ece538f1b2..54ce492da5e9 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -1062,8 +1062,7 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp)
 		goto err;
 	}
 
-	skb_reserve(skb, xdp->data - xdp->data_hard_start);
-	skb_put(skb, xdp->data_end - xdp->data);
+	xdp_skb_reserve_put(xdp, skb);
 
 	skb_set_network_header(skb, ETH_HLEN);
 	skb_reset_mac_header(skb);
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 7babd1e9a378..30701ad5c27d 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2415,8 +2415,7 @@ static int tun_xdp_one(struct tun_struct *tun,
 		goto out;
 	}
 
-	skb_reserve(skb, xdp->data - xdp->data_hard_start);
-	skb_put(skb, xdp->data_end - xdp->data);
+	xdp_skb_reserve_put(xdp, skb);
 
 	/* The externally provided xdp_buff may have no metadata support, which
 	 * is marked by xdp->data_meta being xdp->data + 1. This will lead to a
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 48efacbaa35d..0e7414472464 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -345,6 +345,14 @@ struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
 					 struct net_device *dev);
 struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);
 
+static __always_inline
+void xdp_skb_reserve_put(const struct xdp_buff *xdp,
+			 struct sk_buff *skb)
+{
+	skb_reserve(skb, xdp->data - xdp->data_hard_start);
+	__skb_put(skb, xdp->data_end - xdp->data);
+}
+
 static inline
 void xdp_convert_frame_to_buff(const struct xdp_frame *frame,
 			       struct xdp_buff *xdp)
diff --git a/net/core/xdp.c b/net/core/xdp.c
index f86eedad586a..1fca2aa1d1fe 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -646,8 +646,7 @@ struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)
 	if (unlikely(!skb))
 		return NULL;
 
-	skb_reserve(skb, xdp->data - xdp->data_hard_start);
-	__skb_put(skb, xdp->data_end - xdp->data);
+	xdp_skb_reserve_put(xdp, skb);
 
 	metalen = xdp->data - xdp->data_meta;
 	if (metalen > 0)
-- 
2.43.0


             reply	other threads:[~2025-04-30 17:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30 18:29 Jon Kohler [this message]
2025-04-30 18:25 ` [PATCH net-next] xdp: add xdp_skb_reserve_put helper Willem de Bruijn
2025-04-30 18:40   ` Daniel Borkmann
2025-04-30 18:45     ` Jon Kohler
2025-04-30 19:04       ` Willem de Bruijn
2025-04-30 19:09         ` Jon Kohler

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=20250430182921.1704021-1-jon@nutanix.com \
    --to=jon@nutanix.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=ast@kernel.org \
    --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=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemdebruijn.kernel@gmail.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