Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: limzhineng2@gmail.com
Cc: alexanderduyck@fb.com, kuba@kernel.org, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com,
	linux@roeck-us.net, horms@kernel.org, hmohsin@meta.com,
	mike.marciniszyn@gmail.com, kernel-team@meta.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hwmon@vger.kernel.org, zinclim@meta.com
Subject: Re: [PATCH net-next v4 2/6] eth: fbnic: cache hwmon sensor readings
Date: Sun, 18 Oct 2026 22:50:42 +0000	[thread overview]
Message-ID: <179236384262.3135.12215729347519460836@kernel.org> (raw)
In-Reply-To: <20261014222225.2803660-3-limzhineng2@gmail.com>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] fbnic_mbx_init()
  (drivers/net/ethernet/meta/fbnic/fbnic_fw.c:112-113) resets…

--

eth: fbnic: cache hwmon sensor readings

This commit caches the last TSENE temperature and voltage readings in
struct fbnic_dev. Hwmon reads are served from that cache for the rest of
the current jiffy. The cache is seeded with the FBNIC_SENSOR_NO_DATA
sentinel in fbnic_mbx_init(), so the first read always goes to firmware.

> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
> index 49b8813a35643..82307f212f583 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_fw.c
> @@ -105,6 +105,13 @@ void fbnic_mbx_init(struct fbnic_dev *fbd)
>  	/* Reset FW Capabilities */
>  	memset(&fbd->fw_cap, 0, sizeof(fbd->fw_cap));
>  
> +	/* Seed cache with sentinel so the first read always refreshes. The
> +	 * cache mirrors what firmware reported, so drop it when the mailbox
> +	 * restarts.
> +	 */
> +	fbd->hwmon_cache.temp_mdeg = FBNIC_SENSOR_NO_DATA;
> +	fbd->hwmon_cache.volt_mv = FBNIC_SENSOR_NO_DATA;

[Severity: Low]

Can these stores race with a sysfs read in fbnic_hwmon_sensor_read()?

The hwmon device stays registered during PCI error recovery.
fbnic_hwmon_unregister() is only called from fbnic_remove(). The mailbox
is restarted on that path:

fbnic_err_slot_reset()
  __fbnic_pm_resume()
    fbnic_fw_request_mbx()
      __fbnic_fw_enable_mbx()
        fbnic_mbx_init()

This path runs under devl_lock(). The hwmon read callbacks are only
serialized by the hwmon core lock, so nothing orders the two.

Suppose a reader has already received a successful TSENE completion and is
preempted just before this code in fbnic_hwmon_sensor_read():

	cache->temp_mdeg = fw_cmpl->u.tsene.millidegrees;
	cache->volt_mv = fw_cmpl->u.tsene.millivolts;
	cache->last_read = jiffies;

fbnic_mbx_init() can then store FBNIC_SENSOR_NO_DATA. When the reader
resumes, it writes back the pre-reset readings with a fresh last_read.

Wouldn't that undo the "drop it when the mailbox restarts" invalidation?
KCSAN would also flag these plain concurrent loads and stores.

The practical effect is small. FBNIC depends on 64BIT, so the s32 stores
can't tear, and a stale value would only be served for the rest of one
jiffy.

Could the invalidation be done under hwmon_lock(fbd->hwmon) when
fbd->hwmon is set? Another option is READ_ONCE()/WRITE_ONCE() with a
validity scheme.

The same unlocked pattern appears to remain later in the series, where
temp_alarm and volt_alarm are also seeded in fbnic_mbx_init() without the
lock.

> +
>  	/* Reinitialize mailbox memory */
>  	for (i = 0; i < FBNIC_IPC_MBX_INDICES; i++)
>  		memset(&fbd->mbx[i], 0, sizeof(struct fbnic_fw_mbx));

[ ... ]

> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
> index 6c8c66ab86c13..0c3fe2a372275 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c

[ ... ]

> @@ -72,7 +78,12 @@ static int fbnic_hwmon_sensor_read(struct fbnic_dev *fbd, int id, long *val)
>  		goto exit_cleanup;
>  	}
>  
> -	*val = *sensor;
> +	/* FW returns both readings in one response, cache both. */
> +	cache->temp_mdeg = fw_cmpl->u.tsene.millidegrees;
> +	cache->volt_mv = fw_cmpl->u.tsene.millivolts;
> +	cache->last_read = jiffies;
> +
> +	*val = *cached;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261014222225.2803660-1-limzhineng2%40gmail.com

  reply	other threads:[~2026-10-18 22:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 22:22 [PATCH net-next v4 0/6] eth: fbnic: expand hwmon sensor support Zinc Lim
2026-10-14 22:22 ` [PATCH net-next v4 1/6] eth: fbnic: move sensor read logic out of fbnic_mac Zinc Lim
2026-10-14 22:22 ` [PATCH net-next v4 2/6] eth: fbnic: cache hwmon sensor readings Zinc Lim
2026-10-18 22:50   ` netdev-bot+sashiko [this message]
2026-10-14 22:22 ` [PATCH net-next v4 3/6] eth: fbnic: report temperature and voltage thresholds via hwmon Zinc Lim
2026-10-18 22:50   ` netdev-bot+sashiko
2026-10-14 22:22 ` [PATCH net-next v4 4/6] eth: fbnic: parse the alarm range reported by firmware Zinc Lim
2026-10-18 22:50   ` netdev-bot+sashiko
2026-10-14 22:22 ` [PATCH net-next v4 5/6] eth: fbnic: report temperature and voltage alarms via hwmon Zinc Lim
2026-10-18 22:50   ` netdev-bot+sashiko
2026-10-14 22:22 ` [PATCH net-next v4 6/6] eth: fbnic: derive the alarm range on older firmware Zinc Lim
2026-10-18 22:50   ` 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=179236384262.3135.12215729347519460836@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexanderduyck@fb.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hmohsin@meta.com \
    --cc=horms@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=limzhineng2@gmail.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mike.marciniszyn@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=zinclim@meta.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox