Skip to contentSkip to conversation

eth: fbnic: support RSS contexts and ntuple filters

PATCH In review Jakub Kicinski 6 participants 19 messages Feb 6, 2025 – Feb 12, 2025

Subsystems (5)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover eth: fbnic: support RSS contexts and ntuple filters

Add support for RSS contexts and ntuple filters in fbnic. The device has only one context, intended for use by TCP zero-copy Rx.

First two patches add a check we seem to be missing in the core, to avoid having to copy it to all drivers.

  $ ./drivers/net/hw/rss_ctx.py
  KTAP version 1
  1..16
  ok 1 rss_ctx.test_rss_key_indir
  ok 2 rss_ctx.test_rss_queue_reconfigure
  ok 3 rss_ctx.test_rss_resize
  ok 4 rss_ctx.test_hitless_key_update
  ok 5 rss_ctx.test_rss_context
  # Failed to create context 2, trying to test what we got
  ok 6 rss_ctx.test_rss_context4 # SKIP Tested only 1 contexts, wanted 4
  # Increasing queue count 44 -> 66
  # Failed to create context 2, trying to test what we got
  ok 7 rss_ctx.test_rss_context32 # SKIP Tested only 1 contexts, wanted 32
  # Added only 1 out of 3 contexts
  ok 8 rss_ctx.test_rss_context_dump
  # Driver does not support rss + queue offset
  ok 9 rss_ctx.test_rss_context_queue_reconfigure
  ok 10 rss_ctx.test_rss_context_overlap
  ok 11 rss_ctx.test_rss_context_overlap2 # SKIP Test requires at least 2 contexts, but device only has 1
  ok 12 rss_ctx.test_rss_context_out_of_order # SKIP Test requires at least 4 contexts, but device only has 1
  # Failed to create context 2, trying to test what we got
  ok 13 rss_ctx.test_rss_context4_create_with_cfg # SKIP Tested only 1 contexts, wanted 4
  ok 14 rss_ctx.test_flow_add_context_missing
  ok 15 rss_ctx.test_delete_rss_context_busy
  ok 16 rss_ctx.test_rss_ntuple_addition # SKIP Ntuple filter with RSS and nonzero action not supported
  # Totals: pass:10 fail:0 xfail:0 xpass:0 skip:6 error:0

Alexander Duyck (3):
eth: fbnic: add IP TCAM programming
eth: fbnic: support n-tuple filters
eth: fbnic: support listing tcam content via debugfs

Daniel Zahka (1):
eth: fbnic: support an additional RSS context

Jakub Kicinski (3):
net: ethtool: prevent flow steering to RSS contexts which don't exist
selftests: net-drv: test adding flow rule to invalid RSS context
selftests: drv-net: rss_ctx: skip tests which need multiple contexts
cleanly

 drivers/net/ethernet/meta/fbnic/fbnic.h       |   6 +
 drivers/net/ethernet/meta/fbnic/fbnic_csr.h   |   6 +
 drivers/net/ethernet/meta/fbnic/fbnic_rpc.h   |  35 +
 .../net/ethernet/meta/fbnic/fbnic_debugfs.c   | 138 ++++
 .../net/ethernet/meta/fbnic/fbnic_ethtool.c   | 705 ++++++++++++++++++
 .../net/ethernet/meta/fbnic/fbnic_netdev.c    |   1 +
 drivers/net/ethernet/meta/fbnic/fbnic_rpc.c   | 356 ++++++++-
 net/ethtool/ioctl.c                           |  12 +-
 .../selftests/drivers/net/hw/rss_ctx.py       |  46 +-
 9 files changed, 1294 insertions(+), 11 deletions(-)
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 1/7 net: ethtool: prevent flow steering to RSS contexts which don't exist

Since commit 42dc431f5d0e ("ethtool: rss: prevent rss ctx deletion when in use") we prevent removal of RSS contexts pointed to by existing flow rules. Core should also prevent creation of rules which point to RSS context which don't exist in the first place.

---
CC: [email protected]
CC: [email protected]

---
 net/ethtool/ioctl.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
net/ethtool/ioctl.c +8 -4
index 7609ce2b2c5e..98b7dcea207a 100644
@@ -993,10 +993,14 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
 		return rc;
 
 	/* Nonzero ring with RSS only makes sense if NIC adds them together */
-	if (cmd == ETHTOOL_SRXCLSRLINS && info.fs.flow_type & FLOW_RSS &&
-	    !ops->cap_rss_rxnfc_adds &&
-	    ethtool_get_flow_spec_ring(info.fs.ring_cookie))
-		return -EINVAL;
+	if (cmd == ETHTOOL_SRXCLSRLINS && info.fs.flow_type & FLOW_RSS) {
+		if (!ops->cap_rss_rxnfc_adds &&
+		    ethtool_get_flow_spec_ring(info.fs.ring_cookie))
+			return -EINVAL;
+
+		if (!xa_load(&dev->ethtool->rss_ctx, info.rss_context))
+			return -EINVAL;
+	}
 
 	if (cmd == ETHTOOL_SRXFH && ops->get_rxfh) {
 		struct ethtool_rxfh_param rxfh = {};
Signature · 1 line
2.48.1
author maintainer
#5 lore raw

PATCH 2/7 selftests: net-drv: test adding flow rule to invalid RSS context

In reply to Jakub Kicinski

Check that adding Rx flow steering rules pointing to an RSS context which does not exist is prevented.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 .../selftests/drivers/net/hw/rss_ctx.py       | 27 ++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/hw/rss_ctx.py +26 -1
index 319aaa004c40..7e5f4602e6b3 100755
@@ -4,7 +4,8 @@
 import datetime
 import random
 import re
-from lib.py import ksft_run, ksft_pr, ksft_exit, ksft_eq, ksft_ne, ksft_ge, ksft_lt, ksft_true
+from lib.py import ksft_run, ksft_pr, ksft_exit
+from lib.py import ksft_eq, ksft_ne, ksft_ge, ksft_in, ksft_lt, ksft_true, ksft_raises
 from lib.py import NetDrvEpEnv
 from lib.py import EthtoolFamily, NetdevFamily
 from lib.py import KsftSkipEx, KsftFailEx
@@ -649,6 +650,29 @@ from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
     test_rss_context_overlap(cfg, True)
 
 
+def test_flow_add_context_missing(cfg):
+    """
+    Test that we are not allowed to add a rule pointing to an RSS context
+    which was never created.
+    """
+
+    require_ntuple(cfg)
+
+    # Find a context which doesn't exist
+    for ctx_id in range(1, 100):
+        try:
+            get_rss(cfg, context=ctx_id)
+        except CmdExitFailure:
+            break
+
+    with ksft_raises(CmdExitFailure) as cm:
+        flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port 1234 context {ctx_id}"
+        ntuple_id = ethtool_create(cfg, "-N", flow)
+        ethtool(f"-N {cfg.ifname} delete {ntuple_id}")
+    if cm.exception:
+        ksft_in('Invalid argument', cm.exception.cmd.stderr)
+
+
 def test_delete_rss_context_busy(cfg):
     """
     Test that deletion returns -EBUSY when an rss context is being used
@@ -726,6 +750,7 @@ from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
                   test_rss_context_dump, test_rss_context_queue_reconfigure,
                   test_rss_context_overlap, test_rss_context_overlap2,
                   test_rss_context_out_of_order, test_rss_context4_create_with_cfg,
+                  test_flow_add_context_missing,
                   test_delete_rss_context_busy, test_rss_ntuple_addition],
                  args=(cfg, ))
     ksft_exit()
Signature · 1 line
2.48.1
author maintainer
#8 lore raw

PATCH 3/7 eth: fbnic: support an additional RSS context

In reply to Jakub Kicinski

From: Daniel Zahka <[email protected]>

Add support for an extra RSS context. The device has a primary and a secondary context.

---
 .../net/ethernet/meta/fbnic/fbnic_ethtool.c   | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +59 -0
index 20cd9f5f89e2..4d73b405c8b9 100644
@@ -374,6 +374,61 @@ fbnic_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh,
 	return 0;
 }
 
+static int
+fbnic_modify_rxfh_context(struct net_device *netdev,
+			  struct ethtool_rxfh_context *ctx,
+			  const struct ethtool_rxfh_param *rxfh,
+			  struct netlink_ext_ack *extack)
+{
+	struct fbnic_net *fbn = netdev_priv(netdev);
+	const u32 *indir = rxfh->indir;
+	unsigned int changes;
+
+	if (!indir)
+		indir = ethtool_rxfh_context_indir(ctx);
+
+	changes = fbnic_set_indir(fbn, rxfh->rss_context, indir);
+	if (changes && netif_running(netdev))
+		fbnic_rss_reinit_hw(fbn->fbd, fbn);
+
+	return 0;
+}
+
+static int
+fbnic_create_rxfh_context(struct net_device *netdev,
+			  struct ethtool_rxfh_context *ctx,
+			  const struct ethtool_rxfh_param *rxfh,
+			  struct netlink_ext_ack *extack)
+{
+	struct fbnic_net *fbn = netdev_priv(netdev);
+
+	if (rxfh->hfunc && rxfh->hfunc != ETH_RSS_HASH_TOP) {
+		NL_SET_ERR_MSG_MOD(extack, "RSS hash function not supported");
+		return -EOPNOTSUPP;
+	}
+	ctx->hfunc = ETH_RSS_HASH_TOP;
+
+	if (!rxfh->indir) {
+		u32 *indir = ethtool_rxfh_context_indir(ctx);
+		unsigned int num_rx = fbn->num_rx_queues;
+		unsigned int i;
+
+		for (i = 0; i < FBNIC_RPC_RSS_TBL_SIZE; i++)
+			indir[i] = ethtool_rxfh_indir_default(i, num_rx);
+	}
+
+	return fbnic_modify_rxfh_context(netdev, ctx, rxfh, extack);
+}
+
+static int
+fbnic_remove_rxfh_context(struct net_device *netdev,
+			  struct ethtool_rxfh_context *ctx, u32 rss_context,
+			  struct netlink_ext_ack *extack)
+{
+	/* Nothing to do, contexts are allocated statically */
+	return 0;
+}
+
 static void fbnic_get_channels(struct net_device *netdev,
 			       struct ethtool_channels *ch)
 {
@@ -586,6 +641,7 @@ fbnic_get_eth_mac_stats(struct net_device *netdev,
 }
 
 static const struct ethtool_ops fbnic_ethtool_ops = {
+	.rxfh_max_num_contexts	= FBNIC_RPC_RSS_TBL_COUNT,
 	.get_drvinfo		= fbnic_get_drvinfo,
 	.get_regs_len		= fbnic_get_regs_len,
 	.get_regs		= fbnic_get_regs,
@@ -598,6 +654,9 @@ static const struct ethtool_ops fbnic_ethtool_ops = {
 	.get_rxfh_indir_size	= fbnic_get_rxfh_indir_size,
 	.get_rxfh		= fbnic_get_rxfh,
 	.set_rxfh		= fbnic_set_rxfh,
+	.create_rxfh_context	= fbnic_create_rxfh_context,
+	.modify_rxfh_context	= fbnic_modify_rxfh_context,
+	.remove_rxfh_context	= fbnic_remove_rxfh_context,
 	.get_channels		= fbnic_get_channels,
 	.set_channels		= fbnic_set_channels,
 	.get_ts_info		= fbnic_get_ts_info,
Signature · 1 line
2.48.1
author maintainer
#10 lore raw

PATCH 4/7 eth: fbnic: add IP TCAM programming

In reply to Jakub Kicinski

From: Alexander Duyck <[email protected]>

IPv6 addresses are huge so the device has 4 TCAMs used for narrowing them down to a smaller key before the main match / action engine.

Add the tables in which we'll keep the IP addresses used by ethtool n-tuple rules. Add the code for programming them into the device, and code for allocating and freeing entries.

A bit of copy / paste here as we need to support IPv4 and IPv6 in the same tables, and there is four of them. But it makes the code easier to match up with the device.

---
 drivers/net/ethernet/meta/fbnic/fbnic.h     |   6 +
 drivers/net/ethernet/meta/fbnic/fbnic_csr.h |   3 +
 drivers/net/ethernet/meta/fbnic/fbnic_rpc.h |  26 ++
 drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 354 ++++++++++++++++++++
 4 files changed, 389 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic.h +6 -0
index 14751f16e125..37f81db1fc30 100644
@@ -60,6 +60,12 @@ struct fbnic_dev {
 	u8 mac_addr_boundary;
 	u8 tce_tcam_last;
 
+	/* IP TCAM */
+	struct fbnic_ip_addr ip_src[FBNIC_RPC_TCAM_IP_ADDR_NUM_ENTRIES];
+	struct fbnic_ip_addr ip_dst[FBNIC_RPC_TCAM_IP_ADDR_NUM_ENTRIES];
+	struct fbnic_ip_addr ipo_src[FBNIC_RPC_TCAM_IP_ADDR_NUM_ENTRIES];
+	struct fbnic_ip_addr ipo_dst[FBNIC_RPC_TCAM_IP_ADDR_NUM_ENTRIES];
+
 	/* Number of TCQs/RCQs available on hardware */
 	u16 max_num_queues;
 
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +3 -0
index 02bb81b3c506..d5e9b11ed2f8 100644
@@ -677,6 +677,9 @@ enum {
 
 #define FBNIC_RPC_TCAM_OUTER_IPSRC(m, n)\
 	(0x08c00 + 0x08 * (n) + (m))		/* 0x023000 + 32*n + 4*m */
+#define FBNIC_RPC_TCAM_IP_ADDR_VALUE		CSR_GENMASK(15, 0)
+#define FBNIC_RPC_TCAM_IP_ADDR_MASK		CSR_GENMASK(31, 16)
+
 #define FBNIC_RPC_TCAM_OUTER_IPDST(m, n)\
 	(0x08c48 + 0x08 * (n) + (m))		/* 0x023120 + 32*n + 4*m */
 #define FBNIC_RPC_TCAM_IPSRC(m, n)\
drivers/net/ethernet/meta/fbnic/fbnic_rpc.h +26 -0
index 0d8285fa5b45..b3515f2f5f92 100644
@@ -7,6 +7,8 @@
 #include <uapi/linux/in6.h>
 #include <linux/bitfield.h>
 
+struct in_addr;
+
 /*  The TCAM state definitions follow an expected ordering.
  *  They start out disabled, then move through the following states:
  *  Disabled  0	-> Add	      2
@@ -32,6 +34,12 @@ enum {
 #define FBNIC_RPC_TCAM_MACDA_WORD_LEN		3
 #define FBNIC_RPC_TCAM_MACDA_NUM_ENTRIES	32
 
+/* 8 IPSRC and IPDST TCAM Entries each
+ * 8 registers, Validate each
+ */
+#define FBNIC_RPC_TCAM_IP_ADDR_WORD_LEN		8
+#define FBNIC_RPC_TCAM_IP_ADDR_NUM_ENTRIES	8
+
 #define FBNIC_RPC_TCAM_ACT_WORD_LEN		11
 #define FBNIC_RPC_TCAM_ACT_NUM_ENTRIES		64
 
@@ -47,6 +55,13 @@ struct fbnic_mac_addr {
 	DECLARE_BITMAP(act_tcam, FBNIC_RPC_TCAM_ACT_NUM_ENTRIES);
 };
 
+struct fbnic_ip_addr {
+	struct in6_addr mask, value;
+	unsigned char version;
+	unsigned char state;
+	DECLARE_BITMAP(act_tcam, FBNIC_RPC_TCAM_ACT_NUM_ENTRIES);
+};
+
 struct fbnic_act_tcam {
 	struct {
 		u16 tcam[FBNIC_RPC_TCAM_ACT_WORD_LEN];
@@ -177,6 +192,17 @@ struct fbnic_mac_addr *__fbnic_mc_sync(struct fbnic_dev *fbd,
 void fbnic_sift_macda(struct fbnic_dev *fbd);
 void fbnic_write_macda(struct fbnic_dev *fbd);
 
+struct fbnic_ip_addr *__fbnic_ip4_sync(struct fbnic_dev *fbd,
+				       struct fbnic_ip_addr *ip_addr,
+				       const struct in_addr *addr,
+				       const struct in_addr *mask);
+struct fbnic_ip_addr *__fbnic_ip6_sync(struct fbnic_dev *fbd,
+				       struct fbnic_ip_addr *ip_addr,
+				       const struct in6_addr *addr,
+				       const struct in6_addr *mask);
+int __fbnic_ip_unsync(struct fbnic_ip_addr *ip_addr, unsigned int tcam_idx);
+void fbnic_write_ip_addr(struct fbnic_dev *fbd);
+
 static inline int __fbnic_uc_unsync(struct fbnic_mac_addr *mac_addr)
 {
 	return __fbnic_xc_unsync(mac_addr, FBNIC_MAC_ADDR_T_UNICAST);
drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +354 -0

366 lines not on this page · raw message

Signature · 1 line
2.48.1
author maintainer
#11 lore raw

PATCH 5/7 eth: fbnic: support n-tuple filters

In reply to Jakub Kicinski

From: Alexander Duyck <[email protected]>

Add ethtool -n / -N support. Support only "un-ordered" rule sets (RX_CLS_LOC_ANY), just for simplicity of the code. It's unclear anyone actually cares about the rule ordering.

---
 drivers/net/ethernet/meta/fbnic/fbnic_csr.h   |   3 +
 drivers/net/ethernet/meta/fbnic/fbnic_rpc.h   |   9 +
 .../net/ethernet/meta/fbnic/fbnic_ethtool.c   | 646 ++++++++++++++++++
 .../net/ethernet/meta/fbnic/fbnic_netdev.c    |   1 +
 drivers/net/ethernet/meta/fbnic/fbnic_rpc.c   |   2 +-
 5 files changed, 660 insertions(+), 1 deletion(-)
drivers/net/ethernet/meta/fbnic/fbnic_csr.h +3 -0
index d5e9b11ed2f8..6f24c5f2e175 100644
@@ -605,8 +605,11 @@ enum {
 	FBNIC_RPC_ACT_TBL0_DEST_EI	= 4,
 };
 
+#define FBNIC_RPC_ACT_TBL0_Q_SEL		CSR_BIT(4)
+#define FBNIC_RPC_ACT_TBL0_Q_ID			CSR_GENMASK(15, 8)
 #define FBNIC_RPC_ACT_TBL0_DMA_HINT		CSR_GENMASK(24, 16)
 #define FBNIC_RPC_ACT_TBL0_TS_ENA		CSR_BIT(28)
+#define FBNIC_RPC_ACT_TBL0_ACT_TBL_IDX		CSR_BIT(29)
 #define FBNIC_RPC_ACT_TBL0_RSS_CTXT_ID		CSR_BIT(30)
 
 #define FBNIC_RPC_ACT_TBL1_DEFAULT	0x0840b		/* 0x2102c */
drivers/net/ethernet/meta/fbnic/fbnic_rpc.h +9 -0
index b3515f2f5f92..6892414195c3 100644
@@ -96,6 +96,11 @@ enum {
 #define FBNIC_RPC_ACT_TBL_BMC_OFFSET		0
 #define FBNIC_RPC_ACT_TBL_BMC_ALL_MULTI_OFFSET	1
 
+/* This should leave us with 48 total entries in the TCAM that can be used
+ * for NFC after also deducting the 14 needed for RSS table programming.
+ */
+#define FBNIC_RPC_ACT_TBL_NFC_OFFSET		2
+
 /* We reserve the last 14 entries for RSS rules on the host. The BMC
  * unicast rule will need to be populated above these and is expected to
  * use MACDA TCAM entry 23 to store the BMC MAC address.
@@ -103,6 +108,9 @@ enum {
 #define FBNIC_RPC_ACT_TBL_RSS_OFFSET \
 	(FBNIC_RPC_ACT_TBL_NUM_ENTRIES - FBNIC_RSS_EN_NUM_ENTRIES)
 
+#define FBNIC_RPC_ACT_TBL_NFC_ENTRIES \
+	(FBNIC_RPC_ACT_TBL_RSS_OFFSET - FBNIC_RPC_ACT_TBL_NFC_OFFSET)
+
 /* Flags used to identify the owner for this MAC filter. Note that any
  * flags set for Broadcast thru Promisc indicate that the rule belongs
  * to the RSS filters for the host.
@@ -183,6 +191,7 @@ void fbnic_rss_init_en_mask(struct fbnic_net *fbn);
 void fbnic_rss_disable_hw(struct fbnic_dev *fbd);
 void fbnic_rss_reinit_hw(struct fbnic_dev *fbd, struct fbnic_net *fbn);
 void fbnic_rss_reinit(struct fbnic_dev *fbd, struct fbnic_net *fbn);
+u16 fbnic_flow_hash_2_rss_en_mask(struct fbnic_net *fbn, int flow_type);
 
 int __fbnic_xc_unsync(struct fbnic_mac_addr *mac_addr, unsigned int tcam_idx);
 struct fbnic_mac_addr *__fbnic_uc_sync(struct fbnic_dev *fbd,
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +646 -0

681 lines not on this page · raw message

drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +1 -0
index 1db57c42333e..14e7a8384bce 100644
@@ -639,6 +639,7 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd)
 	netdev->hw_features |= netdev->features;
 	netdev->vlan_features |= netdev->features;
 	netdev->hw_enc_features |= netdev->features;
+	netdev->features |= NETIF_F_NTUPLE;
 
 	netdev->min_mtu = IPV6_MIN_MTU;
 	netdev->max_mtu = FBNIC_MAX_JUMBO_FRAME_SIZE - ETH_HLEN;
drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +1 -1
index be06f43e51e4..8ff07b5562e3 100644
@@ -61,7 +61,7 @@ void fbnic_rss_disable_hw(struct fbnic_dev *fbd)
 #define FBNIC_FH_2_RSSEM_BIT(_fh, _rssem, _val)		\
 	FIELD_PREP(FBNIC_RPC_ACT_TBL1_RSS_ENA_##_rssem,	\
 		   FIELD_GET(RXH_##_fh, _val))
-static u16 fbnic_flow_hash_2_rss_en_mask(struct fbnic_net *fbn, int flow_type)
+u16 fbnic_flow_hash_2_rss_en_mask(struct fbnic_net *fbn, int flow_type)
 {
 	u32 flow_hash = fbn->rss_flow_hash[flow_type];
 	u32 rss_en_mask = 0;
Signature · 1 line
2.48.1
author maintainer
#12 lore raw

PATCH 6/7 selftests: drv-net: rss_ctx: skip tests which need multiple contexts cleanly

In reply to Jakub Kicinski

There's no good API to check how many contexts device supports. But initial tests sense the context count already, so just store that number and skip tests which we know need more.

---
 .../selftests/drivers/net/hw/rss_ctx.py       | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
tools/testing/selftests/drivers/net/hw/rss_ctx.py +14 -5
index 7e5f4602e6b3..d6e69d7d5e43 100755
@@ -59,6 +59,14 @@ from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
         raise KsftSkipEx("Ntuple filters not enabled on the device: " + str(features["ntuple-filters"]))
 
 
+def require_context_cnt(cfg, need_cnt):
+    # There's no good API to get the context count, so the tests
+    # which try to add a lot opportunisitically set the count they
+    # discovered. Careful with test ordering!
+    if need_cnt and cfg.context_cnt and cfg.context_cnt < need_cnt:
+        raise KsftSkipEx(f"Test requires at least {need_cnt} contexts, but device only has {cfg.context_cnt}")
+
+
 # Get Rx packet counts for all queues, as a simple list of integers
 # if @prev is specified the prev counts will be subtracted
 def _get_rx_cnts(cfg, prev=None):
@@ -457,6 +465,8 @@ from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
                 raise
             ksft_pr(f"Failed to create context {i + 1}, trying to test what we got")
             ctx_cnt = i
+            if cfg.context_cnt is None:
+                cfg.context_cnt = ctx_cnt
             break
 
         _rss_key_check(cfg, context=ctx_id)
@@ -512,8 +522,7 @@ from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
     """
 
     require_ntuple(cfg)
-
-    requested_ctx_cnt = ctx_cnt
+    require_context_cnt(cfg, 4)
 
     # Try to allocate more queues when necessary
     qcnt = len(_get_rx_cnts(cfg))
@@ -578,9 +587,6 @@ from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
     remove_ctx(-1)
     check_traffic()
 
-    if requested_ctx_cnt != ctx_cnt:
-        raise KsftSkipEx(f"Tested only {ctx_cnt} contexts, wanted {requested_ctx_cnt}")
-
 
 def test_rss_context_overlap(cfg, other_ctx=0):
     """
@@ -589,6 +595,8 @@ from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
     """
 
     require_ntuple(cfg)
+    if other_ctx:
+        require_context_cnt(cfg, 2)
 
     queue_cnt = len(_get_rx_cnts(cfg))
     if queue_cnt < 4:
@@ -741,6 +749,7 @@ from lib.py import ethtool, ip, defer, GenerateTraffic, CmdExitFailure
 
 def main() -> None:
     with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+        cfg.context_cnt = None
         cfg.ethnl = EthtoolFamily()
         cfg.netdevnl = NetdevFamily()
 
Signature · 1 line
2.48.1
author maintainer
#13 lore raw

PATCH 7/7 eth: fbnic: support listing tcam content via debugfs

In reply to Jakub Kicinski

From: Alexander Duyck <[email protected]>

The device has a handful of relatively small TCAM tables, support dumping the driver state via debugfs.

  # ethtool -N eth0 flow-type tcp6 \
      dst-ip 1111::2222 dst-port $((0x1122)) \
      src-ip 3333::4444 src-port $((0x3344)) \
      action 2
  Added rule with ID 47
  # cd $dbgfs
  # cat ip_src
  Idx S TCAM Bitmap       V Addr/Mask
  ------------------------------------
  00  1 00020000,00000000 6 33330000000000000000000000004444
                            00000000000000000000000000000000
  ...
  # cat ip_dst
  Idx S TCAM Bitmap       V Addr/Mask
  ------------------------------------
  00  1 00020000,00000000 6 11110000000000000000000000002222
                            00000000000000000000000000000000
  ...
  # cat act_tcam
  Idx S Value/Mask                                              RSS  Dest
  ------------------------------------------------------------------------
  ...
  49  1 0000 0000 0000 0000 0000 0000 1122 3344 0000 9c00 0088  000f 00000212
        ffff ffff ffff ffff ffff ffff 0000 0000 ffff 23ff ff00
  ...

The ipo_* tables are for outer IP addresses.
The tce_* table is for directing/stealing traffic to NC-SI.

---
 .../net/ethernet/meta/fbnic/fbnic_debugfs.c   | 138 ++++++++++++++++++
 1 file changed, 138 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c +138 -0
index ac80981f67c0..e8f2d7f2d962 100644
@@ -44,6 +44,132 @@ static int fbnic_dbg_mac_addr_show(struct seq_file *s, void *v)
 }
 DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_mac_addr);
 
