Skip to contentSkip to conversation

netdevsim: support ETS offload

PATCH Superseded Davide Caratti 2 participants 6 messages Mar 17 – Mar 18

Subsystems (5)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover netdevsim: support ETS offload

- patch 1 moves netdevsim tc offloads to a dedicated file
- patch 2 enables ETS offload on netdevsim
- patch 3 is a tdc test for ets offload on netdevsim

v2: don't use x-macro (Jakub Kicinski)
v3: move function declaration from the bottom of netdevsim.h (Jakub Kicinski)

Davide Caratti (3):
netdevsim: move TC offload code to a dedicated file
netdevsim: support tc-ets offload
tc-testing: add a test case for ETS offload

 drivers/net/netdevsim/Makefile                |  2 +-
 drivers/net/netdevsim/netdev.c                | 51 ------------
 drivers/net/netdevsim/netdevsim.h             |  3 +
 drivers/net/netdevsim/tc.c                    | 79 +++++++++++++++++++
 .../tc-testing/tc-tests/qdiscs/ets.json       | 23 ++++++
 5 files changed, 106 insertions(+), 52 deletions(-)
 create mode 100644 drivers/net/netdevsim/tc.c
Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/3 netdevsim: move TC offload code to a dedicated file

This commit has no functional change.

---
 drivers/net/netdevsim/Makefile    |  2 +-
 drivers/net/netdevsim/netdev.c    | 51 ---------------------------
 drivers/net/netdevsim/netdevsim.h |  3 ++
 drivers/net/netdevsim/tc.c        | 57 +++++++++++++++++++++++++++++++
 4 files changed, 61 insertions(+), 52 deletions(-)
 create mode 100644 drivers/net/netdevsim/tc.c
drivers/net/netdevsim/Makefile +1 -1
index 14a553e000ec..87718204fb4d 100644
@@ -3,7 +3,7 @@
 obj-$(CONFIG_NETDEVSIM) += netdevsim.o
 
 netdevsim-objs := \
-	netdev.o dev.o ethtool.o fib.o bus.o health.o hwstats.o udp_tunnels.o
+	netdev.o dev.o ethtool.o fib.o bus.o health.o hwstats.o udp_tunnels.o tc.o
 
 ifeq ($(CONFIG_BPF_SYSCALL),y)
 netdevsim-objs += \
drivers/net/netdevsim/netdev.c +0 -51

63 lines not on this page · raw message

drivers/net/netdevsim/netdevsim.h +3 -0
index f767fc8a7505..c904e14f6b3f 100644
@@ -455,6 +455,9 @@ static inline void
 nsim_psp_handle_ext(struct sk_buff *skb, struct skb_ext *psp_ext) {}
 #endif
 
+int nsim_setup_tc(struct net_device *dev, enum tc_setup_type type,
+		  void *type_data);
+
 struct nsim_bus_dev {
 	struct device dev;
 	struct list_head list;
drivers/net/netdevsim/tc.c new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
2.52.0
#2 lore raw

PATCH v3 2/3 netdevsim: support tc-ets offload

In reply to Davide Caratti

Extend netdevsim to accept ndo_setup_tc(TC_SETUP_QDISC_ETS) calls, so that it's possible to run tdc on ETS offload code path.

---
 drivers/net/netdevsim/tc.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/net/netdevsim/tc.c +22 -0
index 8a1960f5f99e..8f013a5895a2 100644
@@ -2,6 +2,7 @@
 
 #include <linux/netdevice.h>
 #include <net/pkt_sched.h>
+#include <net/pkt_cls.h>
 
 #include "netdevsim.h"
 
@@ -36,6 +37,25 @@ static int nsim_setup_tc_taprio(struct net_device *dev,
 	return err;
 }
 
+static int nsim_setup_tc_ets(struct net_device *dev,
+			     struct tc_ets_qopt_offload *offload)
+{
+	int err = 0;
+
+	switch (offload->command) {
+	case TC_ETS_REPLACE:
+	case TC_ETS_DESTROY:
+		break;
+	case TC_ETS_STATS:
+		_bstats_update(offload->stats.bstats, 0, 0);
+		break;
+	default:
+		err = -EOPNOTSUPP;
+	}
+
+	return err;
+}
+
 static LIST_HEAD(nsim_block_cb_list);
 
 int
@@ -46,6 +66,8 @@ nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data)
 	switch (type) {
 	case TC_SETUP_QDISC_TAPRIO:
 		return nsim_setup_tc_taprio(dev, type_data);
+	case TC_SETUP_QDISC_ETS:
+		return nsim_setup_tc_ets(dev, type_data);
 	case TC_SETUP_BLOCK:
 		return flow_block_cb_setup_simple(type_data,
 						  &nsim_block_cb_list,
Signature · 1 line
2.52.0
#3 lore raw

PATCH v3 3/3 tc-testing: add a test case for ETS offload

In reply to Davide Caratti

While reviewing the fix for unintentional u32 overflows in ets offload code, Jamal said:

[...]

Quoted 2 lines

otherwise a tdc test should cover it fine (when you get to the netdevsim change perhaps)

Add a test case to reproduce the division by zero fixed in [1].

[1] https://lore.kernel.org/all/CAM0EoMm17wsYZmdFLshH3_-GrZtzd=i0xnoO2yiVB=-N4761mw@mail.gmail.com/

---
 .../tc-testing/tc-tests/qdiscs/ets.json       | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/qdiscs/ets.json +23 -0
index a5d94cdec605..479b866031bb 100644
@@ -984,5 +984,28 @@
         "matchCount": "1",
         "teardown": [
         ]
+    },
+    {
+        "id": "41f5",
+        "name": "ETS offload where the sum of quanta wraps u32",
+        "category": [
+            "qdisc",
+            "ets"
+        ],
+        "plugins": {
+            "requires": "nsPlugin"
+        },
+        "setup": [
+            "echo \"1 1 4\" > /sys/bus/netdevsim/new_device",
+            "ethtool -K $ETH hw-tc-offload on"
+        ],
+        "cmdUnderTest": "$TC qdisc add dev $ETH root ets quanta 4294967294 1 1",
+        "expExitCode": "0",
+        "verifyCmd": "$TC qdisc show dev $ETH",
+        "matchPattern": "qdisc ets .*bands 3 quanta 4294967294 1 1",
+        "matchCount": "1",
+        "teardown": [
+            "echo \"1\" > /sys/bus/netdevsim/del_device"
+        ]
     }
 ]
Signature · 1 line
2.52.0
#4 lore raw

Re: [PATCH net-next v3 3/3] tc-testing: add a test case for ETS offload

Quoted 9 lines · Davide Caratti

While reviewing the fix for unintentional u32 overflows in ets offload code, Jamal said:

[...]

Quoted 2 lines

otherwise a tdc test should cover it fine (when you get to the netdevsim change perhaps)

Quoted 8 lines

Add a test case to reproduce the division by zero fixed in [1].

[1] https://lore.kernel.org/all/CAM0EoMm17wsYZmdFLshH3_-GrZtzd=i0xnoO2yiVB=-N4761mw@mail.gmail.com/

Sorry for not noticing this earlier.
I tried some approaches with Jamal to avoid changing your patch, but changing it seems to be the cleanest way to do this. The issue is that tdc overwrites the environment when running the shell command from python so it can't find ethtool. We believe the cleanest approach here is to specify ethtool's path in tdc_config.py (as is done with tc and ip). Am sending a proposed change as an attached diff in this reply.

cheers,
Victor

