All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jens Emil Schulz Østergaard" <jensemil.schulzostergaard@microchip.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org,
	wsa+renesas@sang-engineering.com, robh@kernel.org
Subject: Re: [PATCH net-next v14 9/9] net: dsa: lan9645x: add port statistics
Date: Fri, 09 Oct 2026 09:06:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-165129@kernel.org> (raw)
In-Reply-To: <20261008-dsa_lan9645x_switch_driver_base-v14-9-3d2a72661213@microchip.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: dsa: lan9645x: spin_lock deadlock between process context and ndo_get_stats64
--

commit eaa26add9ac1e5f091f43891f8f2f615b10f01f1
Author: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@microchip.com>

net: dsa: lan9645x: add port statistics

This commit adds support for port statistics counters. It handles overflows
in 32-bit hardware registers by maintaining a 64-bit software cache.

> diff --git a/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c b/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c
> --- /dev/null
> +++ b/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c

[ ... ]

> @@ -321,11 +321,11 @@ 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 this cause a deadlock? The periodic stats update workqueue and ethtool
queries run in process context and acquire s->sw_lock here without disabling
softirqs. Process-context lock acquisitions must use spin_lock_bh() to
prevent a deadlock if a softirq tries to take the lock on the same CPU.

>  		__lan9645x_stats_view_idx_transfer(lan9645x, vtype, idx);
>  		spin_unlock(&s->sw_lock);
>  	}
>  }

[ ... ]

> @@ -536,11 +536,11 @@ void lan9645x_stats_get_stats64(struct lan9645x *lan9645x, int port,
>  				struct rtnl_link_stats64 *stats)
>  {
>  	struct lan9645x_stats *s = lan9645x->stats;
>  	u64 *c;
>  
>  	c = lan9645x_stat_counters(lan9645x, LAN9645X_STAT_PORTS, port);
>  
>  	/* ndo_get_stats64 may run in non-sleepable context (under
>  	 * rcu_read_lock, or with a callers spinlock held as in bonding), so
>  	 * unlike the ethtool paths we must not take the hw_lock mutex or touch
>  	 * hardware here.
>  	 * sw_lock is never taken from softirq/IRQ context by any path, so a
>  	 * plain spin_lock is sufficient, as in ocelot and ksz.
>  	 */
>  	spin_lock(&s->sw_lock);

[Severity: High]
Could this lead to a deadlock on s->sw_lock?

The comment indicates the lock is never taken from softirq/IRQ context, but
ndo_get_stats64 can be called from atomic/softirq context (for example, when
queried by bonding or netfilter). 

If a softirq fires on the same CPU while the preempted process-context thread
holds the lock (from __lan9645x_stats_view_idx_update), it will spin forever
trying to acquire s->sw_lock.

>  
>  	stats->rx_bytes = c[SCNT_RX_OCT] + c[SCNT_RX_PMAC_OCT];

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213@microchip.com?part=9

  reply	other threads:[~2026-10-09  9:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08  9:05 [PATCH net-next v14 0/9] net: dsa: add DSA support for the LAN9645x switch chip family Jens Emil Schulz Østergaard
2026-10-08  9:05 ` [PATCH net-next v14 1/9] net: dsa: add tag driver for LAN9645X Jens Emil Schulz Østergaard
2026-10-09  9:06   ` sashiko-bot
2026-10-12 11:24   ` netdev-bot+sashiko
2026-10-08  9:05 ` [PATCH net-next v14 2/9] dt-bindings: net: dsa: add Microchip LAN9645x switch Jens Emil Schulz Østergaard
2026-10-08 20:29   ` Rob Herring (Arm)
2026-10-12 11:24   ` netdev-bot+sashiko
2026-10-08  9:05 ` [PATCH net-next v14 3/9] net: dsa: lan9645x: add autogenerated register macros Jens Emil Schulz Østergaard
2026-10-08  9:05 ` [PATCH net-next v14 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X Jens Emil Schulz Østergaard
2026-10-12 11:24   ` netdev-bot+sashiko
2026-10-08  9:05 ` [PATCH net-next v14 5/9] net: dsa: lan9645x: add vlan support Jens Emil Schulz Østergaard
2026-10-12 11:24   ` netdev-bot+sashiko
2026-10-08  9:05 ` [PATCH net-next v14 6/9] net: dsa: lan9645x: add mac table integration Jens Emil Schulz Østergaard
2026-10-08  9:05 ` [PATCH net-next v14 7/9] net: dsa: lan9645x: add mdb management Jens Emil Schulz Østergaard
2026-10-12 11:24   ` netdev-bot+sashiko
2026-10-08  9:05 ` [PATCH net-next v14 8/9] net: dsa: lan9645x: add bridge support Jens Emil Schulz Østergaard
2026-10-12 11:24   ` netdev-bot+sashiko
2026-10-08  9:05 ` [PATCH net-next v14 9/9] net: dsa: lan9645x: add port statistics Jens Emil Schulz Østergaard
2026-10-09  9:06   ` sashiko-bot [this message]
2026-10-12 11:24   ` netdev-bot+sashiko

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=sashiko-outbox-165129@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jensemil.schulzostergaard@microchip.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.