+static int fbnic_dbg_tce_tcam_show(struct seq_file *s, void *v)
+{
+	struct fbnic_dev *fbd = s->private;
+	int i, tcam_idx = 0;
+	char hdr[80];
+
+	/* Generate Header */
+	snprintf(hdr, sizeof(hdr), "%3s %s %-17s %s\n",
+		 "Idx", "S", "TCAM Bitmap", "Addr/Mask");
+	seq_puts(s, hdr);
+	fbnic_dbg_desc_break(s, strnlen(hdr, sizeof(hdr)));
+
+	for (i = 0; i < ARRAY_SIZE(fbd->mac_addr); i++) {
+		struct fbnic_mac_addr *mac_addr = &fbd->mac_addr[i];
+
+		/* Verify BMC bit is set */
+		if (!test_bit(FBNIC_MAC_ADDR_T_BMC, mac_addr->act_tcam))
+			continue;
+
+		if (tcam_idx == FBNIC_TCE_TCAM_NUM_ENTRIES)
+			break;
+
+		seq_printf(s, "%02d  %d %64pb %pm\n",
+			   tcam_idx, mac_addr->state, mac_addr->act_tcam,
+			   mac_addr->value.addr8);
+		seq_printf(s, "                        %pm\n",
+			   mac_addr->mask.addr8);
+		tcam_idx++;
+	}
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_tce_tcam);
+
+static int fbnic_dbg_act_tcam_show(struct seq_file *s, void *v)
+{
+	struct fbnic_dev *fbd = s->private;
+	char hdr[80];
+	int i;
+
+	/* Generate Header */
+	snprintf(hdr, sizeof(hdr), "%3s %s %-55s %-4s %s\n",
+		 "Idx", "S", "Value/Mask", "RSS", "Dest");
+	seq_puts(s, hdr);
+	fbnic_dbg_desc_break(s, strnlen(hdr, sizeof(hdr)));
+
+	for (i = 0; i < FBNIC_RPC_TCAM_ACT_NUM_ENTRIES; i++) {
+		struct fbnic_act_tcam *act_tcam = &fbd->act_tcam[i];
+
+		seq_printf(s, "%02d  %d %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x  %04x %08x\n",
+			   i, act_tcam->state,
+			   act_tcam->value.tcam[10], act_tcam->value.tcam[9],
+			   act_tcam->value.tcam[8], act_tcam->value.tcam[7],
+			   act_tcam->value.tcam[6], act_tcam->value.tcam[5],
+			   act_tcam->value.tcam[4], act_tcam->value.tcam[3],
+			   act_tcam->value.tcam[2], act_tcam->value.tcam[1],
+			   act_tcam->value.tcam[0], act_tcam->rss_en_mask,
+			   act_tcam->dest);
+		seq_printf(s, "      %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n",
+			   act_tcam->mask.tcam[10], act_tcam->mask.tcam[9],
+			   act_tcam->mask.tcam[8], act_tcam->mask.tcam[7],
+			   act_tcam->mask.tcam[6], act_tcam->mask.tcam[5],
+			   act_tcam->mask.tcam[4], act_tcam->mask.tcam[3],
+			   act_tcam->mask.tcam[2], act_tcam->mask.tcam[1],
+			   act_tcam->mask.tcam[0]);
+	}
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_act_tcam);
+
+static int fbnic_dbg_ip_addr_show(struct seq_file *s,
+				  struct fbnic_ip_addr *ip_addr)
+{
+	char hdr[80];
+	int i;
+
+	/* Generate Header */
+	snprintf(hdr, sizeof(hdr), "%3s %s %-17s %s %s\n",
+		 "Idx", "S", "TCAM Bitmap", "V", "Addr/Mask");
+	seq_puts(s, hdr);
+	fbnic_dbg_desc_break(s, strnlen(hdr, sizeof(hdr)));
+
+	for (i = 0; i < FBNIC_RPC_TCAM_IP_ADDR_NUM_ENTRIES; i++, ip_addr++) {
+		seq_printf(s, "%02d  %d %64pb %d %pi6\n",
+			   i, ip_addr->state, ip_addr->act_tcam,
+			   ip_addr->version, &ip_addr->value);
+		seq_printf(s, "                          %pi6\n",
+			   &ip_addr->mask);
+	}
+
+	return 0;
+}
+
+static int fbnic_dbg_ip_src_show(struct seq_file *s, void *v)
+{
+	struct fbnic_dev *fbd = s->private;
+
+	return fbnic_dbg_ip_addr_show(s, fbd->ip_src);
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_ip_src);
+
+static int fbnic_dbg_ip_dst_show(struct seq_file *s, void *v)
+{
+	struct fbnic_dev *fbd = s->private;
+
+	return fbnic_dbg_ip_addr_show(s, fbd->ip_dst);
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_ip_dst);
+
+static int fbnic_dbg_ipo_src_show(struct seq_file *s, void *v)
+{
+	struct fbnic_dev *fbd = s->private;
+
+	return fbnic_dbg_ip_addr_show(s, fbd->ipo_src);
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_ipo_src);
+
+static int fbnic_dbg_ipo_dst_show(struct seq_file *s, void *v)
+{
+	struct fbnic_dev *fbd = s->private;
+
+	return fbnic_dbg_ip_addr_show(s, fbd->ipo_dst);
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_ipo_dst);
+
 static int fbnic_dbg_pcie_stats_show(struct seq_file *s, void *v)
 {
 	struct fbnic_dev *fbd = s->private;
@@ -84,6 +210,18 @@ void fbnic_dbg_fbd_init(struct fbnic_dev *fbd)
 			    &fbnic_dbg_pcie_stats_fops);
 	debugfs_create_file("mac_addr", 0400, fbd->dbg_fbd, fbd,
 			    &fbnic_dbg_mac_addr_fops);
