Skip to contentSkip to conversation

Pass the BR_FDB_LOCAL information to switchdev drivers

PATCH RESEND In review Vladimir Oltean 4 participants 9 messages Apr 14, 2021 – Apr 19, 2021

Subsystems (10)
lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

cover Pass the BR_FDB_LOCAL information to switchdev drivers

From: Vladimir Oltean <[email protected]>

Bridge FDB entries with the is_local flag are entries which are terminated locally and not forwarded. Switchdev drivers might want to be notified of these addresses so they can trap them. If they don't program these entries to hardware, there is no guarantee that they will do the right thing with these entries, and they won't be, let's say, flooded.

Ideally none of the switchdev drivers should ignore these entries, but having access to the is_local bit is the bare minimum change that should be done in the bridge layer, before this is even possible.

These 2 changes are extracted from the larger "RX filtering in DSA" series:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
and submitted separately, because they touch all switchdev drivers, while the rest is mostly specific to DSA.

This change is not a functional one, in the sense that everybody still ignores the local FDB entries, but this will be changed by further patches at least for DSA.

Tobias Waldekranz (1):
net: bridge: switchdev: refactor br_switchdev_fdb_notify

Vladimir Oltean (1):
net: bridge: switchdev: include local flag in FDB notifications

 .../ethernet/freescale/dpaa2/dpaa2-switch.c   |  4 +-
 .../marvell/prestera/prestera_switchdev.c     |  2 +-
 .../mellanox/mlxsw/spectrum_switchdev.c       |  5 ++-
 drivers/net/ethernet/rocker/rocker_main.c     |  4 +-
 drivers/net/ethernet/ti/am65-cpsw-switchdev.c |  4 +-
 drivers/net/ethernet/ti/cpsw_switchdev.c      |  4 +-
 include/net/switchdev.h                       |  1 +
 net/bridge/br_switchdev.c                     | 44 +++++--------------
 net/dsa/slave.c                               |  2 +-
 9 files changed, 26 insertions(+), 44 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH RESEND 1/2 net: bridge: switchdev: refactor br_switchdev_fdb_notify

From: Tobias Waldekranz <[email protected]>

Instead of having to add more and more arguments to br_switchdev_fdb_call_notifiers, get rid of it and build the info struct directly in br_switchdev_fdb_notify.

---
 net/bridge/br_switchdev.c | 41 +++++++++++----------------------------
 1 file changed, 11 insertions(+), 30 deletions(-)
net/bridge/br_switchdev.c +11 -30
index 1e24d9a2c9a7..c390f84adea2 100644
@@ -107,25 +107,16 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p,
 	return 0;
 }
 
-static void
-br_switchdev_fdb_call_notifiers(bool adding, const unsigned char *mac,
-				u16 vid, struct net_device *dev,
-				bool added_by_user, bool offloaded)
-{
-	struct switchdev_notifier_fdb_info info;
-	unsigned long notifier_type;
-
-	info.addr = mac;
-	info.vid = vid;
-	info.added_by_user = added_by_user;
-	info.offloaded = offloaded;
-	notifier_type = adding ? SWITCHDEV_FDB_ADD_TO_DEVICE : SWITCHDEV_FDB_DEL_TO_DEVICE;
-	call_switchdev_notifiers(notifier_type, dev, &info.info, NULL);
-}
-
 void
 br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 {
+	struct switchdev_notifier_fdb_info info = {
+		.addr = fdb->key.addr.addr,
+		.vid = fdb->key.vlan_id,
+		.added_by_user = test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags),
+		.offloaded = test_bit(BR_FDB_OFFLOADED, &fdb->flags),
+	};
+
 	if (!fdb->dst)
 		return;
 	if (test_bit(BR_FDB_LOCAL, &fdb->flags))
@@ -133,22 +124,12 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 
 	switch (type) {
 	case RTM_DELNEIGH:
-		br_switchdev_fdb_call_notifiers(false, fdb->key.addr.addr,
-						fdb->key.vlan_id,
-						fdb->dst->dev,
-						test_bit(BR_FDB_ADDED_BY_USER,
-							 &fdb->flags),
-						test_bit(BR_FDB_OFFLOADED,
-							 &fdb->flags));
+		call_switchdev_notifiers(SWITCHDEV_FDB_DEL_TO_DEVICE,
+					 fdb->dst->dev, &info.info, NULL);
 		break;
 	case RTM_NEWNEIGH:
-		br_switchdev_fdb_call_notifiers(true, fdb->key.addr.addr,
-						fdb->key.vlan_id,
-						fdb->dst->dev,
-						test_bit(BR_FDB_ADDED_BY_USER,
-							 &fdb->flags),
-						test_bit(BR_FDB_OFFLOADED,
-							 &fdb->flags));
+		call_switchdev_notifiers(SWITCHDEV_FDB_ADD_TO_DEVICE,
+					 fdb->dst->dev, &info.info, NULL);
 		break;
 	}
 }
