From: "NG, TZE YEE" <tze.yee.ng@altera.com>
To: Guenter Roeck <linux@roeck-us.net>,
Dinh Nguyen <dinguyen@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH v8 2/2] hwmon: add Altera SoC FPGA hardware monitoring driver
Date: Tue, 28 Jul 2026 06:51:53 +0000 [thread overview]
Message-ID: <4336dcd9-9988-463d-aea7-22191ff78636@altera.com> (raw)
In-Reply-To: <20260723061515.BAA0E1F000E9@smtp.kernel.org>
On 23/7/2026 2:15 pm, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] Timeouts in both synchronous and asynchronous read paths abandon pending requests without flushing queues or canceling them, causing permanent data desynchronization or hangs for subsequent reads.
> -->
> --- Patch [2]: [PATCH v8 2/2] hwmon: add Altera SoC FPGA hardware monitoring driver ---
> commit 467543c9f9e3893d8c84995c5e7bc8bab31dfb20
> Author: Tze Yee Ng <tze.yee.ng@altera.com>
>
> hwmon: add Altera SoC FPGA hardware monitoring driver
>
> This commit adds a hardware monitoring driver for Altera SoC FPGA devices
> using the Stratix 10 service layer. It supports temperature and voltage
> sensors based on the service layer compatible string.
>
>> diff --git a/drivers/hwmon/socfpga-hwmon.c b/drivers/hwmon/socfpga-hwmon.c
>> new file mode 100644
>> --- /dev/null
>> +++ b/drivers/hwmon/socfpga-hwmon.c
> [ ... ]
>> +static int socfpga_hwmon_async_read(struct device *dev,
>> + enum hwmon_sensor_types type,
>> + struct stratix10_svc_client_msg *msg)
>> +{
> [ ... ]
>> + ret = -ETIMEDOUT;
>> + while (!time_after(jiffies, deadline)) {
>> + status = stratix10_svc_async_poll(priv->chan, handle, &data);
>> + if (status == -EAGAIN) {
>> + /* still in progress */
>> + } else if (status < 0) {
>> + ret = status;
>> + break;
>> + } else if (status == 0) {
>> + ret = 0;
>> + break;
>> + }
>> + usleep_range(HWMON_RETRY_SLEEP_US, HWMON_RETRY_SLEEP_US * 2);
>> + }
>> +
>> + if (ret) {
>> + dev_err(dev, "Failed to get async response\n");
>> + goto done;
>> + }
> [ ... ]
>> +done:
>> + stratix10_svc_async_done(priv->chan, handle);
>> + return ret;
>> +}
>
> [Severity: High]
> If the polling loop times out, this calls stratix10_svc_async_done() which
> immediately frees the job ID via ida_free().
>
> Since the firmware might still be processing this request, could the next
> async read reuse this job ID and intercept the delayed completion of this
> timed-out request?
>
Agreed — this is a valid concern.
On async timeout we call stratix10_svc_async_done(), which frees the
job ID via ida_free(). Poll is keyed by transaction_id, so if firmware
is still completing the old request, a later async_send() that reuses
that job ID could observe the delayed response.
A proper fix belongs in the SVC / ATF (e.g. cancel before
freeing the ID, or keep the ID allocated until firmware completion).
We will address that in a separate SVC series rather than papering over
it in the hwmon driver.
Please let me know if you would prefer a different approach.
> [ ... ]
>> +static int socfpga_hwmon_sync_read(struct device *dev,
>> + enum hwmon_sensor_types type,
>> + struct stratix10_svc_client_msg *msg)
>> +{
> [ ... ]
>> + ret = wait_for_completion_timeout(&priv->completion, HWMON_TIMEOUT);
>> + if (!ret) {
>> + dev_err(priv->client.dev, "timeout waiting for SMC call\n");
>> + ret = -ETIMEDOUT;
>> + goto status_done;
>> + }
>> +
>> + ret = priv->last_err;
>> +
>> +status_done:
>> + stratix10_svc_done(priv->chan);
>> + return ret;
>> +}
>
> [Severity: High]
> If wait_for_completion_timeout() times out, this calls stratix10_svc_done(),
> which stops the worker thread via kthread_stop() without flushing the pending
> message from the channel's svc_fifo.
>
> If the worker thread evaluates kthread_should_stop() before dequeuing the
> message, will the stale message stay in the queue?
>
> If so, could the next read spawn a new thread that dequeues the stale message
> and returns wrong data (like returning a voltage reading for a temperature
> request)?
>
> Also, if the worker thread is stuck inside the SMC call, won't kthread_stop()
> block indefinitely, hanging the reader process?
>
v8 drops the extra wait_for_completion() after timeout, then it reports
-ETIMEDOUT and calls stratix10_svc_done(). As noted in my earlier reply
to Guenter [1], the remaining concern is that stratix10_svc_done() stops
the worker without flushing svc_fifo, so a request dequeued only after
the client has already timed out could theoretically desynchronize a
later read. We plan to address that with a FIFO flush in the service
layer in a separate series.
[1]
https://lore.kernel.org/all/fc7b576c-6e83-45c9-aeb4-49f02113fdd0@altera.com/
Thanks,
Tze Yee
next prev parent reply other threads:[~2026-07-28 6:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 6:02 [PATCH v8 0/2] hwmon: add Altera SoC FPGA hardware monitoring support tze.yee.ng
2026-07-23 6:02 ` [PATCH v8 1/2] firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device tze.yee.ng
2026-07-23 6:14 ` sashiko-bot
2026-07-27 6:42 ` NG, TZE YEE
2026-07-27 16:21 ` Guenter Roeck
2026-07-27 17:02 ` Dinh Nguyen
2026-07-27 18:45 ` Guenter Roeck
2026-07-23 6:02 ` [PATCH v8 2/2] hwmon: add Altera SoC FPGA hardware monitoring driver tze.yee.ng
2026-07-23 6:15 ` sashiko-bot
2026-07-28 6:51 ` NG, TZE YEE [this message]
2026-07-28 14:17 ` Guenter Roeck
2026-07-29 2:40 ` Dinh Nguyen
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=4336dcd9-9988-463d-aea7-22191ff78636@altera.com \
--to=tze.yee.ng@altera.com \
--cc=corbet@lwn.net \
--cc=dinguyen@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=skhan@linuxfoundation.org \
/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.