+	debugfs_create_file("tce_tcam", 0400, fbd->dbg_fbd, fbd,
+			    &fbnic_dbg_tce_tcam_fops);
+	debugfs_create_file("act_tcam", 0400, fbd->dbg_fbd, fbd,
+			    &fbnic_dbg_act_tcam_fops);
+	debugfs_create_file("ip_src", 0400, fbd->dbg_fbd, fbd,
+			    &fbnic_dbg_ip_src_fops);
+	debugfs_create_file("ip_dst", 0400, fbd->dbg_fbd, fbd,
+			    &fbnic_dbg_ip_dst_fops);
+	debugfs_create_file("ipo_src", 0400, fbd->dbg_fbd, fbd,
+			    &fbnic_dbg_ipo_src_fops);
+	debugfs_create_file("ipo_dst", 0400, fbd->dbg_fbd, fbd,
+			    &fbnic_dbg_ipo_dst_fops);
 }
 
 void fbnic_dbg_fbd_exit(struct fbnic_dev *fbd)
Signature · 1 line
2.48.1
#14 lore raw

Re: [PATCH net-next 7/7] eth: fbnic: support listing tcam content via debugfs

Hi Jakub,

One minor nit in line. Looks good otherwise.

Quoted 48 lines · Jakub Kicinski