tools/testing/selftests/tc-testing/tc-tests/qdiscs/ets.json +1 -1
index 479b866031bb..ee09e6d6fdf3 100644
@@ -997,7 +997,7 @@
         },
         "setup": [
             "echo \"1 1 4\" > /sys/bus/netdevsim/new_device",
-            "ethtool -K $ETH hw-tc-offload on"
+            "$ETHTOOL -K $ETH hw-tc-offload on"
         ],
         "cmdUnderTest": "$TC qdisc add dev $ETH root ets quanta 4294967294 1 1",
         "expExitCode": "0",
tools/testing/selftests/tc-testing/tdc.py +3 -0
index 4f255cec0c22..81b4ac3f050c 100755
@@ -755,6 +755,9 @@ def check_default_settings(args, remaining, pm):
         NAMES['DEV2'] = args.device
     if 'TIMEOUT' not in NAMES:
         NAMES['TIMEOUT'] = None
+    if 'ETHTOOL' in NAMES and not os.path.isfile(NAMES['ETHTOOL']):
+        print(f"The specified ethtool path {NAMES['ETHTOOL']} does not exist.")
+        exit(1)
     if not os.path.isfile(NAMES['TC']):
         print("The specified tc path " + NAMES['TC'] + " does not exist.")
         exit(1)
tools/testing/selftests/tc-testing/tdc_config.py +1 -0
index ccb0f06ef9e3..9488b03cbc2c 100644
@@ -17,6 +17,7 @@ NAMES = {
           'DEV1': 'v0p1',
           'DEV2': '',
           'DUMMY': 'dummy1',
+          'ETHTOOL': '/usr/sbin/ethtool',
 	  'ETH': 'eth0',
           'BATCH_FILE': './batch.txt',
           'BATCH_DIR': 'tmp',
#5 lore raw

Re: [PATCH net-next v3 3/3] tc-testing: add a test case for ETS offload

Quoted 10 lines · Victor Nogueira
Quoted 9 lines · Davide Caratti

While reviewing the fix for unintentional u32 overflows in ets offload code, Jamal said:

[...]

Quoted 2 lines

otherwise a tdc test should cover it fine (when you get to the netdevsim change perhaps)

Quoted 8 lines
Quoted 8 lines

Add a test case to reproduce the division by zero fixed in [1].

[1] https://lore.kernel.org/all/CAM0EoMm17wsYZmdFLshH3_-GrZtzd=i0xnoO2yiVB=-N4761mw@mail.gmail.com/

hello Victor, thanks for investigating!

Quoted 9 lines

Sorry for not noticing this earlier.
I tried some approaches with Jamal to avoid changing your patch, but changing it seems to be the cleanest way to do this. The issue is that tdc overwrites the environment when running the shell command from python so it can't find ethtool. We believe the cleanest approach here is to specify ethtool's path in tdc_config.py (as is done with tc and ip). Am sending a proposed change as an attached diff in this reply.

[...]

tools/testing/selftests/tc-testing/tdc_config.py NAMES = { · line 23

Quoted 12 lines
tools/testing/selftests/tc-testing/tdc_config.py +1 -0
index ccb0f06ef9e3..9488b03cbc2c 100644
@@ -17,6 +17,7 @@ NAMES = {
           'DEV1': 'v0p1',
           'DEV2': '',
           'DUMMY': 'dummy1',
+          'ETHTOOL': '/usr/sbin/ethtool',
 	  'ETH': 'eth0',
           'BATCH_FILE': './batch.txt',
           'BATCH_DIR': 'tmp',

I see, and maybe now understand why I didn't see this problem before. My fedora test setup does:

root@localhost:net# which ethtool 
/usr/bin/ethtool

and inside virtme-ng:

root@virtme-ng:net# which ethtool
/bin/ethtool

Moreover {,/usr}/sbin is a symlink because of [1], so it always finds ethtool _ and would find ethtool also with the $ETHTOOL assignment you did above; I'm ok for editing patch 3/3 adding the above hunks.

Signature · 3 lines
davide

[1] https://fedoraproject.org/wiki/Changes/Unify_bin_and_sbin