Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Selvamani Rajagopal" <Selvamani.Rajagopal@onsemi.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v12 15/15] net: ethernet: onsemi: s2500: Add driver support for S2500
Date: Wed, 25 Nov 2026 22:10:38 +0000	[thread overview]
Message-ID: <sashiko-outbox-234235@kernel.org> (raw)
In-Reply-To: <20261124-s2500-mac-phy-support-v12-15-3575855d99f9@onsemi.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] net: onsemi: s2500: unlocked stats_last_update read and update
  race in s2500_update_stats()
--

commit 9d3f5419946ef1ff66db03059d964b7e06436b9d
Author: Selvamani Rajagopal <Selvamani.Rajagopal@onsemi.com>

net: ethernet: onsemi: s2500: Add driver support for S2500

This commit adds a network driver for the onsemi S2500 10BASE-T1S
MAC-PHY using the OPEN Alliance TC6 framework, including ethtool
statistics and register dump support, multicast filtering, and PTP clock
support.

> diff --git a/drivers/net/ethernet/onsemi/s2500/s2500_ethtool.c b/drivers/net/ethernet/onsemi/s2500/s2500_ethtool.c
> new file mode 100644
> index 0000000000000..77d7d172efe0d
> --- /dev/null
> +++ b/drivers/net/ethernet/onsemi/s2500/s2500_ethtool.c
[ ... ]
> +void s2500_update_stats(struct s2500_info *priv, u64 *buf)
> +{
> +	u32 regs[S2500_NUM_STAT_REGS];
> +	bool have_regs = false;
> +	u32 addr;
> +
> +	if (!time_is_after_jiffies(priv->stats_last_update +
> +				   S2500_STATS_CACHE_PERIOD)) {
> +		addr = FIELD_PREP(S2500_REG_MMS_MASK, OA_TC6_MAC_MMS1) |
> +				  S2500_REG_MAC_STOCTETSTXL;
> +		have_regs = !oa_tc6_read_registers(priv->tc6, addr, regs,
> +						   S2500_NUM_STAT_REGS);
> +	}
> +
> +	if (!have_regs && !buf)
> +		return;
> +
> +	spin_lock_bh(&priv->stats_lock);
> +	if (have_regs) {
> +		priv->stats_last_update = jiffies;
> +		s2500_accumulate_stats(priv, regs);
> +	}
> +	if (buf)
> +		memcpy(buf, priv->stats_data, sizeof(priv->stats_data));
> +	spin_unlock_bh(&priv->stats_lock);
> +}

[Severity: Low]
Can concurrent calls to s2500_update_stats() from s2500_stats_work() and
an ethtool statistics callback race on priv->stats_last_update and the
clear-on-read hardware counters?

struct s2500_info documents that stats_lock protects both stats_data and
stats_last_update, but s2500_update_stats() reads priv->stats_last_update
without holding stats_lock or using READ_ONCE() while another context can
write it under stats_lock, causing a data race.

Because nothing serializes the cache-expiry check, the clear-on-read SPI
register read, and the counter accumulation, an ethtool query can also
observe a stale snapshot after the work item has already cleared the
hardware counters:

kworker                           CPU0 (ethtool)
s2500_stats_work()
  s2500_update_stats(priv, NULL)
    !time_is_after_jiffies(...)
                                  s2500_get_eth_mac_stats()
                                    s2500_update_stats(priv, st)
                                      !time_is_after_jiffies(...)
    oa_tc6_read_registers(...)
      (clears HW counters, holds delta)
                                      oa_tc6_read_registers(...)
                                        (reads 0)
                                      spin_lock_bh(&priv->stats_lock)
                                      memcpy(buf, priv->stats_data, ...)
                                        <-- misses kworker's cleared delta
                                      spin_unlock_bh(&priv->stats_lock)
    spin_lock_bh(&priv->stats_lock)
    s2500_accumulate_stats(priv, regs)
    spin_unlock_bh(&priv->stats_lock)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-s2500-mac-phy-support-v12-0-3575855d99f9@onsemi.com?part=15

      reply	other threads:[~2026-11-25 22:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 22:09 [PATCH net-next v12 00/15] Support for onsemi's S2500 10BASE-T1S MAC-PHY Selvamani Rajagopal via B4 Relay
2026-11-24 22:09 ` [PATCH net-next v12 01/15] dt-bindings: net: add onsemi's S2500 Selvamani Rajagopal via B4 Relay
2026-11-24 22:09 ` [PATCH net-next v12 02/15] Documentation: networking: Add timestamp related APIs to OA TC6 framework Selvamani Rajagopal via B4 Relay
2026-11-24 22:09 ` [PATCH net-next v12 03/15] net: ethernet: oa_tc6: Move oa_tc6.c to its own directory Selvamani Rajagopal via B4 Relay
2026-11-24 22:09 ` [PATCH net-next v12 04/15] net: ethernet: oa_tc6: Move constant definitions to header file Selvamani Rajagopal via B4 Relay
2026-11-24 22:09 ` [PATCH net-next v12 05/15] net: ethernet: microchip: lan865x: Depends on PTP_1588_CLOCK_OPTIONAL Selvamani Rajagopal via B4 Relay
2026-11-25 18:04   ` Selvamani Rajagopal
2026-11-24 22:09 ` [PATCH net-next v12 06/15] net: ethernet: adi: adin1140: " Selvamani Rajagopal via B4 Relay
2026-11-25 18:04   ` Selvamani Rajagopal
2026-11-24 22:09 ` [PATCH net-next v12 07/15] net: ethernet: oa_tc6: Support for hardware timestamp Selvamani Rajagopal via B4 Relay
2026-11-25 18:16   ` Selvamani Rajagopal
2026-11-25 22:10   ` sashiko-bot
2026-11-24 22:09 ` [PATCH net-next v12 08/15] net: ethernet: oa_tc6: Drop frames if footer has FD bit set Selvamani Rajagopal via B4 Relay
2026-11-24 22:09 ` [PATCH net-next v12 09/15] net: ethernet: oa_tc6: Support for vendor specific MMS Selvamani Rajagopal via B4 Relay
2026-11-24 22:37   ` Selvamani Rajagopal
2026-11-24 22:09 ` [PATCH net-next v12 10/15] net: ethernet: oa_tc6: APIs to customize CONFIG0 settings Selvamani Rajagopal via B4 Relay
2026-11-24 22:09 ` [PATCH net-next v12 11/15] net: phy: ncn26000: Enable enhanced noise immunity Selvamani Rajagopal via B4 Relay
2026-11-24 22:10 ` [PATCH net-next v12 12/15] net: phy: Add helper to modify only the PHY loopback bit Selvamani Rajagopal via B4 Relay
2026-11-24 22:10 ` [PATCH net-next v12 13/15] net: phy: ncn26000: Support for onsemi's S2500 internal phy Selvamani Rajagopal via B4 Relay
2026-11-24 22:10 ` [PATCH net-next v12 14/15] net: phy: dp83867: Use genphy_loopback_no_speed() Selvamani Rajagopal via B4 Relay
2026-11-24 22:10 ` [PATCH net-next v12 15/15] net: ethernet: onsemi: s2500: Add driver support for S2500 Selvamani Rajagopal via B4 Relay
2026-11-25 22:10   ` 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=sashiko-outbox-234235@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Selvamani.Rajagopal@onsemi.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