From: Alexander Duyck <[email protected]>

The device has a handful of relatively small TCAM tables, support dumping the driver state via debugfs.

  # ethtool -N eth0 flow-type tcp6 \
      dst-ip 1111::2222 dst-port $((0x1122)) \
      src-ip 3333::4444 src-port $((0x3344)) \
      action 2
  Added rule with ID 47
  # cd $dbgfs
  # cat ip_src
  Idx S TCAM Bitmap       V Addr/Mask
  ------------------------------------
  00  1 00020000,00000000 6 33330000000000000000000000004444
                            00000000000000000000000000000000
  ...
  # cat ip_dst
  Idx S TCAM Bitmap       V Addr/Mask
  ------------------------------------
  00  1 00020000,00000000 6 11110000000000000000000000002222
                            00000000000000000000000000000000
  ...
  # cat act_tcam
  Idx S Value/Mask                                              RSS  Dest
  ------------------------------------------------------------------------
  ...
  49  1 0000 0000 0000 0000 0000 0000 1122 3344 0000 9c00 0088  000f 00000212
        ffff ffff ffff ffff ffff ffff 0000 0000 ffff 23ff ff00
  ...

The ipo_* tables are for outer IP addresses.
The tce_* table is for directing/stealing traffic to NC-SI.

---
 .../net/ethernet/meta/fbnic/fbnic_debugfs.c   | 138 ++++++++++++++++++
 1 file changed, 138 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c +0 -0
