mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Mark Rutland <mark.rutland@arm.com>,
	Lorenzo Pieralisi <lpieralisi@kernel.org>,
	Sudeep Holla <sudeep.holla@kernel.org>
Cc: Salman Nabi <salman.nabi@arm.com>,
	Vedashree Vidwans <vvidwans@nvidia.com>,
	Trilok Soni <trilokkumar.soni@oss.qualcomm.com>,
	Nirmoy Das <nirmoyd@nvidia.com>,
	vsethi@nvidia.com, Varun Wadekar <vwadekar@nvidia.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	devicetree@vger.kernel.org
Subject: [PATCH v4 3/8] firmware: smccc: lfa: Add timeout and trigger watchdog
Date: Fri, 18 Sep 2026 16:11:06 +0200	[thread overview]
Message-ID: <20260918141112.2115555-4-andre.przywara@arm.com> (raw)
In-Reply-To: <20260918141112.2115555-1-andre.przywara@arm.com>

From: Vedashree Vidwans <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>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/firmware/smccc/lfa_fw.c | 43 +++++++++++++++++++++++++++++----
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/smccc/lfa_fw.c b/drivers/firmware/smccc/lfa_fw.c
index 7cf847e102d5a..b6ce478d3fc01 100644
--- a/drivers/firmware/smccc/lfa_fw.c
+++ b/drivers/firmware/smccc/lfa_fw.c
@@ -6,11 +6,14 @@
 #include <linux/arm-smccc.h>
 #include <linux/arm-smccc-bus.h>
 #include <linux/array_size.h>
+#include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/init.h>
 #include <linux/kobject.h>
+#include <linux/ktime.h>
 #include <linux/list.h>
 #include <linux/module.h>
+#include <linux/nmi.h>
 #include <linux/psci.h>
 #include <linux/stop_machine.h>
 #include <linux/string.h>
@@ -27,6 +30,11 @@
 #define LFA_PRIME_CALL_AGAIN		BIT(0)
 #define LFA_ACTIVATE_CALL_AGAIN		BIT(0)
 
+#define LFA_PRIME_BUDGET_MS		30000		/* 30s cap */
+#define LFA_PRIME_DELAY_MS		10		/* 10ms between polls */
+#define LFA_ACTIVATE_BUDGET_MS		10000		/* 10s cap */
+#define LFA_ACTIVATE_DELAY_MS		10		/* 10ms between polls */
+
 /* LFA return values */
 #define LFA_SUCCESS			0
 #define LFA_NOT_SUPPORTED		1
@@ -295,6 +303,7 @@ static int call_lfa_activate(void *data)
 	struct fw_image *image = data;
 	struct arm_smccc_1_2_regs reg = { 0 }, res;
 
+	touch_nmi_watchdog();
 	reg.a0 = ARM_SMCCC_LFA_ACTIVATE;
 	reg.a1 = image->fw_seq_id;
 	/*
@@ -318,6 +327,7 @@ static int call_lfa_activate(void *data)
 
 static int activate_fw_image(struct fw_image *image)
 {
+	ktime_t end = ktime_add_ms(ktime_get(), LFA_ACTIVATE_BUDGET_MS);
 	int ret;
 
 retry:
@@ -339,8 +349,15 @@ static int activate_fw_image(struct fw_image *image)
 	}
 
 	/* SMC returned with call_again flag set, or with LFA_BUSY */
-	if (ret == -EAGAIN || ret == -EBUSY)
-		goto retry;
+	if (ret == -EAGAIN || ret == -EBUSY) {
+		if (ktime_before(ktime_get(), end)) {
+			if (!msleep_interruptible(LFA_ACTIVATE_DELAY_MS))
+				goto retry;
+			ret = -EINTR;
+		} else {
+			ret = -ETIMEDOUT;
+		}
+	}
 
 	lfa_cancel(image);
 
@@ -352,6 +369,7 @@ static int activate_fw_image(struct fw_image *image)
 static int prime_fw_image(struct fw_image *image)
 {
 	struct arm_smccc_1_2_regs reg = { 0 }, res;
+	ktime_t end = ktime_add_ms(ktime_get(), LFA_PRIME_BUDGET_MS);
 	int ret;
 
 	if (image->may_reset_cpu) {
@@ -360,6 +378,8 @@ static int prime_fw_image(struct fw_image *image)
 		return -EINVAL;
 	}
 
+	touch_nmi_watchdog();
+
 	reg.a0 = ARM_SMCCC_LFA_PRIME;
 retry:
 	/*
@@ -378,10 +398,23 @@ static int prime_fw_image(struct fw_image *image)
 		return lfa_to_linux_errno((long)res.a0);
 	}
 
-	if (res.a1 & LFA_PRIME_CALL_AGAIN)
-		goto retry;
+	if (!(res.a1 & LFA_PRIME_CALL_AGAIN))
+		return 0;
 
-	return 0;
+	/* SMC returned with call_again flag set */
+	if (ktime_before(ktime_get(), end)) {
+		if (!msleep_interruptible(LFA_PRIME_DELAY_MS))
+			goto retry;
+		ret = -EINTR;
+	} else {
+		pr_err("LFA_PRIME for image %s timed out",
+		       get_image_name(image));
+		ret = -ETIMEDOUT;
+	}
+
+	lfa_cancel(image);
+
+	return ret;
 }
 
 static ssize_t name_show(struct kobject *kobj, struct kobj_attribute *attr,
-- 
2.43.0


  parent reply	other threads:[~2026-09-18 14:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 14:11 [PATCH v4 0/8] Arm Live Firmware Activation (LFA) support Andre Przywara
2026-09-18 14:11 ` [PATCH v4 1/8] dt-bindings: arm: Add Live Firmware Activation Andre Przywara
2026-09-18 14:11 ` [PATCH v4 2/8] firmware: smccc: Add support for Live Firmware Activation (LFA) Andre Przywara
2026-09-18 15:24   ` Mark Rutland
2026-09-18 14:11 ` Andre Przywara [this message]
2026-09-18 14:11 ` [PATCH v4 4/8] firmware: smccc: lfa: Register ACPI notification Andre Przywara
2026-09-18 14:11 ` [PATCH v4 5/8] firmware: smccc: lfa: Add auto_activate sysfs file Andre Przywara
2026-09-18 14:11 ` [PATCH v4 6/8] firmware: smccc: lfa: Register DT interrupt Andre Przywara
2026-09-18 14:11 ` [PATCH v4 7/8] firmware: smccc: lfa: introduce SMC access lock Andre Przywara
2026-09-18 14:11 ` [PATCH v4 8/8] firmware: smccc: lfa: add sysfs ABI documentation 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=20260918141112.2115555-4-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=nirmoyd@nvidia.com \
    --cc=robh@kernel.org \
    --cc=salman.nabi@arm.com \
    --cc=sudeep.holla@kernel.org \
    --cc=trilokkumar.soni@oss.qualcomm.com \
    --cc=vsethi@nvidia.com \
    --cc=vvidwans@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

all inboxes | Powered by JetHome®