Skip to contentSkip to conversation

eth: mpnic: L2 address filtering

PATCH Applied Daniel Zahka 4 participants 11 messages Nov 16 – Nov 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover eth: mpnic: L2 address filtering

The mpnic device has a TCAM that is keyed on DMAC addresses in the Rx path. Up to this point, the TCAM was unprogrammed, and the default action was set to pass all traffic to the host. This series programs the TCAM to filter Rx packets based on DMAC address.

The device, broadcast, sencondary unicast and multicast addresses are added to the DMAC filter. Promiscuous and all-multicast modes are also supported by reserving the last entry in the TCAM for inexact matches.

The overall design is similar to fbnic. For each entry in the TCAM, the driver tracks the lookup key, mask, state, and users of the entry. Addresses are synced to HW in the ndo_open path, and unsynced in the ndo_stop path. ndo_set_rx_mode_async and ndo_set_mac_address are implemented, so the filtered addresses and promiscuity modes can be updated.

---
Daniel Zahka (4):
eth: mpnic: add filters for dev_addr and broadcast address
eth: mpnic: add promiscuous and all-multicast filters
eth: mpnic: sync unicast and multicast address lists
eth: mpnic: support changing the MAC address

 drivers/net/ethernet/meta/mpnic/Makefile       |   1 +
 drivers/net/ethernet/meta/mpnic/mpnic.h        |   3 +
 drivers/net/ethernet/meta/mpnic/mpnic_csr.h    |  10 ++
 drivers/net/ethernet/meta/mpnic/mpnic_init.c   |  15 ++-
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 116 ++++++++++++++++++++++
 drivers/net/ethernet/meta/mpnic/mpnic_rpc.c    | 129 +++++++++++++++++++++++++
 drivers/net/ethernet/meta/mpnic/mpnic_rpc.h    |  51 ++++++++++
 7 files changed, 321 insertions(+), 4 deletions(-)

---
base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
change-id: 20261112-mpnic-l2-oot-2a185cd5f9bd

Best regards,

Signature · 1 line
Daniel Zahka <[email protected]>
#1 lore raw

PATCH 1/4 eth: mpnic: add filters for dev_addr and broadcast address

The device checks the destination MAC of every frame against a 1024 entry TCAM in order to select a pass or drop action. Up to this point, no addresses have been programmed into the TCAM, and the default action is set to pass.

Program the dev_addr and ethernet broadcast address into the TCAM. At init, all TCAM entries are set to invalid, and all match actions are set to pass. This means adding an address and making the entry valid will result in pass action being taken for that address. When we no longer want to filter for that address, the entry is simply invalidated. We never change the per-entry match actions after initialization.

Because the default action on TCAM miss is still set to pass, the device is still effectively in promiscuous mode even after this commit.

---
 drivers/net/ethernet/meta/mpnic/Makefile       |  1 +
 drivers/net/ethernet/meta/mpnic/mpnic.h        |  3 ++
 drivers/net/ethernet/meta/mpnic/mpnic_csr.h    | 10 ++++++
 drivers/net/ethernet/meta/mpnic/mpnic_init.c   | 10 ++++++
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 49 ++++++++++++++++++++++++++
 drivers/net/ethernet/meta/mpnic/mpnic_rpc.c    | 42 ++++++++++++++++++++++
 drivers/net/ethernet/meta/mpnic/mpnic_rpc.h    | 43 ++++++++++++++++++++++
 7 files changed, 158 insertions(+)
drivers/net/ethernet/meta/mpnic/Makefile +1 -0
index d5bdbd5bd1c7..1910df806d77 100644
@@ -12,5 +12,6 @@ mpnic-y := \
 	mpnic_irq.o \
 	mpnic_netdev.o \
 	mpnic_pci.o \
+	mpnic_rpc.o \
 	mpnic_txrx.o \
 # End of mpnic-y
drivers/net/ethernet/meta/mpnic/mpnic.h +3 -0
index 8b08af0fadcc..9e31bb71aa94 100644
@@ -10,6 +10,7 @@
 #include <linux/workqueue.h>
 
 #include "mpnic_csr.h"
+#include "mpnic_rpc.h"
 
 #define MPNIC_DRV_NAME		"mpnic"
 
@@ -36,6 +37,8 @@ struct mpnic_dev {
 	u32 mps;
 	u32 readrq;
 	u8 relaxed_ord;
+
+	struct mpnic_mac_addr mac_addr[MPNIC_RXB_DMAC_TCAM_CNT];
 };
 
 u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg);
drivers/net/ethernet/meta/mpnic/mpnic_csr.h +10 -0
index 03304e22d6ce..94733b40a96f 100644
@@ -311,6 +311,8 @@ enum {
 	MPNIC_L2_ACTION_PASS	= 1,
 };
 