index ac80981f67c0..e8f2d7f2d962 100644

drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c static int fbnic_dbg_mac_addr_show(struct seq_file *s, void *v) · line 51

Quoted 8 lines
drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c +5 -0
@@ -44,6 +44,132 @@ static int fbnic_dbg_mac_addr_show(struct seq_file *s, void *v)
 }
 DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_mac_addr);
 
+static int fbnic_dbg_tce_tcam_show(struct seq_file *s, void *v)
+{
+       struct fbnic_dev *fbd = s->private;
+       int i, tcam_idx = 0;
+       char hdr[80];

This magic number, 80 is used at multiple places. Can you have a macro for this?

Quoted 147 lines
drivers/net/ethernet/meta/fbnic/fbnic_debugfs.c +133 -1
+
+       /* Generate Header */
+       snprintf(hdr, sizeof(hdr), "%3s %s %-17s %s\n",
+                "Idx", "S", "TCAM Bitmap", "Addr/Mask");
+       seq_puts(s, hdr);
+       fbnic_dbg_desc_break(s, strnlen(hdr, sizeof(hdr)));
+
+       for (i = 0; i < ARRAY_SIZE(fbd->mac_addr); i++) {
+               struct fbnic_mac_addr *mac_addr = &fbd->mac_addr[i];
+
+               /* Verify BMC bit is set */
+               if (!test_bit(FBNIC_MAC_ADDR_T_BMC, mac_addr->act_tcam))
+                       continue;
+
+               if (tcam_idx == FBNIC_TCE_TCAM_NUM_ENTRIES)
+                       break;
+
+               seq_printf(s, "%02d  %d %64pb %pm\n",
+                          tcam_idx, mac_addr->state, mac_addr->act_tcam,
+                          mac_addr->value.addr8);
+               seq_printf(s, "                        %pm\n",
+                          mac_addr->mask.addr8);
+               tcam_idx++;
+       }
+
+       return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_tce_tcam);
+
+static int fbnic_dbg_act_tcam_show(struct seq_file *s, void *v)
+{
+       struct fbnic_dev *fbd = s->private;
+       char hdr[80];
+       int i;
+
+       /* Generate Header */
+       snprintf(hdr, sizeof(hdr), "%3s %s %-55s %-4s %s\n",
+                "Idx", "S", "Value/Mask", "RSS", "Dest");
+       seq_puts(s, hdr);
+       fbnic_dbg_desc_break(s, strnlen(hdr, sizeof(hdr)));
+
+       for (i = 0; i < FBNIC_RPC_TCAM_ACT_NUM_ENTRIES; i++) {
+               struct fbnic_act_tcam *act_tcam = &fbd->act_tcam[i];
+
+               seq_printf(s, "%02d  %d %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x  %04x %08x\n",
+                          i, act_tcam->state,
+                          act_tcam->value.tcam[10], act_tcam->value.tcam[9],
+                          act_tcam->value.tcam[8], act_tcam->value.tcam[7],
+                          act_tcam->value.tcam[6], act_tcam->value.tcam[5],
+                          act_tcam->value.tcam[4], act_tcam->value.tcam[3],
+                          act_tcam->value.tcam[2], act_tcam->value.tcam[1],
+                          act_tcam->value.tcam[0], act_tcam->rss_en_mask,
+                          act_tcam->dest);
+               seq_printf(s, "      %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n",
+                          act_tcam->mask.tcam[10], act_tcam->mask.tcam[9],
+                          act_tcam->mask.tcam[8], act_tcam->mask.tcam[7],
+                          act_tcam->mask.tcam[6], act_tcam->mask.tcam[5],
+                          act_tcam->mask.tcam[4], act_tcam->mask.tcam[3],
+                          act_tcam->mask.tcam[2], act_tcam->mask.tcam[1],
+                          act_tcam->mask.tcam[0]);
+       }
+
+       return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_act_tcam);
+
+static int fbnic_dbg_ip_addr_show(struct seq_file *s,
+                                 struct fbnic_ip_addr *ip_addr)
+{
+       char hdr[80];
+       int i;
+
+       /* Generate Header */
+       snprintf(hdr, sizeof(hdr), "%3s %s %-17s %s %s\n",
+                "Idx", "S", "TCAM Bitmap", "V", "Addr/Mask");
+       seq_puts(s, hdr);
+       fbnic_dbg_desc_break(s, strnlen(hdr, sizeof(hdr)));
+
+       for (i = 0; i < FBNIC_RPC_TCAM_IP_ADDR_NUM_ENTRIES; i++, ip_addr++) {
+               seq_printf(s, "%02d  %d %64pb %d %pi6\n",
+                          i, ip_addr->state, ip_addr->act_tcam,
+                          ip_addr->version, &ip_addr->value);
+               seq_printf(s, "                          %pi6\n",
+                          &ip_addr->mask);
+       }
+
+       return 0;
+}
+
+static int fbnic_dbg_ip_src_show(struct seq_file *s, void *v)
+{
+       struct fbnic_dev *fbd = s->private;
+
+       return fbnic_dbg_ip_addr_show(s, fbd->ip_src);
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_ip_src);
+
+static int fbnic_dbg_ip_dst_show(struct seq_file *s, void *v)
+{
+       struct fbnic_dev *fbd = s->private;
+
+       return fbnic_dbg_ip_addr_show(s, fbd->ip_dst);
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_ip_dst);
+
+static int fbnic_dbg_ipo_src_show(struct seq_file *s, void *v)
+{
+       struct fbnic_dev *fbd = s->private;
+
+       return fbnic_dbg_ip_addr_show(s, fbd->ipo_src);
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_ipo_src);
+
+static int fbnic_dbg_ipo_dst_show(struct seq_file *s, void *v)
+{
+       struct fbnic_dev *fbd = s->private;
+
+       return fbnic_dbg_ip_addr_show(s, fbd->ipo_dst);
+}
+DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_ipo_dst);
+
 static int fbnic_dbg_pcie_stats_show(struct seq_file *s, void *v)
 {
        struct fbnic_dev *fbd = s->private;
@@ -84,6 +210,18 @@ void fbnic_dbg_fbd_init(struct fbnic_dev *fbd)
                            &fbnic_dbg_pcie_stats_fops);
        debugfs_create_file("mac_addr", 0400, fbd->dbg_fbd, fbd,
                            &fbnic_dbg_mac_addr_fops);
