Skip to contentSkip to conversation

macsec: inherit lower device's features and TSO limits when offloading

PATCH Applied Sabrina Dubroca 3 participants 18 messages Nov 6, 2024 – Nov 11, 2024

Subsystems (7)
lore
Share & tools
lore

Sabrina Dubroca

author maintainer
#0 lore raw

cover macsec: inherit lower device's features and TSO limits when offloading

When macsec is offloaded to a NIC, we can take advantage of some of its features, mainly TSO and checksumming. This increases performance significantly. Some features cannot be inherited, because they require additional ops that aren't provided by the macsec netdevice.

We also need to inherit TSO limits from the lower device, like VLAN/macvlan devices do.

This series also moves the existing macsec offload selftest to the netdevsim selftests before adding tests for the new features. To allow this new selftest to work, netdevsim's hw_features are expanded.

Sabrina Dubroca (8):
netdevsim: add more hw_features
selftests: netdevsim: add a test checking ethtool features
macsec: add some of the lower device's features when offloading
macsec: clean up local variables in macsec_notify
macsec: inherit lower device's TSO limits when offloading
selftests: move macsec offload tests from net/rtnetlink to
drivers/net/netdvesim
selftests: netdevsim: add test toggling macsec offload
selftests: netdevsim: add ethtool features to macsec offload tests

 drivers/net/macsec.c                          |  64 +++++++---
 drivers/net/netdevsim/netdev.c                |   6 +-
 .../selftests/drivers/net/netdevsim/Makefile  |   2 +
 .../selftests/drivers/net/netdevsim/config    |   1 +
 .../drivers/net/netdevsim/ethtool-features.sh |  31 +++++
 .../drivers/net/netdevsim/macsec-offload.sh   | 117 ++++++++++++++++++
 tools/testing/selftests/net/rtnetlink.sh      |  68 ----------
 7 files changed, 200 insertions(+), 89 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/netdevsim/ethtool-features.sh
 create mode 100755 tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh
Signature · 1 line
2.47.0
author maintainer
#1 lore raw

PATCH 1/8 netdevsim: add more hw_features

netdevsim currently only set HW_TC in its hw_features, but other features should also be present to better reflect the behavior of real HW.

In my macsec offload testing, this ends up as HW_CSUM being missing from hw_features, so it doesn't stick in wanted_features when offload is turned off. Then HW_CSUM (and thus TSO, thanks to netdev_fix_features) is not automatically turned back on when offload is re-enabled.

---
 drivers/net/netdevsim/netdev.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/netdevsim/netdev.c +5 -1
index cad85bb0cf54..0be47fed4efc 100644
@@ -663,7 +663,11 @@ static void nsim_setup(struct net_device *dev)
 			 NETIF_F_FRAGLIST |
 			 NETIF_F_HW_CSUM |
 			 NETIF_F_TSO;
-	dev->hw_features |= NETIF_F_HW_TC;
+	dev->hw_features |= NETIF_F_HW_TC |
+			    NETIF_F_SG |
+			    NETIF_F_FRAGLIST |
+			    NETIF_F_HW_CSUM |
+			    NETIF_F_TSO;
 	dev->max_mtu = ETH_MAX_MTU;
 	dev->xdp_features = NETDEV_XDP_ACT_HW_OFFLOAD;
 }
Signature · 1 line
2.47.0
author maintainer
#3 lore raw

PATCH 2/8 selftests: netdevsim: add a test checking ethtool features

In reply to Sabrina Dubroca

Add a test checking that some features are active by default and changeable.

---
 .../selftests/drivers/net/netdevsim/Makefile  |  1 +
 .../drivers/net/netdevsim/ethtool-features.sh | 31 +++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/net/netdevsim/ethtool-features.sh
tools/testing/selftests/drivers/net/netdevsim/Makefile +1 -0
index cc08b220323f..df167c637af9 100644
@@ -4,6 +4,7 @@ TEST_PROGS = devlink.sh \
 	devlink_in_netns.sh \
 	devlink_trap.sh \
 	ethtool-coalesce.sh \
+	ethtool-features.sh \
 	ethtool-fec.sh \
 	ethtool-pause.sh \
 	ethtool-ring.sh \
