Devicetree
 help / color / mirror / Atom feed
From: <JensEmil.SchulzOstergaard@microchip.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <robh@kernel.org>, <conor+dt@kernel.org>, <devicetree@vger.kernel.org>
Subject: Re: [PATCH net-next v10 9/9] net: dsa: lan9645x: add port statistics
Date: Mon, 3 Aug 2026 12:55:15 +0000	[thread overview]
Message-ID: <99cc6ec854d1ffb77472ffec42d54080870cbe29.camel@microchip.com> (raw)
In-Reply-To: <20260714144346.E55C71F00A3E@smtp.kernel.org>

On Tue, 2026-07-14 at 14:43 +0000, sashiko-bot@kernel.org wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] Process-context functions acquire `sw_lock` using `spin_lock()` instead of `spin_lock_bh()`, risking a deadlock with softirq contexts.
> --
> 
> --- Patch [9]: [PATCH net-next v10 9/9] net: dsa: lan9645x: add port statistics ---
> commit e9223f3e66d6e1a49c762c181b787e9d1d5b11fa
> Author: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>
> 
> net: dsa: lan9645x: add port statistics
> 
> This commit adds support for port statistics counters. It introduces a 64-bit
> software cache to handle 32-bit hardware register overflows and exposes standard
> as well as private ethtool statistics.
> 
> > diff --git a/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c b/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c
> > new file mode 100644
> > index 0000000000000..e38f510eb8f66
> > --- /dev/null
> > +++ b/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c
> 
> [ ... ]
> 
> > +static void __lan9645x_stats_view_idx_update(struct lan9645x *lan9645x,
> > +                                          enum lan9645x_view_stat_type vtype,
> > +                                          int idx)
> > +{
> > +     struct lan9645x_stats *s = lan9645x->stats;
> > +
> > +     lockdep_assert_held(&s->hw_lock);
> > +
> > +     if (!__lan9645x_stats_view_idx_hw_read(lan9645x, vtype, idx)) {
> > +             spin_lock(&s->sw_lock);
> 
> [Severity: High]
> Can a softirq preempt this process context and cause a deadlock?
> 
> Since this is called from a delayed workqueue context, it runs with softirqs
> enabled. If a network receive softirq fires on the same CPU while this lock
> is held, it will call lan9645x_stats_get_stats64(), which attempts to
> acquire this same spin_lock, leading to a permanent hang.
> 
> Should this and other process-context lock acquisitions use spin_lock_bh()
> to prevent softirq preemption?
> 
> [ ... ]
> 
> > +void lan9645x_stats_get_ethtool_stats(struct lan9645x *lan9645x, int port,
> > +                                   u64 *data)
> > +{
> > +     struct lan9645x_stats *stats = lan9645x->stats;
> > +     u64 *c;
> > +     int i;
> > +
> > +     c = lan9645x_stats_view_idx_update(lan9645x, LAN9645X_STAT_PORTS, port);
> > +
> > +     spin_lock(&stats->sw_lock);
> 
> [Severity: High]
> Is this another location where the lock should be taken with spin_lock_bh()?
> 
> Ethtool callbacks run in process context and are also vulnerable to the same
> softirq preemption race as the workqueue.
> 
> [ ... ]
> 
> > +/* Called in atomic context */
> > +void lan9645x_stats_get_stats64(struct lan9645x *lan9645x, int port,
> > +                             struct rtnl_link_stats64 *stats)
> > +{
> > +     struct lan9645x_stats *s = lan9645x->stats;
> > +     u64 *c;
> > +
> > +     c = STAT_COUNTERS(lan9645x, LAN9645X_STAT_PORTS, port);
> > +
> > +     spin_lock(&s->sw_lock);
> > +
> > +     stats->rx_bytes = c[SCNT_RX_OCT] + c[SCNT_RX_PMAC_OCT];
> 
> [Severity: High]
> This is the softirq-callable path mentioned above that completes the deadlock
> scenario if it preempts the workqueue or ethtool operations holding sw_lock.
> 

I think this is a false positive, since .ndo_get_stats64 is not called from softirq
context, so the deadlock can not occur. Ocelot and ksz also use a straight spin_lock
for the same purpose here.

> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=9


      reply	other threads:[~2026-08-03 12:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 14:32 [PATCH net-next v10 0/9] net: dsa: add DSA support for the LAN9645x switch chip family Jens Emil Schulz Østergaard
2026-07-13 14:32 ` [PATCH net-next v10 1/9] net: dsa: add tag driver for LAN9645X Jens Emil Schulz Østergaard
2026-07-14 14:43   ` sashiko-bot
2026-08-03 14:16     ` JensEmil.SchulzOstergaard
2026-07-13 14:32 ` [PATCH net-next v10 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings Jens Emil Schulz Østergaard
2026-07-14 14:43   ` sashiko-bot
2026-08-03 13:33     ` JensEmil.SchulzOstergaard
2026-07-13 14:32 ` [PATCH net-next v10 3/9] net: dsa: lan9645x: add autogenerated register macros Jens Emil Schulz Østergaard
2026-07-13 14:32 ` [PATCH net-next v10 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X Jens Emil Schulz Østergaard
2026-07-14 14:43   ` sashiko-bot
2026-08-03 13:28     ` JensEmil.SchulzOstergaard
2026-07-23 13:08   ` Paolo Abeni
2026-08-03 12:32     ` Jens Emil Schulz Ostergaard
2026-07-13 14:32 ` [PATCH net-next v10 5/9] net: dsa: lan9645x: add bridge support Jens Emil Schulz Østergaard
2026-07-13 14:32 ` [PATCH net-next v10 6/9] net: dsa: lan9645x: add vlan support Jens Emil Schulz Østergaard
2026-07-13 14:32 ` [PATCH net-next v10 7/9] net: dsa: lan9645x: add mac table integration Jens Emil Schulz Østergaard
2026-07-13 14:32 ` [PATCH net-next v10 8/9] net: dsa: lan9645x: add mdb management Jens Emil Schulz Østergaard
2026-07-13 14:32 ` [PATCH net-next v10 9/9] net: dsa: lan9645x: add port statistics Jens Emil Schulz Østergaard
2026-07-14 14:43   ` sashiko-bot
2026-08-03 12:55     ` JensEmil.SchulzOstergaard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99cc6ec854d1ffb77472ffec42d54080870cbe29.camel@microchip.com \
    --to=jensemil.schulzostergaard@microchip.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox