From: "Arthur Fabre" <arthur@arthurfabre.com>
To: "Lorenzo Bianconi" <lorenzo.bianconi@redhat.com>
Cc: <netdev@vger.kernel.org>, <bpf@vger.kernel.org>,
<jakub@cloudflare.com>, <hawk@kernel.org>, <yan@cloudflare.com>,
<jbrandeburg@cloudflare.com>, <thoiland@redhat.com>,
<lbiancon@redhat.com>, "Arthur Fabre" <afabre@cloudflare.com>
Subject: Re: [PATCH RFC bpf-next 02/20] trait: XDP support
Date: Mon, 10 Mar 2025 16:50:26 +0100 [thread overview]
Message-ID: <D8CPETTWTCDX.23AMDJAQOJX8I@arthurfabre.com> (raw)
In-Reply-To: <Z8tFdSbT7Gg4iO5z@lore-desk>
On Fri Mar 7, 2025 at 8:14 PM CET, Lorenzo Bianconi wrote:
> On Mar 05, arthur@arthurfabre.com wrote:
> > From: Arthur Fabre <afabre@cloudflare.com>
> >
>
> [...]
>
> > +static __always_inline void *xdp_buff_traits(const struct xdp_buff *xdp)
> > +{
> > + return xdp->data_hard_start + _XDP_FRAME_SIZE;
> > +}
> > +
> > static __always_inline void
> > xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
> > {
> > @@ -133,6 +139,13 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
> > xdp->data = data;
> > xdp->data_end = data + data_len;
> > xdp->data_meta = meta_valid ? data : data + 1;
> > +
> > + if (meta_valid) {
>
> can we relax this constraint and use xdp->data as end boundary here?
The problem isn't having a boundary, it's patching all the drivers to
propagate that traits are present to the skb layer. See patch 8 "trait:
Propagate presence of traits to sk_buff", and patches 9-15 for driver
changes.
There's some discussion around updating all the remaining drivers to
support XDP metadata, if instead of making them call skb_metadata_set()
we use a more "generic" hook like "xdp_buff_update_skb()" from this
series, we can use it for traits later.
>
> > + /* We assume drivers reserve enough headroom to store xdp_frame
> > + * and the traits header.
> > + */
> > + traits_init(xdp_buff_traits(xdp), xdp->data_meta);
> > + }
> > }
> >
> > /* Reserve memory area at end-of data area.
> > @@ -267,6 +280,8 @@ struct xdp_frame {
> > u32 flags; /* supported values defined in xdp_buff_flags */
> > };
> >
> > +static_assert(sizeof(struct xdp_frame) == _XDP_FRAME_SIZE);
> > +
> > static __always_inline bool xdp_frame_has_frags(const struct xdp_frame *frame)
> > {
> > return !!(frame->flags & XDP_FLAGS_HAS_FRAGS);
> > @@ -517,6 +532,11 @@ static inline bool xdp_metalen_invalid(unsigned long metalen)
> > return !IS_ALIGNED(metalen, sizeof(u32)) || metalen > meta_max;
> > }
> >
> > +static __always_inline void *xdp_meta_hard_start(const struct xdp_buff *xdp)
> > +{
> > + return xdp_buff_traits(xdp) + traits_size(xdp_buff_traits(xdp));
>
> here we are always consuming sizeof(struct __trait_hdr)), right? We can do
> somehing smarter and check if traits are really used? (e.g. adding in the flags
> in xdp_buff)?
Yes, we're always taking space from the headroom for struct __trait_hdr.
I think it's impossible to tell if traits are used or not early enough:
users could be setting a trait for the first time in iptables or TC. But
we don't know that in XDP.
>
> > +}
> > +
> > struct xdp_attachment_info {
> > struct bpf_prog *prog;
> > u32 flags;
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index dcc53ac5c5458f67a422453134665d43d466a02e..79b78e7cd57fd78c6cc8443da54ae96408c496b0 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -85,6 +85,7 @@
> > #include <linux/un.h>
> > #include <net/xdp_sock_drv.h>
> > #include <net/inet_dscp.h>
> > +#include <net/trait.h>
> >
> > #include "dev.h"
> >
> > @@ -3935,9 +3936,8 @@ static unsigned long xdp_get_metalen(const struct xdp_buff *xdp)
> >
> > BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset)
> > {
> > - void *xdp_frame_end = xdp->data_hard_start + sizeof(struct xdp_frame);
> > unsigned long metalen = xdp_get_metalen(xdp);
> > - void *data_start = xdp_frame_end + metalen;
> > + void *data_start = xdp_meta_hard_start(xdp) + metalen;
>
> We could waste 16byte here, right?
If traits aren't being used?
[...]
next prev parent reply other threads:[~2025-03-10 15:50 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 14:31 [PATCH RFC bpf-next 00/20] traits: Per packet metadata KV store arthur
2025-03-05 14:31 ` [PATCH RFC bpf-next 01/20] trait: limited KV store for packet metadata arthur
2025-03-07 6:36 ` Alexei Starovoitov
2025-03-07 11:14 ` Arthur Fabre
2025-03-07 17:29 ` Alexei Starovoitov
2025-03-10 14:45 ` Arthur Fabre
2025-03-07 19:24 ` Jakub Sitnicki
2025-03-05 14:31 ` [PATCH RFC bpf-next 02/20] trait: XDP support arthur
2025-03-07 19:13 ` Lorenzo Bianconi
2025-03-10 15:50 ` Arthur Fabre [this message]
2025-03-05 14:32 ` [PATCH RFC bpf-next 03/20] trait: basic XDP selftest arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 04/20] trait: basic XDP benchmark arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 05/20] trait: Replace memcpy calls with inline copies arthur
2025-03-10 10:50 ` Lorenzo Bianconi
2025-03-10 15:52 ` Arthur Fabre
2025-03-10 22:15 ` David Laight
2025-03-05 14:32 ` [PATCH RFC bpf-next 06/20] trait: Replace memmove calls with inline move arthur
2025-03-06 10:14 ` Jesper Dangaard Brouer
2025-03-05 14:32 ` [PATCH RFC bpf-next 07/20] xdp: Track if metadata is supported in xdp_frame <> xdp_buff conversions arthur
2025-03-05 15:24 ` Alexander Lobakin
2025-03-05 17:02 ` Arthur Fabre
2025-03-06 11:12 ` Jesper Dangaard Brouer
2025-03-10 11:10 ` Lorenzo Bianconi
2025-03-05 14:32 ` [PATCH RFC bpf-next 08/20] trait: Propagate presence of traits to sk_buff arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 09/20] bnxt: Propagate trait presence to skb arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 10/20] ice: " arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 11/20] veth: " arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 12/20] virtio_net: " arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 13/20] mlx5: move xdp_buff scope one level up arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 14/20] mlx5: Propagate trait presence to skb arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 15/20] xdp generic: " arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 16/20] trait: Support sk_buffs arthur
2025-03-10 11:45 ` Lorenzo Bianconi
2025-03-05 14:32 ` [PATCH RFC bpf-next 17/20] trait: Allow socket filters to access traits arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 18/20] trait: registration API arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 19/20] trait: Sync linux/bpf.h to tools/ for trait registration arthur
2025-03-05 14:32 ` [PATCH RFC bpf-next 20/20] trait: register traits in benchmarks and tests arthur
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=D8CPETTWTCDX.23AMDJAQOJX8I@arthurfabre.com \
--to=arthur@arthurfabre.com \
--cc=afabre@cloudflare.com \
--cc=bpf@vger.kernel.org \
--cc=hawk@kernel.org \
--cc=jakub@cloudflare.com \
--cc=jbrandeburg@cloudflare.com \
--cc=lbiancon@redhat.com \
--cc=lorenzo.bianconi@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=thoiland@redhat.com \
--cc=yan@cloudflare.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