+#define MPNIC_RXB_DMAC_ACTION(i)	(0x62002a + 2 * (i))	/* 0x18800a8 */
+#define MPNIC_RXB_DMAC_ACTION_CNT	16
 #define MPNIC_RXB_TC_CRDTS(i)		(0x620418 + 2 * (i))	/* 0x1881060 */
 #define MPNIC_RXB_POOL_COMMON_CRDTS(i)	(0x620458 + 2 * (i))	/* 0x1881160 */
 #define MPNIC_RXB_COMMON_CRDT_CTRL_TC(i) \
@@ -320,6 +322,14 @@ enum {
 #define MPNIC_RXB_COMMON_CRDT_CTRL_TC_MAX_CRDTS	CSR_GENMASK(47, 32)
 #define MPNIC_RXB_HOST_DROP_THRESH(i)	(0x6205b0 + 2 * (i))	/* 0x18816c0 */
 #define MPNIC_RXB_BMC_CRDTS(i)		(0x6205d0 + 2 * (i))	/* 0x1881740 */
+#define MPNIC_RXB_DMAC_TCAM(i)		(0x620e5e + 4 * (i))	/* 0x1883978 */
+#define MPNIC_RXB_DMAC_TCAM_MASK(i)	(0x620e60 + 4 * (i))	/* 0x1883980 */
+#define MPNIC_RXB_DMAC_TCAM_CNT		1024
+#define MPNIC_RXB_DMAC_TCAM_DMAC	CSR_GENMASK(47, 0)
+#define MPNIC_RXB_DMAC_TCAM_OP		0x622f60		/* 0x188bd80 */
+#define MPNIC_RXB_DMAC_TCAM_OP_RELOAD_TRIG	CSR_BIT(0)
+#define MPNIC_RXB_DMAC_TCAM_OP_UNLOAD_TRIG	CSR_BIT(1)
+#define MPNIC_RXB_DMAC_TCAM_OP_TCAM_ENTRY	CSR_GENMASK(11, 2)
 
 /* NIC_CORE_RPC */
 #define MPNIC_RPC_MEM_INIT_REQ		0x780440		/* 0x1e01100 */
drivers/net/ethernet/meta/mpnic/mpnic_init.c +10 -0
index ab832ec5de0e..889555eb4790 100644
@@ -227,6 +227,16 @@ static void mpnic_rxb_init(struct mpnic_dev *mpd)
 
 	mpnic_wr64(mpd, MPNIC_RXB_BMC_CRDTS(0), MPNIC_RXB_INIT_BMC_CRDTS);
 
+	/* One bit per DMAC TCAM entry, set means pass on hit */
+	for (int i = 0; i < MPNIC_RXB_DMAC_ACTION_CNT; i++)
+		mpnic_wr64(mpd, MPNIC_RXB_DMAC_ACTION(i), ~0ULL);
+
+	/* Start with all DMAC TCAM entries disabled */
+	for (int i = 0; i < MPNIC_RXB_DMAC_TCAM_CNT; i++)
+		mpnic_wr64(mpd, MPNIC_RXB_DMAC_TCAM_OP,
+			   FIELD_PREP(MPNIC_RXB_DMAC_TCAM_OP_TCAM_ENTRY, i) |
+			   MPNIC_RXB_DMAC_TCAM_OP_UNLOAD_TRIG);
+
 	mpnic_wr64(mpd, MPNIC_RXB_MEM_INIT_REQ, MPNIC_MEM_INIT_RXB_VAL);
 }
 
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +49 -0

73 lines not on this page · raw message

drivers/net/ethernet/meta/mpnic/mpnic_rpc.c new file +42 -0

42 lines not on this page · raw message

drivers/net/ethernet/meta/mpnic/mpnic_rpc.h new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.52.1
#2 lore raw

PATCH 2/4 eth: mpnic: add promiscuous and all-multicast filters

In reply to Daniel Zahka

Implement IFF_PROMISC and IFF_ALLMULTI with the last TCAM entry, which matches either every address or only the multicast bit.

Change the default action on TCAM misses to drop frames. With the device, broadcast and promiscuous entries in place, frames that miss the TCAM can be dropped instead of delivered to the stack to drop.

---
 drivers/net/ethernet/meta/mpnic/mpnic_init.c   |  5 +----
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 21 +++++++++++++++++---
 drivers/net/ethernet/meta/mpnic/mpnic_rpc.c    | 27 ++++++++++++++++++++++++++
 drivers/net/ethernet/meta/mpnic/mpnic_rpc.h    |  3 +++
 4 files changed, 49 insertions(+), 7 deletions(-)
drivers/net/ethernet/meta/mpnic/mpnic_init.c +1 -4
index 889555eb4790..0c2878c18c54 100644
@@ -199,12 +199,9 @@ static void mpnic_txb_init(struct mpnic_dev *mpd)
 
 static void mpnic_rxb_init(struct mpnic_dev *mpd)
 {
-	/* Accept all packets that miss dmac tcam, until l2 filtering is
-	 * implemented.
-	 */
 	mpnic_wr64(mpd, MPNIC_RXB_PORT_CLASS_CFG(0),
 		   FIELD_PREP(MPNIC_RXB_PORT_CLASS_CFG_DEFAULT_L2_ACTION,
-			      MPNIC_L2_ACTION_PASS));
+			      MPNIC_L2_ACTION_DROP));
 	mpnic_wr64(mpd, MPNIC_RXB_PORT_CFG(0),
 		   FIELD_PREP(MPNIC_RXB_PORT_CFG_FCS_STRIP_MODE,
 			      MPNIC_FCS_MODE_STRIP));
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +18 -3
index 16611813db55..43547a7d6e5c 100644
@@ -12,8 +12,10 @@
 #include "mpnic_netdev.h"
 #include "mpnic_txrx.h"
 
-static void __mpnic_set_rx_mode(struct mpnic_dev *mpd)
+static void __mpnic_set_rx_mode(struct mpnic_dev *mpd,
+				struct netdev_hw_addr_list *mc)
 {
+	bool uc_promisc = false, mc_promisc = false;
 	struct net_device *netdev = mpd->netdev;
 	struct mpnic_mac_addr *mac_addr;
 
@@ -33,6 +35,14 @@ static void __mpnic_set_rx_mode(struct mpnic_dev *mpd)
 		mac_addr->state = MPNIC_TCAM_S_ADD;
 	}
 
+	if (!netdev_hw_addr_list_empty(mc))
+		mc_promisc = true;
+
+	uc_promisc |= netdev->flags & IFF_PROMISC;
+	mc_promisc |= netdev->flags & IFF_ALLMULTI;
+
+	mpnic_promisc_sync(mpd, uc_promisc, mc_promisc);
+
 	mpnic_write_macda(mpd);
 }
 
@@ -43,7 +53,7 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
 	struct mpnic_net *mpn = netdev_priv(netdev);
 
 	if (netif_running(netdev))
-		__mpnic_set_rx_mode(mpn->mpd);
+		__mpnic_set_rx_mode(mpn->mpd, mc);
 
 	return 0;
 }
@@ -54,6 +64,7 @@ static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
 
 	mac_addr[MPNIC_TCAM_MACDA_BROADCAST_IDX].state = MPNIC_TCAM_S_DELETE;
 	mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX].state = MPNIC_TCAM_S_DELETE;
+	mac_addr[MPNIC_TCAM_MACDA_PROMISC_IDX].state = MPNIC_TCAM_S_DELETE;
 
 	mpnic_write_macda(mpd);
 }
@@ -79,7 +90,11 @@ static int mpnic_open(struct net_device *netdev)
 
 	mpnic_enable(mpn);
 	mpnic_fill(mpn);
-	__mpnic_set_rx_mode(mpn->mpd);
+
+	netif_addr_lock_bh(netdev);
+	__mpnic_set_rx_mode(mpn->mpd, &netdev->mc);
+	netif_addr_unlock_bh(netdev);
+
 	mpnic_napi_enable(mpn);
 
 	netif_tx_wake_all_queues(netdev);
drivers/net/ethernet/meta/mpnic/mpnic_rpc.c +27 -0
index c96aec4de3e4..ebbccf8ec723 100644
@@ -7,6 +7,33 @@
 #include "mpnic.h"
 #include "mpnic_rpc.h"
 