tools/testing/selftests/drivers/net/netdevsim/ethtool-features.sh new file +31 -0
new file mode 100644
index 000000000000..bc210dc6ad2d
@@ -0,0 +1,31 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only
+
+source ethtool-common.sh
+
+NSIM_NETDEV=$(make_netdev)
+
+set -o pipefail
+
+FEATS="
+  tx-checksum-ip-generic
+  tx-scatter-gather
+  tx-tcp-segmentation
+  generic-segmentation-offload
+  generic-receive-offload"
+
+for feat in $FEATS ; do
+    s=$(ethtool --json -k $NSIM_NETDEV | jq ".[].\"$feat\".active" 2>/dev/null)
+    check $? "$s" true
+
+    s=$(ethtool --json -k $NSIM_NETDEV | jq ".[].\"$feat\".fixed" 2>/dev/null)
+    check $? "$s" false
+done
+
+if [ $num_errors -eq 0 ]; then
+    echo "PASSED all $((num_passes)) checks"
+    exit 0
+else
+    echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
+    exit 1
+fi
Signature · 1 line
2.47.0
author maintainer
#5 lore raw

PATCH 3/8 macsec: add some of the lower device's features when offloading

In reply to Sabrina Dubroca

This commit extends the set of netdevice features supported by macsec devices when offload is enabled, which increases performance significantly (for a single TCP stream: 17.5Gbps to 38.5Gbps on my test machines).

Commit c850240b6c41 ("net: macsec: report real_dev features when HW offloading is enabled") previously attempted something similar, but had to be reverted (commit 8bcd560ae878 ("Revert "net: macsec: report real_dev features when HW offloading is enabled"")) because the set of features it exposed was too large.

During initialization, all features are set, and they're then removed via ndo_fix_features (macsec_fix_features). This allows the offloadable features to be automatically enabled if offloading is turned on after device creation.

---
 drivers/net/macsec.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/net/macsec.c +15 -2
index ee2159282573..bee1e0f95d2a 100644
@@ -2666,6 +2666,8 @@ static int macsec_update_offload(struct net_device *dev, enum macsec_offload off
 	macsec_set_head_tail_room(dev);
 	macsec->insert_tx_tag = macsec_needs_tx_tag(macsec, ops);
 
+	netdev_update_features(dev);
+
 	return ret;
 }
 
