Skip to content

Commit

Permalink
net: dsa: b53: serialize access to the ARL table
Browse files Browse the repository at this point in the history
The b53 driver performs non-atomic transactions to the ARL table when
adding, deleting and reading FDB and MDB entries.

Traditionally these were all serialized by the rtnl_lock(), but now it
is possible that DSA calls ->port_fdb_add and ->port_fdb_del without
holding that lock.

So the driver must have its own serialization logic. Add a mutex and
hold it from all entry points (->port_fdb_{add,del,dump},
->port_mdb_{add,del}).

Signed-off-by: Vladimir Oltean <[email protected]>
Reviewed-by: Florian Fainelli <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
vladimiroltean authored and davem330 committed Oct 25, 2021
1 parent 2468346 commit f7eb4a1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
36 changes: 29 additions & 7 deletions drivers/net/dsa/b53/b53_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
}
EXPORT_SYMBOL(b53_vlan_del);

/* Address Resolution Logic routines */
/* Address Resolution Logic routines. Caller must hold &dev->arl_mutex. */
static int b53_arl_op_wait(struct b53_device *dev)
{
unsigned int timeout = 10;
Expand Down Expand Up @@ -1707,23 +1707,33 @@ int b53_fdb_add(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid)
{
struct b53_device *priv = ds->priv;
int ret;

/* 5325 and 5365 require some more massaging, but could
* be supported eventually
*/
if (is5325(priv) || is5365(priv))
return -EOPNOTSUPP;

return b53_arl_op(priv, 0, port, addr, vid, true);
mutex_lock(&priv->arl_mutex);
ret = b53_arl_op(priv, 0, port, addr, vid, true);
mutex_unlock(&priv->arl_mutex);

return ret;
}
EXPORT_SYMBOL(b53_fdb_add);

int b53_fdb_del(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid)
{
struct b53_device *priv = ds->priv;
int ret;

return b53_arl_op(priv, 0, port, addr, vid, false);
mutex_lock(&priv->arl_mutex);
ret = b53_arl_op(priv, 0, port, addr, vid, false);
mutex_unlock(&priv->arl_mutex);

return ret;
}
EXPORT_SYMBOL(b53_fdb_del);

Expand Down Expand Up @@ -1780,32 +1790,36 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,
int ret;
u8 reg;

mutex_lock(&priv->arl_mutex);

/* Start search operation */
reg = ARL_SRCH_STDN;
b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);

do {
ret = b53_arl_search_wait(priv);
if (ret)
return ret;
break;

b53_arl_search_rd(priv, 0, &results[0]);
ret = b53_fdb_copy(port, &results[0], cb, data);
if (ret)
return ret;
break;

if (priv->num_arl_bins > 2) {
b53_arl_search_rd(priv, 1, &results[1]);
ret = b53_fdb_copy(port, &results[1], cb, data);
if (ret)
return ret;
break;

if (!results[0].is_valid && !results[1].is_valid)
break;
}

} while (count++ < b53_max_arl_entries(priv) / 2);

mutex_unlock(&priv->arl_mutex);

return 0;
}
EXPORT_SYMBOL(b53_fdb_dump);
Expand All @@ -1814,14 +1828,19 @@ int b53_mdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb)
{
struct b53_device *priv = ds->priv;
int ret;

/* 5325 and 5365 require some more massaging, but could
* be supported eventually
*/
if (is5325(priv) || is5365(priv))
return -EOPNOTSUPP;

return b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true);
mutex_lock(&priv->arl_mutex);
ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, true);
mutex_unlock(&priv->arl_mutex);

return ret;
}
EXPORT_SYMBOL(b53_mdb_add);

Expand All @@ -1831,7 +1850,9 @@ int b53_mdb_del(struct dsa_switch *ds, int port,
struct b53_device *priv = ds->priv;
int ret;

mutex_lock(&priv->arl_mutex);
ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false);
mutex_unlock(&priv->arl_mutex);
if (ret)
dev_err(ds->dev, "failed to delete MDB entry\n");

Expand Down Expand Up @@ -2668,6 +2689,7 @@ struct b53_device *b53_switch_alloc(struct device *base,

mutex_init(&dev->reg_mutex);
mutex_init(&dev->stats_mutex);
mutex_init(&dev->arl_mutex);

return dev;
}
Expand Down
1 change: 1 addition & 0 deletions drivers/net/dsa/b53/b53_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct b53_device {

struct mutex reg_mutex;
struct mutex stats_mutex;
struct mutex arl_mutex;
const struct b53_io_ops *ops;

/* chip specific data */
Expand Down

0 comments on commit f7eb4a1

Please sign in to comment.