Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jens Emil Schulz Østergaard" <jensemil.schulzostergaard@microchip.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH net-next v7 9/9] net: dsa: lan9645x: add port statistics
Date: Thu, 04 Jun 2026 07:26:45 +0000	[thread overview]
Message-ID: <20260604072645.88B771F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603-dsa_lan9645x_switch_driver_base-v7-9-b2f90e676707@microchip.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Deadlock risk due to using plain `spin_lock()` on `sw_lock` in both process and softirq contexts.
--

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

net: dsa: lan9645x: add port statistics

Add statistics support for the port counters. Chip registers are 32 bit,
so this unit is responsible maintaining a 64bit software cache, and
updating it frequently to handle overflows in hardware.

> 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]
Does this code risk a deadlock? This lock is acquired here in process context
(the delayed workqueue worker) using a plain spin_lock().

However, lan9645x_stats_get_stats64() is called in atomic context (such as
softirq) and also acquires sw_lock. If a softirq preempts the process-context
thread while it holds sw_lock, and the softirq then attempts to read
statistics, the softirq could spin forever trying to acquire the same sw_lock.

Should the process-context paths use spin_lock_bh() instead to disable
bottom halves and prevent this race?

> +		__lan9645x_stats_view_idx_transfer(lan9645x, vtype, idx);
> +		spin_unlock(&s->sw_lock);
> +	}
> +}
[ ... ]
> +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 it possible for a softirq to preempt here as well? Like the update function
above, this is in process context and uses a plain spin_lock(), which carries
the same deadlock risk with the atomic context in lan9645x_stats_get_stats64().

The same pattern is repeated across all the other ethtool callbacks in this
file.

> +	for (i = 0; i < ARRAY_SIZE(lan9645x_port_ethtool_stats); i++)
> +		*data++ = c[lan9645x_port_ethtool_stats[i].idx];
> +	spin_unlock(&stats->sw_lock);
> +}
[ ... ]
> +/* 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);

[Severity: High]
Could the deadlock mentioned above occur here if the lock is acquired by a
preempting softirq, since this is explicitly called in atomic context?

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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260603-dsa_lan9645x_switch_driver_base-v7-0-b2f90e676707@microchip.com?part=9

      reply	other threads:[~2026-06-04  7:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03  7:25 [PATCH net-next v7 0/9] net: dsa: add DSA support for the LAN9645x switch chip family Jens Emil Schulz Østergaard
2026-06-03  7:25 ` [PATCH net-next v7 1/9] net: dsa: add tag driver for LAN9645X Jens Emil Schulz Østergaard
2026-06-03  7:25 ` [PATCH net-next v7 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings Jens Emil Schulz Østergaard
2026-06-04  7:26   ` sashiko-bot
2026-06-03  7:25 ` [PATCH net-next v7 3/9] net: dsa: lan9645x: add autogenerated register macros Jens Emil Schulz Østergaard
2026-06-03  7:25 ` [PATCH net-next v7 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X Jens Emil Schulz Østergaard
2026-06-03 12:37   ` Andrew Lunn
2026-06-04  7:26   ` sashiko-bot
2026-06-03  7:25 ` [PATCH net-next v7 5/9] net: dsa: lan9645x: add bridge support Jens Emil Schulz Østergaard
2026-06-03  7:25 ` [PATCH net-next v7 6/9] net: dsa: lan9645x: add vlan support Jens Emil Schulz Østergaard
2026-06-03  7:25 ` [PATCH net-next v7 7/9] net: dsa: lan9645x: add mac table integration Jens Emil Schulz Østergaard
2026-06-04  7:26   ` sashiko-bot
2026-06-03  7:25 ` [PATCH net-next v7 8/9] net: dsa: lan9645x: add mdb management Jens Emil Schulz Østergaard
2026-06-03  7:25 ` [PATCH net-next v7 9/9] net: dsa: lan9645x: add port statistics Jens Emil Schulz Østergaard
2026-06-04  7:26   ` sashiko-bot [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=20260604072645.88B771F00893@smtp.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 \
    /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