Commit 45ee73a0 authored by Martin KaFai Lau's avatar Martin KaFai Lau
Browse files

Merge branch 'bpf: expose information about netdev xdp-metadata kfunc support'



Stanislav Fomichev says:

====================
Extend netdev netlink family to expose the bitmask with the
kfuncs that the device implements. The source of truth is the
device's xdp_metadata_ops. There is some amount of auto-generated
netlink boilerplate; the change itself is super minimal.

v2:
- add netdev->xdp_metadata_ops NULL check when dumping to netlink (Martin)

Cc: netdev@vger.kernel.org
Cc: Willem de Bruijn <willemb@google.com>
====================

Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parents d609f3d2 0c6c9b10
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -42,6 +42,19 @@ definitions:
        doc:
          This feature informs if netdev implements non-linear XDP buffer
          support in ndo_xdp_xmit callback.
  -
    type: flags
    name: xdp-rx-metadata
    render-max: true
    entries:
      -
        name: timestamp
        doc:
          Device is capable of exposing receive HW timestamp via bpf_xdp_metadata_rx_timestamp().
      -
        name: hash
        doc:
          Device is capable of exposing receive packet hash via bpf_xdp_metadata_rx_hash().

attribute-sets:
  -
@@ -68,6 +81,13 @@ attribute-sets:
        type: u32
        checks:
          min: 1
      -
        name: xdp-rx-metadata-features
        doc: Bitmask of supported XDP receive metadata features.
             See Documentation/networking/xdp-rx-metadata.rst for more details.
        type: u64
        enum: xdp-rx-metadata
        enum-as-flags: true

operations:
  list:
@@ -84,6 +104,7 @@ operations:
            - ifindex
            - xdp-features
            - xdp-zc-max-segs
            - xdp-rx-metadata-features
      dump:
        reply: *dev-all
    -
+7 −0
Original line number Diff line number Diff line
@@ -105,6 +105,13 @@ bpf_tail_call
Adding programs that access metadata kfuncs to the ``BPF_MAP_TYPE_PROG_ARRAY``
is currently not supported.

Supported Devices
=================

It is possible to query which kfunc the particular netdev implements via
netlink. See ``xdp-rx-metadata-features`` attribute set in
``Documentation/netlink/specs/netdev.yaml``.

Example
=======

+15 −4
Original line number Diff line number Diff line
@@ -383,14 +383,25 @@ void xdp_attachment_setup(struct xdp_attachment_info *info,

#define DEV_MAP_BULK_SIZE XDP_BULK_QUEUE_SIZE

/* Define the relationship between xdp-rx-metadata kfunc and
 * various other entities:
 * - xdp_rx_metadata enum
 * - netdev netlink enum (Documentation/netlink/specs/netdev.yaml)
 * - kfunc name
 * - xdp_metadata_ops field
 */
#define XDP_METADATA_KFUNC_xxx	\
	XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_TIMESTAMP, \
			   bpf_xdp_metadata_rx_timestamp) \
			   NETDEV_XDP_RX_METADATA_TIMESTAMP, \
			   bpf_xdp_metadata_rx_timestamp, \
			   xmo_rx_timestamp) \
	XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_HASH, \
			   bpf_xdp_metadata_rx_hash) \
			   NETDEV_XDP_RX_METADATA_HASH, \
			   bpf_xdp_metadata_rx_hash, \
			   xmo_rx_hash) \

enum {
#define XDP_METADATA_KFUNC(name, _) name,
enum xdp_rx_metadata {
#define XDP_METADATA_KFUNC(name, _, __, ___) name,
XDP_METADATA_KFUNC_xxx
#undef XDP_METADATA_KFUNC
MAX_XDP_METADATA_KFUNC,
+16 −0
Original line number Diff line number Diff line
@@ -38,11 +38,27 @@ enum netdev_xdp_act {
	NETDEV_XDP_ACT_MASK = 127,
};

/**
 * enum netdev_xdp_rx_metadata
 * @NETDEV_XDP_RX_METADATA_TIMESTAMP: Device is capable of exposing receive HW
 *   timestamp via bpf_xdp_metadata_rx_timestamp().
 * @NETDEV_XDP_RX_METADATA_HASH: Device is capable of exposing receive packet
 *   hash via bpf_xdp_metadata_rx_hash().
 */
enum netdev_xdp_rx_metadata {
	NETDEV_XDP_RX_METADATA_TIMESTAMP = 1,
	NETDEV_XDP_RX_METADATA_HASH = 2,

	/* private: */
	NETDEV_XDP_RX_METADATA_MASK = 3,
};

enum {
	NETDEV_A_DEV_IFINDEX = 1,
	NETDEV_A_DEV_PAD,
	NETDEV_A_DEV_XDP_FEATURES,
	NETDEV_A_DEV_XDP_ZC_MAX_SEGS,
	NETDEV_A_DEV_XDP_RX_METADATA_FEATURES,

	__NETDEV_A_DEV_MAX,
	NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1)
+5 −4
Original line number Diff line number Diff line
@@ -845,10 +845,11 @@ void *bpf_dev_bound_resolve_kfunc(struct bpf_prog *prog, u32 func_id)
	if (!ops)
		goto out;

	if (func_id == bpf_xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_TIMESTAMP))
		p = ops->xmo_rx_timestamp;
	else if (func_id == bpf_xdp_metadata_kfunc_id(XDP_METADATA_KFUNC_RX_HASH))
		p = ops->xmo_rx_hash;
#define XDP_METADATA_KFUNC(name, _, __, xmo) \
	if (func_id == bpf_xdp_metadata_kfunc_id(name)) p = ops->xmo;
	XDP_METADATA_KFUNC_xxx
#undef XDP_METADATA_KFUNC

out:
	up_read(&bpf_devs_lock);

Loading