Skip to contentSkip to conversation

macsec: Add support for VLAN filtering in offload mode

PATCH Superseded Cosmin Ratiu 3 participants 16 messages Mar 30 – Apr 8

Subsystems (5)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover macsec: Add support for VLAN filtering in offload mode

This short series adds support for VLANs in MACsec devices when offload mode is enabled. This allows VLAN netdevs on top of MACsec netdevs to function, which accidentally used to be the case in the past, but was broken. This series adds back proper support.

As part of this, the existing nsim-only MACsec offload tests were translated to Python so they can run against real HW and new traffic-based tests were added for VLAN filter propagation, since there's currently no uAPI to check VLAN filters.

---

V6:
- Resurrected nsim debugfs file for VLAN filters.
- Switched to WARN_ON_ONCE in nsim, which is always compiled in.
- Tweaked tests to check the nsim VLAN filter file on nsim.
- Disabled ping on nsim in offload mode, data plane doesn't work.
- Added CONFIG_VLAN_8021Q to the test config.

V5: https://lore.kernel.org/netdev/[email protected]/T/#u
- Merged tests and macsec lib in a single file.
- Fixed Python linter issues.
- Added CONFIG_MACSEC to tools/testing/selftests/drivers/net/config

V4:
- Migrated nsim-only macsec tests to Python, usable against real hw.
- Ran these tests against both nsim and mlx5.
- Gave up on nsim patches since the tests no longer use them.

V3: https://lore.kernel.org/netdev/[email protected]/t/#u
- Moved back to net.
- Added proper rollback support for VLAN filters in case of failure.
- Added VLAN as a requirement for the new macsec tests.

V2: https://lore.kernel.org/netdev/[email protected]/
- Sent to net-next instead of net because of apparent complexity.
- Changed VLAN filtering to only function in offload mode.
- Added tests.

V1: https://lore.kernel.org/netdev/[email protected]/

Cosmin Ratiu (4):
selftests: Migrate nsim-only MACsec tests to Python
nsim: Add support for VLAN filters
selftests: Add MACsec VLAN propagation traffic test
macsec: Support VLAN-filtering lower devices

 drivers/net/macsec.c                          |  44 ++-
 drivers/net/netdevsim/netdev.c                |  65 +++-
 drivers/net/netdevsim/netdevsim.h             |   8 +
 tools/testing/selftests/drivers/net/Makefile  |   1 +
 tools/testing/selftests/drivers/net/config    |   2 +
 .../selftests/drivers/net/lib/py/env.py       |   9 +
 tools/testing/selftests/drivers/net/macsec.py | 330 ++++++++++++++++++
 .../selftests/drivers/net/netdevsim/Makefile  |   1 -
 .../drivers/net/netdevsim/macsec-offload.sh   | 117 -------
 9 files changed, 452 insertions(+), 125 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/macsec.py
 delete mode 100755 tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh
Signature · 1 line
2.53.0
#1 lore raw

PATCH v6 1/4 selftests: Migrate nsim-only MACsec tests to Python

Move MACsec offload API and ethtool feature tests from tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh to tools/testing/selftests/drivers/net/macsec.py using the NetDrvEnv framework so tests can run against both netdevsim (default) and real hardware (NETIF=ethX). As some real hardware requires MACsec to use encryption, add that to the tests.

Netdevsim-specific limit checks (max SecY, max RX SC) were moved into separate test cases to avoid failures on real hardware.

---
 tools/testing/selftests/drivers/net/Makefile  |   1 +
 tools/testing/selftests/drivers/net/config    |   1 +
 tools/testing/selftests/drivers/net/macsec.py | 179 ++++++++++++++++++
 .../selftests/drivers/net/netdevsim/Makefile  |   1 -
 .../drivers/net/netdevsim/macsec-offload.sh   | 117 ------------
 5 files changed, 181 insertions(+), 118 deletions(-)
 create mode 100755 tools/testing/selftests/drivers/net/macsec.py
 delete mode 100755 tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh
tools/testing/selftests/drivers/net/Makefile +1 -0
index 8154d6d429d3..5e045dde0273 100644
@@ -13,6 +13,7 @@ TEST_GEN_FILES := \
 TEST_PROGS := \
 	gro.py \
 	hds.py \
+	macsec.py \
 	napi_id.py \
 	napi_threaded.py \
 	netpoll_basic.py \
tools/testing/selftests/drivers/net/config +1 -0
index 77ccf83d87e0..d4b31a317c09 100644
@@ -3,6 +3,7 @@ CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
 CONFIG_INET_PSP=y
 CONFIG_IPV6=y
+CONFIG_MACSEC=m
 CONFIG_NETCONSOLE=m
 CONFIG_NETCONSOLE_DYNAMIC=y
 CONFIG_NETCONSOLE_EXTENDED_LOG=y
tools/testing/selftests/drivers/net/macsec.py new file +179 -0

179 lines not on this page · raw message

tools/testing/selftests/drivers/net/netdevsim/Makefile +0 -1
index 1a228c5430f5..9808c2fbae9e 100644
@@ -11,7 +11,6 @@ TEST_PROGS := \
 	fib.sh \
 	fib_notifications.sh \
 	hw_stats_l3.sh \
-	macsec-offload.sh \
 	nexthop.sh \
 	peer.sh \
 	psample.sh \
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -117

117 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#2 lore raw

Re: [PATCH net v6 1/4] selftests: Migrate nsim-only MACsec tests to Python

Quoted 15 lines · Cosmin Ratiu
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -15
-#
-# 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 $?

[...]

Quoted 3 lines
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -3
-TMP_FEATS_OFF_2="$(ethtool -k $MACSEC_NETDEV)"
-[ "$TMP_FEATS_OFF_1" = "$TMP_FEATS_OFF_2" ]
-check $?

[...]

tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh line 108

Quoted 3 lines
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -3
-TMP_FEATS_ON_3="$(ethtool -k $MACSEC_NETDEV)"
-[ "$TMP_FEATS_ON_1" = "$TMP_FEATS_ON_3" ]
-check $?

Those feature comparisons are missing in the new python test. The rest of the patch looks good.

Signature · 1 line
Sabrina
#3 lore raw

Re: [PATCH net v6 1/4] selftests: Migrate nsim-only MACsec tests to Python

Quoted 22 lines · Sabrina Dubroca
Quoted 16 lines · Cosmin Ratiu
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -5
-#
-# test ethtool features when toggling offload
-#
-
-ip link add link $NSIM_NETDEV $MACSEC_NETDEV type macsec offload

mac

tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -10
-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 $?

[...]

Quoted 3 lines
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -3
-TMP_FEATS_OFF_2="$(ethtool -k $MACSEC_NETDEV)"
-[ "$TMP_FEATS_OFF_1" = "$TMP_FEATS_OFF_2" ]
-check $?

[...]

Quoted 8 lines

tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh line 108

Quoted 3 lines
tools/testing/selftests/drivers/net/netdevsim/macsec-offload.sh deleted +0 -3
-TMP_FEATS_ON_3="$(ethtool -k $MACSEC_NETDEV)"
-[ "$TMP_FEATS_ON_1" = "$TMP_FEATS_ON_3" ]
-check $?

Those feature comparisons are missing in the new python test. The rest
of the patch looks good.

Thanks,
I am not sure why those are missing. I vaguely remember having them at some point, there were issues, I threw them out thinking there's not much value in checking that all netdev features don't change (the tests basically don't deal with only macsec).

I added them back in v7.

Cosmin.

#4 lore raw

PATCH v6 2/4 nsim: Add support for VLAN filters

In reply to Cosmin Ratiu

Add support for storing the list of VLANs in nsim devices, together with ops for adding/removing them and a debug file to show them.

This will be used in upcoming tests.

---
 drivers/net/netdevsim/netdev.c    | 65 ++++++++++++++++++++++++++++++-
 drivers/net/netdevsim/netdevsim.h |  8 ++++
 2 files changed, 71 insertions(+), 2 deletions(-)
drivers/net/netdevsim/netdev.c +63 -2
index 3645ebde049a..19b0ff183c45 100644
@@ -605,6 +605,36 @@ static int nsim_stop(struct net_device *dev)
 	return 0;
 }
 
+static int nsim_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	if (vid >= VLAN_N_VID)
+		return -EINVAL;
+
+	if (proto == htons(ETH_P_8021Q))
+		WARN_ON_ONCE(test_and_set_bit(vid, ns->vlan.ctag));
+	else if (proto == htons(ETH_P_8021AD))
+		WARN_ON_ONCE(test_and_set_bit(vid, ns->vlan.stag));
+
+	return 0;
+}
+
+static int nsim_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
+{
+	struct netdevsim *ns = netdev_priv(dev);
+
+	if (vid >= VLAN_N_VID)
+		return -EINVAL;
+
+	if (proto == htons(ETH_P_8021Q))
+		WARN_ON_ONCE(!test_and_clear_bit(vid, ns->vlan.ctag));
+	else if (proto == htons(ETH_P_8021AD))
+		WARN_ON_ONCE(!test_and_clear_bit(vid, ns->vlan.stag));
+
+	return 0;
+}
+
 static int nsim_shaper_set(struct net_shaper_binding *binding,
 			   const struct net_shaper *shaper,
 			   struct netlink_ext_ack *extack)
@@ -662,6 +692,8 @@ static const struct net_device_ops nsim_netdev_ops = {
 	.ndo_bpf		= nsim_bpf,
 	.ndo_open		= nsim_open,
 	.ndo_stop		= nsim_stop,
+	.ndo_vlan_rx_add_vid	= nsim_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid	= nsim_vlan_rx_kill_vid,
 	.net_shaper_ops		= &nsim_shaper_ops,
 };
 
@@ -673,6 +705,8 @@ static const struct net_device_ops nsim_vf_netdev_ops = {
 	.ndo_change_mtu		= nsim_change_mtu,
 	.ndo_setup_tc		= nsim_setup_tc,
 	.ndo_set_features	= nsim_set_features,
+	.ndo_vlan_rx_add_vid	= nsim_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid	= nsim_vlan_rx_kill_vid,
 };
 
 /* We don't have true per-queue stats, yet, so do some random fakery here.
@@ -970,6 +1004,20 @@ static const struct file_operations nsim_pp_hold_fops = {
 	.owner = THIS_MODULE,
 };
 
+static int nsim_vlan_show(struct seq_file *s, void *data)
+{
+	struct netdevsim *ns = s->private;
+	int vid;
+
+	for_each_set_bit(vid, ns->vlan.ctag, VLAN_N_VID)
+		seq_printf(s, "ctag %d\n", vid);
+	for_each_set_bit(vid, ns->vlan.stag, VLAN_N_VID)
+		seq_printf(s, "stag %d\n", vid);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(nsim_vlan);
+
 static void nsim_setup(struct net_device *dev)
 {
 	ether_setup(dev);
@@ -982,14 +1030,18 @@ static void nsim_setup(struct net_device *dev)
 			 NETIF_F_FRAGLIST |
 			 NETIF_F_HW_CSUM |
 			 NETIF_F_LRO |
-			 NETIF_F_TSO;
+			 NETIF_F_TSO |
+			 NETIF_F_HW_VLAN_CTAG_FILTER |
+			 NETIF_F_HW_VLAN_STAG_FILTER;
 	dev->hw_features |= NETIF_F_HW_TC |
 			    NETIF_F_SG |
 			    NETIF_F_FRAGLIST |
 			    NETIF_F_HW_CSUM |
 			    NETIF_F_LRO |
 			    NETIF_F_TSO |
-			    NETIF_F_LOOPBACK;
+			    NETIF_F_LOOPBACK |
+			    NETIF_F_HW_VLAN_CTAG_FILTER |
+			    NETIF_F_HW_VLAN_STAG_FILTER;
 	dev->pcpu_stat_type = NETDEV_PCPU_STAT_DSTATS;
 	dev->max_mtu = ETH_MAX_MTU;
 	dev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_HW_OFFLOAD;
@@ -1156,6 +1208,8 @@ struct netdevsim *nsim_create(struct nsim_dev *nsim_dev,
 	ns->qr_dfs = debugfs_create_file("queue_reset", 0200,
 					 nsim_dev_port->ddir, ns,
 					 &nsim_qreset_fops);
+	ns->vlan_dfs = debugfs_create_file("vlan", 0400, nsim_dev_port->ddir,
+					   ns, &nsim_vlan_fops);
 	return ns;
 
 err_free_netdev:
@@ -1167,7 +1221,9 @@ void nsim_destroy(struct netdevsim *ns)
 {
 	struct net_device *dev = ns->netdev;
 	struct netdevsim *peer;
+	u16 vid;
 
+	debugfs_remove(ns->vlan_dfs);
 	debugfs_remove(ns->qr_dfs);
 	debugfs_remove(ns->pp_dfs);
 
@@ -1193,6 +1249,11 @@ void nsim_destroy(struct netdevsim *ns)
 	if (nsim_dev_port_is_pf(ns->nsim_dev_port))
 		nsim_exit_netdevsim(ns);
 
+	for_each_set_bit(vid, ns->vlan.ctag, VLAN_N_VID)
+		WARN_ON_ONCE(1);
+	for_each_set_bit(vid, ns->vlan.stag, VLAN_N_VID)
+		WARN_ON_ONCE(1);
+
 	/* Put this intentionally late to exercise the orphaning path */
 	if (ns->page) {
 		page_pool_put_full_page(pp_page_to_nmdesc(ns->page)->pp,
drivers/net/netdevsim/netdevsim.h +8 -0
index f767fc8a7505..f844c27ca78b 100644
@@ -18,6 +18,7 @@
 #include <linux/ethtool.h>
 #include <linux/ethtool_netlink.h>
 #include <linux/kernel.h>
+#include <linux/if_vlan.h>
 #include <linux/list.h>
 #include <linux/netdevice.h>
 #include <linux/ptp_mock.h>
@@ -75,6 +76,11 @@ struct nsim_macsec {
 	u8 nsim_secy_count;
 };
 
+struct nsim_vlan {
+	DECLARE_BITMAP(ctag, VLAN_N_VID);
+	DECLARE_BITMAP(stag, VLAN_N_VID);
+};
+
 struct nsim_ethtool_pauseparam {
 	bool rx;
 	bool tx;
@@ -135,6 +141,7 @@ struct netdevsim {
 	bool bpf_map_accept;
 	struct nsim_ipsec ipsec;
 	struct nsim_macsec macsec;
+	struct nsim_vlan vlan;
 	struct {
 		u32 inject_error;
 		u32 __ports[2][NSIM_UDP_TUNNEL_N_PORTS];
@@ -146,6 +153,7 @@ struct netdevsim {
 	struct page *page;
 	struct dentry *pp_dfs;
 	struct dentry *qr_dfs;
+	struct dentry *vlan_dfs;
 
 	struct nsim_ethtool ethtool;
 	struct netdevsim __rcu *peer;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v6 2/4
#5 lore raw

Re: [PATCH net v6 2/4] nsim: Add support for VLAN filters

Quoted 10 lines · Cosmin Ratiu

Add support for storing the list of VLANs in nsim devices, together with ops for adding/removing them and a debug file to show them.

This will be used in upcoming tests.

---
 drivers/net/netdevsim/netdev.c    | 65 ++++++++++++++++++++++++++++++-
 drivers/net/netdevsim/netdevsim.h |  8 ++++
 2 files changed, 71 insertions(+), 2 deletions(-)
Signature · 1 line
Sabrina
#6 lore raw

PATCH v6 3/4 selftests: Add MACsec VLAN propagation traffic test

In reply to Cosmin Ratiu

Add macsec_traffic.py using NetDrvEpEnv to verify VLAN filter propagation through offloaded MACsec devices via actual traffic.

The test creates MACsec tunnels with matching SAs on both endpoints, stacks VLANs on top, and verifies connectivity with ping. Covers:
- Offloaded MACsec with VLAN (filters propagate to HW)
- Software MACsec with VLAN (no HW filter propagation)
- Toggle offload on/off and verify traffic still works

On netdevsim this makes use of the VLAN filter debugfs file to actually validate that filters are applied/removed correctly.
On real hardware the traffic should validate actual VLAN filter propagation.

---
 tools/testing/selftests/drivers/net/config    |   1 +
 .../selftests/drivers/net/lib/py/env.py       |   9 ++
 tools/testing/selftests/drivers/net/macsec.py | 151 ++++++++++++++++++
 3 files changed, 161 insertions(+)
tools/testing/selftests/drivers/net/config +1 -0
index d4b31a317c09..fd16994366f4 100644
@@ -8,4 +8,5 @@ CONFIG_NETCONSOLE=m
 CONFIG_NETCONSOLE_DYNAMIC=y
 CONFIG_NETCONSOLE_EXTENDED_LOG=y
 CONFIG_NETDEVSIM=m
+CONFIG_VLAN_8021Q=m
 CONFIG_XDP_SOCKETS=y
tools/testing/selftests/drivers/net/lib/py/env.py +9 -0
index 41cc248ac848..b80666277e36 100644
@@ -255,6 +255,15 @@ class NetDrvEpEnv(NetDrvEnvBase):
         if nsim_test is False and self._ns is not None:
             raise KsftXfailEx("Test does not work on netdevsim")
 
+    def get_local_nsim_dev(self):
+        """Returns the local netdevsim device or None.
+           Using this method is discouraged, as it makes tests nsim-specific.
+           Standard interfaces available on all HW should ideally be used.
+           This method is intended for the few cases where nsim-specific
+           assertions need to be verified which cannot be verified otherwise.
+        """
+        return self._ns
+
     def _require_cmd(self, comm, key, host=None):
         cached = self._required_cmd.get(comm, {})
         if cached.get(key) is None:
tools/testing/selftests/drivers/net/macsec.py +151 -0

185 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#7 lore raw

Re: [PATCH net v6 3/4] selftests: Add MACsec VLAN propagation traffic test

tools/testing/selftests/drivers/net/macsec.py def _require_macsec_offload(cfg): · line 63

Quoted 3 lines · Cosmin Ratiu
tools/testing/selftests/drivers/net/macsec.py +3 -0
+def _get_mac(ifname, host=None):
+    """Gets MAC address of an interface."""
+    dev = ip(f"-d link show dev {ifname}", json=True, host=host)

nit: MAC address doesn't need '-d'

I would have used fixed SCI on both ends to avoid this mess with the local/remote MAC address, but it's ok as you wrote it.

Quoted 1 line

+ return dev[0]["address"]

[...]

tools/testing/selftests/drivers/net/macsec.py def test_offload_state(cfg) -> None: · line 260

Quoted 8 lines
tools/testing/selftests/drivers/net/macsec.py +8 -0
+def _check_nsim_vid(cfg, vid, expected) -> None:
+    """Checks if a VLAN is present. Only works on netdevsim."""
+
+    nsim = cfg.get_local_nsim_dev()
+    if not nsim:
+        return
+
+    vlan_path = nsim.nsims[0].dfs_dir + "vlan"

nit: os.path.join for consistency with other users

Quoted 6 lines
tools/testing/selftests/drivers/net/macsec.py +6 -0
+    with open(vlan_path, encoding="utf-8") as f:
+        vids = f.read()
+    found = f"ctag {vid}\n" in vids
+    ksft_eq(found, expected,
+            f"VLAN {vid} {'expected' if expected else 'not expected'}"
+            f" in debugfs")
Signature · 1 line
Sabrina
#8 lore raw

Re: [PATCH net v6 3/4] selftests: Add MACsec VLAN propagation traffic test

Quoted 6 lines · Sabrina Dubroca
Quoted 3 lines · Cosmin Ratiu

+def _get_mac(ifname, host=None):
+    """Gets MAC address of an interface."""
+    dev = ip(f"-d link show dev {ifname}", json=True, host=host)

nit: MAC address doesn't need '-d'

Will do.

Quoted 3 lines

I would have used fixed SCI on both ends to avoid this mess with the local/remote MAC address, but it's ok as you wrote it.

I guess it would make the test slightly simpler but it would no longer exercise the manual rx port address creation. I think the MAC stuff is a small cost to pay for a little extra coverage.

Quoted 13 lines
Quoted 1 line

+    return dev[0]["address"]

[...]

tools/testing/selftests/drivers/net/macsec.py def test_offload_state(cfg) -> None: · line 260

Quoted 8 lines
tools/testing/selftests/drivers/net/macsec.py +8 -0
+def _check_nsim_vid(cfg, vid, expected) -> None:
+    """Checks if a VLAN is present. Only works on netdevsim."""
+
+    nsim = cfg.get_local_nsim_dev()
+    if not nsim:
+        return
+
+    vlan_path = nsim.nsims[0].dfs_dir + "vlan"

nit: os.path.join for consistency with other users

Will do.

Cosmin.

#9 lore raw

PATCH v6 4/4 macsec: Support VLAN-filtering lower devices

In reply to Cosmin Ratiu

VLAN-filtering is done through two netdev features (NETIF_F_HW_VLAN_CTAG_FILTER and NETIF_F_HW_VLAN_STAG_FILTER) and two netdev ops (ndo_vlan_rx_add_vid and ndo_vlan_rx_kill_vid).

Implement these and advertise the features if the lower device supports them. This allows proper VLAN filtering to work on top of MACsec devices, when the lower device is capable of VLAN filtering. As a concrete example, having this chain of interfaces now works:
vlan_filtering_capable_dev(1) -> macsec_dev(2) -> macsec_vlan_dev(3)

Before the mentioned commit this used to accidentally work because the MACsec device (and thus the lower device) was put in promiscuous mode and the VLAN filter was not used. But after commit [1] correctly made the macsec driver expose the IFF_UNICAST_FLT flag, promiscuous mode was no longer used and VLAN filters on dev 1 kicked in. Without support in dev 2 for propagating VLAN filters down, the register_vlan_dev -> vlan_vid_add -> __vlan_vid_add -> vlan_add_rx_filter_info call from dev 3 is silently eaten (because vlan_hw_filter_capable returns false and vlan_add_rx_filter_info silently succeeds).

For MACsec, VLAN filters are only relevant for offload, otherwise the VLANs are encrypted and the lower devices don't care about them. So VLAN filters are only passed on to lower devices in offload mode. Flipping between offload modes now needs to offload/unoffload the filters with vlan_{get,drop}_rx_*_filter_info().

To avoid the back-and-forth filter updating during rollback, the setting of macsec->offload is moved after the add/del secy ops. This is safe since none of the code called from those requires macsec->offload.

Fixes 0349659fd72f ("macsec: set IFF_UNICAST_FLT priv flag")
---
 drivers/net/macsec.c | 44 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)
drivers/net/macsec.c +39 -5
index f6cad0746a02..3bdb6f3fae8e 100644
@@ -2616,14 +2616,22 @@ static int macsec_update_offload(struct net_device *dev, enum macsec_offload off
 	if (!ops)
 		return -EOPNOTSUPP;
 
-	macsec->offload = offload;
-
 	ctx.secy = &macsec->secy;
 	ret = offload == MACSEC_OFFLOAD_OFF ? macsec_offload(ops->mdo_del_secy, &ctx)
 					    : macsec_offload(ops->mdo_add_secy, &ctx);
-	if (ret) {
-		macsec->offload = prev_offload;
+	if (ret)
 		return ret;
+
+	/* Remove VLAN filters when disabling offload. */
+	if (offload == MACSEC_OFFLOAD_OFF) {
+		vlan_drop_rx_ctag_filter_info(dev);
+		vlan_drop_rx_stag_filter_info(dev);
+	}
+	macsec->offload = offload;
+	/* Add VLAN filters when enabling offload. */
+	if (prev_offload == MACSEC_OFFLOAD_OFF) {
+		vlan_get_rx_ctag_filter_info(dev);
+		vlan_get_rx_stag_filter_info(dev);
 	}
 
 	macsec_set_head_tail_room(dev);
@@ -3486,7 +3494,8 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
 }
 
 #define MACSEC_FEATURES \
-	(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
+	(NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
+	 NETIF_F_HW_VLAN_STAG_FILTER | NETIF_F_HW_VLAN_CTAG_FILTER)
 
 #define MACSEC_OFFLOAD_FEATURES \
 	(MACSEC_FEATURES | NETIF_F_GSO_SOFTWARE | NETIF_F_SOFT_FEATURES | \
@@ -3707,6 +3716,29 @@ static int macsec_set_mac_address(struct net_device *dev, void *p)
 	return err;
 }
 
+static int macsec_vlan_rx_add_vid(struct net_device *dev,
+				  __be16 proto, u16 vid)
+{
+	struct macsec_dev *macsec = netdev_priv(dev);
+
+	if (!macsec_is_offloaded(macsec))
+		return 0;
+
+	return vlan_vid_add(macsec->real_dev, proto, vid);
+}
+
+static int macsec_vlan_rx_kill_vid(struct net_device *dev,
+				   __be16 proto, u16 vid)
+{
+	struct macsec_dev *macsec = netdev_priv(dev);
+
+	if (!macsec_is_offloaded(macsec))
+		return 0;
+
+	vlan_vid_del(macsec->real_dev, proto, vid);
+	return 0;
+}
+
 static int macsec_change_mtu(struct net_device *dev, int new_mtu)
 {
 	struct macsec_dev *macsec = macsec_priv(dev);
@@ -3748,6 +3780,8 @@ static const struct net_device_ops macsec_netdev_ops = {
 	.ndo_set_rx_mode	= macsec_dev_set_rx_mode,
 	.ndo_change_rx_flags	= macsec_dev_change_rx_flags,
 	.ndo_set_mac_address	= macsec_set_mac_address,
+	.ndo_vlan_rx_add_vid	= macsec_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid	= macsec_vlan_rx_kill_vid,
 	.ndo_start_xmit		= macsec_start_xmit,
 	.ndo_get_stats64	= macsec_get_stats64,
 	.ndo_get_iflink		= macsec_get_iflink,
Signature · 1 line
2.53.0
maintainer
#10 lore raw

Re: [PATCH net v6 4/4] macsec: Support VLAN-filtering lower devices

Quoted 14 lines · Cosmin Ratiu
drivers/net/macsec.c +2 -4
@@ -2616,14 +2616,22 @@ static int macsec_update_offload(struct net_device *dev, enum macsec_offload off
 	if (!ops)
 		return -EOPNOTSUPP;
 
-	macsec->offload = offload;
-
 	ctx.secy = &macsec->secy;
 	ret = offload == MACSEC_OFFLOAD_OFF ? macsec_offload(ops->mdo_del_secy, &ctx)
 					    : macsec_offload(ops->mdo_add_secy, &ctx);
-	if (ret) {
-		macsec->offload = prev_offload;
+	if (ret)
 		return ret;
+

drivers/net/macsec.c static int macsec_update_offload(struct net_device *dev, enum macsec_offload off · line 2634

Quoted 10 lines
drivers/net/macsec.c +10 -0
+	/* Remove VLAN filters when disabling offload. */
+	if (offload == MACSEC_OFFLOAD_OFF) {
+		vlan_drop_rx_ctag_filter_info(dev);
+		vlan_drop_rx_stag_filter_info(dev);
+	}
+	macsec->offload = offload;
+	/* Add VLAN filters when enabling offload. */
+	if (prev_offload == MACSEC_OFFLOAD_OFF) {
+		vlan_get_rx_ctag_filter_info(dev);
+		vlan_get_rx_stag_filter_info(dev);

Paolo pointed me to the sashiko review for this patch
https://sashiko.dev/#/patchset/20260330130130.989236-1-cratiu%40nvidia.com

A simple way to trigger this is to do s/VLAN_N_VID/500/ in nsim_vlan_rx_*_vid.

For example:

echo 1 > /sys/bus/netdevsim/new_device
ip link add link eni1np1 macsec0 type macsec ip link add link macsec0 macsec0.1 type vlan id 1 ip link add link macsec0 macsec0.1000 type vlan id 1000 ip link set macsec0 type macsec offload mac
cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan # empty

If this happens on a real device, the VLAN filters will be broken. I'm not sure what the right behavior would be:

1. reject the request to enable offload
2. switch to promiscuous mode

OTOH maybe we don't need to care, since __netdev_update_features also (kind of) ignores those errors:

echo 1 > /sys/bus/netdevsim/new_device
ethtool -K eni1np1 rx-vlan-filter off
ip link add link eni1np1 eni1np1.1 type vlan id 1 ip link add link eni1np1 eni1np1.1000 type vlan id 1000

cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan      # empty as expected
ethtool -K eni1np1 rx-vlan-filter on                         # succeeds
ethtool -k eni1np1 | grep rx-vlan-filter                     # "rx-vlan-filter: on"
cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan      # still empty because id=1000 was rejected
                                                             # and everything got rolled back
ip link add link eni1np1 eni1np1.123 type vlan id 123        # succeeds
cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan      # only "ctag 123"

[at this point running
ip link del eni1np1.1
or
ethtool -K eni1np1 rx-vlan-filter off
will splat because vlan_filter_push_vids did a rollback/never added id=1, and now we call vlan_kill_rx_filter_info, but that's specific to this vid limit]

Signature · 1 line
Sabrina
#11 lore raw

Re: [PATCH net v6 4/4] macsec: Support VLAN-filtering lower devices

Quoted 23 lines · Sabrina Dubroca
Quoted 22 lines · Cosmin Ratiu
(quoted diff) +0 -0
@@ -2616,14 +2616,22 @@ static int macsec_update_offload(struct

net_device *dev, enum macsec_offload off
  if (!ops)
  return -EOPNOTSUPP;

drivers/net/macsec.c +0 -2
-	macsec->offload = offload;
-

  ctx.secy = &macsec->secy;
  ret = offload == MACSEC_OFFLOAD_OFF ? macsec_offload(ops-

Quoted 1 line

mdo_del_secy, &ctx)

      : macsec_offload(ops-

Quoted 1 line

mdo_add_secy, &ctx);

drivers/net/macsec.c +1 -2
-	if (ret) {
-		macsec->offload = prev_offload;
+	if (ret)

  return ret;

drivers/net/macsec.c +6 -0
+
+	/* Remove VLAN filters when disabling offload. */
+	if (offload == MACSEC_OFFLOAD_OFF) {
+		vlan_drop_rx_ctag_filter_info(dev);
+		vlan_drop_rx_stag_filter_info(dev);
+	}
Quoted 8 lines

drivers/net/macsec.c static int macsec_update_offload(struct net_device *dev, enum macsec_offload off · line 2634

Quoted 5 lines
drivers/net/macsec.c +5 -0
+	macsec->offload = offload;
+	/* Add VLAN filters when enabling offload. */
+	if (prev_offload == MACSEC_OFFLOAD_OFF) {
+		vlan_get_rx_ctag_filter_info(dev);
+		vlan_get_rx_stag_filter_info(dev);

Paolo pointed me to the sashiko review for this patch
https://sashiko.dev/#/patchset/20260330130130.989236-1-cratiu%40nvidia.com

I should make it a habit to go and look up these reports myself.

Quoted 14 lines

A simple way to trigger this is to do s/VLAN_N_VID/500/ in nsim_vlan_rx_*_vid.

For example:

echo 1 > /sys/bus/netdevsim/new_device
ip link add link eni1np1 macsec0 type macsec
ip link add link macsec0 macsec0.1 type vlan id 1
ip link add link macsec0 macsec0.1000 type vlan id 1000 ip link set macsec0 type macsec offload mac
cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan      # empty

Quoted 6 lines

If this happens on a real device, the VLAN filters will be broken. I'm
not sure what the right behavior would be:

1. reject the request to enable offload
2. switch to promiscuous mode

I implemented and tested option 1. In the unlikely scenario adding VLAN filters prevents offloading, it's better for the driver to be explicit and let the user turn on promisc mode themselves. Keeping track of whether VLAN filters failed and promisc was used as a fallback adds some extra complexity. Plus, I am not sure it is the right place for this decision. What would be the point of IFF_UNICAST_FLT then?

Please let me know if you agree with this approach, so I can send v8 with it.

Quoted 23 lines

OTOH maybe we don't need to care, since __netdev_update_features also (kind of) ignores those errors:

echo 1 > /sys/bus/netdevsim/new_device
ethtool -K eni1np1 rx-vlan-filter off
ip link add link eni1np1 eni1np1.1 type vlan id 1
ip link add link eni1np1 eni1np1.1000 type vlan id 1000 cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan      # empty as expected
ethtool -K eni1np1 rx-vlan-filter on                         # succeeds
ethtool -k eni1np1 | grep rx-vlan-filter                     # "rx-
vlan-filter: on"
cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan      # still empty because id=1000 was rejected

                                                             # and
everything got rolled back
ip link add link eni1np1 eni1np1.123 type vlan id 123        #
succeeds
cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/vlan      # only
"ctag 123"
Quoted 9 lines

[at this point running
    ip link del eni1np1.1
or
    ethtool -K eni1np1 rx-vlan-filter off
will splat because vlan_filter_push_vids did a rollback/never added id=1, and now we call vlan_kill_rx_filter_info, but that's specific to
this vid limit]

Well, in this case we have the chance to do something nicer (even proper error message back to the user via extack) for a small complexity cost. Perhaps the VLAN filter handling could be improved separately.

Cosmin.

maintainer
#12 lore raw

Re: [PATCH net v6 4/4] macsec: Support VLAN-filtering lower devices

Quoted 10 lines · Cosmin Ratiu
Quoted 6 lines · Sabrina Dubroca

If this happens on a real device, the VLAN filters will be broken. I'm
not sure what the right behavior would be:

1. reject the request to enable offload
2. switch to promiscuous mode

I implemented and tested option 1. In the unlikely scenario adding VLAN filters prevents offloading

How unlikely is it? Resource allocation, talking to HW, device limits, anything else that could fail?

Quoted 4 lines

, it's better for the driver to be explicit
and let the user turn on promisc mode themselves. Keeping track of whether VLAN filters failed and promisc was used as a fallback adds some extra complexity.

If it's indeed (very) unlikely, sure. There's still a bit of a regression/change of behavior for users compared to before the IFF_UNICAST_FLT patch, but I think we can wait until someone complains, and then add the tracking if that happens.

Quoted 1 line

What would be the point of IFF_UNICAST_FLT then?

The point is that this would just be a fallback.

Quoted 2 lines

Please let me know if you agree with this approach, so I can send v8 with it.

If you can confirm it's on the "very unlikely" side, yes, this approach sounds ok. Thanks.

Quoted 3 lines
Quoted 3 lines

OTOH maybe we don't need to care, since __netdev_update_features also (kind of) ignores those errors:

[...]

Quoted 3 lines

Well, in this case we have the chance to do something nicer (even proper error message back to the user via extack) for a small

(That reminds me I have a branch of "macsec: add extack to X" patches I still need to polish and submit. I don't think I'll get to it before the merge window opens, I'll rebase on top of your changes.)

Quoted 2 lines

complexity cost. Perhaps the VLAN filter handling could be improved separately.

I'm not sure if this would be an "improvement to VLAN filter handling" or a "(breaking) change of user-visible behavior". Probably improvement. Or maybe it's "unlikely enough" that nobody has ever cared.

Signature · 1 line
Sabrina
#13 lore raw

Re: [PATCH net v6 4/4] macsec: Support VLAN-filtering lower devices

Quoted 30 lines · Sabrina Dubroca
Quoted 6 lines · Cosmin Ratiu
Quoted 5 lines · Sabrina Dubroca

If this happens on a real device, the VLAN filters will be broken.
I'm
not sure what the right behavior would be:

Quoted 6 lines
Quoted 2 lines

1. reject the request to enable offload
2. switch to promiscuous mode

I implemented and tested option 1. In the unlikely scenario adding VLAN
filters prevents offloading

How unlikely is it? Resource allocation, talking to HW, device limits,
anything else that could fail?

Quoted 4 lines

, it's better for the driver to be explicit
and let the user turn on promisc mode themselves. Keeping track of whether VLAN filters failed and promisc was used as a fallback adds some extra complexity.

If it's indeed (very) unlikely, sure. There's still a bit of a regression/change of behavior for users compared to before the IFF_UNICAST_FLT patch, but I think we can wait until someone complains, and then add the tracking if that happens.

Quoted 1 line

What would be the point of IFF_UNICAST_FLT then?

Quoted 8 lines

The point is that this would just be a fallback.

Quoted 3 lines

Please let me know if you agree with this approach, so I can send v8
with it.

If you can confirm it's on the "very unlikely" side, yes, this approach sounds ok. Thanks.

There are many, many drivers which implement .ndo_vlan_rx_add_vid, I can't really browse them all and determine overall likelihood of failure. But presumably there are some memory allocations involved and some FW communication to add the new filter.
An AI prompt of "Explore implementations of .ndo_vlan_rx_add_vid in drivers and classify potential failure sources and their likelihood of failure." resulted in (edited for compactness):
"""
Analyzed 24+ implementations across major drivers. Here's the breakdown:
Category Likelihood Drivers Typical Error
HW/FW cmds Low mlx4, nfp, hinic, qeth, vmxnet3 Device-specific

Mem alloc  Very Low   bnx2x, qede, virtio_net         -ENOMEM
Filter add Low-Medium mlx5, mlx4, ice, qede, ocelot   -ENOSPC, -EEXIST
Locking    Very Low   be2net, mlx4, nfp, hinic        -EBUSY
Res limit  Medium     qede (quota check)              Promisc fallback

Three Driver Archetypes

1. Simple bitfield drivers (never fail): e1000, e1000e, ixgbe, igb — just set a VFTA bit in hardware registers, always return 0.

2. Complex offload drivers (can fail): mlx5 (flow steering rules), mlx4 (FW VLAN registration), ice (switch rules + promisc management), qede (quota-aware with promisc fallback), nfp (mailbox commands), hinic (FW commands with rollback).

3. Delegation/passthrough drivers (inherit failures): bonding, team, hsr, dsa, macvlan, ipvlan, macsec — propagate vlan_vid_add() to lower devices with unwind-on-failure patterns.
"""

So I guess we go with option 1 for now.

Quoted 24 lines
Quoted 5 lines
Quoted 5 lines

OTOH maybe we don't need to care, since __netdev_update_features also
(kind of) ignores those errors:

[...]

Quoted 3 lines

Well, in this case we have the chance to do something nicer (even proper error message back to the user via extack) for a small

(That reminds me I have a branch of "macsec: add extack to X" patches I still need to polish and submit. I don't think I'll get to it before
the merge window opens, I'll rebase on top of your changes.)

Quoted 2 lines

complexity cost. Perhaps the VLAN filter handling could be improved separately.

I'm not sure if this would be an "improvement to VLAN filter handling"
or a "(breaking) change of user-visible behavior". Probably improvement. Or maybe it's "unlikely enough" that nobody has ever cared.

maintainer
#14 lore raw

Re: [PATCH net v6 4/4] macsec: Support VLAN-filtering lower devices

Quoted 37 lines · Cosmin Ratiu
Quoted 36 lines · Sabrina Dubroca
Quoted 6 lines · Cosmin Ratiu
Quoted 5 lines · Sabrina Dubroca

If this happens on a real device, the VLAN filters will be broken.
I'm
not sure what the right behavior would be:

Quoted 6 lines
Quoted 2 lines

1. reject the request to enable offload
2. switch to promiscuous mode

I implemented and tested option 1. In the unlikely scenario adding VLAN
filters prevents offloading

How unlikely is it? Resource allocation, talking to HW, device limits,
anything else that could fail?

Quoted 4 lines

, it's better for the driver to be explicit
and let the user turn on promisc mode themselves. Keeping track of whether VLAN filters failed and promisc was used as a fallback adds some extra complexity.

If it's indeed (very) unlikely, sure. There's still a bit of a regression/change of behavior for users compared to before the IFF_UNICAST_FLT patch, but I think we can wait until someone complains, and then add the tracking if that happens.

Quoted 1 line

What would be the point of IFF_UNICAST_FLT then?

The point is that this would just be a fallback.

Quoted 3 lines

Please let me know if you agree with this approach, so I can send v8
with it.

Quoted 5 lines
Quoted 2 lines

If you can confirm it's on the "very unlikely" side, yes, this approach sounds ok. Thanks.

There are many, many drivers which implement .ndo_vlan_rx_add_vid, I can't really browse them all and determine overall likelihood of

Sorry, I wasn't requesting that much work, more of a "feeling" based on your understanding. Anyway for macsec offload we don't have to care about the vast majority of drivers.

Quoted 2 lines

failure. But presumably there are some memory allocations involved and some FW communication to add the new filter.

I guess if FW communication fails we're in trouble anyway [*], and memory allocation failure is an acceptable reason to reject offloading anyway.

[*] rolling back the mdo_add_secy could be a problem if we had difficulties talking to the HW?

Quoted 23 lines

An AI prompt of "Explore implementations of .ndo_vlan_rx_add_vid in drivers and classify potential failure sources and their likelihood of failure." resulted in (edited for compactness):
"""
Analyzed 24+ implementations across major drivers. Here's the breakdown:
Category Likelihood Drivers Typical Error
HW/FW cmds Low mlx4, nfp, hinic, qeth, vmxnet3 Device-specific

Mem alloc  Very Low   bnx2x, qede, virtio_net         -ENOMEM
Filter add Low-Medium mlx5, mlx4, ice, qede, ocelot   -ENOSPC, -EEXIST
Locking    Very Low   be2net, mlx4, nfp, hinic        -EBUSY
Res limit  Medium     qede (quota check)              Promisc fallback

Three Driver Archetypes

1. Simple bitfield drivers (never fail): e1000, e1000e, ixgbe, igb — just set a VFTA bit in hardware registers, always return 0.

2. Complex offload drivers (can fail): mlx5 (flow steering rules), mlx4 (FW VLAN registration), ice (switch rules + promisc management), qede (quota-aware with promisc fallback), nfp (mailbox commands), hinic (FW commands with rollback).

Quoted 6 lines

3. Delegation/passthrough drivers (inherit failures): bonding, team, hsr, dsa, macvlan, ipvlan, macsec — propagate vlan_vid_add() to lower devices with unwind-on-failure patterns.
"""

So I guess we go with option 1 for now.

ACK

Signature · 1 line
Sabrina
maintainer
#15 lore raw
In reply to Cosmin Ratiu
Quoted 9 lines · On Mon, 30 Mar 2026 16:01:26 +0300 Cosmin Ratiu wrote:

This short series adds support for VLANs in MACsec devices when offload mode is enabled. This allows VLAN netdevs on top of MACsec netdevs to function, which accidentally used to be the case in the past, but was broken. This series adds back proper support.

As part of this, the existing nsim-only MACsec offload tests were translated to Python so they can run against real HW and new traffic-based tests were added for VLAN filter propagation, since there's currently no uAPI to check VLAN filters.

Hi Sabrina, how does this look to you?