提交 f239934c 编写于 作者: V Vladimir Oltean 提交者: David S. Miller

net: dsa: b53: serialize access to the ARL table

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: NVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 f2c4bdf6
...@@ -1546,6 +1546,7 @@ EXPORT_SYMBOL(b53_vlan_del); ...@@ -1546,6 +1546,7 @@ EXPORT_SYMBOL(b53_vlan_del);
/* Address Resolution Logic routines */ /* Address Resolution Logic routines */
static int b53_arl_op_wait(struct b53_device *dev) static int b53_arl_op_wait(struct b53_device *dev)
__must_hold(&dev->arl_mutex)
{ {
unsigned int timeout = 10; unsigned int timeout = 10;
u8 reg; u8 reg;
...@@ -1564,6 +1565,7 @@ static int b53_arl_op_wait(struct b53_device *dev) ...@@ -1564,6 +1565,7 @@ static int b53_arl_op_wait(struct b53_device *dev)
} }
static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) static int b53_arl_rw_op(struct b53_device *dev, unsigned int op)
__must_hold(&dev->arl_mutex)
{ {
u8 reg; u8 reg;
...@@ -1587,6 +1589,7 @@ static int b53_arl_rw_op(struct b53_device *dev, unsigned int op) ...@@ -1587,6 +1589,7 @@ static int b53_arl_rw_op(struct b53_device *dev, unsigned int op)
static int b53_arl_read(struct b53_device *dev, u64 mac, static int b53_arl_read(struct b53_device *dev, u64 mac,
u16 vid, struct b53_arl_entry *ent, u8 *idx) u16 vid, struct b53_arl_entry *ent, u8 *idx)
__must_hold(&dev->arl_mutex)
{ {
DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES); DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES);
unsigned int i; unsigned int i;
...@@ -1632,6 +1635,7 @@ static int b53_arl_read(struct b53_device *dev, u64 mac, ...@@ -1632,6 +1635,7 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,
static int b53_arl_op(struct b53_device *dev, int op, int port, static int b53_arl_op(struct b53_device *dev, int op, int port,
const unsigned char *addr, u16 vid, bool is_valid) const unsigned char *addr, u16 vid, bool is_valid)
__must_hold(&dev->arl_mutex)
{ {
struct b53_arl_entry ent; struct b53_arl_entry ent;
u32 fwd_entry; u32 fwd_entry;
...@@ -1709,6 +1713,7 @@ int b53_fdb_add(struct dsa_switch *ds, int port, ...@@ -1709,6 +1713,7 @@ int b53_fdb_add(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid) const unsigned char *addr, u16 vid)
{ {
struct b53_device *priv = ds->priv; struct b53_device *priv = ds->priv;
int ret;
/* 5325 and 5365 require some more massaging, but could /* 5325 and 5365 require some more massaging, but could
* be supported eventually * be supported eventually
...@@ -1716,7 +1721,11 @@ int b53_fdb_add(struct dsa_switch *ds, int port, ...@@ -1716,7 +1721,11 @@ int b53_fdb_add(struct dsa_switch *ds, int port,
if (is5325(priv) || is5365(priv)) if (is5325(priv) || is5365(priv))
return -EOPNOTSUPP; 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); EXPORT_SYMBOL(b53_fdb_add);
...@@ -1724,12 +1733,18 @@ int b53_fdb_del(struct dsa_switch *ds, int port, ...@@ -1724,12 +1733,18 @@ int b53_fdb_del(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid) const unsigned char *addr, u16 vid)
{ {
struct b53_device *priv = ds->priv; 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); EXPORT_SYMBOL(b53_fdb_del);
static int b53_arl_search_wait(struct b53_device *dev) static int b53_arl_search_wait(struct b53_device *dev)
__must_hold(&dev->arl_mutex)
{ {
unsigned int timeout = 1000; unsigned int timeout = 1000;
u8 reg; u8 reg;
...@@ -1750,6 +1765,7 @@ static int b53_arl_search_wait(struct b53_device *dev) ...@@ -1750,6 +1765,7 @@ static int b53_arl_search_wait(struct b53_device *dev)
static void b53_arl_search_rd(struct b53_device *dev, u8 idx, static void b53_arl_search_rd(struct b53_device *dev, u8 idx,
struct b53_arl_entry *ent) struct b53_arl_entry *ent)
__must_hold(&dev->arl_mutex)
{ {
u64 mac_vid; u64 mac_vid;
u32 fwd_entry; u32 fwd_entry;
...@@ -1782,6 +1798,8 @@ int b53_fdb_dump(struct dsa_switch *ds, int port, ...@@ -1782,6 +1798,8 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,
int ret; int ret;
u8 reg; u8 reg;
mutex_lock(&priv->arl_mutex);
/* Start search operation */ /* Start search operation */
reg = ARL_SRCH_STDN; reg = ARL_SRCH_STDN;
b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg); b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);
...@@ -1789,18 +1807,18 @@ int b53_fdb_dump(struct dsa_switch *ds, int port, ...@@ -1789,18 +1807,18 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,
do { do {
ret = b53_arl_search_wait(priv); ret = b53_arl_search_wait(priv);
if (ret) if (ret)
return ret; break;
b53_arl_search_rd(priv, 0, &results[0]); b53_arl_search_rd(priv, 0, &results[0]);
ret = b53_fdb_copy(port, &results[0], cb, data); ret = b53_fdb_copy(port, &results[0], cb, data);
if (ret) if (ret)
return ret; break;
if (priv->num_arl_bins > 2) { if (priv->num_arl_bins > 2) {
b53_arl_search_rd(priv, 1, &results[1]); b53_arl_search_rd(priv, 1, &results[1]);
ret = b53_fdb_copy(port, &results[1], cb, data); ret = b53_fdb_copy(port, &results[1], cb, data);
if (ret) if (ret)
return ret; break;
if (!results[0].is_valid && !results[1].is_valid) if (!results[0].is_valid && !results[1].is_valid)
break; break;
...@@ -1808,6 +1826,8 @@ int b53_fdb_dump(struct dsa_switch *ds, int port, ...@@ -1808,6 +1826,8 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,
} while (count++ < b53_max_arl_entries(priv) / 2); } while (count++ < b53_max_arl_entries(priv) / 2);
mutex_unlock(&priv->arl_mutex);
return 0; return 0;
} }
EXPORT_SYMBOL(b53_fdb_dump); EXPORT_SYMBOL(b53_fdb_dump);
...@@ -1816,6 +1836,7 @@ int b53_mdb_add(struct dsa_switch *ds, int port, ...@@ -1816,6 +1836,7 @@ int b53_mdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_mdb *mdb) const struct switchdev_obj_port_mdb *mdb)
{ {
struct b53_device *priv = ds->priv; struct b53_device *priv = ds->priv;
int ret;
/* 5325 and 5365 require some more massaging, but could /* 5325 and 5365 require some more massaging, but could
* be supported eventually * be supported eventually
...@@ -1823,7 +1844,11 @@ int b53_mdb_add(struct dsa_switch *ds, int port, ...@@ -1823,7 +1844,11 @@ int b53_mdb_add(struct dsa_switch *ds, int port,
if (is5325(priv) || is5365(priv)) if (is5325(priv) || is5365(priv))
return -EOPNOTSUPP; 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); EXPORT_SYMBOL(b53_mdb_add);
...@@ -1833,7 +1858,9 @@ int b53_mdb_del(struct dsa_switch *ds, int port, ...@@ -1833,7 +1858,9 @@ int b53_mdb_del(struct dsa_switch *ds, int port,
struct b53_device *priv = ds->priv; struct b53_device *priv = ds->priv;
int ret; int ret;
mutex_lock(&priv->arl_mutex);
ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false); ret = b53_arl_op(priv, 0, port, mdb->addr, mdb->vid, false);
mutex_unlock(&priv->arl_mutex);
if (ret) if (ret)
dev_err(ds->dev, "failed to delete MDB entry\n"); dev_err(ds->dev, "failed to delete MDB entry\n");
...@@ -2670,6 +2697,7 @@ struct b53_device *b53_switch_alloc(struct device *base, ...@@ -2670,6 +2697,7 @@ struct b53_device *b53_switch_alloc(struct device *base,
mutex_init(&dev->reg_mutex); mutex_init(&dev->reg_mutex);
mutex_init(&dev->stats_mutex); mutex_init(&dev->stats_mutex);
mutex_init(&dev->arl_mutex);
return dev; return dev;
} }
......
...@@ -107,6 +107,7 @@ struct b53_device { ...@@ -107,6 +107,7 @@ struct b53_device {
struct mutex reg_mutex; struct mutex reg_mutex;
struct mutex stats_mutex; struct mutex stats_mutex;
struct mutex arl_mutex;
const struct b53_io_ops *ops; const struct b53_io_ops *ops;
/* chip specific data */ /* chip specific data */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册