Re: [[RFC PATCH v4 net-next] 0/2] net: dsa: hsr: Enable HSR HW offloading for KSZ9477

From: Vladimir Oltean
Date: Mon Sep 11 2023 - 17:10:33 EST


On Mon, Sep 11, 2023 at 07:05:01PM +0300, Vladimir Oltean wrote:
> Actually, the reason why I haven't yet said anything is because it made
> me realize that there is a pre-existing bug in net/dsa/slave.c where we
> have this pattern:
>
> if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
> dev_uc_add(master, dev->dev_addr);
>
> but there is no replay of the dev_uc_add() call when the master->dev_addr
> changes. This really results in RX packet loss, as I have tested. I don't
> know what is the best way to solve it.

Hi @Jakub, I remember you fixed some issues with the dev->dev_addr writes,
after dev_addr_lists.c was changed to a rbtree. Is it easy for you to
tell if the change below is safe from an API perspective?

Is the answer "yes, because dev_uc_add() uses an addr_type of NETDEV_HW_ADDR_T_UNICAST,
and dev->dev_addr uses NETDEV_HW_ADDR_T_LAN, so they never share a struct netdev_hw_addr
for the same MAC address, and thus, they never collide"?

The DSA and 8021q drivers currently have this pattern, from around 2008.
But 8021q also tracks NETDEV_CHANGEADDR events on the real_dev, which is
absent in DSA. If the change below is safe, it would be a simpler solution.

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 48db91b33390..e40474e13660 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -374,11 +374,9 @@ static int dsa_slave_open(struct net_device *dev)
goto out;
}

- if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) {
- err = dev_uc_add(master, dev->dev_addr);
- if (err < 0)
- goto del_host_addr;
- }
+ err = dev_uc_add(master, dev->dev_addr);
+ if (err < 0)
+ goto del_host_addr;

err = dsa_port_enable_rt(dp, dev->phydev);
if (err)
@@ -387,8 +385,7 @@ static int dsa_slave_open(struct net_device *dev)
return 0;

del_unicast:
- if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
- dev_uc_del(master, dev->dev_addr);
+ dev_uc_del(master, dev->dev_addr);
del_host_addr:
if (dsa_switch_supports_uc_filtering(ds))
dsa_port_standalone_host_fdb_del(dp, dev->dev_addr, 0);
@@ -404,8 +401,7 @@ static int dsa_slave_close(struct net_device *dev)

dsa_port_disable_rt(dp);

- if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
- dev_uc_del(master, dev->dev_addr);
+ dev_uc_del(master, dev->dev_addr);

if (dsa_switch_supports_uc_filtering(ds))
dsa_port_standalone_host_fdb_del(dp, dev->dev_addr, 0);
@@ -469,14 +465,11 @@ static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
return err;
}

- if (!ether_addr_equal(addr->sa_data, master->dev_addr)) {
- err = dev_uc_add(master, addr->sa_data);
- if (err < 0)
- goto del_unicast;
- }
+ err = dev_uc_add(master, addr->sa_data);
+ if (err < 0)
+ goto del_unicast;

- if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
- dev_uc_del(master, dev->dev_addr);
+ dev_uc_del(master, dev->dev_addr);

if (dsa_switch_supports_uc_filtering(ds))
dsa_port_standalone_host_fdb_del(dp, dev->dev_addr, 0);