Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Akshay Gupta" <Akshay.Gupta@amd.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v4 5/8] misc: amd-sbi: Add support for SB-TSI over I3C
Date: Fri, 10 Jul 2026 11:34:55 +0000	[thread overview]
Message-ID: <20260710113456.5FB501F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260710111642.850022-6-Akshay.Gupta@amd.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Concurrent hwmon sysfs accesses cause data races on the shared I3C DMA buffers (`priv->tx` and `priv->rx`) due to missing locking.
- [Medium] The I3C transmit buffer `tx` in `struct sbtsi_i3c_priv` is not cacheline aligned, violating DMA mapping requirements.

Pre-existing issues:
- [High] Temperature register reads are performed non-atomically without a device lock, breaking the SB-TSI hardware latching mechanism on concurrent accesses.
--

--- Patch [5]: [PATCH v4 5/8] misc: amd-sbi: Add support for SB-TSI over I3C ---
commit f466305c592ff454f903d27fc9a9ef283f005d66
Author: Prathima <Prathima.Lk@amd.com>

misc: amd-sbi: Add support for SB-TSI over I3C

This commit extends the AMD SB-TSI driver to support both I2C and I3C bus
interfaces. It selects the appropriate transport based on the probed bus type
and registers both drivers using module_i3c_i2c_driver() while maintaining
backward compatibility with existing I2C deployments.

> diff --git a/drivers/misc/amd-sbi/tsi-core.c b/drivers/misc/amd-sbi/tsi-core.c
> index 6ef1831515bbb..1c6f37f26d945 100644
> --- a/drivers/misc/amd-sbi/tsi-core.c
> +++ b/drivers/misc/amd-sbi/tsi-core.c
[ ... ]
> @@ -23,8 +28,56 @@ static int sbtsi_i2c_xfer(struct sbtsi_data *data, u8 reg, u8 *val, bool is_read
>  	return i2c_smbus_write_byte_data(data->client, reg, *val);
>  }
>  
> +/* I3C read transfer function */
> +static int sbtsi_i3c_read(struct sbtsi_data *data, u8 reg, u8 *val)
> +{
> +	struct sbtsi_i3c_priv *priv = to_sbtsi_i3c_priv(data);
> +	struct i3c_xfer xfers[2] = { };
> +	int ret;
> +
> +	priv->tx[0] = reg;

[Severity: High]
Does this sequence need synchronization to protect the shared priv->tx and 
priv->rx buffers?

The hwmon subsystem does not serialize reads and writes to sysfs attributes.
Without a lock protecting these buffers during the bus transfer, concurrent
sysfs reads from multiple threads could race, causing threads to overwrite
the transmit payload or read incorrect response values before or after
i3c_device_do_xfers() completes.

> +
> +	/* Write the register address (DMA_TO_DEVICE). */
> +	xfers[0].rnw = false;
> +	xfers[0].len = 1;
> +	xfers[0].data.out = priv->tx;
[ ... ]
> +/* I3C write transfer function */
> +static int sbtsi_i3c_write(struct sbtsi_data *data, u8 reg, u8 val)
> +{
> +	struct sbtsi_i3c_priv *priv = to_sbtsi_i3c_priv(data);
> +	struct i3c_xfer xfers = {
> +		.rnw = false,
> +		.len = 2,
> +		.data.out = priv->tx,
> +	};
> +
> +	priv->tx[0] = reg;
> +	priv->tx[1] = val;

[Severity: High]
Similarly, could concurrent sysfs writes overwrite priv->tx here before
the i3c_device_do_xfers() call finishes?

> +
> +	return i3c_device_do_xfers(data->i3cdev, &xfers, 1, I3C_SDR);
> +}
> +
> diff --git a/drivers/misc/amd-sbi/tsi-core.h b/drivers/misc/amd-sbi/tsi-core.h
> new file mode 100644
> index 0000000000000..7e8c0e7c3bcfa
> --- /dev/null
> +++ b/drivers/misc/amd-sbi/tsi-core.h
[ ... ]
> +struct sbtsi_i3c_priv {
> +	struct sbtsi_data data;
> +	u8 tx[2];
> +	u8 rx __aligned(ARCH_DMA_MINALIGN);

[Severity: Medium]
Should the tx array also have the __aligned(ARCH_DMA_MINALIGN) attribute?

Without it, tx might share a cacheline with the preceding struct sbtsi_data
fields. When tx is mapped for DMA to device transfers during I3C operations,
this violates the DMA mapping rules preventing cacheline sharing and can
trigger kernel warnings.

> +};

[Severity: High]
This isn't a bug introduced by this patch, but does the lack of a device-level
lock around temperature register reads break the hardware latching mechanism?

Looking at drivers/hwmon/sbtsi_temp.c in sbtsi_temp_read(), the integer and
decimal registers are read sequentially:

    ret = sbtsi_xfer(data, reg1, val1, true);
    if (!ret)
        ret = sbtsi_xfer(data, reg2, val2, true);

If multiple threads concurrently access sysfs, these non-atomic transfers
could interleave on the bus. This might cause one thread to receive a
mismatched latched decimal value triggered by another thread's integer read,
resulting in corrupted temperature reports.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260710111642.850022-1-Akshay.Gupta@amd.com?part=5

  reply	other threads:[~2026-07-10 11:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 11:16 [PATCH v4 0/8] misc: amd-sbi: Refactor SBTSI driver with I3C support and ioctl interface Akshay Gupta
2026-07-10 11:16 ` [PATCH v4 1/8] hwmon/misc: amd-sbi: Move core sbtsi support from hwmon to misc Akshay Gupta
2026-07-10 11:26   ` sashiko-bot
2026-07-10 14:26   ` Guenter Roeck
2026-07-10 11:16 ` [PATCH v4 2/8] hwmon: sbtsi_temp: Refactor temperature register access into helpers Akshay Gupta
2026-07-10 11:30   ` sashiko-bot
2026-07-10 14:27   ` Guenter Roeck
2026-07-10 11:16 ` [PATCH v4 3/8] hwmon/misc: amd-sbi: Move sbtsi register transfer to core abstraction Akshay Gupta
2026-07-10 11:25   ` sashiko-bot
2026-07-10 14:28   ` Guenter Roeck
2026-07-10 11:16 ` [PATCH v4 4/8] misc: amd-sbi: Consolidate Common SBTSI Probe Path Akshay Gupta
2026-07-10 11:25   ` sashiko-bot
2026-07-10 11:16 ` [PATCH v4 5/8] misc: amd-sbi: Add support for SB-TSI over I3C Akshay Gupta
2026-07-10 11:34   ` sashiko-bot [this message]
2026-07-10 11:16 ` [PATCH v4 6/8] misc: amd-sbi: Add SBTSI ioctl register transfer interface Akshay Gupta
2026-07-10 11:28   ` sashiko-bot
2026-07-10 11:16 ` [PATCH v4 7/8] hwmon: Add mutex protecting for sbtsi read/write through hwmon Akshay Gupta
2026-07-10 11:37   ` sashiko-bot
2026-07-10 14:28   ` Guenter Roeck
2026-07-10 11:16 ` [PATCH v4 8/8] docs: misc: amd-sbi: Document SBTSI userspace interface Akshay Gupta
2026-07-10 11:35   ` sashiko-bot

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=20260710113456.5FB501F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Akshay.Gupta@amd.com \
    --cc=linux-hwmon@vger.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