Signature · 1 line
2.25.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH resend net-next 1/2] net: bridge: switchdev: refactor br_switchdev_fdb_notify

Quoted 9 lines · Vladimir Oltean

From: Tobias Waldekranz <[email protected]>

Instead of having to add more and more arguments to br_switchdev_fdb_call_notifiers, get rid of it and build the info struct directly in br_switchdev_fdb_notify.

Acked-by on v1 1/2
#3 lore raw

Re: [PATCH resend net-next 1/2] net: bridge: switchdev: refactor br_switchdev_fdb_notify

In reply to Vladimir Oltean
Quoted 6 lines · Vladimir Oltean

From: Tobias Waldekranz <[email protected]>

Instead of having to add more and more arguments to br_switchdev_fdb_call_notifiers, get rid of it and build the info struct directly in br_switchdev_fdb_notify.

Quoted 7 lines
---
 net/bridge/br_switchdev.c | 41 +++++++++++----------------------------
 1 file changed, 11 insertions(+), 30 deletions(-)
author maintainer
#4 lore raw

PATCH RESEND 2/2 net: bridge: switchdev: include local flag in FDB notifications

In reply to Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in bugfix commit 6ab4c3117aec ("net: bridge: don't notify switchdev for local FDB addresses") as well as in this discussion:
https://lore.kernel.org/netdev/20210117193009.io3nungdwuzmo5f7@skbuf/

the switchdev notifiers for FDB entries managed to have a zero-day bug, which was that drivers would not know what to do with local FDB entries, because they were not told that they are local. The bug fix was to simply not notify them of those addresses.

Let us now add the 'is_local' bit to bridge FDB entries, and make all drivers ignore these entries by their own choice.

