Skip to content

Commit 26daeb6

Browse files
committed
bpf: make it easier to add new metadata kfunc
JIRA: https://issues.redhat.com/browse/RHEL-31945 commit fc45c5b Author: Stanislav Fomichev <sdf@google.com> Date: Wed Sep 13 10:13:48 2023 -0700 bpf: make it easier to add new metadata kfunc No functional changes. Instead of having hand-crafted code in bpf_dev_bound_resolve_kfunc, move kfunc <> xmo handler relationship into XDP_METADATA_KFUNC_xxx. This way, any time new kfunc is added, we don't have to touch bpf_dev_bound_resolve_kfunc. Also document XDP_METADATA_KFUNC_xxx arguments since we now have more than two and it might be confusing what is what. Cc: netdev@vger.kernel.org Cc: Willem de Bruijn <willemb@google.com> Signed-off-by: Stanislav Fomichev <sdf@google.com> Link: https://lore.kernel.org/r/20230913171350.369987-2-sdf@google.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
1 parent d5927b5 commit 26daeb6

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

include/net/xdp.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,22 @@ void xdp_attachment_setup(struct xdp_attachment_info *info,
419419

420420
#define DEV_MAP_BULK_SIZE XDP_BULK_QUEUE_SIZE
421421

422+
/* Define the relationship between xdp-rx-metadata kfunc and
423+
* various other entities:
424+
* - xdp_rx_metadata enum
425+
* - kfunc name
426+
* - xdp_metadata_ops field
427+
*/
422428
#define XDP_METADATA_KFUNC_xxx \
423429
XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_TIMESTAMP, \
424-
bpf_xdp_metadata_rx_timestamp) \
430+
bpf_xdp_metadata_rx_timestamp, \
431+
xmo_rx_timestamp) \
425432
XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_HASH, \
426-
bpf_xdp_metadata_rx_hash) \
433+
bpf_xdp_metadata_rx_hash, \
434+
xmo_rx_hash) \
427435

428-
enum {
429-
#define XDP_METADATA_KFUNC(name, _) name,
436+
enum xdp_rx_metadata {
437+
#define XDP_METADATA_KFUNC(name, _, __) name,
430438
XDP_METADATA_KFUNC_xxx
431439
#undef XDP_METADATA_KFUNC
432440
MAX_XDP_METADATA_KFUNC,

kernel/bpf/offload.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,11 @@ void *bpf_dev_bound_resolve_kfunc(struct bpf_prog *prog, u32 func_id)
846846
if (!ops)
847847
goto out;
848848

849-
if (func_id == bpf_xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_TIMESTAMP))
850-
p = ops->xmo_rx_timestamp;
851-
else if (func_id == bpf_xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_HASH))
852-
p = ops->xmo_rx_hash;
849+
#define XDP_METADATA_KFUNC(name, _, xmo) \
850+
if (func_id == bpf_xdp_metadata_kfunc_id(name)) p = ops->xmo;
851+
XDP_METADATA_KFUNC_xxx
852+
#undef XDP_METADATA_KFUNC
853+
853854
out:
854855
up_read(&bpf_devs_lock);
855856

net/core/xdp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ __bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash,
757757
__diag_pop();
758758

759759
BTF_SET8_START(xdp_metadata_kfunc_ids)
760-
#define XDP_METADATA_KFUNC(_, name) BTF_ID_FLAGS(func, name, KF_TRUSTED_ARGS)
760+
#define XDP_METADATA_KFUNC(_, name, __) BTF_ID_FLAGS(func, name, KF_TRUSTED_ARGS)
761761
XDP_METADATA_KFUNC_xxx
762762
#undef XDP_METADATA_KFUNC
763763
BTF_SET8_END(xdp_metadata_kfunc_ids)
@@ -768,7 +768,7 @@ static const struct btf_kfunc_id_set xdp_metadata_kfunc_set = {
768768
};
769769

770770
BTF_ID_LIST(xdp_metadata_kfunc_ids_unsorted)
771-
#define XDP_METADATA_KFUNC(name, str) BTF_ID(func, str)
771+
#define XDP_METADATA_KFUNC(name, str, _) BTF_ID(func, str)
772772
XDP_METADATA_KFUNC_xxx
773773
#undef XDP_METADATA_KFUNC
774774

0 commit comments

Comments
 (0)