Skip to content

Commit 0cd917a

Browse files
netoptimizerAlexei Starovoitov
authored andcommitted
xdp: rss hash types representation
The RSS hash type specifies what portion of packet data NIC hardware used when calculating RSS hash value. The RSS types are focused on Internet traffic protocols at OSI layers L3 and L4. L2 (e.g. ARP) often get hash value zero and no RSS type. For L3 focused on IPv4 vs. IPv6, and L4 primarily TCP vs UDP, but some hardware supports SCTP. Hardware RSS types are differently encoded for each hardware NIC. Most hardware represent RSS hash type as a number. Determining L3 vs L4 often requires a mapping table as there often isn't a pattern or sorting according to ISO layer. The patch introduce a XDP RSS hash type (enum xdp_rss_hash_type) that contains both BITs for the L3/L4 types, and combinations to be used by drivers for their mapping tables. The enum xdp_rss_type_bits get exposed to BPF via BTF, and it is up to the BPF-programmer to match using these defines. This proposal change the kfunc API bpf_xdp_metadata_rx_hash() adding a pointer value argument for provide the RSS hash type. Change signature for all xmo_rx_hash calls in drivers to make it compile. The RSS type implementations for each driver comes as separate patches. Fixes: 3d76a4d ("bpf: XDP metadata RX kfuncs") Signed-off-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Toke Høiland-Jørgensen <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/r/168132892042.340624.582563003880565460.stgit@firesoul Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e8163b9 commit 0cd917a

File tree

7 files changed

+64
-6
lines changed

7 files changed

+64
-6
lines changed

drivers/net/ethernet/mellanox/mlx4/en_rx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,8 @@ int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
681681
return 0;
682682
}
683683

684-
int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
684+
int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
685+
enum xdp_rss_hash_type *rss_type)
685686
{
686687
struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
687688

drivers/net/ethernet/mellanox/mlx4/mlx4_en.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,8 @@ int mlx4_en_netdev_event(struct notifier_block *this,
798798

799799
struct xdp_md;
800800
int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp);
801-
int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash);
801+
int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
802+
enum xdp_rss_hash_type *rss_type);
802803

803804
/*
804805
* Functions for time stamping

drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
169169
return 0;
170170
}
171171

172-
static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
172+
static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
173+
enum xdp_rss_hash_type *rss_type)
173174
{
174175
const struct mlx5e_xdp_buff *_ctx = (void *)ctx;
175176

drivers/net/veth.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,8 @@ static int veth_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
16481648
return 0;
16491649
}
16501650

1651-
static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
1651+
static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
1652+
enum xdp_rss_hash_type *rss_type)
16521653
{
16531654
struct veth_xdp_buff *_ctx = (void *)ctx;
16541655

include/linux/netdevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,8 @@ struct net_device_ops {
16241624

16251625
struct xdp_metadata_ops {
16261626
int (*xmo_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp);
1627-
int (*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash);
1627+
int (*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash,
1628+
enum xdp_rss_hash_type *rss_type);
16281629
};
16291630

16301631
/**

include/net/xdp.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/skbuff.h> /* skb_shared_info */
1010
#include <uapi/linux/netdev.h>
11+
#include <linux/bitfield.h>
1112

