Commit 675c807a authored by Horatiu Vultur's avatar Horatiu Vultur Committed by Jakub Kicinski

net: lan966x: Fix usage of lan966x->mac_lock when used by FDB

When the SW bridge was trying to add/remove entries to/from HW, the
access to HW was not protected by any lock. In this way, it was
possible to have race conditions.
Fix this by using the lan966x->mac_lock to protect parallel access to HW
for this cases.

Fixes: 25ee9561 ("net: lan966x: More MAC table functionality")
Signed-off-by: default avatarHoratiu Vultur <horatiu.vultur@microchip.com>
Reviewed-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c1924684
...@@ -201,7 +201,6 @@ static struct lan966x_mac_entry *lan966x_mac_find_entry(struct lan966x *lan966x, ...@@ -201,7 +201,6 @@ static struct lan966x_mac_entry *lan966x_mac_find_entry(struct lan966x *lan966x,
struct lan966x_mac_entry *res = NULL; struct lan966x_mac_entry *res = NULL;
struct lan966x_mac_entry *mac_entry; struct lan966x_mac_entry *mac_entry;
spin_lock(&lan966x->mac_lock);
list_for_each_entry(mac_entry, &lan966x->mac_entries, list) { list_for_each_entry(mac_entry, &lan966x->mac_entries, list) {
if (mac_entry->vid == vid && if (mac_entry->vid == vid &&
ether_addr_equal(mac, mac_entry->mac) && ether_addr_equal(mac, mac_entry->mac) &&
...@@ -210,7 +209,6 @@ static struct lan966x_mac_entry *lan966x_mac_find_entry(struct lan966x *lan966x, ...@@ -210,7 +209,6 @@ static struct lan966x_mac_entry *lan966x_mac_find_entry(struct lan966x *lan966x,
break; break;
} }
} }
spin_unlock(&lan966x->mac_lock);
return res; return res;
} }
...@@ -253,8 +251,11 @@ int lan966x_mac_add_entry(struct lan966x *lan966x, struct lan966x_port *port, ...@@ -253,8 +251,11 @@ int lan966x_mac_add_entry(struct lan966x *lan966x, struct lan966x_port *port,
{ {
struct lan966x_mac_entry *mac_entry; struct lan966x_mac_entry *mac_entry;
if (lan966x_mac_lookup(lan966x, addr, vid, ENTRYTYPE_NORMAL)) spin_lock(&lan966x->mac_lock);
if (lan966x_mac_lookup(lan966x, addr, vid, ENTRYTYPE_NORMAL)) {
spin_unlock(&lan966x->mac_lock);
return 0; return 0;
}
/* In case the entry already exists, don't add it again to SW, /* In case the entry already exists, don't add it again to SW,
* just update HW, but we need to look in the actual HW because * just update HW, but we need to look in the actual HW because
...@@ -263,21 +264,25 @@ int lan966x_mac_add_entry(struct lan966x *lan966x, struct lan966x_port *port, ...@@ -263,21 +264,25 @@ int lan966x_mac_add_entry(struct lan966x *lan966x, struct lan966x_port *port,
* add the entry but without the extern_learn flag. * add the entry but without the extern_learn flag.
*/ */
mac_entry = lan966x_mac_find_entry(lan966x, addr, vid, port->chip_port); mac_entry = lan966x_mac_find_entry(lan966x, addr, vid, port->chip_port);
if (mac_entry) if (mac_entry) {
return lan966x_mac_learn(lan966x, port->chip_port, spin_unlock(&lan966x->mac_lock);
addr, vid, ENTRYTYPE_LOCKED); goto mac_learn;
}
mac_entry = lan966x_mac_alloc_entry(addr, vid, port->chip_port); mac_entry = lan966x_mac_alloc_entry(addr, vid, port->chip_port);
if (!mac_entry) if (!mac_entry) {
spin_unlock(&lan966x->mac_lock);
return -ENOMEM; return -ENOMEM;
}
spin_lock(&lan966x->mac_lock);
list_add_tail(&mac_entry->list, &lan966x->mac_entries); list_add_tail(&mac_entry->list, &lan966x->mac_entries);
spin_unlock(&lan966x->mac_lock); spin_unlock(&lan966x->mac_lock);
lan966x_mac_learn(lan966x, port->chip_port, addr, vid, ENTRYTYPE_LOCKED);
lan966x_fdb_call_notifiers(SWITCHDEV_FDB_OFFLOADED, addr, vid, port->dev); lan966x_fdb_call_notifiers(SWITCHDEV_FDB_OFFLOADED, addr, vid, port->dev);
mac_learn:
lan966x_mac_learn(lan966x, port->chip_port, addr, vid, ENTRYTYPE_LOCKED);
return 0; return 0;
} }
...@@ -291,8 +296,9 @@ int lan966x_mac_del_entry(struct lan966x *lan966x, const unsigned char *addr, ...@@ -291,8 +296,9 @@ int lan966x_mac_del_entry(struct lan966x *lan966x, const unsigned char *addr,
list) { list) {
if (mac_entry->vid == vid && if (mac_entry->vid == vid &&
ether_addr_equal(addr, mac_entry->mac)) { ether_addr_equal(addr, mac_entry->mac)) {
lan966x_mac_forget(lan966x, mac_entry->mac, mac_entry->vid, lan966x_mac_forget_locked(lan966x, mac_entry->mac,
ENTRYTYPE_LOCKED); mac_entry->vid,
ENTRYTYPE_LOCKED);
list_del(&mac_entry->list); list_del(&mac_entry->list);
kfree(mac_entry); kfree(mac_entry);
...@@ -428,6 +434,12 @@ static void lan966x_mac_irq_process(struct lan966x *lan966x, u32 row, ...@@ -428,6 +434,12 @@ static void lan966x_mac_irq_process(struct lan966x *lan966x, u32 row,
continue; continue;
spin_lock(&lan966x->mac_lock); spin_lock(&lan966x->mac_lock);
mac_entry = lan966x_mac_find_entry(lan966x, mac, vid, dest_idx);
if (mac_entry) {
spin_unlock(&lan966x->mac_lock);
continue;
}
mac_entry = lan966x_mac_alloc_entry(mac, vid, dest_idx); mac_entry = lan966x_mac_alloc_entry(mac, vid, dest_idx);
if (!mac_entry) { if (!mac_entry) {
spin_unlock(&lan966x->mac_lock); spin_unlock(&lan966x->mac_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment