Commit 22d842e3 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: mscc: ocelot: turn stats_lock into a spinlock

ocelot_get_stats64() currently runs unlocked and therefore may collide
with ocelot_port_update_stats() which indirectly accesses the same
counters. However, ocelot_get_stats64() runs in atomic context, and we
cannot simply take the sleepable ocelot->stats_lock mutex. We need to
convert it to an atomic spinlock first. Do that as a preparatory change.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 173ca866
...@@ -2171,7 +2171,7 @@ static void vsc9959_psfp_sgi_table_del(struct ocelot *ocelot, ...@@ -2171,7 +2171,7 @@ static void vsc9959_psfp_sgi_table_del(struct ocelot *ocelot,
static void vsc9959_psfp_counters_get(struct ocelot *ocelot, u32 index, static void vsc9959_psfp_counters_get(struct ocelot *ocelot, u32 index,
struct felix_stream_filter_counters *counters) struct felix_stream_filter_counters *counters)
{ {
mutex_lock(&ocelot->stats_lock); spin_lock(&ocelot->stats_lock);
ocelot_rmw(ocelot, SYS_STAT_CFG_STAT_VIEW(index), ocelot_rmw(ocelot, SYS_STAT_CFG_STAT_VIEW(index),
SYS_STAT_CFG_STAT_VIEW_M, SYS_STAT_CFG_STAT_VIEW_M,
...@@ -2188,7 +2188,7 @@ static void vsc9959_psfp_counters_get(struct ocelot *ocelot, u32 index, ...@@ -2188,7 +2188,7 @@ static void vsc9959_psfp_counters_get(struct ocelot *ocelot, u32 index,
SYS_STAT_CFG_STAT_CLEAR_SHOT(0x10), SYS_STAT_CFG_STAT_CLEAR_SHOT(0x10),
SYS_STAT_CFG); SYS_STAT_CFG);
mutex_unlock(&ocelot->stats_lock); spin_unlock(&ocelot->stats_lock);
} }
static int vsc9959_psfp_filter_add(struct ocelot *ocelot, int port, static int vsc9959_psfp_filter_add(struct ocelot *ocelot, int port,
......
...@@ -1906,13 +1906,13 @@ static void ocelot_check_stats_work(struct work_struct *work) ...@@ -1906,13 +1906,13 @@ static void ocelot_check_stats_work(struct work_struct *work)
stats_work); stats_work);
int i, err; int i, err;
mutex_lock(&ocelot->stats_lock); spin_lock(&ocelot->stats_lock);
for (i = 0; i < ocelot->num_phys_ports; i++) { for (i = 0; i < ocelot->num_phys_ports; i++) {
err = ocelot_port_update_stats(ocelot, i); err = ocelot_port_update_stats(ocelot, i);
if (err) if (err)
break; break;
} }
mutex_unlock(&ocelot->stats_lock); spin_unlock(&ocelot->stats_lock);
if (err) if (err)
dev_err(ocelot->dev, "Error %d updating ethtool stats\n", err); dev_err(ocelot->dev, "Error %d updating ethtool stats\n", err);
...@@ -1925,7 +1925,7 @@ void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data) ...@@ -1925,7 +1925,7 @@ void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data)
{ {
int i, err; int i, err;
mutex_lock(&ocelot->stats_lock); spin_lock(&ocelot->stats_lock);
/* check and update now */ /* check and update now */
err = ocelot_port_update_stats(ocelot, port); err = ocelot_port_update_stats(ocelot, port);
...@@ -1934,7 +1934,7 @@ void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data) ...@@ -1934,7 +1934,7 @@ void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data)
for (i = 0; i < ocelot->num_stats; i++) for (i = 0; i < ocelot->num_stats; i++)
*data++ = ocelot->stats[port * ocelot->num_stats + i]; *data++ = ocelot->stats[port * ocelot->num_stats + i];
mutex_unlock(&ocelot->stats_lock); spin_unlock(&ocelot->stats_lock);
if (err) if (err)
dev_err(ocelot->dev, "Error %d updating ethtool stats\n", err); dev_err(ocelot->dev, "Error %d updating ethtool stats\n", err);
...@@ -3363,7 +3363,7 @@ int ocelot_init(struct ocelot *ocelot) ...@@ -3363,7 +3363,7 @@ int ocelot_init(struct ocelot *ocelot)
if (!ocelot->stats) if (!ocelot->stats)
return -ENOMEM; return -ENOMEM;
mutex_init(&ocelot->stats_lock); spin_lock_init(&ocelot->stats_lock);
mutex_init(&ocelot->ptp_lock); mutex_init(&ocelot->ptp_lock);
mutex_init(&ocelot->mact_lock); mutex_init(&ocelot->mact_lock);
mutex_init(&ocelot->fwd_domain_lock); mutex_init(&ocelot->fwd_domain_lock);
...@@ -3511,7 +3511,6 @@ void ocelot_deinit(struct ocelot *ocelot) ...@@ -3511,7 +3511,6 @@ void ocelot_deinit(struct ocelot *ocelot)
cancel_delayed_work(&ocelot->stats_work); cancel_delayed_work(&ocelot->stats_work);
destroy_workqueue(ocelot->stats_queue); destroy_workqueue(ocelot->stats_queue);
destroy_workqueue(ocelot->owq); destroy_workqueue(ocelot->owq);
mutex_destroy(&ocelot->stats_lock);
} }
EXPORT_SYMBOL(ocelot_deinit); EXPORT_SYMBOL(ocelot_deinit);
......
...@@ -752,7 +752,7 @@ struct ocelot { ...@@ -752,7 +752,7 @@ struct ocelot {
struct ocelot_psfp_list psfp; struct ocelot_psfp_list psfp;
/* Workqueue to check statistics for overflow with its lock */ /* Workqueue to check statistics for overflow with its lock */
struct mutex stats_lock; spinlock_t stats_lock;
u64 *stats; u64 *stats;
struct delayed_work stats_work; struct delayed_work stats_work;
struct workqueue_struct *stats_queue; struct workqueue_struct *stats_queue;
......
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