1213
/**
1314
* DOC: XDP RX-queue information
@@ -425,6 +426,50 @@ XDP_METADATA_KFUNC_xxx
425426
MAX_XDP_METADATA_KFUNC,
426427
};
427428

429+
enum xdp_rss_hash_type {
430+
/* First part: Individual bits for L3/L4 types */
431+
XDP_RSS_L3_IPV4 = BIT(0),
432+
XDP_RSS_L3_IPV6 = BIT(1),
433+
434+
/* The fixed (L3) IPv4 and IPv6 headers can both be followed by
435+
* variable/dynamic headers, IPv4 called Options and IPv6 called
436+
* Extension Headers. HW RSS type can contain this info.
437+
*/
438+
XDP_RSS_L3_DYNHDR = BIT(2),
439+
440+
/* When RSS hash covers L4 then drivers MUST set XDP_RSS_L4 bit in
441+
* addition to the protocol specific bit. This ease interaction with
442+
* SKBs and avoids reserving a fixed mask for future L4 protocol bits.
443+
*/
444+
XDP_RSS_L4 = BIT(3), /* L4 based hash, proto can be unknown */
445+
XDP_RSS_L4_TCP = BIT(4),
446+
XDP_RSS_L4_UDP = BIT(5),
447+
XDP_RSS_L4_SCTP = BIT(6),
448+
XDP_RSS_L4_IPSEC = BIT(7), /* L4 based hash include IPSEC SPI */
449+
450+
/* Second part: RSS hash type combinations used for driver HW mapping */
451+
XDP_RSS_TYPE_NONE = 0,
452+
XDP_RSS_TYPE_L2 = XDP_RSS_TYPE_NONE,
453+
454+
XDP_RSS_TYPE_L3_IPV4 = XDP_RSS_L3_IPV4,
455+
XDP_RSS_TYPE_L3_IPV6 = XDP_RSS_L3_IPV6,
456+
XDP_RSS_TYPE_L3_IPV4_OPT = XDP_RSS_L3_IPV4 | XDP_RSS_L3_DYNHDR,
457+
XDP_RSS_TYPE_L3_IPV6_EX = XDP_RSS_L3_IPV6 | XDP_RSS_L3_DYNHDR,
458+
459+
XDP_RSS_TYPE_L4_ANY = XDP_RSS_L4,
460+
XDP_RSS_TYPE_L4_IPV4_TCP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
461+
XDP_RSS_TYPE_L4_IPV4_UDP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
462+
XDP_RSS_TYPE_L4_IPV4_SCTP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
463+
464+
XDP_RSS_TYPE_L4_IPV6_TCP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
465+
XDP_RSS_TYPE_L4_IPV6_UDP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
466+
XDP_RSS_TYPE_L4_IPV6_SCTP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
467+
468+
XDP_RSS_TYPE_L4_IPV6_TCP_EX = XDP_RSS_TYPE_L4_IPV6_TCP | XDP_RSS_L3_DYNHDR,
469+
XDP_RSS_TYPE_L4_IPV6_UDP_EX = XDP_RSS_TYPE_L4_IPV6_UDP | XDP_RSS_L3_DYNHDR,
470+
XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
471+
};
472+
428473
#ifdef CONFIG_NET
429474
u32 bpf_xdp_metadata_kfunc_id(int id);
430475
bool bpf_dev_bound_kfunc_id(u32 btf_id);

net/core/xdp.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,13 +734,21 @@ __bpf_kfunc int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, u64 *tim
734734
* bpf_xdp_metadata_rx_hash - Read XDP frame RX hash.
735735
* @ctx: XDP context pointer.
736736
* @hash: Return value pointer.
737+
* @rss_type: Return value pointer for RSS type.
738+
*
739+
* The RSS hash type (@rss_type) specifies what portion of packet headers NIC
740+
* hardware used when calculating RSS hash value. The RSS type can be decoded
741+
* via &enum xdp_rss_hash_type either matching on individual L3/L4 bits
742+
* ``XDP_RSS_L*`` or by combined traditional *RSS Hashing Types*
743+
* ``XDP_RSS_TYPE_L*``.
737744
*
738745
* Return:
739746
* * Returns 0 on success or ``-errno`` on error.
740747
* * ``-EOPNOTSUPP`` : means device driver doesn't implement kfunc
741748
* * ``-ENODATA`` : means no RX-hash available for this frame
742749
*/
743-
__bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash)
750+
__bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash,
751+
enum xdp_rss_hash_type *rss_type)
744752
{
745753
return -EOPNOTSUPP;
746754
}

0 commit comments

Comments
 (0)