Skip to contentSkip to conversation

platform/chrome: cros_ec: Report EC panic as uevent

PATCH Superseded Rob Barnes 3 participants 10 messages Apr 20, 2023 – May 19, 2023

Subsystems (2)
lore
Share & tools
lore

Rob Barnes

author
#0 lore raw

PATCH 1/1 platform/chrome: cros_ec: Report EC panic as uevent

Create a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. E.g. a udev rule could be added to create an EC coredump. This approach allows more code to be moved out of the kernel drivers.

Change-Id I4fe7e4e603dcbf0ae6d4c4506f8978b0486abbbf
---
 drivers/platform/chrome/cros_ec_lpc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/platform/chrome/cros_ec_lpc.c +20 -0
index b399f7cbf17be..f2d5b00e6c3a0 100644
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
+#include <linux/kobject.h>
 #include <linux/module.h>
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
@@ -313,6 +314,23 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
 	return cnt;
 }
 
+/**
+ * cros_ec_lpc_panic_uevent() - Publish EC panic uevent
+ * @ec_dev: Device that panic'd
+ *
+ * This function will generate a uevent to notify userspace.
+ * Typically the system will be reset shortly after an EC panic occurs.
+ *
+ * Return: 0 on success or <0 on error.
+ */
+static int cros_ec_lpc_panic_uevent(struct cros_ec_device *ec_dev)
+{
+	struct device *dev = ec_dev->dev;
+	static char *env[] = { "ERROR=PANIC", NULL };
+
+	return kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, env);
+}
+
 static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 {
 	struct cros_ec_device *ec_dev = data;
@@ -324,6 +342,8 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 	if (value == ACPI_NOTIFY_CROS_EC_PANIC) {
 		dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!");
 		blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev);
+		cros_ec_lpc_panic_uevent(ec_dev);
+
 		/* Begin orderly shutdown. Force shutdown after 1 second. */
 		hw_protection_shutdown("CrOS EC Panic", 1000);
 		/* Do not query for other events after a panic is reported */
Signature · 1 line
2.39.2
#1 lore raw
Quoted 5 lines · Rob Barnes

Create a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. E.g. a udev rule could be added to create an EC coredump. This approach allows more code to be moved out of the kernel drivers.

Can you elaborate? What code do you plan on moving out of the kernel drivers? Is there a follow up patch which does this?

Also, do you have a link to the userspace code that generates the coredump?

Quoted 2 lines

Change-Id: I4fe7e4e603dcbf0ae6d4c4506f8978b0486abbbf

Change-Id's are not accepted in upstream submissions.

Quoted 27 lines
---
 drivers/platform/chrome/cros_ec_lpc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/platform/chrome/cros_ec_lpc.c +7 -0
index b399f7cbf17be..f2d5b00e6c3a0 100644
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
+#include <linux/kobject.h>
 #include <linux/module.h>
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
@@ -313,6 +314,23 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
        return cnt;
 }
 
+/**
+ * cros_ec_lpc_panic_uevent() - Publish EC panic uevent
+ * @ec_dev: Device that panic'd
+ *
+ * This function will generate a uevent to notify userspace.
+ * Typically the system will be reset shortly after an EC panic occurs.

drivers/platform/chrome/cros_ec_lpc.c static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset, · line 332

Quoted 10 lines
drivers/platform/chrome/cros_ec_lpc.c +10 -0
+ *
+ * Return: 0 on success or <0 on error.
+ */
+static int cros_ec_lpc_panic_uevent(struct cros_ec_device *ec_dev)
+{
+       struct device *dev = ec_dev->dev;
+       static char *env[] = { "ERROR=PANIC", NULL };
+
+       return kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, env);
+}

I think it's better to just inline this. I don't see any other user for this, and the return value is being ignored anyway.

Quoted 17 lines
drivers/platform/chrome/cros_ec_lpc.c +3 -1
+
 static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 {
        struct cros_ec_device *ec_dev = data;
@@ -324,6 +342,8 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
        if (value == ACPI_NOTIFY_CROS_EC_PANIC) {
                dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!");
                blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev);
+               cros_ec_lpc_panic_uevent(ec_dev);
+
                /* Begin orderly shutdown. Force shutdown after 1 second. */
                hw_protection_shutdown("CrOS EC Panic", 1000);
                /* Do not query for other events after a panic is reported */
--

2.39.2

author
#2 lore raw
Quoted 11 lines · Prashant Malani
Quoted 5 lines · Rob Barnes

Create a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. E.g. a udev rule could be added to create an EC coredump. This approach allows more code to be moved out of the kernel drivers.

Can you elaborate? What code do you plan on moving out of the kernel drivers? Is there a follow up patch which does this?

More accurately, it's preventing the need for more code to be added to the kernel drivers
to support new features, like EC coredump.

Quoted 2 lines

Also, do you have a link to the userspace code that generates the coredump?

This CL adss a udev rule to trigger the crash collector on EC panic:
https://chromium-review.googlesource.com/c/chromiumos/platform2/+/4450501

This WIP CL adds the EC coredump utility:
https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4421417

This WIP CL adds a udev rule to trigger EC coredump utility on ec panic:
https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/4424209

The WIP CLs should be ready for review later this week.

Quoted 62 lines
Quoted 2 lines

Change-Id: I4fe7e4e603dcbf0ae6d4c4506f8978b0486abbbf

Change-Id's are not accepted in upstream submissions.

Quoted 27 lines
---
 drivers/platform/chrome/cros_ec_lpc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/platform/chrome/cros_ec_lpc.c +7 -0
index b399f7cbf17be..f2d5b00e6c3a0 100644
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
+#include <linux/kobject.h>
 #include <linux/module.h>
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
@@ -313,6 +314,23 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
        return cnt;
 }
 
+/**
+ * cros_ec_lpc_panic_uevent() - Publish EC panic uevent
+ * @ec_dev: Device that panic'd
+ *
+ * This function will generate a uevent to notify userspace.
+ * Typically the system will be reset shortly after an EC panic occurs.

drivers/platform/chrome/cros_ec_lpc.c static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset, · line 332

Quoted 10 lines
drivers/platform/chrome/cros_ec_lpc.c +10 -0
+ *
+ * Return: 0 on success or <0 on error.
+ */
+static int cros_ec_lpc_panic_uevent(struct cros_ec_device *ec_dev)
+{
+       struct device *dev = ec_dev->dev;
+       static char *env[] = { "ERROR=PANIC", NULL };
+
+       return kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, env);
+}

I think it's better to just inline this. I don't see any other user for this, and the return value is being ignored anyway.

Quoted 17 lines
drivers/platform/chrome/cros_ec_lpc.c +3 -1
+
 static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 {
        struct cros_ec_device *ec_dev = data;
@@ -324,6 +342,8 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
        if (value == ACPI_NOTIFY_CROS_EC_PANIC) {
                dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!");
                blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev);
+               cros_ec_lpc_panic_uevent(ec_dev);
+
                /* Begin orderly shutdown. Force shutdown after 1 second. */
                hw_protection_shutdown("CrOS EC Panic", 1000);
                /* Do not query for other events after a panic is reported */
--

2.39.2

author
#3 lore raw

PATCH v2 1/1 platform/chrome: cros_ec: Report EC panic as uevent

Create a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. E.g. a udev rule could be added to capture an EC coredump. This approach avoids the need to stuff all the processing into the driver.

---
Changlog since v1:
- Inline uevent call

 drivers/platform/chrome/cros_ec_lpc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/platform/chrome/cros_ec_lpc.c +4 -0
index b399f7cbf17be..fbce9898dc7e1 100644
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
+#include <linux/kobject.h>
 #include <linux/module.h>
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
@@ -322,8 +323,11 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 	ec_dev->last_event_time = cros_ec_get_time_ns();
 
 	if (value == ACPI_NOTIFY_CROS_EC_PANIC) {
+		static const char *env[] = { "ERROR=PANIC", NULL };
 		dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!");
 		blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev);
+		/* Publish uevent for userspace handlers */
+		kobject_uevent_env(&ec_dev->dev->kobj, KOBJ_CHANGE, (char **)env);
 		/* Begin orderly shutdown. Force shutdown after 1 second. */
 		hw_protection_shutdown("CrOS EC Panic", 1000);
 		/* Do not query for other events after a panic is reported */
Signature · 1 line
2.39.2
Reviewed-by on v2 1/1
#4 lore raw

Hi Rob,

Quoted 7 lines · Rob Barnes

Create a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. E.g. a udev rule could be added to capture an EC coredump. This approach avoids the need to stuff all the processing into the driver.

I listed a couple of nits, but once those are fixed, please feel free to add:

Quoted 20 lines

---
Changlog since v1:
- Inline uevent call

 drivers/platform/chrome/cros_ec_lpc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/platform/chrome/cros_ec_lpc.c +1 -0
index b399f7cbf17be..fbce9898dc7e1 100644
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
+#include <linux/kobject.h>
 #include <linux/module.h>
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>

drivers/platform/chrome/cros_ec_lpc.c static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data) · line 326

Quoted 4 lines
drivers/platform/chrome/cros_ec_lpc.c +1 -0
@@ -322,8 +323,11 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
        ec_dev->last_event_time = cros_ec_get_time_ns();
 
        if (value == ACPI_NOTIFY_CROS_EC_PANIC) {
+               static const char *env[] = { "ERROR=PANIC", NULL };

The convention in this file is to have variable declarations at the beginning of the function block,
so please follow that here.

drivers/platform/chrome/cros_ec_lpc.c static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data) · line 329

Quoted 3 lines
drivers/platform/chrome/cros_ec_lpc.c +1 -0
                dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!");
                blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev);
+               /* Publish uevent for userspace handlers */

I don't think this comment is necessary. uevents are for use by userspace (by definition).

Best regards,

-Prashant

author
#5 lore raw

PATCH v3 1/1 platform/chrome: cros_ec: Report EC panic as uevent

iCreate a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. E.g. a udev rule could be added to capture an EC coredump. This approach avoids the need to stuff all the processing into the driver.

---
Changlog since v2:
- Move variable declaration to top of function

Changlog since v1:
- Inline uevent call

 drivers/platform/chrome/cros_ec_lpc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/platform/chrome/cros_ec_lpc.c +3 -0
index b399f7cbf17be..c6920df1e95dd 100644
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
+#include <linux/kobject.h>
 #include <linux/module.h>
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
@@ -315,6 +316,7 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
 
 static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 {
+	static const char *env[] = { "ERROR=PANIC", NULL };
 	struct cros_ec_device *ec_dev = data;
 	bool ec_has_more_events;
 	int ret;
@@ -324,6 +326,7 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 	if (value == ACPI_NOTIFY_CROS_EC_PANIC) {
 		dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!");
 		blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev);
+		kobject_uevent_env(&ec_dev->dev->kobj, KOBJ_CHANGE, (char **)env);
 		/* Begin orderly shutdown. Force shutdown after 1 second. */
 		hw_protection_shutdown("CrOS EC Panic", 1000);
 		/* Do not query for other events after a panic is reported */
Signature · 1 line
2.39.2
#6 lore raw
Quoted 2 lines · Rob Barnes

iCreate a uevent when an EC panic is detected. This will allow udev rules

Looks like a typo slipped through :/

author
#7 lore raw

PATCH v4 1/1 platform/chrome: cros_ec: Report EC panic as uevent

In reply to Rob Barnes

Create a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. For example, a udev rule could be added to capture an EC coredump. This approach avoids the need to stuff all the processing into the driver.

---
Changelog since v3:
- Fix typos in commit message

Changelog since v2:
- Move variable declaration to top of function

Changelog since v1:
- Inline uevent call

drivers/platform/chrome/cros_ec_lpc.c | 3 +++

1 file changed, 3 insertions(+)
drivers/platform/chrome/cros_ec_lpc.c +3 -0
index b399f7cbf17be..c6920df1e95dd 100644
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
+#include <linux/kobject.h>
 #include <linux/module.h>
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
@@ -315,6 +316,7 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
 
 static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 {
+	static const char *env[] = { "ERROR=PANIC", NULL };
 	struct cros_ec_device *ec_dev = data;
 	bool ec_has_more_events;
 	int ret;
@@ -324,6 +326,7 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
 	if (value == ACPI_NOTIFY_CROS_EC_PANIC) {
 		dev_emerg(ec_dev->dev, "CrOS EC Panic Reported. Shutdown is imminent!");
 		blocking_notifier_call_chain(&ec_dev->panic_notifier, 0, ec_dev);
+		kobject_uevent_env(&ec_dev->dev->kobj, KOBJ_CHANGE, (char **)env);
 		/* Begin orderly shutdown. Force shutdown after 1 second. */
 		hw_protection_shutdown("CrOS EC Panic", 1000);
 		/* Do not query for other events after a panic is reported */
Signature · 1 line
2.39.2
#8 lore raw
This patch was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Quoted 9 lines · On Tue, 9 May 2023 23:26:24 +0000 you wrote:

Create a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. For example, a udev rule could be added to capture an EC coredump. This approach avoids the need to stuff all the processing into the driver.

[...]

Here is the summary with links:
- [v4] platform/chrome: cros_ec: Report EC panic as uevent

    https://git.kernel.org/chrome-platform/c/2cbf475a04b2

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#9 lore raw
In reply to Rob Barnes
This patch was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Quoted 9 lines · On Tue, 9 May 2023 23:26:24 +0000 you wrote:

Create a uevent when an EC panic is detected. This will allow udev rules to trigger when a panic occurs. For example, a udev rule could be added to capture an EC coredump. This approach avoids the need to stuff all the processing into the driver.

[...]

Here is the summary with links:
- [v4] platform/chrome: cros_ec: Report EC panic as uevent

    https://git.kernel.org/chrome-platform/c/2cbf475a04b2

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html