From: Vedashree Vidwans <vvidwans@nvidia.com>
To: <salman.nabi@arm.com>, <sudeep.holla@arm.com>,
<andre.przywara@arm.com>, <lpieralisi@kernel.org>,
<mark.rutland@arm.com>
Cc: linux-kernel@vger.kernel.org, vwadekar@nvidia.com,
sdonthineni@nvidia.com, vsethi@nvidia.com,
linux-coco@lists.linux.dev, ardb@kernel.org,
linux-arm-kernel@lists.infradead.org, chao.gao@intel.com
Subject: [RFC PATCH 3/5] firmware: smccc: add timeout, touch wdt
Date: Mon, 8 Dec 2025 22:13:13 +0000 [thread overview]
Message-ID: <20251208221319.1524888-4-vvidwans@nvidia.com> (raw)
In-Reply-To: <20251208221319.1524888-1-vvidwans@nvidia.com>
Enhance PRIME/ACTIVATION functions to touch watchdog and implement
timeout mechanism. This update ensures that any potential hangs are
detected promptly and that the LFA process is allocated sufficient
execution time before the watchdog timer expires. These changes improve
overall system reliability by reducing the risk of undetected process
stalls and unexpected watchdog resets.
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
---
drivers/firmware/smccc/lfa_fw.c | 74 +++++++++++++++++++++++++++++----
1 file changed, 67 insertions(+), 7 deletions(-)
diff --git a/drivers/firmware/smccc/lfa_fw.c b/drivers/firmware/smccc/lfa_fw.c
index df8b65324413..0e420cefa260 100644
--- a/drivers/firmware/smccc/lfa_fw.c
+++ b/drivers/firmware/smccc/lfa_fw.c
@@ -16,6 +16,9 @@
#include <linux/uuid.h>
#include <linux/array_size.h>
#include <linux/list.h>
+#include <linux/nmi.h>
+#include <linux/ktime.h>
+#include <linux/delay.h>
#define LFA_ERROR_STRING(name) \
[name] = #name
@@ -34,6 +37,18 @@
#define LFA_1_0_FN_ACTIVATE LFA_1_0_FN(5)
#define LFA_1_0_FN_CANCEL LFA_1_0_FN(6)
+/* CALL_AGAIN flags (returned by SMC) */
+#define LFA_PRIME_CALL_AGAIN BIT(0)
+#define LFA_ACTIVATE_CALL_AGAIN BIT(0)
+
+/* Prime loop limits, TODO: tune after testing */
+#define LFA_PRIME_BUDGET_US 30000000 /* 30s cap */
+#define LFA_PRIME_POLL_DELAY_US 10 /* 10us between polls */
+
+/* Activation loop limits, TODO: tune after testing */
+#define LFA_ACTIVATE_BUDGET_US 20000000 /* 20s cap */
+#define LFA_ACTIVATE_POLL_DELAY_US 10 /* 10us between polls */
+
/* LFA return values */
#define LFA_SUCCESS 0
#define LFA_NOT_SUPPORTED 1
@@ -159,6 +174,8 @@ static int call_lfa_activate(void *data)
struct image_props *attrs = data;
struct arm_smccc_1_2_regs args = { 0 };
struct arm_smccc_1_2_regs res = { 0 };
+ ktime_t end = ktime_add_us(ktime_get(), LFA_ACTIVATE_BUDGET_US);
+ int ret;
args.a0 = LFA_1_0_FN_ACTIVATE;
args.a1 = attrs->fw_seq_id; /* fw_seq_id under consideration */
@@ -172,9 +189,34 @@ static int call_lfa_activate(void *data)
*/
args.a2 = !(attrs->cpu_rendezvous_forced || attrs->cpu_rendezvous);
- do {
+ for (;;) {
+ /* Touch watchdog, ACTIVATE shouldn't take longer than watchdog_thresh */
+ touch_nmi_watchdog();
arm_smccc_1_2_invoke(&args, &res);
- } while (res.a0 == 0 && res.a1 == 1);
+
+ if ((long)res.a0 < 0) {
+ pr_err("ACTIVATE for image %s failed: %s",
+ attrs->image_name, lfa_error_strings[-res.a0]);
+ return res.a0;
+ }
+
+ /* SMC returned with success */
+ if (!(res.a1 & LFA_ACTIVATE_CALL_AGAIN))
+ break; /* ACTIVATE successful */
+
+ /* SMC returned with call_again flag set */
+ if (ktime_before(ktime_get(), end)) {
+ udelay(LFA_ACTIVATE_POLL_DELAY_US);
+ continue;
+ }
+
+ pr_err("ACTIVATE timed out for image %s", attrs->image_name);
+ ret = lfa_cancel(attrs);
+ if (ret == 0)
+ return -ETIMEDOUT;
+ else
+ return ret;
+ }
return res.a0;
}
@@ -183,6 +225,7 @@ static int activate_fw_image(struct image_props *attrs)
{
struct arm_smccc_1_2_regs args = { 0 };
struct arm_smccc_1_2_regs res = { 0 };
+ ktime_t end = ktime_add_us(ktime_get(), LFA_PRIME_BUDGET_US);
int ret;
if (attrs->may_reset_cpu) {
@@ -198,15 +241,32 @@ static int activate_fw_image(struct image_props *attrs)
*/
args.a0 = LFA_1_0_FN_PRIME;
args.a1 = attrs->fw_seq_id; /* fw_seq_id under consideration */
- do {
+ for (;;) {
+ /* Touch watchdog, PRIME shouldn't take longer than watchdog_thresh */
+ touch_nmi_watchdog();
arm_smccc_1_2_invoke(&args, &res);
- if (res.a0 != LFA_SUCCESS) {
- pr_err("LFA_PRIME failed: %s\n",
- lfa_error_strings[-res.a0]);
+ if ((long)res.a0 < 0) {
+ pr_err("LFA_PRIME for image %s failed: %s\n",
+ attrs->image_name, lfa_error_strings[-res.a0]);
return res.a0;
}
- } while (res.a1 == 1);
+ if (!(res.a1 & LFA_PRIME_CALL_AGAIN))
+ break; /* PRIME successful */
+
+ /* SMC returned with call_again flag set */
+ if (ktime_before(ktime_get(), end)) {
+ udelay(LFA_PRIME_POLL_DELAY_US);
+ continue;
+ }
+
+ pr_err("PRIME timed out for image %s", attrs->image_name);
+ ret = lfa_cancel(attrs);
+ if (ret == 0)
+ return -ETIMEDOUT;
+ else
+ return ret;
+ }
if (attrs->cpu_rendezvous_forced || attrs->cpu_rendezvous)
ret = stop_machine(call_lfa_activate, attrs, cpu_online_mask);
--
2.43.0
next prev parent reply other threads:[~2025-12-08 22:14 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 22:13 [RFC PATCH 0/5] Arm LFA: Improvements and interrupt support Vedashree Vidwans
2025-12-08 22:13 ` [RFC PATCH 1/5] firmware: smccc: LFA: use smcc 1.2 Vedashree Vidwans
2025-12-09 11:42 ` Sudeep Holla
2025-12-19 8:47 ` Vedashree Vidwans
2025-12-19 10:37 ` Sudeep Holla
2025-12-08 22:13 ` [RFC PATCH 2/5] firmware: smccc: LFA: refactor Vedashree Vidwans
2025-12-08 22:13 ` Vedashree Vidwans [this message]
2025-12-08 22:13 ` [RFC PATCH 4/5] firmware: smccc: register as platform driver Vedashree Vidwans
2025-12-09 11:47 ` Sudeep Holla
2025-12-19 8:26 ` Vedashree Vidwans
2025-12-19 10:40 ` Sudeep Holla
2025-12-12 15:31 ` Matt Ochs
2025-12-18 21:41 ` Vedashree Vidwans
2026-01-20 14:07 ` Salman Nabi
2025-12-08 22:13 ` [RFC PATCH 5/5] firmware: smccc: lfa: refresh fw details Vedashree Vidwans
2025-12-12 15:37 ` Matt Ochs
2025-12-18 21:40 ` Vedashree Vidwans
2026-01-19 19:50 ` Salman Nabi
2025-12-09 11:39 ` [RFC PATCH 0/5] Arm LFA: Improvements and interrupt support Sudeep Holla
2025-12-19 8:38 ` Vedashree Vidwans
2025-12-19 10:32 ` Sudeep Holla
2026-01-13 17:30 ` Andre Przywara
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=20251208221319.1524888-4-vvidwans@nvidia.com \
--to=vvidwans@nvidia.com \
--cc=andre.przywara@arm.com \
--cc=ardb@kernel.org \
--cc=chao.gao@intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mark.rutland@arm.com \
--cc=salman.nabi@arm.com \
--cc=sdonthineni@nvidia.com \
--cc=sudeep.holla@arm.com \
--cc=vsethi@nvidia.com \
--cc=vwadekar@nvidia.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