* [PATCH v1 net 0/1] ocelot stats mutex fix
@ 2022-02-10 15:04 Colin Foster
2022-02-10 15:04 ` [PATCH v1 net 1/1] net: mscc: ocelot: fix mutex lock error during ethtool stats read Colin Foster
2022-02-10 20:00 ` [PATCH v1 net 0/1] ocelot stats mutex fix patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Colin Foster @ 2022-02-10 15:04 UTC (permalink / raw)
To: linux-kernel, netdev
Cc: Andrew Lunn, Jakub Kicinski, David S. Miller, UNGLinuxDriver,
Alexandre Belloni, Claudiu Manoil, Vladimir Oltean
Originally submitted to net-next as part of
20220210041345.321216-6-colin.foster@in-advantage.com, this patch
resolves a bug where a mutex was not guarding a buffer read that could
be concurrently written into.
Break this out as a separate patch to be applied to net.
Colin Foster (1):
net: mscc: ocelot: fix mutex lock error during ethtool stats read
drivers/net/ethernet/mscc/ocelot.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v1 net 1/1] net: mscc: ocelot: fix mutex lock error during ethtool stats read
2022-02-10 15:04 [PATCH v1 net 0/1] ocelot stats mutex fix Colin Foster
@ 2022-02-10 15:04 ` Colin Foster
2022-02-10 20:00 ` [PATCH v1 net 0/1] ocelot stats mutex fix patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Colin Foster @ 2022-02-10 15:04 UTC (permalink / raw)
To: linux-kernel, netdev
Cc: Andrew Lunn, Jakub Kicinski, David S. Miller, UNGLinuxDriver,
Alexandre Belloni, Claudiu Manoil, Vladimir Oltean
An ongoing workqueue populates the stats buffer. At the same time, a user
might query the statistics. While writing to the buffer is mutex-locked,
reading from the buffer wasn't. This could lead to buggy reads by ethtool.
This patch fixes the former blamed commit, but the bug was introduced in
the latter.
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
Fixes: 1e1caa9735f90 ("ocelot: Clean up stats update deferred work")
Fixes: a556c76adc052 ("net: mscc: Add initial Ocelot switch support")
Reported-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/mscc/ocelot.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
index 354e4474bcc3..e6de86552df0 100644
--- a/drivers/net/ethernet/mscc/ocelot.c
+++ b/drivers/net/ethernet/mscc/ocelot.c
@@ -1745,12 +1745,11 @@ void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data)
}
EXPORT_SYMBOL(ocelot_get_strings);
+/* Caller must hold &ocelot->stats_lock */
static void ocelot_update_stats(struct ocelot *ocelot)
{
int i, j;
- mutex_lock(&ocelot->stats_lock);
-
for (i = 0; i < ocelot->num_phys_ports; i++) {
/* Configure the port to read the stats from */
ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG);
@@ -1769,8 +1768,6 @@ static void ocelot_update_stats(struct ocelot *ocelot)
~(u64)U32_MAX) + val;
}
}
-
- mutex_unlock(&ocelot->stats_lock);
}
static void ocelot_check_stats_work(struct work_struct *work)
@@ -1779,7 +1776,9 @@ static void ocelot_check_stats_work(struct work_struct *work)
struct ocelot *ocelot = container_of(del_work, struct ocelot,
stats_work);
+ mutex_lock(&ocelot->stats_lock);
ocelot_update_stats(ocelot);
+ mutex_unlock(&ocelot->stats_lock);
queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work,
OCELOT_STATS_CHECK_DELAY);
@@ -1789,12 +1788,16 @@ void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data)
{
int i;
+ mutex_lock(&ocelot->stats_lock);
+
/* check and update now */
ocelot_update_stats(ocelot);
/* Copy all counters */
for (i = 0; i < ocelot->num_stats; i++)
*data++ = ocelot->stats[port * ocelot->num_stats + i];
+
+ mutex_unlock(&ocelot->stats_lock);
}
EXPORT_SYMBOL(ocelot_get_ethtool_stats);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1 net 0/1] ocelot stats mutex fix
2022-02-10 15:04 [PATCH v1 net 0/1] ocelot stats mutex fix Colin Foster
2022-02-10 15:04 ` [PATCH v1 net 1/1] net: mscc: ocelot: fix mutex lock error during ethtool stats read Colin Foster
@ 2022-02-10 20:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-10 20:00 UTC (permalink / raw)
To: Colin Foster
Cc: linux-kernel, netdev, andrew, kuba, davem, UNGLinuxDriver,
alexandre.belloni, claudiu.manoil, vladimir.oltean
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 10 Feb 2022 07:04:50 -0800 you wrote:
> Originally submitted to net-next as part of
> 20220210041345.321216-6-colin.foster@in-advantage.com, this patch
> resolves a bug where a mutex was not guarding a buffer read that could
> be concurrently written into.
>
> Break this out as a separate patch to be applied to net.
>
> [...]
Here is the summary with links:
- [v1,net,1/1] net: mscc: ocelot: fix mutex lock error during ethtool stats read
https://git.kernel.org/netdev/net/c/7fbf6795d127
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-10 20:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 15:04 [PATCH v1 net 0/1] ocelot stats mutex fix Colin Foster
2022-02-10 15:04 ` [PATCH v1 net 1/1] net: mscc: ocelot: fix mutex lock error during ethtool stats read Colin Foster
2022-02-10 20:00 ` [PATCH v1 net 0/1] ocelot stats mutex fix patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).