[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250422-afabre-traits-010-rfc2-v2-2-92bcc6b146c9@arthurfabre.com>
Date: Tue, 22 Apr 2025 15:23:31 +0200
From: Arthur Fabre <arthur@...hurfabre.com>
To: netdev@...r.kernel.org, bpf@...r.kernel.org
Cc: jakub@...udflare.com, hawk@...nel.org, yan@...udflare.com,
jbrandeburg@...udflare.com, thoiland@...hat.com, lbiancon@...hat.com,
ast@...nel.org, kuba@...nel.org, edumazet@...gle.com,
Arthur Fabre <arthur@...hurfabre.com>
Subject: [PATCH RFC bpf-next v2 02/17] xdp: Track if metadata is supported
in xdp_frame <> xdp_buff conversions
xdp_buff stores whether metadata is supported by a NIC by setting
data_meta to be greater than data.
But xdp_frame only stores the metadata size (as metasize), so converting
between xdp_frame and xdp_buff is lossy.
This won't let us add "generic" functions for setting skb fields from
either xdp_frame or xdp_buff in drivers.
Switch to storing whether metadata is supported or not in a new
XDP_FLAG, as flags are copied as is between xdp_frame and xdp_buff.
This also resolves the slight awkward checks needed for calculating the
metadata length: data - data_meta can now always be used.
Signed-off-by: Arthur Fabre <arthur@...hurfabre.com>
---
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 5 -----
include/net/xdp.h | 12 +++++++++---
net/core/filter.c | 3 +--
net/core/xdp.c | 3 +--
net/xdp/xsk.c | 11 ++---------
5 files changed, 13 insertions(+), 21 deletions(-)
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 4948b4906584e099515b1e1fc46428f6f0a56d1b..b009b88b5b410200500af717ca05ba72e7d2ffb8 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -2629,12 +2629,7 @@ static u32 dpaa_run_xdp(struct dpaa_priv *priv, struct qm_fd *fd, void *vaddr,
switch (xdp_act) {
case XDP_PASS:
-#ifdef CONFIG_DPAA_ERRATUM_A050385
- *xdp_meta_len = xdp_data_meta_unsupported(&xdp) ? 0 :
- xdp.data - xdp.data_meta;
-#else
*xdp_meta_len = xdp.data - xdp.data_meta;
-#endif
break;
case XDP_TX:
/* We can access the full headroom when sending the frame
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 48efacbaa35da6c4ec76d8d8e78b86e8f7c23e4b..16c36813cbf8631ea170d2698f1d3408286129a2 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -76,6 +76,9 @@ enum xdp_buff_flags {
XDP_FLAGS_FRAGS_PF_MEMALLOC = BIT(1), /* xdp paged memory is under
* pressure
*/
+ XDP_FLAGS_META_SUPPORTED = BIT(2), /* metadata in headroom supported
+ * by driver
+ */
};
struct xdp_buff {
@@ -132,7 +135,10 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
xdp->data_hard_start = hard_start;
xdp->data = data;
xdp->data_end = data + data_len;
- xdp->data_meta = meta_valid ? data : data + 1;
+ xdp->data_meta = data;
+
+ if (meta_valid)
+ xdp->flags |= XDP_FLAGS_META_SUPPORTED;
}
/* Reserve memory area at end-of data area.
@@ -497,13 +503,13 @@ static inline void xdp_rxq_info_detach_mem_model(struct xdp_rxq_info *xdp_rxq)
static __always_inline void
xdp_set_data_meta_invalid(struct xdp_buff *xdp)
{
- xdp->data_meta = xdp->data + 1;
+ xdp->flags &= ~XDP_FLAGS_META_SUPPORTED;
}
static __always_inline bool
xdp_data_meta_unsupported(const struct xdp_buff *xdp)
{
- return unlikely(xdp->data_meta > xdp->data);
+ return unlikely(!(xdp->flags & XDP_FLAGS_META_SUPPORTED));
}
static inline bool xdp_metalen_invalid(unsigned long metalen)
diff --git a/net/core/filter.c b/net/core/filter.c
index 79cab4d78dc3c6fe8a3a16e76fd0daf51af3282e..f9b3358e274fa4b85e39509b04192c282ba2009c 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3937,8 +3937,7 @@ const struct bpf_func_proto bpf_xdp_get_buff_len_trace_proto = {
static unsigned long xdp_get_metalen(const struct xdp_buff *xdp)
{
- return xdp_data_meta_unsupported(xdp) ? 0 :
- xdp->data - xdp->data_meta;
+ return xdp->data - xdp->data_meta;
}
BPF_CALL_2(bpf_xdp_adjust_head, struct xdp_buff *, xdp, int, offset)
diff --git a/net/core/xdp.c b/net/core/xdp.c
index f86eedad586a77eb63a96a85aa6d068d3e94f077..4ee9ff9dbd0e810425e00c1e8bcc0d7088ddaad4 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -580,8 +580,7 @@ struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp)
struct page *page;
/* Clone into a MEM_TYPE_PAGE_ORDER0 xdp_frame. */
- metasize = xdp_data_meta_unsupported(xdp) ? 0 :
- xdp->data - xdp->data_meta;
+ metasize = xdp->data - xdp->data_meta;
totsize = xdp->data_end - xdp->data + metasize;
if (sizeof(*xdpf) + totsize > PAGE_SIZE)
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 5696af45bcf711ce6b9df46a8783db0f4561e79a..eb771c7fcbd461b3899a5f45bf8a3071aeaa6a9a 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -188,14 +188,6 @@ static int xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
return err;
}
-static void *xsk_copy_xdp_start(struct xdp_buff *from)
-{
- if (unlikely(xdp_data_meta_unsupported(from)))
- return from->data;
- else
- return from->data_meta;
-}
-
static u32 xsk_copy_xdp(void *to, void **from, u32 to_len,
u32 *from_len, skb_frag_t **frag, u32 rem)
{
@@ -227,12 +219,13 @@ static u32 xsk_copy_xdp(void *to, void **from, u32 to_len,
static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
{
u32 frame_size = xsk_pool_get_rx_frame_size(xs->pool);
- void *copy_from = xsk_copy_xdp_start(xdp), *copy_to;
+ void *copy_from, *copy_to;
u32 from_len, meta_len, rem, num_desc;
struct xdp_buff_xsk *xskb;
struct xdp_buff *xsk_xdp;
skb_frag_t *frag;
+ copy_from = xdp->data_meta;
from_len = xdp->data_end - copy_from;
meta_len = xdp->data - copy_from;
rem = len + meta_len;
--
2.43.0
Powered by blists - more mailing lists