linux/net/dsa
Vladimir Oltean d3bd892437 net: dsa: introduce locking for the address lists on CPU and DSA ports
Now that the rtnl_mutex is going away for dsa_port_{host_,}fdb_{add,del},
no one is serializing access to the address lists that DSA keeps for the
purpose of reference counting on shared ports (CPU and cascade ports).

It can happen for one dsa_switch_do_fdb_del to do list_del on a dp->fdbs
element while another dsa_switch_do_fdb_{add,del} is traversing dp->fdbs.
We need to avoid that.

Currently dp->mdbs is not at risk, because dsa_switch_do_mdb_{add,del}
still runs under the rtnl_mutex. But it would be nice if it would not
depend on that being the case. So let's introduce a mutex per port (the
address lists are per port too) and share it between dp->mdbs and
dp->fdbs.

The place where we put the locking is interesting. It could be tempting
to put a DSA-level lock which still serializes calls to
.port_fdb_{add,del}, but it would still not avoid concurrency with other
driver code paths that are currently under rtnl_mutex (.port_fdb_dump,
.port_fast_age). So it would add a very false sense of security (and
adding a global switch-wide lock in DSA to resynchronize with the
rtnl_lock is also counterproductive and hard).

So the locking is intentionally done only where the dp->fdbs and dp->mdbs
lists are traversed. That means, from a driver perspective, that
.port_fdb_add will be called with the dp->addr_lists_lock mutex held on
the CPU port, but not held on user ports. This is done so that driver
writers are not encouraged to rely on any guarantee offered by
dp->addr_lists_lock.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-24 13:47:44 +01:00
..
dsa2.c net: dsa: introduce locking for the address lists on CPU and DSA ports 2021-10-24 13:47:44 +01:00
dsa_priv.h net: dsa: flush switchdev workqueue before tearing down CPU/DSA ports 2021-09-15 15:09:46 -07:00
dsa.c net: dsa: remove the "dsa_to_port in a loop" antipattern from the core 2021-10-21 12:44:06 +01:00
Kconfig net: dsa: tag_rtl8_4: add realtek 8 byte protocol 4 tag 2021-10-18 14:02:56 +01:00
Makefile net: dsa: tag_rtl8_4: add realtek 8 byte protocol 4 tag 2021-10-18 14:02:56 +01:00
master.c dev_ioctl: split out ndo_eth_ioctl 2021-07-27 20:11:45 +01:00
port.c net: dsa: remove gratuitous use of dsa_is_{user,dsa,cpu}_port 2021-10-21 12:44:07 +01:00
slave.c net: dsa: remove the "dsa_to_port in a loop" antipattern from the core 2021-10-21 12:44:06 +01:00
switch.c net: dsa: introduce locking for the address lists on CPU and DSA ports 2021-10-24 13:47:44 +01:00
tag_8021q.c net: dsa: tag_8021q: make dsa_8021q_{rx,tx}_vid take dp as argument 2021-10-21 12:44:07 +01:00
tag_ar9331.c net: dsa: remove the struct packet_type argument from dsa_device_ops::rcv() 2021-08-02 15:13:15 +01:00
tag_brcm.c net: dsa: create a helper for locating EtherType DSA headers on RX 2021-08-11 14:44:58 +01:00
tag_dsa.c net: dsa: mv88e6xxx: isolate the ATU databases of standalone and bridged ports 2021-10-08 15:47:46 -07:00
tag_gswip.c net: dsa: remove the struct packet_type argument from dsa_device_ops::rcv() 2021-08-02 15:13:15 +01:00
tag_hellcreek.c net: dsa: remove the struct packet_type argument from dsa_device_ops::rcv() 2021-08-02 15:13:15 +01:00
tag_ksz.c net/dsa/tag_ksz.c: remove superfluous headers 2021-09-29 11:38:21 +01:00
tag_lan9303.c net: dsa: create a helper for locating EtherType DSA headers on TX 2021-08-11 14:44:58 +01:00
tag_mtk.c net: dsa: create a helper for locating EtherType DSA headers on TX 2021-08-11 14:44:58 +01:00
tag_ocelot_8021q.c net: dsa: tag_8021q: make dsa_8021q_{rx,tx}_vid take dp as argument 2021-10-21 12:44:07 +01:00
tag_ocelot.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2021-10-14 16:50:14 -07:00
tag_qca.c net: dsa: create a helper for locating EtherType DSA headers on TX 2021-08-11 14:44:58 +01:00
tag_rtl4_a.c net: dsa: tag_rtl4_a: Drop bit 9 from egress frames 2021-09-14 19:34:03 -07:00
tag_rtl8_4.c net: dsa: tag_rtl8_4: add realtek 8 byte protocol 4 tag 2021-10-18 14:02:56 +01:00
tag_sja1105.c net: dsa: tag_8021q: make dsa_8021q_{rx,tx}_vid take dp as argument 2021-10-21 12:44:07 +01:00
tag_trailer.c net: dsa: remove the struct packet_type argument from dsa_device_ops::rcv() 2021-08-02 15:13:15 +01:00
tag_xrs700x.c net: dsa: remove the struct packet_type argument from dsa_device_ops::rcv() 2021-08-02 15:13:15 +01:00