Skip to contentSkip to conversation

ACPI, APEI, EINJ: Relax platform response timeout to 1 second.

PATCH Superseded Shuai Xue 3 participants 14 messages Oct 15, 2021 – Oct 27, 2021

Subsystems (2)
lore
Share & tools
lore

Shuai Xue

author reviewer
#0 lore raw

PATCH 1/1 ACPI, APEI, EINJ: Relax platform response timeout to 1 second.

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platfrom, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platfrom.

In this patch, we relax the response timeout to 1 second and allow user to pass the time out value as a argument.

---
 drivers/acpi/apei/einj.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/acpi/apei/einj.c +8 -5
index 133156759551..fa2386ee37db 100644
@@ -14,6 +14,7 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/debugfs.h>
@@ -28,9 +29,9 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SPIN_UNIT		100			/* 100us */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * USEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -40,6 +41,8 @@
  * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
  */
 static int acpi5;
+static int timeout_default = FIRMWARE_TIMEOUT;
+module_param(timeout_default, int, 0644);
 
 struct set_error_type_with_address {
 	u32	type;
@@ -176,7 +179,7 @@ static int einj_timedout(u64 *t)
 		return 1;
 	}
 	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
+	udelay(SPIN_UNIT);
 	touch_nmi_watchdog();
 	return 0;
 }
@@ -403,7 +406,7 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
 			       u64 param3, u64 param4)
 {
 	struct apei_exec_context ctx;
-	u64 val, trigger_paddr, timeout = FIRMWARE_TIMEOUT;
+	u64 val, trigger_paddr, timeout = timeout_default;
 	int rc;
 
 	einj_exec_ctx_init(&ctx);
Signature · 1 line
2.20.1.12.g72788fdb
reviewer
#1 lore raw
Quoted 5 lines

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platfrom.

In this patch, we relax the response timeout to 1 second and allow user to pass the time out value as a argument.

Spinning for 1ms was maybe ok. Spinning for up to 1s seems like a bad idea.

This code is executed inside a mutex ... so maybe it is safe to sleep instead of spin?

-Tony

author reviewer
#2 lore raw

Hi, Tony,

Thank you for your reply.

Quoted 3 lines

Spinning for 1ms was maybe ok. Spinning for up to 1s seems like a bad idea.

This code is executed inside a mutex ... so maybe it is safe to sleep instead of spin?

May the email Subject misled you. This code do NOT spin for 1 sec. The period of the spinning depends on the SPIN_UNIT.

drivers/acpi/apei/einj.c line 34

Quoted 6 lines
drivers/acpi/apei/einj.c +3 -3
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SPIN_UNIT		100			/* 100us */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * USEC_PER_SEC)

The period was 100 ns and changed to 100 us now. In my opinion, spinning for 100 ns or 100 us is OK :)

The timeout_default is set with FIRMWARE_TIMEOUT (1 sec) by default. If the platform do not respond within timeout_default after multiple spins, the OSPM will print a warning message to dmesg.

Regards,
Shuai

Quoted 12 lines · Tony
Quoted 5 lines

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platfrom.

In this patch, we relax the response timeout to 1 second and allow user to pass the time out value as a argument.

Spinning for 1ms was maybe ok. Spinning for up to 1s seems like a bad idea.

This code is executed inside a mutex ... so maybe it is safe to sleep instead of spin?

-Tony

reviewer
#3 lore raw
Quoted 10 lines · Shuai Xue

Hi, Tony,

Thank you for your reply.

Quoted 3 lines

Spinning for 1ms was maybe ok. Spinning for up to 1s seems like a bad idea.

This code is executed inside a mutex ... so maybe it is safe to sleep instead of spin?

May the email Subject misled you. This code do NOT spin for 1 sec. The period of the spinning depends on the SPIN_UNIT.

Not just the subject line. See the comment you changed here:

Quoted 6 lines

drivers/acpi/apei/einj.c line 34

Quoted 6 lines
drivers/acpi/apei/einj.c +3 -3
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SPIN_UNIT		100			/* 100us */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * USEC_PER_SEC)

That definitely reads to me that the timeout was increased from 1 millisecond to 1 second. With the old code polling for completion every 100ns, and the new code polling every 100us

Quoted 2 lines

The period was 100 ns and changed to 100 us now. In my opinion, spinning for 100 ns or 100 us is OK :)

But what does the code do in between polls? The calling code is:

        for (;;) {
                rc = apei_exec_run(&ctx, ACPI_EINJ_CHECK_BUSY_STATUS);
                if (rc)
                        return rc;
                val = apei_exec_ctx_get_output(&ctx);
                if (!(val & EINJ_OP_BUSY))
                        break;
                if (einj_timedout(&timeout))
                        return -EIO;
        }

Now apei_exec_run() and apei_exec_ctx_get_output() are a maze of functions & macros. But I don't think they can block, sleep, or context switch.

So this code is "spinning" until either BIOS says the operation is complete, or the FIRMWARE_TIMEOUT is reached.

It avoids triggering a watchdog by the call to touch_nmi_watchdog() after each spin between polls. But the whole thing may be spinning for a second.

I'm not at all sure that I'm right that the spin could be replaced with an msleep(). It will certainly slow things down for systems and EINJ operations that actually complete quickly (because instead of returnining within 100ns (or 100us with your patch) it will sleep for 1 ms (rounded up to next jiffie ... so 4 ms of HZ=250 systems.

But I don't care if my error injections take 4ms.

I do care that one logical CPU spins for 1 second.

-Tony

author reviewer
#4 lore raw

Hi Tony,

Quoted 9 lines

I'm not at all sure that I'm right that the spin could be replaced with an msleep(). It will certainly slow things down for systems and EINJ operations that actually complete quickly (because instead of returnining within 100ns (or 100us with your patch) it will sleep for 1 ms (rounded up to next jiffie ... so 4 ms of HZ=250 systems.

But I don't care if my error injections take 4ms.

I do care that one logical CPU spins for 1 second.

Agree. The side effect of sleep is to slow down the injection that actually complete quickly and error injection is not concerned with real-time.

I will send a v2 patch implemented in msleep soon.

Regards.
Shuai

Quoted 63 lines · Tony
Quoted 10 lines · Shuai Xue

Hi, Tony,

Thank you for your reply.

Quoted 3 lines

Spinning for 1ms was maybe ok. Spinning for up to 1s seems like a bad idea.

This code is executed inside a mutex ... so maybe it is safe to sleep instead of spin?

May the email Subject misled you. This code do NOT spin for 1 sec. The period of the spinning depends on the SPIN_UNIT.

Not just the subject line. See the comment you changed here:

Quoted 6 lines

drivers/acpi/apei/einj.c line 34

Quoted 6 lines
drivers/acpi/apei/einj.c +3 -3
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SPIN_UNIT		100			/* 100us */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * USEC_PER_SEC)

That definitely reads to me that the timeout was increased from 1 millisecond to 1 second. With the old code polling for completion every 100ns, and the new code polling every 100us

Quoted 2 lines

The period was 100 ns and changed to 100 us now. In my opinion, spinning for 100 ns or 100 us is OK :)

But what does the code do in between polls? The calling code is:

        for (;;) {
                rc = apei_exec_run(&ctx, ACPI_EINJ_CHECK_BUSY_STATUS);
                if (rc)
                        return rc;
                val = apei_exec_ctx_get_output(&ctx);
                if (!(val & EINJ_OP_BUSY))
                        break;
                if (einj_timedout(&timeout))
                        return -EIO;
        }

Now apei_exec_run() and apei_exec_ctx_get_output() are a maze of functions & macros. But I don't think they can block, sleep, or context switch.

So this code is "spinning" until either BIOS says the operation is complete, or the FIRMWARE_TIMEOUT is reached.

It avoids triggering a watchdog by the call to touch_nmi_watchdog() after each spin between polls. But the whole thing may be spinning for a second.

I'm not at all sure that I'm right that the spin could be replaced with an msleep(). It will certainly slow things down for systems and EINJ operations that actually complete quickly (because instead of returnining within 100ns (or 100us with your patch) it will sleep for 1 ms (rounded up to next jiffie ... so 4 ms of HZ=250 systems.

But I don't care if my error injections take 4ms.

I do care that one logical CPU spins for 1 second.

-Tony

author reviewer
#5 lore raw

PATCH v2 1/1 ACPI, APEI, EINJ: Relax platform response timeout to 1 second.

In reply to Shuai Xue

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platform, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platform.

In this patch, we relax the response timeout to 1 second and allow user to pass the time out value as a argument.

---
Changelog v1 -> v2:
- Implemented the timeout in msleep instead of udelay.
- Link to the v1 patch: https://lkml.org/lkml/2021/10/14/1402

---
 drivers/acpi/apei/einj.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/acpi/apei/einj.c +9 -7
index 133156759551..e411eb30e0ee 100644
@@ -28,9 +28,9 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SLEEP_UNIT		1			/* 1ms */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * MSEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -40,6 +40,8 @@
  * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
  */
 static int acpi5;
+static int timeout_default = FIRMWARE_TIMEOUT;
+module_param(timeout_default, int, 0644);
 
 struct set_error_type_with_address {
 	u32	type;
@@ -171,12 +173,12 @@ static int einj_get_available_error_type(u32 *type)
 
 static int einj_timedout(u64 *t)
 {
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
+	*t -= SLEEP_UNIT;
+	msleep(SLEEP_UNIT);
 	touch_nmi_watchdog();
 	return 0;
 }
@@ -403,7 +405,7 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
 			       u64 param3, u64 param4)
 {
 	struct apei_exec_context ctx;
-	u64 val, trigger_paddr, timeout = FIRMWARE_TIMEOUT;
+	u64 val, trigger_paddr, timeout = timeout_default;
 	int rc;
 
 	einj_exec_ctx_init(&ctx);
Signature · 1 line
2.20.1.12.g72788fdb
reviewer
#6 lore raw
Quoted 35 lines · Shuai Xue

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platform, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platform.

In this patch, we relax the response timeout to 1 second and allow user to pass the time out value as a argument.

---
Changelog v1 -> v2:
- Implemented the timeout in msleep instead of udelay.
- Link to the v1 patch: https://lkml.org/lkml/2021/10/14/1402

---
 drivers/acpi/apei/einj.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/acpi/apei/einj.c +0 -0
index 133156759551..e411eb30e0ee 100644

drivers/acpi/apei/einj.c line 31

Quoted 7 lines
drivers/acpi/apei/einj.c +1 -3
@@ -28,9 +28,9 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SLEEP_UNIT		1			/* 1ms */

I know I pointed you to msleep() ... sorry, I was wrong. For a 1 ms sleep the recommendation is to use usleep_range()

See this write-up in Documentation/timers/timers-howto.rst:

- Why not msleep for (1ms - 20ms)? Explained originally here:
https://lore.kernel.org/r/[email protected]

msleep(1~20) may not do what the caller intends, and will often sleep longer (~20 ms actual sleep for any value given in the 1~20ms range). In many cases this is not the desired behavior.

To answer the question posed in that document on "What is a good range?"

I don't think injection cares too much about precision here. Maybe go with

	usleep_range(1000, 5000);

[with #defines for SLEEP_UNIT_MIN, SLEEP_UNIT_MAX instead of those numbers]

drivers/acpi/apei/einj.c line 44

Quoted 11 lines
drivers/acpi/apei/einj.c +4 -0
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * MSEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -40,6 +40,8 @@
  * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
  */
 static int acpi5;
+static int timeout_default = FIRMWARE_TIMEOUT;
+module_param(timeout_default, int, 0644);

You've set the default to 1 second. Who would use this parameter? Do you anticipate systems that take even longer to inject? A user might set a shorter limit ... but I don't see why they would want to.

Quoted 7 lines
drivers/acpi/apei/einj.c +0 -0
 struct set_error_type_with_address {
 	u32	type;
@@ -171,12 +173,12 @@ static int einj_get_available_error_type(u32 *type)
 
 static int einj_timedout(u64 *t)
 {

drivers/acpi/apei/einj.c static int einj_get_available_error_type(u32 *type) · line 182

Quoted 10 lines
drivers/acpi/apei/einj.c +3 -3
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
+	*t -= SLEEP_UNIT;
+	msleep(SLEEP_UNIT);
 	touch_nmi_watchdog();

Since we are sleeping instead of spinning, maybe we don't need to touch the nmi watchdog?

Quoted 14 lines
drivers/acpi/apei/einj.c +1 -1
 	return 0;
 }
@@ -403,7 +405,7 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
 			       u64 param3, u64 param4)
 {
 	struct apei_exec_context ctx;
-	u64 val, trigger_paddr, timeout = FIRMWARE_TIMEOUT;
+	u64 val, trigger_paddr, timeout = timeout_default;
 	int rc;
 
 	einj_exec_ctx_init(&ctx);
Signature · 1 line
2.20.1.12.g72788fdb

-Tony

author reviewer
#7 lore raw

Hi, Tony,

Thank you for your comments.

Quoted 14 lines

I know I pointed you to msleep() ... sorry, I was wrong. For a 1 ms sleep the recommendation is to use usleep_range()

See this write-up in Documentation/timers/timers-howto.rst:

- Why not msleep for (1ms - 20ms)?
Explained originally here:
https://lore.kernel.org/r/[email protected]

msleep(1~20) may not do what the caller intends, and will often sleep longer (~20 ms actual sleep for any value given in the 1~20ms range). In many cases this is not the desired behavior.

Quoted 8 lines

To answer the question posed in that document on "What is a good range?"

I don't think injection cares too much about precision here. Maybe go with

	usleep_range(1000, 5000);

[with #defines for SLEEP_UNIT_MIN, SLEEP_UNIT_MAX instead of those numbers]

Got it. Thank you. I will change it latter.

Quoted 8 lines
Quoted 8 lines
drivers/acpi/apei/einj.c +2 -0
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * MSEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -40,6 +40,8 @@
  * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
  */
Quoted 8 lines

drivers/acpi/apei/einj.c line 44

Quoted 3 lines
drivers/acpi/apei/einj.c +2 -0
 static int acpi5;
+static int timeout_default = FIRMWARE_TIMEOUT;
+module_param(timeout_default, int, 0644);

You've set the default to 1 second. Who would use this parameter? Do you anticipate systems that take even longer to inject? A user might set a shorter limit ... but I don't see why they would want to.

No, I don't. EINJ provides a hardware error injection mechanism to develop and debug firmware code and hardware RAS feature. While we test on Arm platform, it cannot meet the original timeout limit. Therefore, we send this patch to relax the upper bound of timeout. In order to facilitate other platforms to encounter the same problems, we expose timeout as a configurable parameter in user space.

Quoted 4 lines
Quoted 4 lines
drivers/acpi/apei/einj.c +0 -0
 struct set_error_type_with_address {
 	u32	type;
@@ -171,12 +173,12 @@ static int einj_get_available_error_type(u32 *type)
 
Quoted 15 lines

drivers/acpi/apei/einj.c static int einj_get_available_error_type(u32 *type) · line 182

Quoted 12 lines
drivers/acpi/apei/einj.c +3 -3
 static int einj_timedout(u64 *t)
 {
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
+	*t -= SLEEP_UNIT;
+	msleep(SLEEP_UNIT);
 	touch_nmi_watchdog();

Since we are sleeping instead of spinning, maybe we don't need to touch the nmi watchdog?

Agree. I will delete it in next version.

Regards,
Shuai

Quoted 122 lines · Tony
Quoted 35 lines · Shuai Xue

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platform, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platform.

In this patch, we relax the response timeout to 1 second and allow user to pass the time out value as a argument.

---
Changelog v1 -> v2:
- Implemented the timeout in msleep instead of udelay.
- Link to the v1 patch: https://lkml.org/lkml/2021/10/14/1402

---
 drivers/acpi/apei/einj.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/acpi/apei/einj.c +0 -0
index 133156759551..e411eb30e0ee 100644

drivers/acpi/apei/einj.c line 31

Quoted 7 lines
drivers/acpi/apei/einj.c +1 -3
@@ -28,9 +28,9 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SLEEP_UNIT		1			/* 1ms */

I know I pointed you to msleep() ... sorry, I was wrong. For a 1 ms sleep the recommendation is to use usleep_range()

See this write-up in Documentation/timers/timers-howto.rst:

- Why not msleep for (1ms - 20ms)? Explained originally here:
https://lore.kernel.org/r/[email protected]

msleep(1~20) may not do what the caller intends, and will often sleep longer (~20 ms actual sleep for any value given in the 1~20ms range). In many cases this is not the desired behavior.

To answer the question posed in that document on "What is a good range?"

I don't think injection cares too much about precision here. Maybe go with

	usleep_range(1000, 5000);

[with #defines for SLEEP_UNIT_MIN, SLEEP_UNIT_MAX instead of those numbers]

drivers/acpi/apei/einj.c line 44

Quoted 11 lines
drivers/acpi/apei/einj.c +4 -0
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * MSEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -40,6 +40,8 @@
  * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
  */
 static int acpi5;
+static int timeout_default = FIRMWARE_TIMEOUT;
+module_param(timeout_default, int, 0644);

You've set the default to 1 second. Who would use this parameter? Do you anticipate systems that take even longer to inject? A user might set a shorter limit ... but I don't see why they would want to.

Quoted 7 lines
drivers/acpi/apei/einj.c +0 -0
 struct set_error_type_with_address {
 	u32	type;
@@ -171,12 +173,12 @@ static int einj_get_available_error_type(u32 *type)
 
 static int einj_timedout(u64 *t)
 {

drivers/acpi/apei/einj.c static int einj_get_available_error_type(u32 *type) · line 182

Quoted 10 lines
drivers/acpi/apei/einj.c +3 -3
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
+	*t -= SLEEP_UNIT;
+	msleep(SLEEP_UNIT);
 	touch_nmi_watchdog();

Since we are sleeping instead of spinning, maybe we don't need to touch the nmi watchdog?

Quoted 14 lines
drivers/acpi/apei/einj.c +1 -1
 	return 0;
 }
@@ -403,7 +405,7 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
 			       u64 param3, u64 param4)
 {
 	struct apei_exec_context ctx;
-	u64 val, trigger_paddr, timeout = FIRMWARE_TIMEOUT;
+	u64 val, trigger_paddr, timeout = timeout_default;
 	int rc;
 
 	einj_exec_ctx_init(&ctx);
Signature · 1 line
2.20.1.12.g72788fdb

-Tony

author reviewer
#8 lore raw

Hi, Tony,

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
drivers/acpi/apei/einj.c +2 -0
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * MSEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -40,6 +40,8 @@
  * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
  */
Quoted 8 lines

drivers/acpi/apei/einj.c line 44

Quoted 3 lines
drivers/acpi/apei/einj.c +2 -0
 static int acpi5;
+static int timeout_default = FIRMWARE_TIMEOUT;
+module_param(timeout_default, int, 0644);

You've set the default to 1 second. Who would use this parameter? Do you anticipate systems that take even longer to inject? A user might set a shorter limit ... but I don't see why they would want to.

Quoted 6 lines

No, I don't. EINJ provides a hardware error injection mechanism to develop and debug firmware code and hardware RAS feature. While we test on Arm platform, it cannot meet the original timeout limit. Therefore, we send this patch to relax the upper bound of timeout. In order to facilitate other platforms to encounter the same problems, we expose timeout as a configurable parameter in user space.

What's your opinion about this interface?

Regards,

Shuai.

Quoted 200 lines · Shuai Xue

Hi, Tony,

Thank you for your comments.

Quoted 14 lines

I know I pointed you to msleep() ... sorry, I was wrong. For a 1 ms sleep the recommendation is to use usleep_range()

See this write-up in Documentation/timers/timers-howto.rst:

- Why not msleep for (1ms - 20ms)?
Explained originally here:
https://lore.kernel.org/r/[email protected]

msleep(1~20) may not do what the caller intends, and will often sleep longer (~20 ms actual sleep for any value given in the 1~20ms range). In many cases this is not the desired behavior.

Quoted 8 lines

To answer the question posed in that document on "What is a good range?"

I don't think injection cares too much about precision here. Maybe go with

	usleep_range(1000, 5000);

[with #defines for SLEEP_UNIT_MIN, SLEEP_UNIT_MAX instead of those numbers]

Got it. Thank you. I will change it latter.

Quoted 8 lines
Quoted 8 lines
drivers/acpi/apei/einj.c +2 -0
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * MSEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -40,6 +40,8 @@
  * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
  */
Quoted 8 lines

drivers/acpi/apei/einj.c line 44

Quoted 3 lines
drivers/acpi/apei/einj.c +2 -0
 static int acpi5;
+static int timeout_default = FIRMWARE_TIMEOUT;
+module_param(timeout_default, int, 0644);

You've set the default to 1 second. Who would use this parameter? Do you anticipate systems that take even longer to inject? A user might set a shorter limit ... but I don't see why they would want to.

No, I don't. EINJ provides a hardware error injection mechanism to develop and debug firmware code and hardware RAS feature. While we test on Arm platform, it cannot meet the original timeout limit. Therefore, we send this patch to relax the upper bound of timeout. In order to facilitate other platforms to encounter the same problems, we expose timeout as a configurable parameter in user space.

Quoted 4 lines
Quoted 4 lines
drivers/acpi/apei/einj.c +0 -0
 struct set_error_type_with_address {
 	u32	type;
@@ -171,12 +173,12 @@ static int einj_get_available_error_type(u32 *type)
 
Quoted 15 lines

drivers/acpi/apei/einj.c static int einj_get_available_error_type(u32 *type) · line 182

Quoted 12 lines
drivers/acpi/apei/einj.c +3 -3
 static int einj_timedout(u64 *t)
 {
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
+	*t -= SLEEP_UNIT;
+	msleep(SLEEP_UNIT);
 	touch_nmi_watchdog();

Since we are sleeping instead of spinning, maybe we don't need to touch the nmi watchdog?

Agree. I will delete it in next version.

Regards,
Shuai

Quoted 122 lines · Tony
Quoted 35 lines · Shuai Xue

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platform, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platform.

In this patch, we relax the response timeout to 1 second and allow user to pass the time out value as a argument.

---
Changelog v1 -> v2:
- Implemented the timeout in msleep instead of udelay.
- Link to the v1 patch: https://lkml.org/lkml/2021/10/14/1402

---
 drivers/acpi/apei/einj.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/acpi/apei/einj.c +0 -0
index 133156759551..e411eb30e0ee 100644

drivers/acpi/apei/einj.c line 31

Quoted 7 lines
drivers/acpi/apei/einj.c +1 -3
@@ -28,9 +28,9 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SLEEP_UNIT		1			/* 1ms */

I know I pointed you to msleep() ... sorry, I was wrong. For a 1 ms sleep the recommendation is to use usleep_range()

See this write-up in Documentation/timers/timers-howto.rst:

- Why not msleep for (1ms - 20ms)? Explained originally here:
https://lore.kernel.org/r/[email protected]

msleep(1~20) may not do what the caller intends, and will often sleep longer (~20 ms actual sleep for any value given in the 1~20ms range). In many cases this is not the desired behavior.

To answer the question posed in that document on "What is a good range?"

I don't think injection cares too much about precision here. Maybe go with

	usleep_range(1000, 5000);

[with #defines for SLEEP_UNIT_MIN, SLEEP_UNIT_MAX instead of those numbers]

drivers/acpi/apei/einj.c line 44

Quoted 11 lines
drivers/acpi/apei/einj.c +4 -0
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * MSEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -40,6 +40,8 @@
  * ACPI version 5 provides a SET_ERROR_TYPE_WITH_ADDRESS action.
  */
 static int acpi5;
+static int timeout_default = FIRMWARE_TIMEOUT;
+module_param(timeout_default, int, 0644);

You've set the default to 1 second. Who would use this parameter? Do you anticipate systems that take even longer to inject? A user might set a shorter limit ... but I don't see why they would want to.

Quoted 7 lines
drivers/acpi/apei/einj.c +0 -0
 struct set_error_type_with_address {
 	u32	type;
@@ -171,12 +173,12 @@ static int einj_get_available_error_type(u32 *type)
 
 static int einj_timedout(u64 *t)
 {

drivers/acpi/apei/einj.c static int einj_get_available_error_type(u32 *type) · line 182

Quoted 10 lines
drivers/acpi/apei/einj.c +3 -3
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
+	*t -= SLEEP_UNIT;
+	msleep(SLEEP_UNIT);
 	touch_nmi_watchdog();

Since we are sleeping instead of spinning, maybe we don't need to touch the nmi watchdog?

Quoted 14 lines
drivers/acpi/apei/einj.c +1 -1
 	return 0;
 }
@@ -403,7 +405,7 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
 			       u64 param3, u64 param4)
 {
 	struct apei_exec_context ctx;
-	u64 val, trigger_paddr, timeout = FIRMWARE_TIMEOUT;
+	u64 val, trigger_paddr, timeout = timeout_default;
 	int rc;
 
 	einj_exec_ctx_init(&ctx);
Signature · 1 line
2.20.1.12.g72788fdb

-Tony

reviewer
#9 lore raw
Quoted 8 lines
Quoted 6 lines

No, I don't. EINJ provides a hardware error injection mechanism to develop and debug firmware code and hardware RAS feature. While we test on Arm platform, it cannot meet the original timeout limit. Therefore, we send this patch to relax the upper bound of timeout. In order to facilitate other platforms to encounter the same problems, we expose timeout as a configurable parameter in user space.

What's your opinion about this interface?

I can't see a case where anyone would use it. So it is just useless fluff.

I say drop it from the next rev of the patch.

-Tony

author reviewer
#10 lore raw

PATCH v3 1/1 ACPI, APEI, EINJ: Relax platform response timeout to 1 second.

In reply to Shuai Xue

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platform, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platform.

In this patch, we relax the response timeout to 1 second.

---
Changelog v2 -> v3:
- Implemented the timeout in usleep_range instead of msleep.
- Dropped command line interface of timeout.
- Link to the v1 patch: https://lkml.org/lkml/2021/10/14/1402

---
 drivers/acpi/apei/einj.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/acpi/apei/einj.c +8 -7
index 133156759551..6e1ff4b62a8f 100644
@@ -28,9 +28,10 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SLEEP_UNIT_MIN		1000			/* 1ms */
+#define SLEEP_UNIT_MAX		5000			/* 5ms */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * USEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -171,13 +172,13 @@ static int einj_get_available_error_type(u32 *type)
 
 static int einj_timedout(u64 *t)
 {
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT_MIN) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
-	touch_nmi_watchdog();
+	*t -= SLEEP_UNIT_MIN;
+	usleep_range(SLEEP_UNIT_MIN, SLEEP_UNIT_MAX);
+
 	return 0;
 }
 
Signature · 1 line
2.20.1.12.g72788fdb
reviewer Reviewed-by on v3 1/1
#11 lore raw
Quoted 15 lines · Shuai Xue

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platform, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

Quoted 6 lines

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platform.

In this patch, we relax the response timeout to 1 second.

Rafael: Do you want to take this in the acpi tree? If not, I can apply it to the RAS tree (already at -rc7, so in next merge cycle after 5.16-rc1 comes out).

Quoted 48 lines

---
Changelog v2 -> v3:
- Implemented the timeout in usleep_range instead of msleep.
- Dropped command line interface of timeout.
- Link to the v1 patch: https://lkml.org/lkml/2021/10/14/1402

---
 drivers/acpi/apei/einj.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/acpi/apei/einj.c +8 -7
index 133156759551..6e1ff4b62a8f 100644
@@ -28,9 +28,10 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SLEEP_UNIT_MIN		1000			/* 1ms */
+#define SLEEP_UNIT_MAX		5000			/* 5ms */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * USEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -171,13 +172,13 @@ static int einj_get_available_error_type(u32 *type)
 
 static int einj_timedout(u64 *t)
 {
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT_MIN) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
-	touch_nmi_watchdog();
+	*t -= SLEEP_UNIT_MIN;
+	usleep_range(SLEEP_UNIT_MIN, SLEEP_UNIT_MAX);
+
 	return 0;
 }
 
Signature · 1 line
2.20.1.12.g72788fdb
author reviewer
#12 lore raw

Hi Tony,

Thank you for your patient revision. :)

Cheers,
Shuai

Quoted 77 lines · Tony
Quoted 15 lines · Shuai Xue

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platform, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

Quoted 6 lines

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platform.

In this patch, we relax the response timeout to 1 second.

Rafael: Do you want to take this in the acpi tree? If not, I can apply it to the RAS tree (already at -rc7, so in next merge cycle after 5.16-rc1 comes out).

Quoted 48 lines

---
Changelog v2 -> v3:
- Implemented the timeout in usleep_range instead of msleep.
- Dropped command line interface of timeout.
- Link to the v1 patch: https://lkml.org/lkml/2021/10/14/1402

---
 drivers/acpi/apei/einj.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/acpi/apei/einj.c +8 -7
index 133156759551..6e1ff4b62a8f 100644
@@ -28,9 +28,10 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT		100			/* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT	(1 * NSEC_PER_MSEC)
+#define SLEEP_UNIT_MIN		1000			/* 1ms */
+#define SLEEP_UNIT_MAX		5000			/* 5ms */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT	(1 * USEC_PER_SEC)
 #define ACPI5_VENDOR_BIT	BIT(31)
 #define MEM_ERROR_MASK		(ACPI_EINJ_MEMORY_CORRECTABLE | \
 				ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -171,13 +172,13 @@ static int einj_get_available_error_type(u32 *type)
 
 static int einj_timedout(u64 *t)
 {
-	if ((s64)*t < SPIN_UNIT) {
+	if ((s64)*t < SLEEP_UNIT_MIN) {
 		pr_warn(FW_WARN "Firmware does not respond in time\n");
 		return 1;
 	}
-	*t -= SPIN_UNIT;
-	ndelay(SPIN_UNIT);
-	touch_nmi_watchdog();
+	*t -= SLEEP_UNIT_MIN;
+	usleep_range(SLEEP_UNIT_MIN, SLEEP_UNIT_MAX);
+
 	return 0;
 }
 
Signature · 1 line
2.20.1.12.g72788fdb
#13 lore raw
In reply to Luck, Tony
Quoted 22 lines · Tony
Quoted 20 lines · Shuai Xue

When injecting an error into the platform, the OSPM executes an EXECUTE_OPERATION action to instruct the platform to begin the injection operation. And then, the OSPM busy waits for a while by continually executing CHECK_BUSY_STATUS action until the platform indicates that the operation is complete. More specifically, the platform is limited to respond within 1 millisecond right now. This is too strict for some platforms.

For example, in Arm platform, when injecting a Processor Correctable error, the OSPM will warn:
Firmware does not respond in time.

And a message is printed on the console:
echo: write error: Input/output error

We observe that the waiting time for DDR error injection is about 10 ms and that for PCIe error injection is about 500 ms in Arm platform.

In this patch, we relax the response timeout to 1 second.

Quoted 7 lines
Quoted 1 line

Rafael: Do you want to take this in the acpi tree? If not, I can apply it to the RAS tree (already at -rc7, so in next merge cycle after 5.16-rc1 comes out).

I'll queue it up for 5.16.

Thanks!

Quoted 48 lines
Quoted 48 lines

---
Changelog v2 -> v3:
- Implemented the timeout in usleep_range instead of msleep.
- Dropped command line interface of timeout.
- Link to the v1 patch: https://lkml.org/lkml/2021/10/14/1402

---
 drivers/acpi/apei/einj.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/acpi/apei/einj.c +8 -8
index 133156759551..6e1ff4b62a8f 100644
@@ -28,9 +28,10 @@
 #undef pr_fmt
 #define pr_fmt(fmt) "EINJ: " fmt
 
-#define SPIN_UNIT            100                     /* 100ns */
-/* Firmware should respond within 1 milliseconds */
-#define FIRMWARE_TIMEOUT     (1 * NSEC_PER_MSEC)
+#define SLEEP_UNIT_MIN               1000                    /* 1ms */
+#define SLEEP_UNIT_MAX               5000                    /* 5ms */
+/* Firmware should respond within 1 seconds */
+#define FIRMWARE_TIMEOUT     (1 * USEC_PER_SEC)
 #define ACPI5_VENDOR_BIT     BIT(31)
 #define MEM_ERROR_MASK               (ACPI_EINJ_MEMORY_CORRECTABLE | \
                              ACPI_EINJ_MEMORY_UNCORRECTABLE | \
@@ -171,13 +172,13 @@ static int einj_get_available_error_type(u32 *type)
 
 static int einj_timedout(u64 *t)
 {
-     if ((s64)*t < SPIN_UNIT) {
+     if ((s64)*t < SLEEP_UNIT_MIN) {
              pr_warn(FW_WARN "Firmware does not respond in time\n");
              return 1;
      }
-     *t -= SPIN_UNIT;
-     ndelay(SPIN_UNIT);
-     touch_nmi_watchdog();
+     *t -= SLEEP_UNIT_MIN;
+     usleep_range(SLEEP_UNIT_MIN, SLEEP_UNIT_MAX);
+
      return 0;
 }
 
--

2.20.1.12.g72788fdb