+void mpnic_promisc_sync(struct mpnic_dev *mpd, bool uc_promisc,
+			bool mc_promisc)
+{
+	struct mpnic_mac_addr *mac_addr;
+
+	mac_addr = &mpd->mac_addr[MPNIC_TCAM_MACDA_PROMISC_IDX];
+	if (uc_promisc) {
+		if (!is_zero_ether_addr(mac_addr->value) ||
+		    mac_addr->state != MPNIC_TCAM_S_VALID) {
+			eth_zero_addr(mac_addr->value);
+			eth_zero_addr(mac_addr->mask);
+			mac_addr->state = MPNIC_TCAM_S_ADD;
+		}
+	} else if (mc_promisc) {
+		if (!is_multicast_ether_addr(mac_addr->value) ||
+		    mac_addr->state != MPNIC_TCAM_S_VALID) {
+			eth_zero_addr(mac_addr->value);
+			eth_zero_addr(mac_addr->mask);
+			mac_addr->value[0] ^= 1;
+			mac_addr->mask[0] ^= 1;
+			mac_addr->state = MPNIC_TCAM_S_ADD;
+		}
+	} else if (mac_addr->state == MPNIC_TCAM_S_VALID) {
+		mac_addr->state = MPNIC_TCAM_S_DELETE;
+	}
+}
+
 static void mpnic_write_macda_entry(struct mpnic_dev *mpd, unsigned int idx,
 				    struct mpnic_mac_addr *mac_addr)
 {
drivers/net/ethernet/meta/mpnic/mpnic_rpc.h +3 -0
index f6e4f60180d6..0eec09df7642 100644
@@ -31,6 +31,7 @@ enum {
 
 #define MPNIC_TCAM_MACDA_BROADCAST_IDX	0
 #define MPNIC_TCAM_MACDA_HOST_ADDR_IDX	(MPNIC_RXB_DMAC_TCAM_CNT - 2)
+#define MPNIC_TCAM_MACDA_PROMISC_IDX	(MPNIC_RXB_DMAC_TCAM_CNT - 1)
 
 struct mpnic_mac_addr {
 	u8 mask[ETH_ALEN];
@@ -38,6 +39,8 @@ struct mpnic_mac_addr {
 	u8 state;
 } __aligned(2);
 
+void mpnic_promisc_sync(struct mpnic_dev *mpd, bool uc_promisc,
+			bool mc_promisc);
 void mpnic_write_macda(struct mpnic_dev *mpd);
 
 #endif /* _MPNIC_RPC_H_ */
Signature · 1 line
2.52.1
#3 lore raw

Re: [PATCH net-next 2/4] eth: mpnic: add promiscuous and all-multicast filters

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] On every ndo_stop, mpnic_clear_rx_mode() (drivers/net/ethernet/meta/mpnic/mpnic_netdev.c, called from…

--

eth: mpnic: add promiscuous and all-multicast filters

This commit implements IFF_PROMISC and IFF_ALLMULTI using the last DMAC TCAM entry, which matches either every address or only the multicast bit. It also changes the default action on TCAM misses from pass to drop.

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
index 16611813db555..43547a7d6e5c7 100644

[ ... ]

drivers/net/ethernet/meta/mpnic/mpnic_netdev.c static void mpnic_clear_rx_mode(struct mpnic_dev *mpd) · line 67

Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +1 -0
@@ -54,6 +64,7 @@ static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
 
 	mac_addr[MPNIC_TCAM_MACDA_BROADCAST_IDX].state = MPNIC_TCAM_S_DELETE;
 	mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX].state = MPNIC_TCAM_S_DELETE;
+	mac_addr[MPNIC_TCAM_MACDA_PROMISC_IDX].state = MPNIC_TCAM_S_DELETE;

[Severity: Low]
Should this check for MPNIC_TCAM_S_VALID before moving the promisc entry to delete?

The broadcast and host address entries are always valid while the interface is up. The promisc entry is usually MPNIC_TCAM_S_DISABLED, though. That is its state whenever IFF_PROMISC and IFF_ALLMULTI are both clear and the mc list is empty, and also after mpnic_promisc_sync() has already removed it.

The state comment in mpnic_rpc.h only lists valid as a source of delete:

 *  Valid     1	-> Delete     3
 *  Delete    3	-> Disabled   0

The other place this patch adds that deletes the same entry follows that rule:

mpnic_promisc_sync() {
    ...
	} else if (mac_addr->state == MPNIC_TCAM_S_VALID) {
		mac_addr->state = MPNIC_TCAM_S_DELETE;
	}
}

With ip link set dev X up and no promisc/allmulti flags set, followed by ip link set dev X down, the path is mpnic_stop()->mpnic_clear_rx_mode() ->mpnic_write_macda(). This takes a disabled entry straight to delete, and then issues an UNLOAD_TRIG for entry 1023 even though it was never loaded.

The extra unload looks harmless, because mpnic_rxb_init() already unloads every entry at init. The remaining problem is that the code no longer matches the documented state ordering, and the two delete sites behave differently.

This is still the case at the end of the series. The later commit "eth:
mpnic: sync unicast and multicast address lists" updates the same comment to add "Delete 3 -> Add 2". It does not add a disabled to delete transition, and it does not add a state check here.

Could this either check the state, the way mpnic_promisc_sync() does, or document disabled to delete as an allowed transition?

Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
 	mpnic_write_macda(mpd);
 }

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-mpnic-l2-oot-v1-0-8dc6eb3582b0%40gmail.com
#4 lore raw

Re: [PATCH net-next 2/4] eth: mpnic: add promiscuous and all-multicast filters

Quoted 66 lines · netdev-bot+sashiko

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] On every ndo_stop, mpnic_clear_rx_mode() (drivers/net/ethernet/meta/mpnic/mpnic_netdev.c, called from…

--

eth: mpnic: add promiscuous and all-multicast filters

This commit implements IFF_PROMISC and IFF_ALLMULTI using the last DMAC TCAM entry, which matches either every address or only the multicast bit. It also changes the default action on TCAM misses from pass to drop.

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
index 16611813db555..43547a7d6e5c7 100644

[ ... ]

drivers/net/ethernet/meta/mpnic/mpnic_netdev.c static void mpnic_clear_rx_mode(struct mpnic_dev *mpd) · line 67

Quoted 5 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +1 -0
@@ -54,6 +64,7 @@ static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
 
 	mac_addr[MPNIC_TCAM_MACDA_BROADCAST_IDX].state = MPNIC_TCAM_S_DELETE;
 	mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX].state = MPNIC_TCAM_S_DELETE;