---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c        | 4 ++--
 drivers/net/ethernet/marvell/prestera/prestera_switchdev.c | 2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c   | 5 +++--
 drivers/net/ethernet/rocker/rocker_main.c                  | 4 ++--
 drivers/net/ethernet/ti/am65-cpsw-switchdev.c              | 4 ++--
 drivers/net/ethernet/ti/cpsw_switchdev.c                   | 4 ++--
 include/net/switchdev.h                                    | 1 +
 net/bridge/br_switchdev.c                                  | 3 +--
 net/dsa/slave.c                                            | 2 +-
 9 files changed, 15 insertions(+), 14 deletions(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +2 -2
index 80efc8116963..d7c0e11b16f7 100644
@@ -1832,7 +1832,7 @@ static void dpaa2_switch_event_work(struct work_struct *work)
 
 	switch (switchdev_work->event) {
 	case SWITCHDEV_FDB_ADD_TO_DEVICE:
-		if (!fdb_info->added_by_user)
+		if (!fdb_info->added_by_user || fdb_info->is_local)
 			break;
 		if (is_unicast_ether_addr(fdb_info->addr))
 			err = dpaa2_switch_port_fdb_add_uc(netdev_priv(dev),
@@ -1847,7 +1847,7 @@ static void dpaa2_switch_event_work(struct work_struct *work)
 					 &fdb_info->info, NULL);
 		break;
 	case SWITCHDEV_FDB_DEL_TO_DEVICE:
-		if (!fdb_info->added_by_user)
+		if (!fdb_info->added_by_user || fdb_info->is_local)
 			break;
 		if (is_unicast_ether_addr(fdb_info->addr))
 			dpaa2_switch_port_fdb_del_uc(netdev_priv(dev), fdb_info->addr);
drivers/net/ethernet/marvell/prestera/prestera_switchdev.c +1 -1
index 49e052273f30..cb564890a3dc 100644
@@ -798,7 +798,7 @@ static void prestera_fdb_event_work(struct work_struct *work)
 	switch (swdev_work->event) {
 	case SWITCHDEV_FDB_ADD_TO_DEVICE:
 		fdb_info = &swdev_work->fdb_info;
-		if (!fdb_info->added_by_user)
+		if (!fdb_info->added_by_user || fdb_info->is_local)
 			break;
 
 		err = prestera_port_fdb_set(port, fdb_info, true);
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +3 -2
index c1f05c17557d..eeccd586e781 100644
@@ -2916,7 +2916,8 @@ mlxsw_sp_switchdev_bridge_nve_fdb_event(struct mlxsw_sp_switchdev_event_work *
 		return;
 
 	if (switchdev_work->event == SWITCHDEV_FDB_ADD_TO_DEVICE &&
-	    !switchdev_work->fdb_info.added_by_user)
+	    (!switchdev_work->fdb_info.added_by_user ||
+	     switchdev_work->fdb_info.is_local))
 		return;
 
 	if (!netif_running(dev))
@@ -2971,7 +2972,7 @@ static void mlxsw_sp_switchdev_bridge_fdb_event_work(struct work_struct *work)
 	switch (switchdev_work->event) {
 	case SWITCHDEV_FDB_ADD_TO_DEVICE:
 		fdb_info = &switchdev_work->fdb_info;
-		if (!fdb_info->added_by_user)
+		if (!fdb_info->added_by_user || fdb_info->is_local)
 			break;
 		err = mlxsw_sp_port_fdb_set(mlxsw_sp_port, fdb_info, true);
 		if (err)
drivers/net/ethernet/rocker/rocker_main.c +2 -2
index 3473d296b2e2..a46633606cae 100644
@@ -2736,7 +2736,7 @@ static void rocker_switchdev_event_work(struct work_struct *work)
 	switch (switchdev_work->event) {
 	case SWITCHDEV_FDB_ADD_TO_DEVICE:
 		fdb_info = &switchdev_work->fdb_info;
-		if (!fdb_info->added_by_user)
+		if (!fdb_info->added_by_user || fdb_info->is_local)
 			break;
 		err = rocker_world_port_fdb_add(rocker_port, fdb_info);
 		if (err) {
@@ -2747,7 +2747,7 @@ static void rocker_switchdev_event_work(struct work_struct *work)
 		break;
 	case SWITCHDEV_FDB_DEL_TO_DEVICE:
 		fdb_info = &switchdev_work->fdb_info;
-		if (!fdb_info->added_by_user)
+		if (!fdb_info->added_by_user || fdb_info->is_local)
 			break;
 		err = rocker_world_port_fdb_del(rocker_port, fdb_info);
 		if (err)
drivers/net/ethernet/ti/am65-cpsw-switchdev.c +2 -2
index d93ffd8a08b0..23cfb91e9c4d 100644
@@ -385,7 +385,7 @@ static void am65_cpsw_switchdev_event_work(struct work_struct *work)
 			   fdb->addr, fdb->vid, fdb->added_by_user,
 			   fdb->offloaded, port_id);
 
-		if (!fdb->added_by_user)
+		if (!fdb->added_by_user || fdb->is_local)
 			break;
 		if (memcmp(port->slave.mac_addr, (u8 *)fdb->addr, ETH_ALEN) == 0)
 			port_id = HOST_PORT_NUM;
@@ -401,7 +401,7 @@ static void am65_cpsw_switchdev_event_work(struct work_struct *work)
 			   fdb->addr, fdb->vid, fdb->added_by_user,
 			   fdb->offloaded, port_id);
 
-		if (!fdb->added_by_user)
+		if (!fdb->added_by_user || fdb->is_local)
 			break;
 		if (memcmp(port->slave.mac_addr, (u8 *)fdb->addr, ETH_ALEN) == 0)
 			port_id = HOST_PORT_NUM;
drivers/net/ethernet/ti/cpsw_switchdev.c +2 -2
index a72bb570756f..05a64fb7a04f 100644
@@ -395,7 +395,7 @@ static void cpsw_switchdev_event_work(struct work_struct *work)
 			fdb->addr, fdb->vid, fdb->added_by_user,
 			fdb->offloaded, port);
 
-		if (!fdb->added_by_user)
+		if (!fdb->added_by_user || fdb->is_local)
 			break;
 		if (memcmp(priv->mac_addr, (u8 *)fdb->addr, ETH_ALEN) == 0)
 			port = HOST_PORT_NUM;
@@ -411,7 +411,7 @@ static void cpsw_switchdev_event_work(struct work_struct *work)
 			fdb->addr, fdb->vid, fdb->added_by_user,
 			fdb->offloaded, port);
 
-		if (!fdb->added_by_user)
+		if (!fdb->added_by_user || fdb->is_local)
 			break;
 		if (memcmp(priv->mac_addr, (u8 *)fdb->addr, ETH_ALEN) == 0)
 			port = HOST_PORT_NUM;
include/net/switchdev.h +1 -0
index 8c3218177136..f1a5a9a3634d 100644
@@ -209,6 +209,7 @@ struct switchdev_notifier_fdb_info {
 	const unsigned char *addr;
 	u16 vid;
 	u8 added_by_user:1,
+	   is_local:1,
 	   offloaded:1;
 };
 
net/bridge/br_switchdev.c +1 -2
index c390f84adea2..a5e601e41cb9 100644
@@ -114,13 +114,12 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 		.addr = fdb->key.addr.addr,
 		.vid = fdb->key.vlan_id,
 		.added_by_user = test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags),
+		.is_local = test_bit(BR_FDB_LOCAL, &fdb->flags),
 		.offloaded = test_bit(BR_FDB_OFFLOADED, &fdb->flags),
 	};
 
 	if (!fdb->dst)
 		return;
