Current API for bpf_xdp_metadata_rx_hash() returns the raw RSS hash value,
but doesn't provide information on the RSS hash type (part of 6.3-rc).
This patchset proposal is to change the function call signature via adding
a pointer value argument for providing the RSS hash type.
Patchset also disables all bpf_printk's from xdp_hw_metadata program
that we expect driver developers to use.
---
Jesper Dangaard Brouer (7):
selftests/bpf: xdp_hw_metadata default disable bpf_printk
selftests/bpf: Add counters to xdp_hw_metadata
xdp: rss hash types representation
mlx5: bpf_xdp_metadata_rx_hash add xdp rss hash type
veth: bpf_xdp_metadata_rx_hash add xdp rss hash type
mlx4: bpf_xdp_metadata_rx_hash add xdp rss hash type
selftests/bpf: Adjust bpf_xdp_metadata_rx_hash for new arg
drivers/net/ethernet/mellanox/mlx4/en_rx.c | 22 ++++++-
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 +-
.../net/ethernet/mellanox/mlx5/core/en/xdp.c | 63 ++++++++++++++++++-
drivers/net/veth.c | 10 ++-
include/linux/mlx5/device.h | 14 ++++-
include/linux/netdevice.h | 3 +-
include/net/xdp.h | 47 ++++++++++++++
net/core/xdp.c | 10 ++-
.../selftests/bpf/prog_tests/xdp_metadata.c | 2 +
.../selftests/bpf/progs/xdp_hw_metadata.c | 42 ++++++++++---
.../selftests/bpf/progs/xdp_metadata.c | 6 +-
.../selftests/bpf/progs/xdp_metadata2.c | 7 ++-
tools/testing/selftests/bpf/xdp_hw_metadata.c | 10 ++-
tools/testing/selftests/bpf/xdp_metadata.h | 4 ++
14 files changed, 213 insertions(+), 30 deletions(-)
--
The tool xdp_hw_metadata can be used by driver developers
implementing XDP-hints kfuncs. The tool transfers the
XDP-hints via metadata information to an AF_XDP userspace
process. When everything works the bpf_printk calls are
unncesssary. Thus, disable bpf_printk by default, but
make it easy to reenable for driver developers to use
when debugging their driver implementation.
This also converts bpf_printk "forwarding UDP:9091 to AF_XDP"
into a code comment. The bpf_printk's that are important
to the driver developers is when bpf_xdp_adjust_meta fails.
The likely mistake from driver developers is expected to
be that they didn't implement XDP metadata adjust support.
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
---
.../testing/selftests/bpf/progs/xdp_hw_metadata.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
index 4c55b4d79d3d..980eb60d8e5b 100644
--- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
@@ -5,6 +5,19 @@
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
+/* Per default below bpf_printk() calls are disabled. Can be
+ * reenabled manually for convenience by XDP-hints driver developer,
+ * when troublshooting the drivers kfuncs implementation details.
+ *
+ * Remember BPF-prog bpf_printk info output can be access via:
+ * /sys/kernel/debug/tracing/trace_pipe
+ */
+//#define DEBUG 1
+#ifndef DEBUG
+#undef bpf_printk
+#define bpf_printk(fmt, ...) ({})
+#endif
+
struct {
__uint(type, BPF_MAP_TYPE_XSKMAP);
__uint(max_entries, 256);
@@ -49,11 +62,10 @@ int rx(struct xdp_md *ctx)
if (!udp)
return XDP_PASS;
+ /* Forwarding UDP:9091 to AF_XDP */
if (udp->dest != bpf_htons(9091))
return XDP_PASS;
- bpf_printk("forwarding UDP:9091 to AF_XDP");
-
ret = bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta));
if (ret != 0) {
bpf_printk("bpf_xdp_adjust_meta returned %d", ret);
Add counters for skipped, failed and redirected packets.
The xdp_hw_metadata program only redirects UDP port 9091.
This helps users to quickly identify then packets are
skipped and identify failures of bpf_xdp_adjust_meta.
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
---
.../testing/selftests/bpf/progs/xdp_hw_metadata.c | 15 +++++++++++++--
tools/testing/selftests/bpf/xdp_hw_metadata.c | 4 +++-
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
index 980eb60d8e5b..d11aca50e54d 100644
--- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
@@ -25,6 +25,10 @@ struct {
__type(value, __u32);
} xsk SEC(".maps");
+volatile __u64 pkts_skip = 0;
+volatile __u64 pkts_fail = 0;
+volatile __u64 pkts_redir = 0;
+
extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
__u64 *timestamp) __ksym;
extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx,
@@ -59,16 +63,21 @@ int rx(struct xdp_md *ctx)
udp = NULL;
}
- if (!udp)
+ if (!udp) {
+ pkts_skip++;
return XDP_PASS;
+ }
/* Forwarding UDP:9091 to AF_XDP */
- if (udp->dest != bpf_htons(9091))
+ if (udp->dest != bpf_htons(9091)) {
+ pkts_skip++;
return XDP_PASS;
+ }
ret = bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta));
if (ret != 0) {
bpf_printk("bpf_xdp_adjust_meta returned %d", ret);
+ pkts_fail++;
return XDP_PASS;
}
@@ -78,6 +87,7 @@ int rx(struct xdp_md *ctx)
if (meta + 1 > data) {
bpf_printk("bpf_xdp_adjust_meta doesn't appear to work");
+ pkts_fail++;
return XDP_PASS;
}
@@ -91,6 +101,7 @@ int rx(struct xdp_md *ctx)
else
meta->rx_hash = 0; /* Used by AF_XDP as not avail signal */
+ pkts_redir++;
return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
}
diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testing/selftests/bpf/xdp_hw_metadata.c
index 1c8acb68b977..3b942ef7297b 100644
--- a/tools/testing/selftests/bpf/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c
@@ -212,7 +212,9 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd)
while (true) {
errno = 0;
ret = poll(fds, rxq + 1, 1000);
- printf("poll: %d (%d)\n", ret, errno);
+ printf("poll: %d (%d) skip=%llu fail=%llu redir=%llu\n",
+ ret, errno, bpf_obj->bss->pkts_skip,
+ bpf_obj->bss->pkts_fail, bpf_obj->bss->pkts_redir);
if (ret < 0)
break;
if (ret == 0)
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
contain combinations to be used by drivers, which gets build up with bits
from enum xdp_rss_type_bits. Both enum xdp_rss_type_bits and
xdp_rss_hash_type 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 function 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: 3d76a4d3d4e5 ("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]>
---
drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 +
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 3 +
drivers/net/veth.c | 3 +
include/linux/netdevice.h | 3 +
include/net/xdp.h | 45 ++++++++++++++++++++++
net/core/xdp.c | 10 ++++-
6 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 4b5e459b6d49..73d10aa4c503 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -681,7 +681,8 @@ int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
return 0;
}
-int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
+int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
+ enum xdp_rss_hash_type *rss_type)
{
struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
index c5dae48b7932..efe609f8e3aa 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
@@ -169,7 +169,8 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
return 0;
}
-static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
+static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
+ enum xdp_rss_hash_type *rss_type)
{
const struct mlx5e_xdp_buff *_ctx = (void *)ctx;
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index c1178915496d..424e8876a16b 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1648,7 +1648,8 @@ static int veth_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
return 0;
}
-static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
+static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
+ enum xdp_rss_hash_type *rss_type)
{
struct veth_xdp_buff *_ctx = (void *)ctx;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 470085b121d3..c35f04f636f1 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1624,7 +1624,8 @@ struct net_device_ops {
struct xdp_metadata_ops {
int (*xmo_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp);
- int (*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash);
+ int (*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash,
+ enum xdp_rss_hash_type *rss_type);
};
/**
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 41c57b8b1671..a76c4ea203ea 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -8,6 +8,7 @@
#include <linux/skbuff.h> /* skb_shared_info */
#include <uapi/linux/netdev.h>
+#include <linux/bitfield.h>
/**
* DOC: XDP RX-queue information
@@ -425,6 +426,50 @@ XDP_METADATA_KFUNC_xxx
MAX_XDP_METADATA_KFUNC,
};
+enum xdp_rss_hash_type {
+ /* First part: Individual bits for L3/L4 types */
+ XDP_RSS_L3_IPV4 = BIT(0),
+ XDP_RSS_L3_IPV6 = BIT(1),
+
+ /* The fixed (L3) IPv4 and IPv6 headers can both be followed by
+ * variable/dynamic headers, IPv4 called Options and IPv6 called
+ * Extension Headers. HW RSS type can contain this info.
+ */
+ XDP_RSS_L3_DYNHDR = BIT(2),
+
+ /* When RSS hash covers L4 then drivers MUST set XDP_RSS_L4 bit in
+ * addition to the protocol specific bit. This ease interaction with
+ * SKBs and avoids reserving a fixed mask for future L4 protocol bits.
+ */
+ XDP_RSS_L4 = BIT(3), /* L4 based hash, proto can be unknown */
+ XDP_RSS_L4_TCP = BIT(4),
+ XDP_RSS_L4_UDP = BIT(5),
+ XDP_RSS_L4_SCTP = BIT(6),
+ XDP_RSS_L4_IPSEC = BIT(7), /* L4 based hash include IPSEC SPI */
+
+ /* Second part: RSS hash type combinations used for driver HW mapping */
+ XDP_RSS_TYPE_NONE = 0,
+ XDP_RSS_TYPE_L2 = XDP_RSS_TYPE_NONE,
+
+ XDP_RSS_TYPE_L3_IPV4 = XDP_RSS_L3_IPV4,
+ XDP_RSS_TYPE_L3_IPV6 = XDP_RSS_L3_IPV6,
+ XDP_RSS_TYPE_L3_IPV4_OPT = XDP_RSS_L3_IPV4 | XDP_RSS_L3_DYNHDR,
+ XDP_RSS_TYPE_L3_IPV6_EX = XDP_RSS_L3_IPV6 | XDP_RSS_L3_DYNHDR,
+
+ XDP_RSS_TYPE_L4_ANY = XDP_RSS_L4,
+ XDP_RSS_TYPE_L4_IPV4_TCP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
+ XDP_RSS_TYPE_L4_IPV4_UDP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
+ XDP_RSS_TYPE_L4_IPV4_SCTP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
+
+ XDP_RSS_TYPE_L4_IPV6_TCP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
+ XDP_RSS_TYPE_L4_IPV6_UDP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
+ XDP_RSS_TYPE_L4_IPV6_SCTP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
+
+ XDP_RSS_TYPE_L4_IPV6_TCP_EX = XDP_RSS_TYPE_L4_IPV6_TCP | XDP_RSS_L3_DYNHDR,
+ XDP_RSS_TYPE_L4_IPV6_UDP_EX = XDP_RSS_TYPE_L4_IPV6_UDP | XDP_RSS_L3_DYNHDR,
+ XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
+};
+
#ifdef CONFIG_NET
u32 bpf_xdp_metadata_kfunc_id(int id);
bool bpf_dev_bound_kfunc_id(u32 btf_id);
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 528d4b37983d..fb85aca81961 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -734,13 +734,21 @@ __bpf_kfunc int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, u64 *tim
* bpf_xdp_metadata_rx_hash - Read XDP frame RX hash.
* @ctx: XDP context pointer.
* @hash: Return value pointer.
+ * @rss_type: Return value pointer for RSS type.
+ *
+ * The RSS hash type (@rss_type) specifies what portion of packet headers NIC
+ * hardware used when calculating RSS hash value. The RSS type can be decoded
+ * via &enum xdp_rss_hash_type either matching on individual L3/L4 bits
+ * ``XDP_RSS_L*`` or by combined traditional *RSS Hashing Types*
+ * ``XDP_RSS_TYPE_L*``.
*
* Return:
* * Returns 0 on success or ``-errno`` on error.
* * ``-EOPNOTSUPP`` : means device driver doesn't implement kfunc
* * ``-ENODATA`` : means no RX-hash available for this frame
*/
-__bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash)
+__bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash,
+ enum xdp_rss_hash_type *rss_type)
{
return -EOPNOTSUPP;
}
Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type.
The veth driver currently only support XDP-hints based on SKB code path.
The SKB have lost information about the RSS hash type, by compressing
the information down to a single bitfield skb->l4_hash, that only knows
if this was a L4 hash value.
In preparation for veth, the xdp_rss_hash_type have an L4 indication
bit that allow us to return a meaningful L4 indication when working
with SKB based packets.
Fixes: 306531f0249f ("veth: Support RX XDP metadata")
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Acked-by: Toke Høiland-Jørgensen <[email protected]>
Acked-by: Stanislav Fomichev <[email protected]>
---
drivers/net/veth.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 424e8876a16b..e1b38fbf1dd9 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1652,11 +1652,14 @@ static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
enum xdp_rss_hash_type *rss_type)
{
struct veth_xdp_buff *_ctx = (void *)ctx;
+ struct sk_buff *skb = _ctx->skb;
- if (!_ctx->skb)
+ if (!skb)
return -ENODATA;
- *hash = skb_get_hash(_ctx->skb);
+ *hash = skb_get_hash(skb);
+ *rss_type = skb->l4_hash ? XDP_RSS_TYPE_L4_ANY : XDP_RSS_TYPE_NONE;
+
return 0;
}
Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type
via mapping table.
The mlx5 hardware can also identify and RSS hash IPSEC. This indicate
hash includes SPI (Security Parameters Index) as part of IPSEC hash.
Extend xdp core enum xdp_rss_hash_type with IPSEC hash type.
Fixes: bc8d405b1ba9 ("net/mlx5e: Support RX XDP metadata")
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Acked-by: Toke Høiland-Jørgensen <[email protected]>
Acked-by: Stanislav Fomichev <[email protected]>
---
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 60 ++++++++++++++++++++++
include/linux/mlx5/device.h | 14 ++++-
include/net/xdp.h | 2 +
3 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
index efe609f8e3aa..97ef1df94d50 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
@@ -34,6 +34,7 @@
#include <net/xdp_sock_drv.h>
#include "en/xdp.h"
#include "en/params.h"
+#include <linux/bitfield.h>
int mlx5e_xdp_max_mtu(struct mlx5e_params *params, struct mlx5e_xsk_param *xsk)
{
@@ -169,15 +170,72 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
return 0;
}
+/* Mapping HW RSS Type bits CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 into 4-bits*/
+#define RSS_TYPE_MAX_TABLE 16 /* 4-bits max 16 entries */
+#define RSS_L4 GENMASK(1, 0)
+#define RSS_L3 GENMASK(3, 2) /* Same as CQE_RSS_HTYPE_IP */
+
+/* Valid combinations of CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 sorted numerical */
+enum mlx5_rss_hash_type {
+ RSS_TYPE_NO_HASH = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IP_NONE) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
+ RSS_TYPE_L3_IPV4 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
+ RSS_TYPE_L4_IPV4_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
+ RSS_TYPE_L4_IPV4_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
+ RSS_TYPE_L4_IPV4_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
+ RSS_TYPE_L3_IPV6 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
+ RSS_TYPE_L4_IPV6_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
+ RSS_TYPE_L4_IPV6_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
+ RSS_TYPE_L4_IPV6_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
+ FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
+} mlx5_rss_hash_type;
+
+/* Invalid combinations will simply return zero, allows no boundary checks */
+static const enum xdp_rss_hash_type mlx5_xdp_rss_type[RSS_TYPE_MAX_TABLE] = {
+ [RSS_TYPE_NO_HASH] = XDP_RSS_TYPE_NONE,
+ [1] = XDP_RSS_TYPE_NONE, /* Implicit zero */
+ [2] = XDP_RSS_TYPE_NONE, /* Implicit zero */
+ [3] = XDP_RSS_TYPE_NONE, /* Implicit zero */
+ [RSS_TYPE_L3_IPV4] = XDP_RSS_TYPE_L3_IPV4,
+ [RSS_TYPE_L4_IPV4_TCP] = XDP_RSS_TYPE_L4_IPV4_TCP,
+ [RSS_TYPE_L4_IPV4_UDP] = XDP_RSS_TYPE_L4_IPV4_UDP,
+ [RSS_TYPE_L4_IPV4_IPSEC] = XDP_RSS_TYPE_L4_IPV4_IPSEC,
+ [RSS_TYPE_L3_IPV6] = XDP_RSS_TYPE_L3_IPV6,
+ [RSS_TYPE_L4_IPV6_TCP] = XDP_RSS_TYPE_L4_IPV6_TCP,
+ [RSS_TYPE_L4_IPV6_UDP] = XDP_RSS_TYPE_L4_IPV6_UDP,
+ [RSS_TYPE_L4_IPV6_IPSEC] = XDP_RSS_TYPE_L4_IPV6_IPSEC,
+ [12] = XDP_RSS_TYPE_NONE, /* Implicit zero */
+ [13] = XDP_RSS_TYPE_NONE, /* Implicit zero */
+ [14] = XDP_RSS_TYPE_NONE, /* Implicit zero */
+ [15] = XDP_RSS_TYPE_NONE, /* Implicit zero */
+};
+
static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
enum xdp_rss_hash_type *rss_type)
{
const struct mlx5e_xdp_buff *_ctx = (void *)ctx;
+ const struct mlx5_cqe64 *cqe = _ctx->cqe;
+ u32 hash_type, l4_type, ip_type, lookup;
if (unlikely(!(_ctx->xdp.rxq->dev->features & NETIF_F_RXHASH)))
return -ENODATA;
- *hash = be32_to_cpu(_ctx->cqe->rss_hash_result);
+ *hash = be32_to_cpu(cqe->rss_hash_result);
+
+ hash_type = cqe->rss_hash_type;
+ BUILD_BUG_ON(CQE_RSS_HTYPE_IP != RSS_L3); /* same mask */
+ ip_type = hash_type & CQE_RSS_HTYPE_IP;
+ l4_type = FIELD_GET(CQE_RSS_HTYPE_L4, hash_type);
+ lookup = ip_type | l4_type;
+ *rss_type = mlx5_xdp_rss_type[lookup];
+
return 0;
}
diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h
index 71b06ebad402..1db19a9d26e3 100644
--- a/include/linux/mlx5/device.h
+++ b/include/linux/mlx5/device.h
@@ -36,6 +36,7 @@
#include <linux/types.h>
#include <rdma/ib_verbs.h>
#include <linux/mlx5/mlx5_ifc.h>
+#include <linux/bitfield.h>
#if defined(__LITTLE_ENDIAN)
#define MLX5_SET_HOST_ENDIANNESS 0
@@ -980,14 +981,23 @@ enum {
};
enum {
- CQE_RSS_HTYPE_IP = 0x3 << 2,
+ CQE_RSS_HTYPE_IP = GENMASK(3, 2),
/* cqe->rss_hash_type[3:2] - IP destination selected for hash
* (00 = none, 01 = IPv4, 10 = IPv6, 11 = Reserved)
*/
- CQE_RSS_HTYPE_L4 = 0x3 << 6,
+ CQE_RSS_IP_NONE = 0x0,
+ CQE_RSS_IPV4 = 0x1,
+ CQE_RSS_IPV6 = 0x2,
+ CQE_RSS_RESERVED = 0x3,
+
+ CQE_RSS_HTYPE_L4 = GENMASK(7, 6),
/* cqe->rss_hash_type[7:6] - L4 destination selected for hash
* (00 = none, 01 = TCP. 10 = UDP, 11 = IPSEC.SPI
*/
+ CQE_RSS_L4_NONE = 0x0,
+ CQE_RSS_L4_TCP = 0x1,
+ CQE_RSS_L4_UDP = 0x2,
+ CQE_RSS_L4_IPSEC = 0x3,
};
enum {
diff --git a/include/net/xdp.h b/include/net/xdp.h
index a76c4ea203ea..76aa748e7923 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -460,10 +460,12 @@ enum xdp_rss_hash_type {
XDP_RSS_TYPE_L4_IPV4_TCP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
XDP_RSS_TYPE_L4_IPV4_UDP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
XDP_RSS_TYPE_L4_IPV4_SCTP = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
+ XDP_RSS_TYPE_L4_IPV4_IPSEC = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_IPSEC,
XDP_RSS_TYPE_L4_IPV6_TCP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
XDP_RSS_TYPE_L4_IPV6_UDP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
XDP_RSS_TYPE_L4_IPV6_SCTP = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
+ XDP_RSS_TYPE_L4_IPV6_IPSEC = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_IPSEC,
XDP_RSS_TYPE_L4_IPV6_TCP_EX = XDP_RSS_TYPE_L4_IPV6_TCP | XDP_RSS_L3_DYNHDR,
XDP_RSS_TYPE_L4_IPV6_UDP_EX = XDP_RSS_TYPE_L4_IPV6_UDP | XDP_RSS_L3_DYNHDR,
Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type
via matching indiviual Completion Queue Entry (CQE) status bits.
Fixes: ab46182d0dcb ("net/mlx4_en: Support RX XDP metadata")
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Acked-by: Toke Høiland-Jørgensen <[email protected]>
Acked-by: Stanislav Fomichev <[email protected]>
---
drivers/net/ethernet/mellanox/mlx4/en_rx.c | 19 ++++++++++++++++++-
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 73d10aa4c503..332472fe4990 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -685,11 +685,28 @@ int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
enum xdp_rss_hash_type *rss_type)
{
struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
+ struct mlx4_cqe *cqe = _ctx->cqe;
+ enum xdp_rss_hash_type xht = 0;
+ __be16 status;
if (unlikely(!(_ctx->dev->features & NETIF_F_RXHASH)))
return -ENODATA;
- *hash = be32_to_cpu(_ctx->cqe->immed_rss_invalid);
+ *hash = be32_to_cpu(cqe->immed_rss_invalid);
+ status = cqe->status;
+ if (status & cpu_to_be16(MLX4_CQE_STATUS_TCP))
+ xht = XDP_RSS_L4_TCP;
+ if (status & cpu_to_be16(MLX4_CQE_STATUS_UDP))
+ xht = XDP_RSS_L4_UDP;
+ if (status & cpu_to_be16(MLX4_CQE_STATUS_IPV4 | MLX4_CQE_STATUS_IPV4F))
+ xht |= XDP_RSS_L3_IPV4;
+ if (status & cpu_to_be16(MLX4_CQE_STATUS_IPV6)) {
+ xht |= XDP_RSS_L3_IPV6;
+ if (cqe->ipv6_ext_mask)
+ xht |= XDP_RSS_L3_DYNHDR;
+ }
+ *rss_type = xht;
+
return 0;
}
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index 544e09b97483..4ac4d883047b 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -798,7 +798,8 @@ int mlx4_en_netdev_event(struct notifier_block *this,
struct xdp_md;
int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp);
-int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash);
+int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
+ enum xdp_rss_hash_type *rss_type);
/*
* Functions for time stamping
Update BPF selftests to use the new RSS type argument for kfunc
bpf_xdp_metadata_rx_hash.
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Acked-by: Toke Høiland-Jørgensen <[email protected]>
Acked-by: Stanislav Fomichev <[email protected]>
---
.../selftests/bpf/prog_tests/xdp_metadata.c | 2 ++
.../testing/selftests/bpf/progs/xdp_hw_metadata.c | 11 +++++------
tools/testing/selftests/bpf/progs/xdp_metadata.c | 6 +++---
tools/testing/selftests/bpf/progs/xdp_metadata2.c | 7 ++++---
tools/testing/selftests/bpf/xdp_hw_metadata.c | 6 +++++-
tools/testing/selftests/bpf/xdp_metadata.h | 4 ++++
6 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
index aa4beae99f4f..8c5e98da9ae9 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
@@ -273,6 +273,8 @@ static int verify_xsk_metadata(struct xsk *xsk)
if (!ASSERT_NEQ(meta->rx_hash, 0, "rx_hash"))
return -1;
+ ASSERT_EQ(meta->rx_hash_type, 0, "rx_hash_type");
+
xsk_ring_cons__release(&xsk->rx, 1);
refill_rx(xsk, comp_addr);
diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
index d11aca50e54d..de63595af5c4 100644
--- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
@@ -31,8 +31,8 @@ volatile __u64 pkts_redir = 0;
extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
__u64 *timestamp) __ksym;
-extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx,
- __u32 *hash) __ksym;
+extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
+ enum xdp_rss_hash_type *rss_type) __ksym;
SEC("xdp")
int rx(struct xdp_md *ctx)
@@ -96,10 +96,9 @@ int rx(struct xdp_md *ctx)
else
meta->rx_timestamp = 0; /* Used by AF_XDP as not avail signal */
- if (!bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash))
- bpf_printk("populated rx_hash with %u", meta->rx_hash);
- else
- meta->rx_hash = 0; /* Used by AF_XDP as not avail signal */
+ ret = bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
+ if (ret < 0)
+ meta->rx_hash_err = ret; /* Used by AF_XDP as no hash signal */
pkts_redir++;
return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
index 77678b034389..d151d406a123 100644
--- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
@@ -21,8 +21,8 @@ struct {
extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
__u64 *timestamp) __ksym;
-extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx,
- __u32 *hash) __ksym;
+extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
+ enum xdp_rss_hash_type *rss_type) __ksym;
SEC("xdp")
int rx(struct xdp_md *ctx)
@@ -56,7 +56,7 @@ int rx(struct xdp_md *ctx)
if (timestamp == 0)
meta->rx_timestamp = 1;
- bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash);
+ bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
}
diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata2.c b/tools/testing/selftests/bpf/progs/xdp_metadata2.c
index cf69d05451c3..85f88d9d7a78 100644
--- a/tools/testing/selftests/bpf/progs/xdp_metadata2.c
+++ b/tools/testing/selftests/bpf/progs/xdp_metadata2.c
@@ -5,17 +5,18 @@
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
-extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx,
- __u32 *hash) __ksym;
+extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
+ enum xdp_rss_hash_type *rss_type) __ksym;
int called;
SEC("freplace/rx")
int freplace_rx(struct xdp_md *ctx)
{
+ enum xdp_rss_hash_type type = 0;
u32 hash = 0;
/* Call _any_ metadata function to make sure we don't crash. */
- bpf_xdp_metadata_rx_hash(ctx, &hash);
+ bpf_xdp_metadata_rx_hash(ctx, &hash, &type);
called++;
return XDP_PASS;
}
diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testing/selftests/bpf/xdp_hw_metadata.c
index 3b942ef7297b..987cf0db5ebc 100644
--- a/tools/testing/selftests/bpf/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c
@@ -141,7 +141,11 @@ static void verify_xdp_metadata(void *data)
meta = data - sizeof(*meta);
printf("rx_timestamp: %llu\n", meta->rx_timestamp);
- printf("rx_hash: %u\n", meta->rx_hash);
+ if (meta->rx_hash_err < 0)
+ printf("No rx_hash err=%d\n", meta->rx_hash_err);
+ else
+ printf("rx_hash: 0x%X with RSS type:0x%X\n",
+ meta->rx_hash, meta->rx_hash_type);
}
static void verify_skb_metadata(int fd)
diff --git a/tools/testing/selftests/bpf/xdp_metadata.h b/tools/testing/selftests/bpf/xdp_metadata.h
index f6780fbb0a21..0c4624dc6f2f 100644
--- a/tools/testing/selftests/bpf/xdp_metadata.h
+++ b/tools/testing/selftests/bpf/xdp_metadata.h
@@ -12,4 +12,8 @@
struct xdp_meta {
__u64 rx_timestamp;
__u32 rx_hash;
+ union {
+ __u32 rx_hash_type;
+ __s32 rx_hash_err;
+ };
};
On Sat, Apr 08, 2023 at 09:24:41PM +0200, Jesper Dangaard Brouer wrote:
> The tool xdp_hw_metadata can be used by driver developers
> implementing XDP-hints kfuncs. The tool transfers the
> XDP-hints via metadata information to an AF_XDP userspace
> process. When everything works the bpf_printk calls are
> unncesssary. Thus, disable bpf_printk by default, but
> make it easy to reenable for driver developers to use
> when debugging their driver implementation.
>
> This also converts bpf_printk "forwarding UDP:9091 to AF_XDP"
> into a code comment. The bpf_printk's that are important
> to the driver developers is when bpf_xdp_adjust_meta fails.
> The likely mistake from driver developers is expected to
> be that they didn't implement XDP metadata adjust support.
>
> Signed-off-by: Jesper Dangaard Brouer <[email protected]>
> ---
> .../testing/selftests/bpf/progs/xdp_hw_metadata.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> index 4c55b4d79d3d..980eb60d8e5b 100644
> --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> @@ -5,6 +5,19 @@
> #include <bpf/bpf_helpers.h>
> #include <bpf/bpf_endian.h>
>
> +/* Per default below bpf_printk() calls are disabled. Can be
> + * reenabled manually for convenience by XDP-hints driver developer,
> + * when troublshooting the drivers kfuncs implementation details.
Hi Jesper,
a minor nit from my side:
nit: s/troublshooting/troubleshooting/
...
On Sat, Apr 08, 2023 at 09:24:51PM +0200, Jesper Dangaard Brouer wrote:
> 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
> contain combinations to be used by drivers, which gets build up with bits
> from enum xdp_rss_type_bits. Both enum xdp_rss_type_bits and
> xdp_rss_hash_type 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 function 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: 3d76a4d3d4e5 ("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]>
> ---
> drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 +
> drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 3 +
> drivers/net/veth.c | 3 +
> include/linux/netdevice.h | 3 +
> include/net/xdp.h | 45 ++++++++++++++++++++++
> net/core/xdp.c | 10 ++++-
> 6 files changed, 62 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> index 4b5e459b6d49..73d10aa4c503 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> @@ -681,7 +681,8 @@ int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
> return 0;
> }
>
> -int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
> +int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
> + enum xdp_rss_hash_type *rss_type)
> {
> struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
>
Hi Jesper,
I think you also need to update the declaration of mlx4_en_xdp_rx_hash()
in mlx4_en.h.
...
On Sat, Apr 08, 2023 at 09:24:56PM +0200, Jesper Dangaard Brouer wrote:
> Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type
> via mapping table.
>
> The mlx5 hardware can also identify and RSS hash IPSEC. This indicate
> hash includes SPI (Security Parameters Index) as part of IPSEC hash.
>
> Extend xdp core enum xdp_rss_hash_type with IPSEC hash type.
>
> Fixes: bc8d405b1ba9 ("net/mlx5e: Support RX XDP metadata")
> Signed-off-by: Jesper Dangaard Brouer <[email protected]>
> Acked-by: Toke Høiland-Jørgensen <[email protected]>
> Acked-by: Stanislav Fomichev <[email protected]>
> ---
> drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 60 ++++++++++++++++++++++
> include/linux/mlx5/device.h | 14 ++++-
> include/net/xdp.h | 2 +
> 3 files changed, 73 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
> index efe609f8e3aa..97ef1df94d50 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
> @@ -34,6 +34,7 @@
> #include <net/xdp_sock_drv.h>
> #include "en/xdp.h"
> #include "en/params.h"
> +#include <linux/bitfield.h>
>
> int mlx5e_xdp_max_mtu(struct mlx5e_params *params, struct mlx5e_xsk_param *xsk)
> {
> @@ -169,15 +170,72 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
> return 0;
> }
>
> +/* Mapping HW RSS Type bits CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 into 4-bits*/
> +#define RSS_TYPE_MAX_TABLE 16 /* 4-bits max 16 entries */
> +#define RSS_L4 GENMASK(1, 0)
> +#define RSS_L3 GENMASK(3, 2) /* Same as CQE_RSS_HTYPE_IP */
> +
> +/* Valid combinations of CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 sorted numerical */
> +enum mlx5_rss_hash_type {
> + RSS_TYPE_NO_HASH = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IP_NONE) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
> + RSS_TYPE_L3_IPV4 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
> + RSS_TYPE_L4_IPV4_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
> + RSS_TYPE_L4_IPV4_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
> + RSS_TYPE_L4_IPV4_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
> + RSS_TYPE_L3_IPV6 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
> + RSS_TYPE_L4_IPV6_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
> + RSS_TYPE_L4_IPV6_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
> + RSS_TYPE_L4_IPV6_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
> +} mlx5_rss_hash_type;
Hi Jesper,
Sparse seems confused about 'mlx5_rss_hash_type' on the line above.
And I am too. Perhaps it can be removed?
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c:198:3: warning: symbol 'mlx5_rss_hash_type' was not declared. Should it be static?
...
On Sat, Apr 08, 2023 at 09:25:06PM +0200, Jesper Dangaard Brouer wrote:
> Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type
> via matching indiviual Completion Queue Entry (CQE) status bits.
nit: s/indiviual/individual/
>
> Fixes: ab46182d0dcb ("net/mlx4_en: Support RX XDP metadata")
> Signed-off-by: Jesper Dangaard Brouer <[email protected]>
> Acked-by: Toke Høiland-Jørgensen <[email protected]>
> Acked-by: Stanislav Fomichev <[email protected]>
...
On Sat, Apr 8, 2023 at 12:24 PM Jesper Dangaard Brouer
<[email protected]> wrote:
>
> The tool xdp_hw_metadata can be used by driver developers
> implementing XDP-hints kfuncs. The tool transfers the
> XDP-hints via metadata information to an AF_XDP userspace
> process. When everything works the bpf_printk calls are
> unncesssary. Thus, disable bpf_printk by default, but
> make it easy to reenable for driver developers to use
> when debugging their driver implementation.
>
> This also converts bpf_printk "forwarding UDP:9091 to AF_XDP"
> into a code comment. The bpf_printk's that are important
> to the driver developers is when bpf_xdp_adjust_meta fails.
> The likely mistake from driver developers is expected to
> be that they didn't implement XDP metadata adjust support.
>
> Signed-off-by: Jesper Dangaard Brouer <[email protected]>
> ---
> .../testing/selftests/bpf/progs/xdp_hw_metadata.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> index 4c55b4d79d3d..980eb60d8e5b 100644
> --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> @@ -5,6 +5,19 @@
> #include <bpf/bpf_helpers.h>
> #include <bpf/bpf_endian.h>
>
> +/* Per default below bpf_printk() calls are disabled. Can be
> + * reenabled manually for convenience by XDP-hints driver developer,
> + * when troublshooting the drivers kfuncs implementation details.
> + *
> + * Remember BPF-prog bpf_printk info output can be access via:
> + * /sys/kernel/debug/tracing/trace_pipe
> + */
> +//#define DEBUG 1
> +#ifndef DEBUG
> +#undef bpf_printk
> +#define bpf_printk(fmt, ...) ({})
> +#endif
Are you planning to eventually do somethike similar to what I've
mentioned in [0]? If not, should I try to send a patch?
0: https://lore.kernel.org/netdev/CAKH8qBupRYEg+SPMTMb4h532GESG7P1QdaFJ-+zrbARVN9xrdA@mail.gmail.com/
> +
> struct {
> __uint(type, BPF_MAP_TYPE_XSKMAP);
> __uint(max_entries, 256);
> @@ -49,11 +62,10 @@ int rx(struct xdp_md *ctx)
> if (!udp)
> return XDP_PASS;
>
> + /* Forwarding UDP:9091 to AF_XDP */
> if (udp->dest != bpf_htons(9091))
> return XDP_PASS;
>
> - bpf_printk("forwarding UDP:9091 to AF_XDP");
> -
> ret = bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta));
> if (ret != 0) {
> bpf_printk("bpf_xdp_adjust_meta returned %d", ret);
>
>
On 12/04/2023 00.42, Stanislav Fomichev wrote:
> On Sat, Apr 8, 2023 at 12:24 PM Jesper Dangaard Brouer
> <[email protected]> wrote:
>>
>> The tool xdp_hw_metadata can be used by driver developers
>> implementing XDP-hints kfuncs. The tool transfers the
>> XDP-hints via metadata information to an AF_XDP userspace
>> process. When everything works the bpf_printk calls are
>> unncesssary. Thus, disable bpf_printk by default, but
>> make it easy to reenable for driver developers to use
>> when debugging their driver implementation.
>>
>> This also converts bpf_printk "forwarding UDP:9091 to AF_XDP"
>> into a code comment. The bpf_printk's that are important
>> to the driver developers is when bpf_xdp_adjust_meta fails.
>> The likely mistake from driver developers is expected to
>> be that they didn't implement XDP metadata adjust support.
>>
>> Signed-off-by: Jesper Dangaard Brouer <[email protected]>
>> ---
>> .../testing/selftests/bpf/progs/xdp_hw_metadata.c | 16 ++++++++++++++--
>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
>> index 4c55b4d79d3d..980eb60d8e5b 100644
>> --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
>> +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
>> @@ -5,6 +5,19 @@
>> #include <bpf/bpf_helpers.h>
>> #include <bpf/bpf_endian.h>
>>
>> +/* Per default below bpf_printk() calls are disabled. Can be
>> + * reenabled manually for convenience by XDP-hints driver developer,
>> + * when troublshooting the drivers kfuncs implementation details.
>> + *
>> + * Remember BPF-prog bpf_printk info output can be access via:
>> + * /sys/kernel/debug/tracing/trace_pipe
>> + */
>> +//#define DEBUG 1
>> +#ifndef DEBUG
>> +#undef bpf_printk
>> +#define bpf_printk(fmt, ...) ({})
>> +#endif
>
> Are you planning to eventually do somethike similar to what I've
> mentioned in [0]? If not, should I try to send a patch?
See next patch:
- [PATCH bpf V7 2/7] selftests/bpf: Add counters to xdp_hw_metadata
where I add these counters :-)
>
> 0: https://lore.kernel.org/netdev/CAKH8qBupRYEg+SPMTMb4h532GESG7P1QdaFJ-+zrbARVN9xrdA@mail.gmail.com/
>
On 10/04/2023 17.04, Simon Horman wrote:
> On Sat, Apr 08, 2023 at 09:24:51PM +0200, Jesper Dangaard Brouer wrote:
>> 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
>> contain combinations to be used by drivers, which gets build up with bits
>> from enum xdp_rss_type_bits. Both enum xdp_rss_type_bits and
>> xdp_rss_hash_type 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 function 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: 3d76a4d3d4e5 ("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]>
>> ---
>> drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 +
>> drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 3 +
>> drivers/net/veth.c | 3 +
>> include/linux/netdevice.h | 3 +
>> include/net/xdp.h | 45 ++++++++++++++++++++++
>> net/core/xdp.c | 10 ++++-
>> 6 files changed, 62 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
>> index 4b5e459b6d49..73d10aa4c503 100644
>> --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
>> +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
>> @@ -681,7 +681,8 @@ int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
>> return 0;
>> }
>>
>> -int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash)
>> +int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
>> + enum xdp_rss_hash_type *rss_type)
>> {
>> struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
>>
>
> Hi Jesper,
>
> I think you also need to update the declaration of mlx4_en_xdp_rx_hash()
> in mlx4_en.h.
>
Thanks a lot for spotting this. fixed in V8.
--Jesper
On 10/04/2023 17.11, Simon Horman wrote:
> On Sat, Apr 08, 2023 at 09:24:56PM +0200, Jesper Dangaard Brouer wrote:
>> Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type
>> via mapping table.
>>
>> The mlx5 hardware can also identify and RSS hash IPSEC. This indicate
>> hash includes SPI (Security Parameters Index) as part of IPSEC hash.
>>
>> Extend xdp core enum xdp_rss_hash_type with IPSEC hash type.
>>
>> Fixes: bc8d405b1ba9 ("net/mlx5e: Support RX XDP metadata")
>> Signed-off-by: Jesper Dangaard Brouer <[email protected]>
>> Acked-by: Toke Høiland-Jørgensen <[email protected]>
>> Acked-by: Stanislav Fomichev <[email protected]>
>> ---
>> drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 60 ++++++++++++++++++++++
>> include/linux/mlx5/device.h | 14 ++++-
>> include/net/xdp.h | 2 +
>> 3 files changed, 73 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
>> index efe609f8e3aa..97ef1df94d50 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
>> @@ -34,6 +34,7 @@
>> #include <net/xdp_sock_drv.h>
>> #include "en/xdp.h"
>> #include "en/params.h"
>> +#include <linux/bitfield.h>
>>
>> int mlx5e_xdp_max_mtu(struct mlx5e_params *params, struct mlx5e_xsk_param *xsk)
>> {
>> @@ -169,15 +170,72 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
>> return 0;
>> }
>>
>> +/* Mapping HW RSS Type bits CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 into 4-bits*/
>> +#define RSS_TYPE_MAX_TABLE 16 /* 4-bits max 16 entries */
>> +#define RSS_L4 GENMASK(1, 0)
>> +#define RSS_L3 GENMASK(3, 2) /* Same as CQE_RSS_HTYPE_IP */
>> +
>> +/* Valid combinations of CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 sorted numerical */
>> +enum mlx5_rss_hash_type {
>> + RSS_TYPE_NO_HASH = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IP_NONE) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
>> + RSS_TYPE_L3_IPV4 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
>> + RSS_TYPE_L4_IPV4_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
>> + RSS_TYPE_L4_IPV4_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
>> + RSS_TYPE_L4_IPV4_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
>> + RSS_TYPE_L3_IPV6 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
>> + RSS_TYPE_L4_IPV6_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
>> + RSS_TYPE_L4_IPV6_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
>> + RSS_TYPE_L4_IPV6_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
>> + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
>> +} mlx5_rss_hash_type;
>
> Hi Jesper,
>
> Sparse seems confused about 'mlx5_rss_hash_type' on the line above.
> And I am too. Perhaps it can be removed?
>
Yes, it can be removed (in V8).
The reason/trick for doing this was to get compiler to create the enum
symbol, which allowed me to inspect the type using pahole (see cmd
below). (This will also expose this to BTF, but it isn't actually
useful to keep around for BTF, so I will remove it in V8.)
$ pahole -C mlx5_rss_hash_type
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.o
enum mlx5_rss_hash_type {
RSS_TYPE_NO_HASH = 0,
RSS_TYPE_L3_IPV4 = 4,
RSS_TYPE_L4_IPV4_TCP = 5,
RSS_TYPE_L4_IPV4_UDP = 6,
RSS_TYPE_L4_IPV4_IPSEC = 7,
RSS_TYPE_L3_IPV6 = 8,
RSS_TYPE_L4_IPV6_TCP = 9,
RSS_TYPE_L4_IPV6_UDP = 10,
RSS_TYPE_L4_IPV6_IPSEC = 11,
};
This is practical to for reviewers to see if below code is correct:
> +/* Invalid combinations will simply return zero, allows no boundary
checks */
> +static const enum xdp_rss_hash_type
mlx5_xdp_rss_type[RSS_TYPE_MAX_TABLE] = {
> + [RSS_TYPE_NO_HASH] = XDP_RSS_TYPE_NONE,
> + [1] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> + [2] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> + [3] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> + [RSS_TYPE_L3_IPV4] = XDP_RSS_TYPE_L3_IPV4,
> + [RSS_TYPE_L4_IPV4_TCP] = XDP_RSS_TYPE_L4_IPV4_TCP,
> + [RSS_TYPE_L4_IPV4_UDP] = XDP_RSS_TYPE_L4_IPV4_UDP,
> + [RSS_TYPE_L4_IPV4_IPSEC] = XDP_RSS_TYPE_L4_IPV4_IPSEC,
> + [RSS_TYPE_L3_IPV6] = XDP_RSS_TYPE_L3_IPV6,
> + [RSS_TYPE_L4_IPV6_TCP] = XDP_RSS_TYPE_L4_IPV6_TCP,
> + [RSS_TYPE_L4_IPV6_UDP] = XDP_RSS_TYPE_L4_IPV6_UDP,
> + [RSS_TYPE_L4_IPV6_IPSEC] = XDP_RSS_TYPE_L4_IPV6_IPSEC,
> + [12] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> + [13] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> + [14] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> + [15] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> +};
> drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c:198:3: warning: symbol 'mlx5_rss_hash_type' was not declared. Should it be static?
>
> ...
>
On 04/12, Jesper Dangaard Brouer wrote:
>
> On 12/04/2023 00.42, Stanislav Fomichev wrote:
> > On Sat, Apr 8, 2023 at 12:24 PM Jesper Dangaard Brouer
> > <[email protected]> wrote:
> > >
> > > The tool xdp_hw_metadata can be used by driver developers
> > > implementing XDP-hints kfuncs. The tool transfers the
> > > XDP-hints via metadata information to an AF_XDP userspace
> > > process. When everything works the bpf_printk calls are
> > > unncesssary. Thus, disable bpf_printk by default, but
> > > make it easy to reenable for driver developers to use
> > > when debugging their driver implementation.
> > >
> > > This also converts bpf_printk "forwarding UDP:9091 to AF_XDP"
> > > into a code comment. The bpf_printk's that are important
> > > to the driver developers is when bpf_xdp_adjust_meta fails.
> > > The likely mistake from driver developers is expected to
> > > be that they didn't implement XDP metadata adjust support.
> > >
> > > Signed-off-by: Jesper Dangaard Brouer <[email protected]>
> > > ---
> > > .../testing/selftests/bpf/progs/xdp_hw_metadata.c | 16 ++++++++++++++--
> > > 1 file changed, 14 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> > > index 4c55b4d79d3d..980eb60d8e5b 100644
> > > --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> > > +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> > > @@ -5,6 +5,19 @@
> > > #include <bpf/bpf_helpers.h>
> > > #include <bpf/bpf_endian.h>
> > >
> > > +/* Per default below bpf_printk() calls are disabled. Can be
> > > + * reenabled manually for convenience by XDP-hints driver developer,
> > > + * when troublshooting the drivers kfuncs implementation details.
> > > + *
> > > + * Remember BPF-prog bpf_printk info output can be access via:
> > > + * /sys/kernel/debug/tracing/trace_pipe
> > > + */
> > > +//#define DEBUG 1
> > > +#ifndef DEBUG
> > > +#undef bpf_printk
> > > +#define bpf_printk(fmt, ...) ({})
> > > +#endif
> >
> > Are you planning to eventually do somethike similar to what I've
> > mentioned in [0]? If not, should I try to send a patch?
>
> See next patch:
> - [PATCH bpf V7 2/7] selftests/bpf: Add counters to xdp_hw_metadata
>
> where I add these counters :-)
Oh, nice, let me take a look. I was assuming v7 is mostly the same as
v6..
> >
> > 0: https://lore.kernel.org/netdev/CAKH8qBupRYEg+SPMTMb4h532GESG7P1QdaFJ-+zrbARVN9xrdA@mail.gmail.com/
> >
>
On 12/04/2023 18.06, Stanislav Fomichev wrote:
> On 04/12, Jesper Dangaard Brouer wrote:
>> On 12/04/2023 00.42, Stanislav Fomichev wrote:
>>> On Sat, Apr 8, 2023 at 12:24 PM Jesper Dangaard Brouer
>>>>
[...]
>>>
>>> Are you planning to eventually do somethike similar to what I've
>>> mentioned in [0]? If not, should I try to send a patch?
>>
>> See next patch:
>> - [PATCH bpf V7 2/7] selftests/bpf: Add counters to xdp_hw_metadata
>>
>> where I add these counters :-)
>
> Oh, nice, let me take a look. I was assuming v7 is mostly the same as
> v6..
>
Alexei explicitly asked for these changes to be included in V7.
Notice, I've already send out a [V8] (addressing Simon's notes).
Please take a look at V8 instead of V7.
We are at RC6 and I hope we soon have something we can agree on.
[V8]
https://lore.kernel.org/all/168130333143.150247.11159481574477358816.stgit@firesoul/
[patchwork]
https://patchwork.kernel.org/project/netdevbpf/list/?series=739144&state=%2A&archive=both
--Jesper
On Wed, Apr 12, 2023 at 01:31:18PM +0200, Jesper Dangaard Brouer wrote:
> [You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On 10/04/2023 17.11, Simon Horman wrote:
> > On Sat, Apr 08, 2023 at 09:24:56PM +0200, Jesper Dangaard Brouer wrote:
> > > Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type
> > > via mapping table.
> > >
> > > The mlx5 hardware can also identify and RSS hash IPSEC. This indicate
> > > hash includes SPI (Security Parameters Index) as part of IPSEC hash.
> > >
> > > Extend xdp core enum xdp_rss_hash_type with IPSEC hash type.
> > >
> > > Fixes: bc8d405b1ba9 ("net/mlx5e: Support RX XDP metadata")
> > > Signed-off-by: Jesper Dangaard Brouer <[email protected]>
> > > Acked-by: Toke Høiland-Jørgensen <[email protected]>
> > > Acked-by: Stanislav Fomichev <[email protected]>
> > > ---
> > > drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 60 ++++++++++++++++++++++
> > > include/linux/mlx5/device.h | 14 ++++-
> > > include/net/xdp.h | 2 +
> > > 3 files changed, 73 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
> > > index efe609f8e3aa..97ef1df94d50 100644
> > > --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
> > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c
> > > @@ -34,6 +34,7 @@
> > > #include <net/xdp_sock_drv.h>
> > > #include "en/xdp.h"
> > > #include "en/params.h"
> > > +#include <linux/bitfield.h>
> > >
> > > int mlx5e_xdp_max_mtu(struct mlx5e_params *params, struct mlx5e_xsk_param *xsk)
> > > {
> > > @@ -169,15 +170,72 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
> > > return 0;
> > > }
> > >
> > > +/* Mapping HW RSS Type bits CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 into 4-bits*/
> > > +#define RSS_TYPE_MAX_TABLE 16 /* 4-bits max 16 entries */
> > > +#define RSS_L4 GENMASK(1, 0)
> > > +#define RSS_L3 GENMASK(3, 2) /* Same as CQE_RSS_HTYPE_IP */
> > > +
> > > +/* Valid combinations of CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 sorted numerical */
> > > +enum mlx5_rss_hash_type {
> > > + RSS_TYPE_NO_HASH = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IP_NONE) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
> > > + RSS_TYPE_L3_IPV4 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
> > > + RSS_TYPE_L4_IPV4_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
> > > + RSS_TYPE_L4_IPV4_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
> > > + RSS_TYPE_L4_IPV4_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
> > > + RSS_TYPE_L3_IPV6 = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)),
> > > + RSS_TYPE_L4_IPV6_TCP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)),
> > > + RSS_TYPE_L4_IPV6_UDP = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)),
> > > + RSS_TYPE_L4_IPV6_IPSEC = (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6) |
> > > + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)),
> > > +} mlx5_rss_hash_type;
> >
> > Hi Jesper,
> >
> > Sparse seems confused about 'mlx5_rss_hash_type' on the line above.
> > And I am too. Perhaps it can be removed?
> >
>
> Yes, it can be removed (in V8).
>
> The reason/trick for doing this was to get compiler to create the enum
> symbol, which allowed me to inspect the type using pahole (see cmd
> below). (This will also expose this to BTF, but it isn't actually
> useful to keep around for BTF, so I will remove it in V8.)
Thanks Jesper,
I didn't know that trick :)
> $ pahole -C mlx5_rss_hash_type
> drivers/net/ethernet/mellanox/mlx5/core/en/xdp.o
> enum mlx5_rss_hash_type {
> RSS_TYPE_NO_HASH = 0,
> RSS_TYPE_L3_IPV4 = 4,
> RSS_TYPE_L4_IPV4_TCP = 5,
> RSS_TYPE_L4_IPV4_UDP = 6,
> RSS_TYPE_L4_IPV4_IPSEC = 7,
> RSS_TYPE_L3_IPV6 = 8,
> RSS_TYPE_L4_IPV6_TCP = 9,
> RSS_TYPE_L4_IPV6_UDP = 10,
> RSS_TYPE_L4_IPV6_IPSEC = 11,
> };
>
> This is practical to for reviewers to see if below code is correct:
>
> > +/* Invalid combinations will simply return zero, allows no boundary
> checks */
> > +static const enum xdp_rss_hash_type
> mlx5_xdp_rss_type[RSS_TYPE_MAX_TABLE] = {
> > + [RSS_TYPE_NO_HASH] = XDP_RSS_TYPE_NONE,
> > + [1] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> > + [2] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> > + [3] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> > + [RSS_TYPE_L3_IPV4] = XDP_RSS_TYPE_L3_IPV4,
> > + [RSS_TYPE_L4_IPV4_TCP] = XDP_RSS_TYPE_L4_IPV4_TCP,
> > + [RSS_TYPE_L4_IPV4_UDP] = XDP_RSS_TYPE_L4_IPV4_UDP,
> > + [RSS_TYPE_L4_IPV4_IPSEC] = XDP_RSS_TYPE_L4_IPV4_IPSEC,
> > + [RSS_TYPE_L3_IPV6] = XDP_RSS_TYPE_L3_IPV6,
> > + [RSS_TYPE_L4_IPV6_TCP] = XDP_RSS_TYPE_L4_IPV6_TCP,
> > + [RSS_TYPE_L4_IPV6_UDP] = XDP_RSS_TYPE_L4_IPV6_UDP,
> > + [RSS_TYPE_L4_IPV6_IPSEC] = XDP_RSS_TYPE_L4_IPV6_IPSEC,
> > + [12] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> > + [13] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> > + [14] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> > + [15] = XDP_RSS_TYPE_NONE, /* Implicit zero */
> > +};
>
> > drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c:198:3: warning: symbol 'mlx5_rss_hash_type' was not declared. Should it be static?
> >
> > ...
> >
>