+	mac_addr[MPNIC_TCAM_MACDA_PROMISC_IDX].state = MPNIC_TCAM_S_DELETE;

[Severity: Low]
Should this check for MPNIC_TCAM_S_VALID before moving the promisc entry to delete?

The broadcast and host address entries are always valid while the interface is up. The promisc entry is usually MPNIC_TCAM_S_DISABLED, though. That is its state whenever IFF_PROMISC and IFF_ALLMULTI are both clear and the mc list is empty, and also after mpnic_promisc_sync() has already removed it.

The state comment in mpnic_rpc.h only lists valid as a source of delete:

 *  Valid     1	-> Delete     3
 *  Delete    3	-> Disabled   0

The other place this patch adds that deletes the same entry follows that rule:

mpnic_promisc_sync() {
    ...
	} else if (mac_addr->state == MPNIC_TCAM_S_VALID) {
		mac_addr->state = MPNIC_TCAM_S_DELETE;
	}
}

With ip link set dev X up and no promisc/allmulti flags set, followed by ip link set dev X down, the path is mpnic_stop()->mpnic_clear_rx_mode() ->mpnic_write_macda(). This takes a disabled entry straight to delete, and then issues an UNLOAD_TRIG for entry 1023 even though it was never loaded.

The extra unload looks harmless, because mpnic_rxb_init() already unloads every entry at init. The remaining problem is that the code no longer matches the documented state ordering, and the two delete sites behave differently.

Quoted 8 lines

This is still the case at the end of the series. The later commit "eth:
mpnic: sync unicast and multicast address lists" updates the same comment to add "Delete 3 -> Add 2". It does not add a disabled to delete transition, and it does not add a state check here.

Could this either check the state, the way mpnic_promisc_sync() does, or document disabled to delete as an allowed transition?

A check is not necessary. If I respin a v2, I'll adjust the comment, but I think overall this isn't an issue.

Quoted 5 lines
Quoted 3 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
 	mpnic_write_macda(mpd);
 }

[ ... ]

#5 lore raw

PATCH 3/4 eth: mpnic: sync unicast and multicast address lists

In reply to Daniel Zahka

Add the secondary unicast and multicast addresses to the MACDA TCAM. Advertise IFF_UNICAST_FLT so we don't need to use promiscuous mode to handle extra unicast addresses.

When the unicast or multicast list outgrows the table, fall back to promiscuous or all-multicast mode respectively.

Track the number of users of a HW filter, because the same address can be used in the dev->uc and dev->mc lists.

Allow a filter slot pending deletion to be reused during mpnic_macda_sync(). Document this transition in the state machine comment.

---
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 38 ++++++++++++++--
 drivers/net/ethernet/meta/mpnic/mpnic_rpc.c    | 60 ++++++++++++++++++++++++++
 drivers/net/ethernet/meta/mpnic/mpnic_rpc.h    |  5 +++
 3 files changed, 100 insertions(+), 3 deletions(-)
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +35 -3
index 43547a7d6e5c..c01e276c4a74 100644
@@ -12,12 +12,30 @@
 #include "mpnic_netdev.h"
 #include "mpnic_txrx.h"
 
+static int mpnic_addr_sync(struct net_device *netdev,
+			   const unsigned char *addr)
+{
+	struct mpnic_net *mpn = netdev_priv(netdev);
+
+	return mpnic_macda_sync(mpn->mpd, addr);
+}
+
+static int mpnic_addr_unsync(struct net_device *netdev,
+			     const unsigned char *addr)
+{
+	struct mpnic_net *mpn = netdev_priv(netdev);
+
+	return mpnic_macda_unsync(mpn->mpd, addr);
+}
+
 static void __mpnic_set_rx_mode(struct mpnic_dev *mpd,
+				struct netdev_hw_addr_list *uc,
 				struct netdev_hw_addr_list *mc)
 {
 	bool uc_promisc = false, mc_promisc = false;
 	struct net_device *netdev = mpd->netdev;
 	struct mpnic_mac_addr *mac_addr;
+	int err;
 
 	mac_addr = &mpd->mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX];
 	if (!ether_addr_equal(mac_addr->value, netdev->dev_addr) ||
@@ -35,7 +53,14 @@ static void __mpnic_set_rx_mode(struct mpnic_dev *mpd,
 		mac_addr->state = MPNIC_TCAM_S_ADD;
 	}
 
-	if (!netdev_hw_addr_list_empty(mc))
+	err = __hw_addr_sync_dev(uc, netdev, mpnic_addr_sync,
+				 mpnic_addr_unsync);
+	if (err == -ENOSPC)
+		uc_promisc = true;
+
+	err = __hw_addr_sync_dev(mc, netdev, mpnic_addr_sync,
+				 mpnic_addr_unsync);
+	if (err == -ENOSPC)
 		mc_promisc = true;
 
 	uc_promisc |= netdev->flags & IFF_PROMISC;
@@ -53,7 +78,7 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
 	struct mpnic_net *mpn = netdev_priv(netdev);
 
 	if (netif_running(netdev))
-		__mpnic_set_rx_mode(mpn->mpd, mc);
+		__mpnic_set_rx_mode(mpn->mpd, uc, mc);
 
 	return 0;
 }