-	if (test_bit(BR_FDB_LOCAL, &fdb->flags))
-		return;
 
 	switch (type) {
 	case RTM_DELNEIGH:
net/dsa/slave.c +1 -1
index 995e0e16f295..6e348d2222a9 100644
@@ -2329,7 +2329,7 @@ static int dsa_slave_switchdev_event(struct notifier_block *unused,
 		fdb_info = ptr;
 
 		if (dsa_slave_dev_check(dev)) {
-			if (!fdb_info->added_by_user)
+			if (!fdb_info->added_by_user || fdb_info->is_local)
 				return NOTIFY_OK;
 
 			dp = dsa_slave_to_port(dev);
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH resend net-next 2/2] net: bridge: switchdev: include local flag in FDB notifications

Quoted 17 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in bugfix commit 6ab4c3117aec ("net: bridge: don't notify switchdev for local FDB addresses") as well as in this discussion:
https://lore.kernel.org/netdev/20210117193009.io3nungdwuzmo5f7@skbuf/

the switchdev notifiers for FDB entries managed to have a zero-day bug, which was that drivers would not know what to do with local FDB entries, because they were not told that they are local. The bug fix was to simply not notify them of those addresses.

Let us now add the 'is_local' bit to bridge FDB entries, and make all drivers ignore these entries by their own choice.

Quoted 11 lines
---
  drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c        | 4 ++--
  drivers/net/ethernet/marvell/prestera/prestera_switchdev.c | 2 +-
  drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c   | 5 +++--
  drivers/net/ethernet/rocker/rocker_main.c                  | 4 ++--
  drivers/net/ethernet/ti/am65-cpsw-switchdev.c              | 4 ++--
  drivers/net/ethernet/ti/cpsw_switchdev.c                   | 4 ++--
  include/net/switchdev.h                                    | 1 +
  net/bridge/br_switchdev.c                                  | 3 +--
  net/dsa/slave.c                                            | 2 +-
  9 files changed, 15 insertions(+), 14 deletions(-)

For cpsw:

Thank you.

Signature · 2 lines
Best regards,
grygorii
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH resend net-next 2/2] net: bridge: switchdev: include local flag in FDB notifications

In reply to Vladimir Oltean
Quoted 11 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in bugfix commit 6ab4c3117aec ("net: bridge: don't notify switchdev for local FDB addresses") as well as in this discussion:
https://lore.kernel.org/netdev/20210117193009.io3nungdwuzmo5f7@skbuf/

the switchdev notifiers for FDB entries managed to have a zero-day bug, which was that drivers would not know what to do with local FDB entries, because they were not told that they are local. The bug fix was to simply not notify them of those addresses.

Quoted 6 lines

Let us now add the 'is_local' bit to bridge FDB entries, and make all drivers ignore these entries by their own choice.

One comment below

Quoted 5 lines
net/bridge/br_switchdev.c +0 -0
index c390f84adea2..a5e601e41cb9 100644

net/bridge/br_switchdev.c br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type) · line 122

Quoted 9 lines
net/bridge/br_switchdev.c +1 -0
@@ -114,13 +114,12 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 		.addr = fdb->key.addr.addr,
 		.vid = fdb->key.vlan_id,
 		.added_by_user = test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags),
+		.is_local = test_bit(BR_FDB_LOCAL, &fdb->flags),
 		.offloaded = test_bit(BR_FDB_OFFLOADED, &fdb->flags),
 	};
 
 	if (!fdb->dst)
 		return;

Do you plan to eventually remove this check so that entries pointing to the bridge device itself will be notified? For example:

# bridge fdb add 00:01:02:03:04:05 dev br0 self local
Quoted 5 lines
net/bridge/br_switchdev.c +0 -2
-	if (test_bit(BR_FDB_LOCAL, &fdb->flags))
-		return;
 
 	switch (type) {
 	case RTM_DELNEIGH:
author maintainer
#7 lore raw

Re: [PATCH resend net-next 2/2] net: bridge: switchdev: include local flag in FDB notifications

Quoted 12 lines · Ido Schimmel
Quoted 11 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in bugfix commit 6ab4c3117aec ("net: bridge: don't notify switchdev for local FDB addresses") as well as in this discussion:
https://lore.kernel.org/netdev/20210117193009.io3nungdwuzmo5f7@skbuf/

the switchdev notifiers for FDB entries managed to have a zero-day bug, which was that drivers would not know what to do with local FDB entries, because they were not told that they are local. The bug fix was to simply not notify them of those addresses.

Quoted 8 lines
Quoted 6 lines

Let us now add the 'is_local' bit to bridge FDB entries, and make all drivers ignore these entries by their own choice.

Thanks!

Quoted 20 lines

One comment below

Quoted 5 lines
net/bridge/br_switchdev.c +0 -0
index c390f84adea2..a5e601e41cb9 100644

net/bridge/br_switchdev.c br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type) · line 122

Quoted 9 lines
net/bridge/br_switchdev.c +1 -0
@@ -114,13 +114,12 @@ br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type)
 		.addr = fdb->key.addr.addr,
 		.vid = fdb->key.vlan_id,
 		.added_by_user = test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags),
+		.is_local = test_bit(BR_FDB_LOCAL, &fdb->flags),
 		.offloaded = test_bit(BR_FDB_OFFLOADED, &fdb->flags),
 	};
 
 	if (!fdb->dst)
 		return;

Do you plan to eventually remove this check so that entries pointing to the bridge device itself will be notified? For example:

Quoted 7 lines
# bridge fdb add 00:01:02:03:04:05 dev br0 self local

net/bridge/br_switchdev.c br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type) · line 125

Quoted 5 lines
net/bridge/br_switchdev.c +0 -2
-	if (test_bit(BR_FDB_LOCAL, &fdb->flags))
-		return;
 
 	switch (type) {
 	case RTM_DELNEIGH:

Yes I do, it's this patch over here:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

One at a time though.

Acked-by on v1 2/2
#8 lore raw

Re: [PATCH resend net-next 2/2] net: bridge: switchdev: include local flag in FDB notifications

In reply to Vladimir Oltean
Quoted 17 lines · Vladimir Oltean

From: Vladimir Oltean <[email protected]>

As explained in bugfix commit 6ab4c3117aec ("net: bridge: don't notify switchdev for local FDB addresses") as well as in this discussion:
https://lore.kernel.org/netdev/20210117193009.io3nungdwuzmo5f7@skbuf/

the switchdev notifiers for FDB entries managed to have a zero-day bug, which was that drivers would not know what to do with local FDB entries, because they were not told that they are local. The bug fix was to simply not notify them of those addresses.

Let us now add the 'is_local' bit to bridge FDB entries, and make all drivers ignore these entries by their own choice.

Quoted 12 lines
---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c        | 4 ++--
 drivers/net/ethernet/marvell/prestera/prestera_switchdev.c | 2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c   | 5 +++--
 drivers/net/ethernet/rocker/rocker_main.c                  | 4 ++--
 drivers/net/ethernet/ti/am65-cpsw-switchdev.c              | 4 ++--
 drivers/net/ethernet/ti/cpsw_switchdev.c                   | 4 ++--
 include/net/switchdev.h                                    | 1 +
 net/bridge/br_switchdev.c                                  | 3 +--
 net/dsa/slave.c                                            | 2 +-
 9 files changed, 15 insertions(+), 14 deletions(-)

For the bridge change: