diff mbox series

[net,1/2] net: dsa: xrs700x: Use irqsave variant for u64 stats update

Message ID 20220825113645.212996-2-bigeasy@linutronix.de (mailing list archive)
State Accepted
Commit 3f8ae9fe0409698799e173f698b714f34570b64b
Delegated to: Netdev Maintainers
Headers show
Series net: u64_stats fixups for 32bit. | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 85 this patch: 85
netdev/cc_maintainers warning 2 maintainers not CCed: edumazet@google.com pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 85 this patch: 85
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sebastian Andrzej Siewior Aug. 25, 2022, 11:36 a.m. UTC
xrs700x_read_port_counters() updates the stats from a worker using the
u64_stats_update_begin() version. This is okay on 32-UP since on the
reader side preemption is disabled.
On 32bit-SMP the writer can be preempted by the reader at which point
the reader will spin on the seqcount until writer continues and
completes the update.

Assigning the mib_mutex mutex to the underlying seqcount would ensure
proper synchronisation. The API for that on the u64_stats_init() side
isn't available. Since it is the only user, just use disable interrupts
during the update.

Use u64_stats_update_begin_irqsave() on the writer side to ensure an
uninterrupted update.

Fixes: ee00b24f32eb8 ("net: dsa: add Arrow SpeedChips XRS700x driver")
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: George McCollister <george.mccollister@gmail.com>
Cc: Vivien Didelot <vivien.didelot@gmail.com>
Cc: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/net/dsa/xrs700x/xrs700x.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

George McCollister Aug. 25, 2022, 11:51 a.m. UTC | #1
On Thu, Aug 25, 2022 at 6:36 AM Sebastian Andrzej Siewior
<bigeasy@linutronix.de> wrote:
>
> xrs700x_read_port_counters() updates the stats from a worker using the
> u64_stats_update_begin() version. This is okay on 32-UP since on the
> reader side preemption is disabled.
> On 32bit-SMP the writer can be preempted by the reader at which point
> the reader will spin on the seqcount until writer continues and
> completes the update.
>
> Assigning the mib_mutex mutex to the underlying seqcount would ensure
> proper synchronisation. The API for that on the u64_stats_init() side
> isn't available. Since it is the only user, just use disable interrupts
> during the update.
>
> Use u64_stats_update_begin_irqsave() on the writer side to ensure an
> uninterrupted update.
>
> Fixes: ee00b24f32eb8 ("net: dsa: add Arrow SpeedChips XRS700x driver")
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Florian Fainelli <f.fainelli@gmail.com>
> Cc: George McCollister <george.mccollister@gmail.com>
> Cc: Vivien Didelot <vivien.didelot@gmail.com>
> Cc: Vladimir Oltean <olteanv@gmail.com>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  drivers/net/dsa/xrs700x/xrs700x.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/dsa/xrs700x/xrs700x.c b/drivers/net/dsa/xrs700x/xrs700x.c
> index 3887ed33c5fe2..fa622639d6401 100644
> --- a/drivers/net/dsa/xrs700x/xrs700x.c
> +++ b/drivers/net/dsa/xrs700x/xrs700x.c
> @@ -109,6 +109,7 @@ static void xrs700x_read_port_counters(struct xrs700x *priv, int port)
>  {
>         struct xrs700x_port *p = &priv->ports[port];
>         struct rtnl_link_stats64 stats;
> +       unsigned long flags;
>         int i;
>
>         memset(&stats, 0, sizeof(stats));
> @@ -138,9 +139,9 @@ static void xrs700x_read_port_counters(struct xrs700x *priv, int port)
>          */
>         stats.rx_packets += stats.multicast;
>
> -       u64_stats_update_begin(&p->syncp);
> +       flags = u64_stats_update_begin_irqsave(&p->syncp);
>         p->stats64 = stats;
> -       u64_stats_update_end(&p->syncp);
> +       u64_stats_update_end_irqrestore(&p->syncp, flags);
>
>         mutex_unlock(&p->mib_mutex);
>  }
> --
> 2.37.2
>

Acked-by: George McCollister <george.mccollister@gmail.com>

Thanks,
George
diff mbox series

Patch

diff --git a/drivers/net/dsa/xrs700x/xrs700x.c b/drivers/net/dsa/xrs700x/xrs700x.c
index 3887ed33c5fe2..fa622639d6401 100644
--- a/drivers/net/dsa/xrs700x/xrs700x.c
+++ b/drivers/net/dsa/xrs700x/xrs700x.c
@@ -109,6 +109,7 @@  static void xrs700x_read_port_counters(struct xrs700x *priv, int port)
 {
 	struct xrs700x_port *p = &priv->ports[port];
 	struct rtnl_link_stats64 stats;
+	unsigned long flags;
 	int i;
 
 	memset(&stats, 0, sizeof(stats));
@@ -138,9 +139,9 @@  static void xrs700x_read_port_counters(struct xrs700x *priv, int port)
 	 */
 	stats.rx_packets += stats.multicast;
 
-	u64_stats_update_begin(&p->syncp);
+	flags = u64_stats_update_begin_irqsave(&p->syncp);
 	p->stats64 = stats;
-	u64_stats_update_end(&p->syncp);
+	u64_stats_update_end_irqrestore(&p->syncp, flags);
 
 	mutex_unlock(&p->mib_mutex);
 }