@@ -61,6 +86,12 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
 static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
 {
 	struct mpnic_mac_addr *mac_addr = mpd->mac_addr;
+	struct net_device *netdev = mpd->netdev;
+
+	netif_addr_lock_bh(netdev);
+	__dev_uc_unsync(netdev, mpnic_addr_unsync);
+	__dev_mc_unsync(netdev, mpnic_addr_unsync);
+	netif_addr_unlock_bh(netdev);
 
 	mac_addr[MPNIC_TCAM_MACDA_BROADCAST_IDX].state = MPNIC_TCAM_S_DELETE;
 	mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX].state = MPNIC_TCAM_S_DELETE;
@@ -92,7 +123,7 @@ static int mpnic_open(struct net_device *netdev)
 	mpnic_fill(mpn);
 
 	netif_addr_lock_bh(netdev);
-	__mpnic_set_rx_mode(mpn->mpd, &netdev->mc);
+	__mpnic_set_rx_mode(mpn->mpd, &netdev->uc, &netdev->mc);
 	netif_addr_unlock_bh(netdev);
 
 	mpnic_napi_enable(mpn);
@@ -366,6 +397,7 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd)
 	netdev->netdev_ops = &mpnic_netdev_ops;
 	netdev->stat_ops = &mpnic_stat_ops;
 	netdev->request_ops_lock = true;
+	netdev->priv_flags |= IFF_UNICAST_FLT;
 
 	mpn = netdev_priv(netdev);
 	mpn->netdev = netdev;
drivers/net/ethernet/meta/mpnic/mpnic_rpc.c +60 -0

66 lines not on this page · raw message

drivers/net/ethernet/meta/mpnic/mpnic_rpc.h +5 -0
index 0eec09df7642..8ed507daaf6f 100644
@@ -21,6 +21,8 @@ struct mpnic_dev;
  *
  *  Valid     1	-> Delete     3
  *  Delete    3	-> Disabled   0
+ *
+ *  Delete    3	-> Add	      2
  */
 enum {
 	MPNIC_TCAM_S_DISABLED	= 0,
@@ -37,8 +39,11 @@ struct mpnic_mac_addr {
 	u8 mask[ETH_ALEN];
 	u8 value[ETH_ALEN];
 	u8 state;
+	u8 users;
 } __aligned(2);
 
+int mpnic_macda_sync(struct mpnic_dev *mpd, const u8 *addr);
+int mpnic_macda_unsync(struct mpnic_dev *mpd, const u8 *addr);
 void mpnic_promisc_sync(struct mpnic_dev *mpd, bool uc_promisc,
 			bool mc_promisc);
 void mpnic_write_macda(struct mpnic_dev *mpd);
Signature · 1 line
2.52.1
#6 lore raw

Re: [PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The unicast and multicast lists are synced in the wrong order in __mpnic_set_rx_mode()…

--

eth: mpnic: sync unicast and multicast address lists

This commit adds the secondary unicast and multicast addresses to the MACDA TCAM and advertises IFF_UNICAST_FLT. When either list outgrows the table, the driver falls back to promiscuous or all-multicast mode. A per-slot users count is kept so the same address can sit in both dev->uc and dev->mc.

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
index 43547a7d6e5c7..c01e276c4a74d 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
@@ -35,7 +53,14 @@ static void __mpnic_set_rx_mode(struct mpnic_dev *mpd,
 		mac_addr->state = MPNIC_TCAM_S_ADD;
 	}
 

drivers/net/ethernet/meta/mpnic/mpnic_netdev.c static void __mpnic_set_rx_mode(struct mpnic_dev *mpd, · line 64

Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +8 -1
-	if (!netdev_hw_addr_list_empty(mc))
+	err = __hw_addr_sync_dev(uc, netdev, mpnic_addr_sync,
+				 mpnic_addr_unsync);
+	if (err == -ENOSPC)
+		uc_promisc = true;
+
+	err = __hw_addr_sync_dev(mc, netdev, mpnic_addr_sync,
+				 mpnic_addr_unsync);
+	if (err == -ENOSPC)
 		mc_promisc = true;

[Severity: Medium]
Can the device get stuck in unicast promiscuous mode here, even though a TCAM slot is free?

The uc and mc lists share the same MACDA slots (between MPNIC_TCAM_MACDA_BROADCAST_IDX and MPNIC_TCAM_MACDA_HOST_ADDR_IDX). The whole uc pass, both its flush and its add phase, runs before the mc pass flushes stale multicast entries.

Consider this sequence:

1. The table is full of multicast entries and a secondary unicast address U is added. mpnic_macda_sync() returns -ENOSPC, U stays at sync_cnt == 0, and mpnic_promisc_sync() enables unicast promisc.

2. A multicast address M is then removed. The core runs netif_rx_mode_run()->mpnic_set_rx_mode()->__mpnic_set_rx_mode().

3. The uc pass retries U. M's slot is still MPNIC_TCAM_S_VALID, so mpnic_macda_free() rejects it, mpnic_macda_sync() returns -ENOSPC again, and uc_promisc is set.

4. The mc flush runs only after that. It calls mpnic_macda_unsync() on M:

	if (!--mac_addr->users)
		mac_addr->state = MPNIC_TCAM_S_DELETE;

mpnic_write_macda() then frees the slot.

The reverse case works. A unicast removal can make room for a pending multicast address, because the uc flush runs before the mc add.

Would it make sense to flush stale entries from both lists before either add phase runs?

[ ... ]

drivers/net/ethernet/meta/mpnic/mpnic_netdev.c static int mpnic_set_rx_mode(struct net_device *netdev, · line 84

Quoted 9 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +1 -1
@@ -53,7 +78,7 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
 	struct mpnic_net *mpn = netdev_priv(netdev);
 
 	if (netif_running(netdev))
-		__mpnic_set_rx_mode(mpn->mpd, mc);
+		__mpnic_set_rx_mode(mpn->mpd, uc, mc);
 
 	return 0;
 }

Because mpnic_set_rx_mode() always returns 0, netif_rx_mode_run() never calls netif_rx_mode_schedule_retry() for the case above.

mpnic_service_task() doesn't re-run the rx mode sync either. So U stays unsynced and the promisc entry (zero mask) stays installed until some unrelated rx-mode event happens. The commit message says:

Advertise IFF_UNICAST_FLT so we don't need to use promiscuous mode to handle extra unicast addresses.

The later patch in the series, "eth: mpnic: support changing the MAC address", keeps the same uc-then-mc ordering.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-mpnic-l2-oot-v1-0-8dc6eb3582b0%40gmail.com
#7 lore raw

Re: [PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists

Quoted 73 lines · netdev-bot+sashiko

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The unicast and multicast lists are synced in the wrong order in __mpnic_set_rx_mode()…

--

eth: mpnic: sync unicast and multicast address lists

This commit adds the secondary unicast and multicast addresses to the MACDA TCAM and advertises IFF_UNICAST_FLT. When either list outgrows the table, the driver falls back to promiscuous or all-multicast mode. A per-slot users count is kept so the same address can sit in both dev->uc and dev->mc.

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
index 43547a7d6e5c7..c01e276c4a74d 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +0 -0
@@ -35,7 +53,14 @@ static void __mpnic_set_rx_mode(struct mpnic_dev *mpd,
 		mac_addr->state = MPNIC_TCAM_S_ADD;
 	}
 

drivers/net/ethernet/meta/mpnic/mpnic_netdev.c static void __mpnic_set_rx_mode(struct mpnic_dev *mpd, · line 64

Quoted 10 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +8 -1
-	if (!netdev_hw_addr_list_empty(mc))
+	err = __hw_addr_sync_dev(uc, netdev, mpnic_addr_sync,
+				 mpnic_addr_unsync);
+	if (err == -ENOSPC)
+		uc_promisc = true;
+
+	err = __hw_addr_sync_dev(mc, netdev, mpnic_addr_sync,
+				 mpnic_addr_unsync);
+	if (err == -ENOSPC)
 		mc_promisc = true;

[Severity: Medium]
Can the device get stuck in unicast promiscuous mode here, even though a TCAM slot is free?

The uc and mc lists share the same MACDA slots (between MPNIC_TCAM_MACDA_BROADCAST_IDX and MPNIC_TCAM_MACDA_HOST_ADDR_IDX). The whole uc pass, both its flush and its add phase, runs before the mc pass flushes stale multicast entries.

Consider this sequence:

1. The table is full of multicast entries and a secondary unicast address U is added. mpnic_macda_sync() returns -ENOSPC, U stays at sync_cnt == 0, and mpnic_promisc_sync() enables unicast promisc.

2. A multicast address M is then removed. The core runs netif_rx_mode_run()->mpnic_set_rx_mode()->__mpnic_set_rx_mode().

3. The uc pass retries U. M's slot is still MPNIC_TCAM_S_VALID, so mpnic_macda_free() rejects it, mpnic_macda_sync() returns -ENOSPC again, and uc_promisc is set.

4. The mc flush runs only after that. It calls mpnic_macda_unsync() on M:

	if (!--mac_addr->users)
		mac_addr->state = MPNIC_TCAM_S_DELETE;
Quoted 8 lines

mpnic_write_macda() then frees the slot.

The reverse case works. A unicast removal can make room for a pending multicast address, because the uc flush runs before the mc add.

Would it make sense to flush stale entries from both lists before either add phase runs?

I see this more as a low severity issue, because having the device be in promiscuous mode when a slot is free is not incorrect, just not optimal.

If anything I would probably just rerun __hw_addr_sync_dev() on the uc list again after the mc one, if the first call returned -ENOSPC. I didn't think that was really worth it when this same comment came up in local review though.

Quoted 24 lines

[ ... ]

drivers/net/ethernet/meta/mpnic/mpnic_netdev.c static int mpnic_set_rx_mode(struct net_device *netdev, · line 84

Quoted 9 lines
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +1 -1
@@ -53,7 +78,7 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
 	struct mpnic_net *mpn = netdev_priv(netdev);
 
 	if (netif_running(netdev))
-		__mpnic_set_rx_mode(mpn->mpd, mc);
+		__mpnic_set_rx_mode(mpn->mpd, uc, mc);
 
 	return 0;
 }

Because mpnic_set_rx_mode() always returns 0, netif_rx_mode_run() never calls netif_rx_mode_schedule_retry() for the case above.

mpnic_service_task() doesn't re-run the rx mode sync either. So U stays unsynced and the promisc entry (zero mask) stays installed until some unrelated rx-mode event happens. The commit message says:

Advertise IFF_UNICAST_FLT so we don't need to use promiscuous mode to handle extra unicast addresses.

The later patch in the series, "eth: mpnic: support changing the MAC address", keeps the same uc-then-mc ordering.

maintainer
#8 lore raw

Re: [PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists

Quoted 11 lines · On Wed, 18 Nov 2026 05:21:44 -0500 Daniel Zahka wrote:
Quoted 3 lines

Would it make sense to flush stale entries from both lists before either add phase runs?

I see this more as a low severity issue, because having the device be in promiscuous mode when a slot is free is not incorrect, just not optimal.

If anything I would probably just rerun __hw_addr_sync_dev() on the uc list again after the mc one, if the first call returned -ENOSPC. I didn't think that was really worth it when this same comment came up in local review though.

Ack, IIRC the MAC table is at least 100 addrs, so micro-optimizing the ~128 -> 127 transition isn't worth the LoC.

#9 lore raw

PATCH 4/4 eth: mpnic: support changing the MAC address

In reply to Daniel Zahka

Let the user change the primary dev_addr used by the device. Core doesn't schedule an rx mode update for an address change, so the TCAM is updated inline. The device address entry is rewritten in place, so frames to the old address stop matching once the new one is written.

---
 drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c +20 -0
index c01e276c4a74..fff35d150572 100644
@@ -83,6 +83,25 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
 	return 0;
 }
 
+static int mpnic_set_mac(struct net_device *netdev, void *p)
+{
+	struct mpnic_net *mpn = netdev_priv(netdev);
+	struct sockaddr *addr = p;
+
+	if (!is_valid_ether_addr(addr->sa_data))
+		return -EADDRNOTAVAIL;
+
+	eth_hw_addr_set(netdev, addr->sa_data);
+
+	if (netif_running(netdev)) {
+		netif_addr_lock_bh(netdev);
+		__mpnic_set_rx_mode(mpn->mpd, &netdev->uc, &netdev->mc);
+		netif_addr_unlock_bh(netdev);
+	}
+
+	return 0;
+}
+
 static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
 {
 	struct mpnic_mac_addr *mac_addr = mpd->mac_addr;
@@ -237,6 +256,7 @@ static const struct net_device_ops mpnic_netdev_ops = {
 	.ndo_open		= mpnic_open,
 	.ndo_stop		= mpnic_stop,
 	.ndo_validate_addr	= eth_validate_addr,
+	.ndo_set_mac_address	= mpnic_set_mac,
 	.ndo_start_xmit		= mpnic_xmit_frame,
 	.ndo_features_check	= mpnic_features_check,
 	.ndo_set_rx_mode_async	= mpnic_set_rx_mode,
Signature · 1 line
2.52.1
#10 lore raw
In reply to Daniel Zahka
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 10 lines · On Mon, 16 Nov 2026 13:11:18 -0800 you wrote:

The mpnic device has a TCAM that is keyed on DMAC addresses in the Rx path. Up to this point, the TCAM was unprogrammed, and the default action was set to pass all traffic to the host. This series programs the TCAM to filter Rx packets based on DMAC address.

The device, broadcast, sencondary unicast and multicast addresses are added to the DMAC filter. Promiscuous and all-multicast modes are also supported by reserving the last entry in the TCAM for inexact matches.

[...]

Here is the summary with links:
- [net-next,1/4] eth: mpnic: add filters for dev_addr and broadcast address

    https://git.kernel.org/netdev/net-next/c/419c42cb567e
  - [net-next,2/4] eth: mpnic: add promiscuous and all-multicast filters
    https://git.kernel.org/netdev/net-next/c/5f969cf59b64
  - [net-next,3/4] eth: mpnic: sync unicast and multicast address lists
    https://git.kernel.org/netdev/net-next/c/135603cd9dd9
  - [net-next,4/4] eth: mpnic: support changing the MAC address
    https://git.kernel.org/netdev/net-next/c/1b271185a32b

You are awesome, thank you!

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