+       debugfs_create_file("tce_tcam", 0400, fbd->dbg_fbd, fbd,
+                           &fbnic_dbg_tce_tcam_fops);
+       debugfs_create_file("act_tcam", 0400, fbd->dbg_fbd, fbd,
+                           &fbnic_dbg_act_tcam_fops);
+       debugfs_create_file("ip_src", 0400, fbd->dbg_fbd, fbd,
+                           &fbnic_dbg_ip_src_fops);
+       debugfs_create_file("ip_dst", 0400, fbd->dbg_fbd, fbd,
+                           &fbnic_dbg_ip_dst_fops);
+       debugfs_create_file("ipo_src", 0400, fbd->dbg_fbd, fbd,
+                           &fbnic_dbg_ipo_src_fops);
+       debugfs_create_file("ipo_dst", 0400, fbd->dbg_fbd, fbd,
+                           &fbnic_dbg_ipo_dst_fops);
 }
 
 void fbnic_dbg_fbd_exit(struct fbnic_dev *fbd)
--

2.48.1

Signature · 2 lines
Regards,
Kalesh AP
author maintainer
#15 lore raw

Re: [PATCH net-next 7/7] eth: fbnic: support listing tcam content via debugfs

Quoted 2 lines · On Fri, 7 Feb 2025 08:16:18 +0530 Kalesh Anakkur Purayil wrote:
Quoted 1 line

+ char hdr[80];

This magic number, 80 is used at multiple places. Can you have a macro for this?

Can do, tho, it doesn't have any particular meaning. It's just the default terminal width.

Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH net-next 1/7] net: ethtool: prevent flow steering to RSS contexts which don't exist

In reply to Jakub Kicinski
Quoted 5 lines · Jakub Kicinski

Since commit 42dc431f5d0e ("ethtool: rss: prevent rss ctx deletion when in use") we prevent removal of RSS contexts pointed to by existing flow rules. Core should also prevent creation of rules which point to RSS context which don't exist in the first place.

Quoted 7 lines

---
CC: [email protected]
CC: [email protected]

---
 net/ethtool/ioctl.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Reviewed-by on v1 2/7
#7 lore raw

Re: [PATCH net-next 2/7] selftests: net-drv: test adding flow rule to invalid RSS context

In reply to Jakub Kicinski
Quoted 11 lines · Jakub Kicinski

Check that adding Rx flow steering rules pointing to an RSS context which does not exist is prevented.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 .../selftests/drivers/net/hw/rss_ctx.py       | 27 ++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
Reviewed-by on v1 3/7
#9 lore raw

Re: [PATCH net-next 3/7] eth: fbnic: support an additional RSS context

In reply to Jakub Kicinski
Quoted 21 lines · Jakub Kicinski

From: Daniel Zahka <[email protected]>

Add support for an extra RSS context. The device has a primary and a secondary context.

---
 .../net/ethernet/meta/fbnic/fbnic_ethtool.c   | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +2 -0
index 20cd9f5f89e2..4d73b405c8b9 100644
@@ -374,6 +374,61 @@ fbnic_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh,
 	return 0;
 }
 
