Skip to contentSkip to conversation

acpi: reboot: fix racing after writing to ACPI RESET_REG

PATCH Superseded Zhang Rui 2 participants 3 messages Oct 10, 2020 – Oct 13, 2020 ACPI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zhang Rui

author
#0 lore raw

PATCH 1/1 acpi: reboot: fix racing after writing to ACPI RESET_REG

According to the ACPI spec, "The system must reset immediately following the write to the ACPI RESET_REG register.", but there are cases that the system does not follow this and results in racing with the subsequetial reboot mechanism, which brings unexpected behavior.

Fix this by adding a 15ms delay after writing to the ACPI RESET_REG.

---
 drivers/acpi/reboot.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/reboot.c +7 -0
index ca707f5b521d..88e6b083d702 100644
@@ -3,6 +3,7 @@
 #include <linux/pci.h>
 #include <linux/acpi.h>
 #include <acpi/reboot.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_PCI
 static void acpi_pci_reboot(struct acpi_generic_address *rr, u8 reset_value)
@@ -66,4 +67,10 @@ void acpi_reboot(void)
 		acpi_reset();
 		break;
 	}
+
+	/*
+	 * delay for 15ms in case the system does not shutdown immediately after
+	 * writing to the ACPI reset register
+	 */
+	mdelay(15);
 }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 27 lines · Zhang Rui

According to the ACPI spec, "The system must reset immediately following the write to the ACPI RESET_REG register.", but there are cases that the system does not follow this and results in racing with the subsequetial reboot mechanism, which brings unexpected behavior.

Fix this by adding a 15ms delay after writing to the ACPI RESET_REG.

---
 drivers/acpi/reboot.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/reboot.c +1 -0
index ca707f5b521d..88e6b083d702 100644
@@ -3,6 +3,7 @@
 #include <linux/pci.h>
 #include <linux/acpi.h>
 #include <acpi/reboot.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_PCI
 static void acpi_pci_reboot(struct acpi_generic_address *rr, u8 reset_value)

drivers/acpi/reboot.c void acpi_reboot(void) · line 73

Quoted 7 lines
drivers/acpi/reboot.c +4 -0
@@ -66,4 +67,10 @@ void acpi_reboot(void)
                acpi_reset();
                break;
        }
+
+       /*
+        * delay for 15ms in case the system does not shutdown immediately after
+        * writing to the ACPI reset register

It would also be good to make a note of where the 15ms value comes from.

Even if it has been guessed, it will still be good to know that, say, 5 years from now.

Quoted 6 lines
drivers/acpi/reboot.c +2 -1
+        */
+       mdelay(15);
 }
--

2.17.1

author
#2 lore raw
Quoted 46 lines · Rafael J. Wysocki
Quoted 38 lines · Zhang Rui

According to the ACPI spec, "The system must reset immediately following
the write to the ACPI RESET_REG register.", but there are cases that the
system does not follow this and results in racing with the subsequetial
reboot mechanism, which brings unexpected behavior.

Fix this by adding a 15ms delay after writing to the ACPI RESET_REG.

---
 drivers/acpi/reboot.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/reboot.c +1 -0
index ca707f5b521d..88e6b083d702 100644
@@ -3,6 +3,7 @@
 #include <linux/pci.h>
 #include <linux/acpi.h>
 #include <acpi/reboot.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_PCI
 static void acpi_pci_reboot(struct acpi_generic_address *rr, u8

reset_value)

drivers/acpi/reboot.c +3 -0
@@ -66,4 +67,10 @@ void acpi_reboot(void)
                acpi_reset();
                break;
        }
+
+       /*
+        * delay for 15ms in case the system does not shutdown
Quoted 2 lines

immediately after
+ * writing to the ACPI reset register

It would also be good to make a note of where the 15ms value comes from.

Quoted 3 lines

Even if it has been guessed, it will still be good to know that, say, 5 years from now.

Agreed, patch V2 sent out.

-rui

Quoted 6 lines
Quoted 6 lines
drivers/acpi/reboot.c +2 -1
+        */
+       mdelay(15);
 }
--

2.17.1