Devices will be able to communicate received packets queue index with bpf_xdp_metadata_rx_queue_index(). Signed-off-by: Mehdi Ben Hadj Khelifa --- Documentation/netlink/specs/netdev.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index c035dc0f64fd..25fe17ea1625 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -61,6 +61,11 @@ definitions: doc: | Device is capable of exposing receive packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag(). + - + name: queue-index + doc: | + Device is capable of exposing receive packet queue index via + bpf_xdp_metadata_rx_queue_index(). - type: flags name: xsk-flags -- 2.51.0 Introduce xmo_rx_queue_index netdev callback in order allow the eBPF program bounded to the device to retrieve the RX queue index from the hw NIC. Signed-off-by: Mehdi Ben Hadj Khelifa --- include/net/xdp.h | 5 +++++ net/core/xdp.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/net/xdp.h b/include/net/xdp.h index b40f1f96cb11..edbf66c31f83 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -547,6 +547,10 @@ void xdp_attachment_setup(struct xdp_attachment_info *info, NETDEV_XDP_RX_METADATA_VLAN_TAG, \ bpf_xdp_metadata_rx_vlan_tag, \ xmo_rx_vlan_tag) \ + XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_QUEUE_INDEX, \ + NETDEV_XDP_RX_METADATA_QUEUE_INDEX, \ + bpf_xdp_metadata_rx_queue_index, \ + xmo_rx_queue_index) \ enum xdp_rx_metadata { #define XDP_METADATA_KFUNC(name, _, __, ___) name, @@ -610,6 +614,7 @@ struct xdp_metadata_ops { enum xdp_rss_hash_type *rss_type); int (*xmo_rx_vlan_tag)(const struct xdp_md *ctx, __be16 *vlan_proto, u16 *vlan_tci); + int (*xmo_rx_queue_index)(const struct xdp_md *ctx, u32 *queue_index); }; #ifdef CONFIG_NET diff --git a/net/core/xdp.c b/net/core/xdp.c index 491334b9b8be..78c0c63e343c 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -962,6 +962,21 @@ __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx, return -EOPNOTSUPP; } +/** + * bpf_xdp_metadata_rx_queue_index - Read XDP frame RX queue index. + * @ctx: XDP context pointer. + * @queue_index: Return value pointer. + * + * Return: + * * Returns 0 on success or ``-errno`` on error. + * * ``-EOPNOTSUPP`` : means device driver does not implement kfunc + * * ``-ENODATA`` : means no RX queue index available for this frame + */ +__bpf_kfunc int bpf_xdp_metadata_rx_queue_index(const struct xdp_md *ctx, u32 *queue_index) +{ + return -EOPNOTSUPP; +} + __bpf_kfunc_end_defs(); BTF_KFUNCS_START(xdp_metadata_kfunc_ids) -- 2.51.0 Added NETDEV_XDP_RX_METADATA_QUEUE_INDEX flag to both netdev.h files for the bpf_xdp_metadata_rx_queue_index() function. Signed-off-by: Mehdi Ben Hadj Khelifa --- include/uapi/linux/netdev.h | 3 +++ tools/include/uapi/linux/netdev.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 48eb49aa03d4..59033a607c16 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -46,11 +46,14 @@ enum netdev_xdp_act { * hash via bpf_xdp_metadata_rx_hash(). * @NETDEV_XDP_RX_METADATA_VLAN_TAG: Device is capable of exposing receive * packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag(). + * @NETDEV_XDP_RX_METADATA_QUEUE_INDEX: Device is capable of exposing receive HW + * queue index via bpf_xdp_metadata_rx_queue_index(). */ enum netdev_xdp_rx_metadata { NETDEV_XDP_RX_METADATA_TIMESTAMP = 1, NETDEV_XDP_RX_METADATA_HASH = 2, NETDEV_XDP_RX_METADATA_VLAN_TAG = 4, + NETDEV_XDP_RX_METADATA_QUEUE_INDEX = 8, }; /** diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index 48eb49aa03d4..59033a607c16 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -46,11 +46,14 @@ enum netdev_xdp_act { * hash via bpf_xdp_metadata_rx_hash(). * @NETDEV_XDP_RX_METADATA_VLAN_TAG: Device is capable of exposing receive * packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag(). + * @NETDEV_XDP_RX_METADATA_QUEUE_INDEX: Device is capable of exposing receive HW + * queue index via bpf_xdp_metadata_rx_queue_index(). */ enum netdev_xdp_rx_metadata { NETDEV_XDP_RX_METADATA_TIMESTAMP = 1, NETDEV_XDP_RX_METADATA_HASH = 2, NETDEV_XDP_RX_METADATA_VLAN_TAG = 4, + NETDEV_XDP_RX_METADATA_QUEUE_INDEX = 8, }; /** -- 2.51.0 Implement xmo_rx_queue_index callback in veth driver to export queue_index for use in eBPF programs. Signed-off-by: Mehdi Ben Hadj Khelifa --- drivers/net/veth.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index a3046142cb8e..be76dd292819 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1692,6 +1692,17 @@ static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto, return err; } +static int veth_xdp_rx_queue_index(const struct xdp_md *ctx, u32 *queue_index) +{ + const struct veth_xdp_buff *_ctx = (void *)ctx; + + if (!_ctx->xdp.rxq) + return -ENODATA; + + *queue_index = _ctx->xdp.rxq->queue_index; + return 0; +} + static const struct net_device_ops veth_netdev_ops = { .ndo_init = veth_dev_init, .ndo_open = veth_open, @@ -1717,6 +1728,7 @@ static const struct xdp_metadata_ops veth_xdp_metadata_ops = { .xmo_rx_timestamp = veth_xdp_rx_timestamp, .xmo_rx_hash = veth_xdp_rx_hash, .xmo_rx_vlan_tag = veth_xdp_rx_vlan_tag, + .xmo_rx_queue_index = veth_xdp_rx_queue_index, }; #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \ -- 2.51.0