From: Stanislav Fomichev <stfomichev@gmail.com>
To: Marcus Wichelmann <marcus.wichelmann@hetzner-cloud.de>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, willemdebruijn.kernel@gmail.com,
jasowang@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org,
john.fastabend@gmail.com
Subject: Re: [PATCH 1/1] net: tun: add XDP metadata support
Date: Thu, 30 Jan 2025 15:16:55 -0800 [thread overview]
Message-ID: <Z5wIZ2LAjz0wTWg5@mini-arch> (raw)
In-Reply-To: <20250130171614.1657224-2-marcus.wichelmann@hetzner-cloud.de>
On 01/30, Marcus Wichelmann wrote:
> Enable the support for bpf_xdp_adjust_meta for XDP buffers initialized
> by the tun driver. This is useful to pass metadata from an XDP program
> that's attached to a tap device to following XDP/TC programs.
>
> When used together with vhost_net, the batched XDP buffers were already
> initialized with metadata support by the vhost_net driver, but the
> metadata was not yet passed to the skb on XDP_PASS. So this also adds
> the required skb_metadata_set calls.
Can you expand more on what kind of metadata is present with vhost_net
and who fills it in? Is it virtio header stuff? I wonder how you
want to consume it..
Can you also add a selftest to use this new functionality?
> Signed-off-by: Marcus Wichelmann <marcus.wichelmann@hetzner-cloud.de>
> ---
> drivers/net/tun.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index e816aaba8..d3cfea40a 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1600,7 +1600,8 @@ static bool tun_can_build_skb(struct tun_struct *tun, struct tun_file *tfile,
>
> static struct sk_buff *__tun_build_skb(struct tun_file *tfile,
> struct page_frag *alloc_frag, char *buf,
> - int buflen, int len, int pad)
> + int buflen, int len, int pad,
> + int metasize)
> {
> struct sk_buff *skb = build_skb(buf, buflen);
>
> @@ -1609,6 +1610,8 @@ static struct sk_buff *__tun_build_skb(struct tun_file *tfile,
>
> skb_reserve(skb, pad);
> skb_put(skb, len);
> + if (metasize)
> + skb_metadata_set(skb, metasize);
> skb_set_owner_w(skb, tfile->socket.sk);
>
> get_page(alloc_frag->page);
> @@ -1668,6 +1671,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
> char *buf;
> size_t copied;
> int pad = TUN_RX_PAD;
> + int metasize = 0;
> int err = 0;
>
> rcu_read_lock();
> @@ -1695,7 +1699,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
> if (hdr->gso_type || !xdp_prog) {
> *skb_xdp = 1;
> return __tun_build_skb(tfile, alloc_frag, buf, buflen, len,
> - pad);
> + pad, metasize);
> }
>
> *skb_xdp = 0;
> @@ -1709,7 +1713,7 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
> u32 act;
>
> xdp_init_buff(&xdp, buflen, &tfile->xdp_rxq);
> - xdp_prepare_buff(&xdp, buf, pad, len, false);
> + xdp_prepare_buff(&xdp, buf, pad, len, true);
>
> act = bpf_prog_run_xdp(xdp_prog, &xdp);
> if (act == XDP_REDIRECT || act == XDP_TX) {
> @@ -1730,12 +1734,16 @@ static struct sk_buff *tun_build_skb(struct tun_struct *tun,
>
> pad = xdp.data - xdp.data_hard_start;
> len = xdp.data_end - xdp.data;
> +
> + metasize = xdp.data - xdp.data_meta;
[..]
> + metasize = metasize > 0 ? metasize : 0;
Why is this part needed?
next prev parent reply other threads:[~2025-01-30 23:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 17:16 [PATCH 0/1] XDP metadata support for tun driver Marcus Wichelmann
2025-01-30 17:16 ` [PATCH 1/1] net: tun: add XDP metadata support Marcus Wichelmann
2025-01-30 23:16 ` Stanislav Fomichev [this message]
2025-01-31 14:25 ` Marcus Wichelmann
2025-02-01 3:39 ` Stanislav Fomichev
2025-02-03 1:32 ` Willem de Bruijn
2025-02-03 1:39 ` Willem de Bruijn
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=Z5wIZ2LAjz0wTWg5@mini-arch \
--to=stfomichev@gmail.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=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcus.wichelmann@hetzner-cloud.de \
--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