+static int
+fbnic_modify_rxfh_context(struct net_device *netdev,

drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c fbnic_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh, · line 388

Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +10 -0
+			  struct ethtool_rxfh_context *ctx,
+			  const struct ethtool_rxfh_param *rxfh,
+			  struct netlink_ext_ack *extack)
+{
+	struct fbnic_net *fbn = netdev_priv(netdev);
+	const u32 *indir = rxfh->indir;
+	unsigned int changes;
+
+	if (!indir)
+		indir = ethtool_rxfh_context_indir(ctx);

Was slightly confused by this, but I assume that there's an indirection table in core and its possible that modify_rxfh_context is called without a call to create... maybe in the case of the default RSS context or something?

At any rate after browsing the fbnic code a bit: LGTM.

#3 lore raw

Re: [PATCH net-next 1/7] net: ethtool: prevent flow steering to RSS contexts which don't exist

In reply to Jakub Kicinski
Quoted 2 lines · Jakub Kicinski

Since commit 42dc431f5d0e ("ethtool: rss: prevent rss ctx deletion when in use") we prevent removal of RSS contexts pointed to by

Nit: I would try to avoid the line break in the middle of the cited commit.

Quoted 16 lines

existing flow rules. Core should also prevent creation of rules which point to RSS context which don't exist in the first place.

---
CC: [email protected]
CC: [email protected]

---
 net/ethtool/ioctl.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
net/ethtool/ioctl.c +0 -0
index 7609ce2b2c5e..98b7dcea207a 100644

net/ethtool/ioctl.c static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, · line 995

Quoted 3 lines
net/ethtool/ioctl.c +0 -0
@@ -993,10 +993,14 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
 		return rc;
 
 	/* Nonzero ring with RSS only makes sense if NIC adds them together */

This comment should be moved inside the if statement.

net/ethtool/ioctl.c static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, · line 1001

Quoted 10 lines
net/ethtool/ioctl.c +6 -4
-	if (cmd == ETHTOOL_SRXCLSRLINS && info.fs.flow_type & FLOW_RSS &&
-	    !ops->cap_rss_rxnfc_adds &&
-	    ethtool_get_flow_spec_ring(info.fs.ring_cookie))
-		return -EINVAL;
+	if (cmd == ETHTOOL_SRXCLSRLINS && info.fs.flow_type & FLOW_RSS) {
+		if (!ops->cap_rss_rxnfc_adds &&
+		    ethtool_get_flow_spec_ring(info.fs.ring_cookie))
+			return -EINVAL;
+
+		if (!xa_load(&dev->ethtool->rss_ctx, info.rss_context))

Accessing rss_ctx without rss_lock?

Quoted 5 lines
net/ethtool/ioctl.c +2 -0
+			return -EINVAL;
+	}
 
 	if (cmd == ETHTOOL_SRXFH && ops->get_rxfh) {
 		struct ethtool_rxfh_param rxfh = {};
#16 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 33 lines · On Thu, 6 Feb 2025 15:53:27 -0800 you wrote:

Add support for RSS contexts and ntuple filters in fbnic. The device has only one context, intended for use by TCP zero-copy Rx.

First two patches add a check we seem to be missing in the core, to avoid having to copy it to all drivers.

  $ ./drivers/net/hw/rss_ctx.py
  KTAP version 1
  1..16
  ok 1 rss_ctx.test_rss_key_indir
  ok 2 rss_ctx.test_rss_queue_reconfigure
  ok 3 rss_ctx.test_rss_resize
  ok 4 rss_ctx.test_hitless_key_update
  ok 5 rss_ctx.test_rss_context
  # Failed to create context 2, trying to test what we got
  ok 6 rss_ctx.test_rss_context4 # SKIP Tested only 1 contexts, wanted 4
  # Increasing queue count 44 -> 66
  # Failed to create context 2, trying to test what we got
  ok 7 rss_ctx.test_rss_context32 # SKIP Tested only 1 contexts, wanted 32
  # Added only 1 out of 3 contexts
  ok 8 rss_ctx.test_rss_context_dump
  # Driver does not support rss + queue offset
  ok 9 rss_ctx.test_rss_context_queue_reconfigure
  ok 10 rss_ctx.test_rss_context_overlap
  ok 11 rss_ctx.test_rss_context_overlap2 # SKIP Test requires at least 2 contexts, but device only has 1
  ok 12 rss_ctx.test_rss_context_out_of_order # SKIP Test requires at least 4 contexts, but device only has 1
  # Failed to create context 2, trying to test what we got
  ok 13 rss_ctx.test_rss_context4_create_with_cfg # SKIP Tested only 1 contexts, wanted 4
  ok 14 rss_ctx.test_flow_add_context_missing
  ok 15 rss_ctx.test_delete_rss_context_busy
  ok 16 rss_ctx.test_rss_ntuple_addition # SKIP Ntuple filter with RSS and nonzero action not supported
  # Totals: pass:10 fail:0 xfail:0 xpass:0 skip:6 error:0
Quoted 1 line

[...]

Here is the summary with links:
- [net-next,1/7] net: ethtool: prevent flow steering to RSS contexts which don't exist

    https://git.kernel.org/netdev/net-next/c/de7f7582dff2
  - [net-next,2/7] selftests: net-drv: test adding flow rule to invalid RSS context
    https://git.kernel.org/netdev/net-next/c/23bac399104c
  - [net-next,3/7] eth: fbnic: support an additional RSS context
    https://git.kernel.org/netdev/net-next/c/260676ebb1f3
  - [net-next,4/7] eth: fbnic: add IP TCAM programming
    (no matching commit)
  - [net-next,5/7] eth: fbnic: support n-tuple filters
    (no matching commit)
  - [net-next,6/7] selftests: drv-net: rss_ctx: skip tests which need multiple contexts cleanly
    https://git.kernel.org/netdev/net-next/c/d2348b4bf748
  - [net-next,7/7] eth: fbnic: support listing tcam content via debugfs
    https://git.kernel.org/netdev/net-next/c/5797d3c62db8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#18 lore raw
Quoted 7 lines · On Wed, 12 Feb 2025 08:05:31 +0200 Gal Pressman wrote:
Quoted 4 lines · On 10/02/2025 18:30, [email protected] wrote:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

You ignored my comments on patch #1.

Ah, sorry about that! Not sure how I missed it, maybe the ongoing lore problems :(

author maintainer
#4 lore raw

Re: [PATCH net-next 1/7] net: ethtool: prevent flow steering to RSS contexts which don't exist

In reply to Gal Pressman
Quoted 3 lines · On Sun, 9 Feb 2025 10:17:30 +0200 Gal Pressman wrote:
Quoted 1 line

/* Nonzero ring with RSS only makes sense if NIC adds them together */

This comment should be moved inside the if statement.

Will follow up, sorry.

Quoted 4 lines
Quoted 4 lines
net/ethtool/ioctl.c +0 -4
-	if (cmd == ETHTOOL_SRXCLSRLINS && info.fs.flow_type & FLOW_RSS &&
-	    !ops->cap_rss_rxnfc_adds &&
-	    ethtool_get_flow_spec_ring(info.fs.ring_cookie))
-		return -EINVAL;
Quoted 8 lines

net/ethtool/ioctl.c static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, · line 1001

Quoted 6 lines
net/ethtool/ioctl.c +6 -0
+	if (cmd == ETHTOOL_SRXCLSRLINS && info.fs.flow_type & FLOW_RSS) {
+		if (!ops->cap_rss_rxnfc_adds &&
+		    ethtool_get_flow_spec_ring(info.fs.ring_cookie))
+			return -EINVAL;
+
+		if (!xa_load(&dev->ethtool->rss_ctx, info.rss_context))  

Accessing rss_ctx without rss_lock?

Yes, same as ethtool_get_max_rxnfc_channel(). Since we'd have to drop the lock instantly after the check the whole rule addition wouldn't be atomic under that lock, anyway. IOW the xa_load() access is safe in itself, and I couldn't think of practical use for taking the rss lock.