@@ -3521,6 +3523,10 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
 #define MACSEC_FEATURES \
 	(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
 
+#define MACSEC_OFFLOAD_FEATURES \
+	(MACSEC_FEATURES | NETIF_F_GSO_SOFTWARE | NETIF_F_SOFT_FEATURES | \
+	 NETIF_F_LRO | NETIF_F_RXHASH | NETIF_F_CSUM_MASK | NETIF_F_RXCSUM)
+
 static int macsec_dev_init(struct net_device *dev)
 {
 	struct macsec_dev *macsec = macsec_priv(dev);
@@ -3531,7 +3537,10 @@ static int macsec_dev_init(struct net_device *dev)
 	if (err)
 		return err;
 
-	dev->features = real_dev->features & MACSEC_FEATURES;
+	dev->hw_features = real_dev->hw_features & MACSEC_OFFLOAD_FEATURES;
+	dev->hw_features |= NETIF_F_GSO_SOFTWARE;
+
+	dev->features = real_dev->features & MACSEC_OFFLOAD_FEATURES;
 	dev->features |= NETIF_F_GSO_SOFTWARE;
 	dev->lltx = true;
 	dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
@@ -3561,8 +3570,12 @@ static netdev_features_t macsec_fix_features(struct net_device *dev,
 {
 	struct macsec_dev *macsec = macsec_priv(dev);
 	struct net_device *real_dev = macsec->real_dev;
+	netdev_features_t mask;
+
+	mask = macsec_is_offloaded(macsec) ? MACSEC_OFFLOAD_FEATURES
+					   : MACSEC_FEATURES;
 
-	features &= (real_dev->features & MACSEC_FEATURES) |
+	features &= (real_dev->features & mask) |
 		    NETIF_F_GSO_SOFTWARE | NETIF_F_SOFT_FEATURES;
 
 	return features;
Signature · 1 line
2.47.0
author maintainer
#7 lore raw

PATCH 4/8 macsec: clean up local variables in macsec_notify

In reply to Sabrina Dubroca

For all events, we need to loop over the list of secys, so let's move the common variables out of the switch/case.

---
 drivers/net/macsec.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)
drivers/net/macsec.c +7 -18
index bee1e0f95d2a..e6670e876ff6 100644
@@ -4441,31 +4441,26 @@ static int macsec_notify(struct notifier_block *this, unsigned long event,
 			 void *ptr)
 {
 	struct net_device *real_dev = netdev_notifier_info_to_dev(ptr);
+	struct macsec_rxh_data *rxd;
+	struct macsec_dev *m, *n;
 	LIST_HEAD(head);
 
 	if (!is_macsec_master(real_dev))
 		return NOTIFY_DONE;
 
+	rxd = macsec_data_rtnl(real_dev);
+
 	switch (event) {
 	case NETDEV_DOWN:
 	case NETDEV_UP:
-	case NETDEV_CHANGE: {
-		struct macsec_dev *m, *n;
-		struct macsec_rxh_data *rxd;
-
-		rxd = macsec_data_rtnl(real_dev);
+	case NETDEV_CHANGE:
 		list_for_each_entry_safe(m, n, &rxd->secys, secys) {
 			struct net_device *dev = m->secy.netdev;
 
 			netif_stacked_transfer_operstate(real_dev, dev);
 		}
 		break;
-	}
-	case NETDEV_UNREGISTER: {
-		struct macsec_dev *m, *n;
-		struct macsec_rxh_data *rxd;
-
-		rxd = macsec_data_rtnl(real_dev);
+	case NETDEV_UNREGISTER:
 		list_for_each_entry_safe(m, n, &rxd->secys, secys) {
 			macsec_common_dellink(m->secy.netdev, &head);
 		}
@@ -4475,12 +4470,7 @@ static int macsec_notify(struct notifier_block *this, unsigned long event,
 
 		unregister_netdevice_many(&head);
 		break;
-	}
-	case NETDEV_CHANGEMTU: {
-		struct macsec_dev *m;
-		struct macsec_rxh_data *rxd;
-
-		rxd = macsec_data_rtnl(real_dev);
+	case NETDEV_CHANGEMTU:
 		list_for_each_entry(m, &rxd->secys, secys) {
 			struct net_device *dev = m->secy.netdev;
 			unsigned int mtu = real_dev->mtu - (m->secy.icv_len +
@@ -4490,7 +4480,6 @@ static int macsec_notify(struct notifier_block *this, unsigned long event,
 				dev_set_mtu(dev, mtu);
 		}
 	}
-	}
 
 	return NOTIFY_OK;
 }
Signature · 1 line
2.47.0
author maintainer
#9 lore raw

PATCH 5/8 macsec: inherit lower device's TSO limits when offloading

In reply to Sabrina Dubroca

If macsec is offloaded, we need to follow the lower device's capabilities, like VLAN devices do.

Leave the limits unchanged when the offload is disabled.

---
 drivers/net/macsec.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/net/macsec.c +22 -0
index e6670e876ff6..24c190d9b959 100644
@@ -2621,6 +2621,17 @@ static void macsec_set_head_tail_room(struct net_device *dev)
 	dev->needed_tailroom = real_dev->needed_tailroom + needed_tailroom;
 }
 
+static void macsec_inherit_tso_max(struct net_device *dev)
+{
+	struct macsec_dev *macsec = macsec_priv(dev);
+
+	/* if macsec is offloaded, we need to follow the lower
+	 * device's capabilities. otherwise, we can ignore them.
+	 */
+	if (macsec_is_offloaded(macsec))
+		netif_inherit_tso_max(dev, macsec->real_dev);
+}
+
 static int macsec_update_offload(struct net_device *dev, enum macsec_offload offload)
 {
 	enum macsec_offload prev_offload;
@@ -2666,6 +2677,8 @@ static int macsec_update_offload(struct net_device *dev, enum macsec_offload off
 	macsec_set_head_tail_room(dev);
 	macsec->insert_tx_tag = macsec_needs_tx_tag(macsec, ops);
 
+	macsec_inherit_tso_max(dev);
+
 	netdev_update_features(dev);
 
 	return ret;
@@ -3537,6 +3550,8 @@ static int macsec_dev_init(struct net_device *dev)
 	if (err)
 		return err;
 
+	macsec_inherit_tso_max(dev);
+
 	dev->hw_features = real_dev->hw_features & MACSEC_OFFLOAD_FEATURES;
 	dev->hw_features |= NETIF_F_GSO_SOFTWARE;
 
@@ -4479,6 +4494,13 @@ static int macsec_notify(struct notifier_block *this, unsigned long event,
 			if (dev->mtu > mtu)
 				dev_set_mtu(dev, mtu);
 		}
+		break;
+	case NETDEV_FEAT_CHANGE:
+		list_for_each_entry(m, &rxd->secys, secys) {
+			macsec_inherit_tso_max(m->secy.netdev);
+			netdev_update_features(m->secy.netdev);
+		}
+		break;
 	}
 
 	return NOTIFY_OK;
Signature · 1 line
2.47.0
author maintainer
#11 lore raw

PATCH 6/8 selftests: move macsec offload tests from net/rtnetlink to drivers/net/netdvesim

In reply to Sabrina Dubroca

We're going to expand this test, and macsec offload is only lightly related to rtnetlink.

---
 .../selftests/drivers/net/netdevsim/Makefile  |  1 +
 .../selftests/drivers/net/netdevsim/config    |  1 +
 .../drivers/net/netdevsim/macsec-offload.sh   | 63 +++++++++++++++++
 tools/testing/selftests/net/rtnetlink.sh      | 68 -------------------
 4 files changed, 65 insertions(+), 68 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh
tools/testing/selftests/drivers/net/netdevsim/Makefile +1 -0
index df167c637af9..07b7c46d3311 100644
@@ -11,6 +11,7 @@ TEST_PROGS = devlink.sh \
 	fib.sh \
 	fib_notifications.sh \
 	hw_stats_l3.sh \
+	macsec-offload.sh \
 	nexthop.sh \
 	peer.sh \
 	psample.sh \
tools/testing/selftests/drivers/net/netdevsim/config +1 -0
index adf45a3a78b4..5117c78ddf0a 100644
@@ -1,6 +1,7 @@
 CONFIG_DUMMY=y
 CONFIG_GENEVE=m
 CONFIG_IPV6=y
+CONFIG_MACSEC=m
 CONFIG_NETDEVSIM=m
 CONFIG_NET_SCH_MQPRIO=y
 CONFIG_NET_SCH_MULTIQ=y
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh new file +63 -0

63 lines not on this page · raw message

tools/testing/selftests/net/rtnetlink.sh +0 -68

80 lines not on this page · raw message

Signature · 1 line
2.47.0
author maintainer
#13 lore raw

PATCH 7/8 selftests: netdevsim: add test toggling macsec offload

In reply to Sabrina Dubroca

The test verifies that toggling offload works (both via rtnetlink and macsec's genetlink APIs). This is only possible when no SA is configured.

---
 .../drivers/net/netdevsim/macsec-offload.sh   | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh +21 -0
index 7babcfd76b22..1f2775846ea0 100755
@@ -48,6 +48,27 @@ check $?
 ip macsec add "${MACSEC_NETDEV}" rx port 1235 address "1c:ed:de:ad:be:ef" 2> /dev/null
 check $? '' '' 1
 
+# can't disable macsec offload when SAs are configured
+ip link set "${MACSEC_NETDEV}" type macsec offload off 2> /dev/null
+check $? '' '' 1
+
+ip macsec offload "${MACSEC_NETDEV}" off 2> /dev/null
+check $? '' '' 1
+
+# toggle macsec offload via rtnetlink
+ip link set "${MACSEC_NETDEV}2" type macsec offload off
+check $?
+
+ip link set "${MACSEC_NETDEV}2" type macsec offload mac
+check $?
+
+# toggle macsec offload via genetlink
+ip macsec offload "${MACSEC_NETDEV}2" off
+check $?
+
+ip macsec offload "${MACSEC_NETDEV}2" mac
+check $?
+
 for dev in ${MACSEC_NETDEV}{,2,3} ; do
     ip link del $dev
     check $?
Signature · 1 line
2.47.0
author maintainer
#15 lore raw

PATCH 8/8 selftests: netdevsim: add ethtool features to macsec offload tests

In reply to Sabrina Dubroca

The test verifies that available features aren't changed by toggling offload on the device. Creating a device with offload off and then enabling it later should result in the same features as creating the device with offload enabled directly.

---
 .../drivers/net/netdevsim/macsec-offload.sh   | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh +33 -0
index 1f2775846ea0..98033e6667d2 100755
@@ -75,6 +75,39 @@ for dev in ${MACSEC_NETDEV}{,2,3} ; do
 done
 
 
+#
+# test ethtool features when toggling offload
+#
+
+ip link add link $NSIM_NETDEV $MACSEC_NETDEV type macsec offload mac
+TMP_FEATS_ON_1="$(ethtool -k $MACSEC_NETDEV)"
+
+ip link set $MACSEC_NETDEV type macsec offload off
+TMP_FEATS_OFF_1="$(ethtool -k $MACSEC_NETDEV)"
+
+ip link set $MACSEC_NETDEV type macsec offload mac
+TMP_FEATS_ON_2="$(ethtool -k $MACSEC_NETDEV)"
+
+[ "$TMP_FEATS_ON_1" = "$TMP_FEATS_ON_2" ]
+check $?
+
+ip link del $MACSEC_NETDEV
+
+ip link add link $NSIM_NETDEV $MACSEC_NETDEV type macsec
+check $?
+
+TMP_FEATS_OFF_2="$(ethtool -k $MACSEC_NETDEV)"
+[ "$TMP_FEATS_OFF_1" = "$TMP_FEATS_OFF_2" ]
+check $?
+
+ip link set $MACSEC_NETDEV type macsec offload mac
+check $?
+
+TMP_FEATS_ON_3="$(ethtool -k $MACSEC_NETDEV)"
+[ "$TMP_FEATS_ON_1" = "$TMP_FEATS_ON_3" ]
+check $?
+
+
 if [ $num_errors -eq 0 ]; then
     echo "PASSED all $((num_passes)) checks"
     exit 0
Signature · 1 line
2.47.0
reviewer Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH net-next 1/8] netdevsim: add more hw_features

In reply to Sabrina Dubroca
Quoted 11 lines · Sabrina Dubroca

netdevsim currently only set HW_TC in its hw_features, but other features should also be present to better reflect the behavior of real HW.

In my macsec offload testing, this ends up as HW_CSUM being missing from hw_features, so it doesn't stick in wanted_features when offload is turned off. Then HW_CSUM (and thus TSO, thanks to netdev_fix_features) is not automatically turned back on when offload is re-enabled.

reviewer Reviewed-by on v1 3/8
#6 lore raw

Re: [PATCH net-next 3/8] macsec: add some of the lower device's features when offloading

In reply to Sabrina Dubroca
Quoted 11 lines · Sabrina Dubroca

This commit extends the set of netdevice features supported by macsec devices when offload is enabled, which increases performance significantly (for a single TCP stream: 17.5Gbps to 38.5Gbps on my test machines).

Commit c850240b6c41 ("net: macsec: report real_dev features when HW offloading is enabled") previously attempted something similar, but had to be reverted (commit 8bcd560ae878 ("Revert "net: macsec: report real_dev features when HW offloading is enabled"")) because the set of features it exposed was too large.

Quoted 6 lines

During initialization, all features are set, and they're then removed via ndo_fix_features (macsec_fix_features). This allows the offloadable features to be automatically enabled if offloading is turned on after device creation.

reviewer Reviewed-by on v1 8/8
#16 lore raw

Re: [PATCH net-next 8/8] selftests: netdevsim: add ethtool features to macsec offload tests

In reply to Sabrina Dubroca
Quoted 6 lines · Sabrina Dubroca

The test verifies that available features aren't changed by toggling offload on the device. Creating a device with offload off and then enabling it later should result in the same features as creating the device with offload enabled directly.

#17 lore raw
In reply to Sabrina Dubroca
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 9 lines · On Thu, 7 Nov 2024 00:13:26 +0100 you wrote:

When macsec is offloaded to a NIC, we can take advantage of some of its features, mainly TSO and checksumming. This increases performance significantly. Some features cannot be inherited, because they require additional ops that aren't provided by the macsec netdevice.

We also need to inherit TSO limits from the lower device, like VLAN/macvlan devices do.

[...]

Here is the summary with links:
- [net-next,1/8] netdevsim: add more hw_features

    https://git.kernel.org/netdev/net-next/c/494bd83bb519
  - [net-next,2/8] selftests: netdevsim: add a test checking ethtool features
    https://git.kernel.org/netdev/net-next/c/0189270117c3
  - [net-next,3/8] macsec: add some of the lower device's features when offloading
    https://git.kernel.org/netdev/net-next/c/bd97c29f7e9e
  - [net-next,4/8] macsec: clean up local variables in macsec_notify
    https://git.kernel.org/netdev/net-next/c/f29d24a2106a
  - [net-next,5/8] macsec: inherit lower device's TSO limits when offloading
    https://git.kernel.org/netdev/net-next/c/de187a390838
  - [net-next,6/8] selftests: move macsec offload tests from net/rtnetlink to drivers/net/netdvesim
    https://git.kernel.org/netdev/net-next/c/415b7cef1c73
  - [net-next,7/8] selftests: netdevsim: add test toggling macsec offload
    https://git.kernel.org/netdev/net-next/c/29084ea5d0e8
  - [net-next,8/8] selftests: netdevsim: add ethtool features to macsec offload tests
    https://git.kernel.org/netdev/net-next/c/0f8800eb67ae

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html