From: Jesper Dangaard Brouer <brouer@redhat.com>
To: bpf@vger.kernel.org
Cc: Jesper Dangaard Brouer <brouer@redhat.com>,
netdev@vger.kernel.org, xdp-hints@xdp-project.net,
larysa.zaremba@intel.com, memxor@gmail.com,
Lorenzo Bianconi <lorenzo@kernel.org>,
mtahhan@redhat.com,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Daniel Borkmann <borkmann@iogearbox.net>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
dave@dtucker.co.uk, Magnus Karlsson <magnus.karlsson@intel.com>,
bjorn@kernel.org
Subject: [xdp-hints] [PATCH RFCv2 bpf-next 06/18] xdp: controlling XDP-hints from BPF-prog via helper
Date: Wed, 07 Sep 2022 17:45:30 +0200 [thread overview]
Message-ID: <166256553093.1434226.11320655607309623999.stgit@firesoul> (raw)
In-Reply-To: <166256538687.1434226.15760041133601409770.stgit@firesoul>
XDP BPF-prog's need a way to interact with the XDP-hints. This patch
introduces a BPF-helper function, that allow XDP BPF-prog's to interact
with the XDP-hints. Choosing BPF-helper to avoid directly exposing
xdp_buff_flags as UAPI.
BPF-prog can query if any XDP-hints have been setup and if this is
compatible with the xdp_hints_common struct.
Notice that XDP-hints are setup by the driver prior to calling the XDP
BPF-prog, which is useful as a BPF software layer for adjusting the HW
provided XDP-hints in-case of HW issues or missing HW features, for
use-case like xdp2skb or AF_XDP.
The BPF-prog might also prefer to use metadata area for other things,
either disabling XDP-hints or updating with another XDP-hints layout
that might still be compatible with common struct. Thus, helper have
"update" and "delete" mode flags.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
include/net/xdp.h | 41 ++++++++++++++++++++++++++++----
include/uapi/linux/bpf.h | 41 ++++++++++++++++++++++++++++++++
net/core/filter.c | 52 ++++++++++++++++++++++++++++++++++++++++
tools/include/uapi/linux/bpf.h | 43 ++++++++++++++++++++++++++++++++-
4 files changed, 172 insertions(+), 5 deletions(-)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index ea5836ccee82..c7cdcef83fa5 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -213,14 +213,19 @@ struct xdp_txq_info {
};
enum xdp_buff_flags {
- XDP_FLAGS_HAS_FRAGS = BIT(0), /* non-linear xdp buff */
- XDP_FLAGS_FRAGS_PF_MEMALLOC = BIT(1), /* xdp paged memory is under
+ XDP_FLAGS_HINTS_ENABLED = BIT(0),/* enum xdp_hint */
+#define XDP_FLAGS_HINTS_COMPAT_COMMON_ BIT(1) /* HINTS_BTF_COMPAT_COMMON */
+ XDP_FLAGS_HINTS_COMPAT_COMMON = XDP_FLAGS_HINTS_COMPAT_COMMON_,
+
+ XDP_FLAGS_HAS_FRAGS = BIT(2), /* non-linear xdp buff */
+ XDP_FLAGS_FRAGS_PF_MEMALLOC = BIT(3), /* xdp paged memory is under
* pressure
*/
- XDP_FLAGS_HAS_HINTS = BIT(2),
- XDP_FLAGS_HINTS_COMPAT_COMMON = BIT(3),
};
+#define XDP_FLAGS_HINTS_MASK (XDP_FLAGS_HINTS_ENABLED | \
+ XDP_FLAGS_HINTS_COMPAT_COMMON)
+
struct xdp_buff {
void *data;
void *data_end;
@@ -257,6 +262,34 @@ static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
}
+static __always_inline bool xdp_buff_has_hints(struct xdp_buff *xdp)
+{
+ return !!(xdp->flags & XDP_FLAGS_HINTS_MASK);
+}
+
+static __always_inline bool xdp_buff_has_hints_compat(struct xdp_buff *xdp)
+{
+ u32 flags = xdp->flags;
+
+ if (!(flags & XDP_FLAGS_HINTS_COMPAT_COMMON))
+ return false;
+
+ return !!(flags & XDP_FLAGS_HINTS_MASK);
+}
+
+static __always_inline void xdp_buff_set_hints_flags(struct xdp_buff *xdp,
+ bool is_compat_common)
+{
+ u32 common = is_compat_common ? XDP_FLAGS_HINTS_COMPAT_COMMON : 0;
+
+ xdp->flags |= XDP_FLAGS_HINTS_ENABLED | common;
+}
+
+static __always_inline void xdp_buff_clear_hints_flags(struct xdp_buff *xdp)
+{
+ xdp->flags &= ~XDP_FLAGS_HINTS_MASK;
+}
+
static __always_inline void
xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
{
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 934a2a8beb87..36ba104e612e 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -5355,6 +5355,37 @@ union bpf_attr {
* Return
* Current *ktime*.
*
+ * long xdp_hints_btf(struct xdp_buff *xdp_md, u64 flags)
+ * Description
+ * Update and get info on XDP hints ctx state.
+ *
+ * Drivers can provide XDP-hints information via the metadata area,
+ * which defines the layout of this area via BTF. The *full* BTF ID
+ * is available as the last member.
+ *
+ * This **full** BTF ID is a 64-bit value, encoding the BTF
+ * **object** ID as the high 32-bit and BTF *type* ID as lower
+ * 32-bit. This is needed as the BTF **type** ID (32-bit) can
+ * originate from different BTF **object** sources, e.g. vmlinux,
+ * module or local BTF-object.
+ *
+ * In-case a BPF-prog want to redefine the layout of this area it
+ * should update the full BTF ID (last-member) and call this helper
+ * to specify if the layout is compatible with kernel struct
+ * xdp_hints_common.
+ *
+ * The **flags** are used to control the mode of the helper.
+ * See enum xdp_hints_btf_mode_flags.
+ *
+ * Return
+ * 0 if driver didn't populate XDP-hints.
+ *
+ * Flag **HINTS_BTF_ENABLED** (1) if driver populated hints.
+ *
+ * Flag **HINTS_BTF_COMPAT_COMMON** (2) if layout is compatible
+ * with kernel struct xdp_hints_common. Thus, return value 3 as
+ * both flags will be set.
+ *
*/
#define __BPF_FUNC_MAPPER(FN) \
FN(unspec), \
@@ -5566,6 +5597,7 @@ union bpf_attr {
FN(tcp_raw_check_syncookie_ipv4), \
FN(tcp_raw_check_syncookie_ipv6), \
FN(ktime_get_tai_ns), \
+ FN(xdp_hints_btf), \
/* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
@@ -5977,6 +6009,15 @@ struct xdp_md {
__u32 egress_ifindex; /* txq->dev->ifindex */
};
+/* Mode flags for BPF_FUNC_xdp_hints_btf helper. */
+enum xdp_hints_btf_mode_flags {
+ HINTS_BTF_QUERY_ONLY = (1U << 0),
+ HINTS_BTF_ENABLED = (1U << 0), /* Return value */
+ HINTS_BTF_COMPAT_COMMON = (1U << 1), /* Return and query value */
+ HINTS_BTF_UPDATE = (1U << 2),
+ HINTS_BTF_DISABLE = (1U << 3),
+};
+
/* DEVMAP map-value layout
*
* The struct data-layout of map-value is a configuration interface.
diff --git a/net/core/filter.c b/net/core/filter.c
index 1acfaffeaf32..35f29990a67e 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -6094,6 +6094,56 @@ static const struct bpf_func_proto bpf_xdp_check_mtu_proto = {
.arg5_type = ARG_ANYTHING,
};
+/* flags type &enum xdp_hints_btf_mode_flags */
+BPF_CALL_2(bpf_xdp_hints_btf, struct xdp_buff *, xdp, u64, flags)
+{
+ bool is_compat_common;
+ s64 ret = 0;
+
+ /* UAPI value HINTS_BTF_COMPAT_COMMON happens to match xdp_buff->flags
+ * XDP_FLAGS_HINTS_COMPAT_COMMON which makes below code easier
+ */
+ BUILD_BUG_ON(HINTS_BTF_COMPAT_COMMON != XDP_FLAGS_HINTS_COMPAT_COMMON_);
+
+ if (flags & HINTS_BTF_QUERY_ONLY) {
+ ret = xdp->flags & XDP_FLAGS_HINTS_MASK;
+ goto out;
+ }
+ if (flags & HINTS_BTF_DISABLE) {
+ xdp_buff_clear_hints_flags(xdp);
+ goto out;
+ }
+ if (flags & HINTS_BTF_UPDATE) {
+ is_compat_common = !!(flags & HINTS_BTF_COMPAT_COMMON);
+
+ if (is_compat_common) {
+ unsigned long metalen = xdp_get_metalen(xdp);
+
+ if (sizeof(struct xdp_hints_common) < metalen)
+ is_compat_common = false;
+ /* TODO: Can kernel validate if hints are BTF compat
+ * with common?
+ */
+ }
+ /* TODO: Could BPF prog provide BTF as ARG_PTR_TO_BTF_ID to prove compat_common ? */
+ xdp_buff_set_hints_flags(xdp, is_compat_common);
+
+ ret = xdp->flags & XDP_FLAGS_HINTS_MASK;
+ goto out;
+ }
+
+ out:
+ return ret;
+}
+
+static const struct bpf_func_proto bpf_xdp_hints_btf_proto = {
+ .func = bpf_xdp_hints_btf,
+ .gpl_only = true,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_CTX,
+ .arg2_type = ARG_ANYTHING,
+};
+
#if IS_ENABLED(CONFIG_IPV6_SEG6_BPF)
static int bpf_push_seg6_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
{
@@ -7944,6 +7994,8 @@ xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
return &bpf_xdp_fib_lookup_proto;
case BPF_FUNC_check_mtu:
return &bpf_xdp_check_mtu_proto;
+ case BPF_FUNC_xdp_hints_btf:
+ return &bpf_xdp_hints_btf_proto;
#ifdef CONFIG_INET
case BPF_FUNC_sk_lookup_udp:
return &bpf_xdp_sk_lookup_udp_proto;
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 1d6085e15fc8..36ba104e612e 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -79,7 +79,7 @@ struct bpf_insn {
/* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
struct bpf_lpm_trie_key {
__u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */
- __u8 data[0]; /* Arbitrary size */
+ __u8 data[]; /* Arbitrary size */
};
struct bpf_cgroup_storage_key {
@@ -5355,6 +5355,37 @@ union bpf_attr {
* Return
* Current *ktime*.
*
+ * long xdp_hints_btf(struct xdp_buff *xdp_md, u64 flags)
+ * Description
+ * Update and get info on XDP hints ctx state.
+ *
+ * Drivers can provide XDP-hints information via the metadata area,
+ * which defines the layout of this area via BTF. The *full* BTF ID
+ * is available as the last member.
+ *
+ * This **full** BTF ID is a 64-bit value, encoding the BTF
+ * **object** ID as the high 32-bit and BTF *type* ID as lower
+ * 32-bit. This is needed as the BTF **type** ID (32-bit) can
+ * originate from different BTF **object** sources, e.g. vmlinux,
+ * module or local BTF-object.
+ *
+ * In-case a BPF-prog want to redefine the layout of this area it
+ * should update the full BTF ID (last-member) and call this helper
+ * to specify if the layout is compatible with kernel struct
+ * xdp_hints_common.
+ *
+ * The **flags** are used to control the mode of the helper.
+ * See enum xdp_hints_btf_mode_flags.
+ *
+ * Return
+ * 0 if driver didn't populate XDP-hints.
+ *
+ * Flag **HINTS_BTF_ENABLED** (1) if driver populated hints.
+ *
+ * Flag **HINTS_BTF_COMPAT_COMMON** (2) if layout is compatible
+ * with kernel struct xdp_hints_common. Thus, return value 3 as
+ * both flags will be set.
+ *
*/
#define __BPF_FUNC_MAPPER(FN) \
FN(unspec), \
@@ -5566,6 +5597,7 @@ union bpf_attr {
FN(tcp_raw_check_syncookie_ipv4), \
FN(tcp_raw_check_syncookie_ipv6), \
FN(ktime_get_tai_ns), \
+ FN(xdp_hints_btf), \
/* */
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
@@ -5977,6 +6009,15 @@ struct xdp_md {
__u32 egress_ifindex; /* txq->dev->ifindex */
};
+/* Mode flags for BPF_FUNC_xdp_hints_btf helper. */
+enum xdp_hints_btf_mode_flags {
+ HINTS_BTF_QUERY_ONLY = (1U << 0),
+ HINTS_BTF_ENABLED = (1U << 0), /* Return value */
+ HINTS_BTF_COMPAT_COMMON = (1U << 1), /* Return and query value */
+ HINTS_BTF_UPDATE = (1U << 2),
+ HINTS_BTF_DISABLE = (1U << 3),
+};
+
/* DEVMAP map-value layout
*
* The struct data-layout of map-value is a configuration interface.
next prev parent reply other threads:[~2022-09-07 15:45 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-07 15:45 [xdp-hints] [PATCH RFCv2 bpf-next 00/18] XDP-hints: XDP gaining access to HW offload hints via BTF Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 01/18] libbpf: factor out BTF loading from load_module_btfs() Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 02/18] libbpf: try to load vmlinux BTF from the kernel first Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 03/18] libbpf: patch module BTF obj+type ID into BPF insns Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 04/18] net: create xdp_hints_common and set functions Jesper Dangaard Brouer
2022-09-09 10:49 ` [xdp-hints] " Burakov, Anatoly
2022-09-09 14:13 ` Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 05/18] net: add net_device feature flag for XDP-hints Jesper Dangaard Brouer
2022-09-07 15:45 ` Jesper Dangaard Brouer [this message]
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 07/18] i40e: Refactor i40e_ptp_rx_hwtstamp Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 08/18] i40e: refactor i40e_rx_checksum with helper Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 09/18] bpf: export btf functions for modules Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 10/18] btf: Add helper for kernel modules to lookup full BTF ID Jesper Dangaard Brouer
2022-09-07 15:45 ` [xdp-hints] [PATCH RFCv2 bpf-next 11/18] i40e: add XDP-hints handling Jesper Dangaard Brouer
2022-09-07 15:46 ` [xdp-hints] [PATCH RFCv2 bpf-next 12/18] net: use XDP-hints in xdp_frame to SKB conversion Jesper Dangaard Brouer
2022-09-07 15:46 ` [xdp-hints] [PATCH RFCv2 bpf-next 13/18] mvneta: add XDP-hints support Jesper Dangaard Brouer
2022-09-07 15:46 ` [xdp-hints] [PATCH RFCv2 bpf-next 14/18] i40e: Add xdp_hints_union Jesper Dangaard Brouer
2022-09-07 15:46 ` [xdp-hints] [PATCH RFCv2 bpf-next 15/18] ixgbe: enable xdp-hints Jesper Dangaard Brouer
2022-09-07 15:46 ` [xdp-hints] [PATCH RFCv2 bpf-next 16/18] ixgbe: add rx timestamp xdp hints support Jesper Dangaard Brouer
2022-09-07 15:46 ` [xdp-hints] [PATCH RFCv2 bpf-next 17/18] xsk: AF_XDP xdp-hints support in desc options Jesper Dangaard Brouer
2022-09-08 8:06 ` [xdp-hints] " Magnus Karlsson
2022-09-08 10:10 ` Maryam Tahhan
2022-09-08 15:04 ` Jesper Dangaard Brouer
2022-09-09 6:43 ` Magnus Karlsson
2022-09-09 8:12 ` Maryam Tahhan
2022-09-09 9:42 ` Jesper Dangaard Brouer
2022-09-09 10:14 ` Magnus Karlsson
2022-09-09 12:35 ` Jesper Dangaard Brouer
2022-09-09 12:44 ` Magnus Karlsson
2022-09-07 15:46 ` [xdp-hints] [PATCH RFCv2 bpf-next 18/18] ixgbe: AF_XDP xdp-hints processing in ixgbe_clean_rx_irq_zc Jesper Dangaard Brouer
2022-09-08 9:30 ` [xdp-hints] Re: [PATCH RFCv2 bpf-next 00/18] XDP-hints: XDP gaining access to HW offload hints via BTF Alexander Lobakin
2022-09-09 13:48 ` Jesper Dangaard Brouer
2022-10-03 23:55 ` sdf
2022-10-04 9:29 ` Jesper Dangaard Brouer
2022-10-04 18:26 ` Stanislav Fomichev
2022-10-05 0:25 ` Martin KaFai Lau
2022-10-05 0:59 ` Jakub Kicinski
2022-10-05 1:02 ` Stanislav Fomichev
2022-10-05 1:24 ` Jakub Kicinski
2022-10-05 2:15 ` Stanislav Fomichev
2022-10-05 19:26 ` Martin KaFai Lau
2022-10-06 9:14 ` Magnus Karlsson
2022-10-06 15:29 ` Jesper Dangaard Brouer
2022-10-11 6:29 ` Martin KaFai Lau
2022-10-11 11:57 ` Jesper Dangaard Brouer
2022-10-05 10:06 ` Toke Høiland-Jørgensen
2022-10-05 18:47 ` sdf
2022-10-06 8:19 ` Maryam Tahhan
2022-10-06 17:22 ` sdf
2022-10-05 14:19 ` Jesper Dangaard Brouer
2022-10-06 14:59 ` Jakub Kicinski
2022-10-05 13:43 ` Jesper Dangaard Brouer
2022-10-05 16:29 ` Jesper Dangaard Brouer
2022-10-05 18:43 ` sdf
2022-10-06 17:47 ` Jesper Dangaard Brouer
2022-10-07 15:05 ` David Ahern
2022-10-05 13:14 ` Burakov, Anatoly
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
List information: https://lists.xdp-project.net/postorius/lists/xdp-hints.xdp-project.net/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=166256553093.1434226.11320655607309623999.stgit@firesoul \
--to=brouer@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=bjorn@kernel.org \
--cc=borkmann@iogearbox.net \
--cc=bpf@vger.kernel.org \
--cc=dave@dtucker.co.uk \
--cc=larysa.zaremba@intel.com \
--cc=lorenzo@kernel.org \
--cc=magnus.karlsson@intel.com \
--cc=memxor@gmail.com \
--cc=mtahhan@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=xdp-hints@xdp-project.net \
/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