Skip to contentSkip to conversation

efi/reboot: Enable platform specific reset on arm64

PATCH In review Sumit Garg 3 participants 12 messages Nov 14, 2025 – Nov 17, 2025

Subsystems (3)
lore
Share & tools
lore

Sumit Garg

author
#0 lore raw

cover efi/reboot: Enable platform specific reset on arm64

From: Sumit Garg <[email protected]>

Vendor/platform specific reset types are common on arm64 platforms as can be seen from this patch-set [1]. EFI runtime ResetSystem service provide an alternate method known as EFI_RESET_PLATFORM_SPECIFIC [2]. It should be able to handle these reset scenarios where the platform specific UEFI implementation will decode the reboot command as reset data passed as a parameter.

On UEFI systems, it is rather a better abstracted interface for the OS to use EFI platform specific runtime reset method rather than overriding PSCI reset method with DT based overrides on arm64 platforms.

[1] https://lore.kernel.org/all/20251109-arm-psci-system_reset2-vendor-reboots-v17-0-46e085bca4cc@oss.qualcomm.com/
[2] https://uefi.org/specs/UEFI/2.10/08_Services_Runtime_Services.html?highlight=resetsystem#resetsystem

Sumit Garg (2):
efi/reboot: Add support for EFI_RESET_PLATFORM_SPECIFIC
arm64: efi: Pass reboot cmd parameter to efi_reboot()

 arch/arm64/kernel/process.c   |  2 +-
 drivers/firmware/efi/reboot.c | 25 +++++++++++++++----------
 include/linux/efi.h           |  5 +++--
 3 files changed, 19 insertions(+), 13 deletions(-)
Signature · 1 line
2.48.1
author
#1 lore raw

PATCH 1/2 efi/reboot: Add support for EFI_RESET_PLATFORM_SPECIFIC

From: Sumit Garg <[email protected]>

UEFI specification provides support for EfiResetPlatformSpecific reset type as follows:

"
ResetSystem:

Calling this interface with ResetType of EfiResetPlatformSpecific causes a system-wide reset. The exact type of the reset is defined by the EFI_GUID that follows the Null-terminated Unicode string passed into ResetData. If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs.
"

Lets use the ResetData to pass the platform specific reboot command issued and leave it's interpretation to UEFI implementation following the specification.

---
 drivers/firmware/efi/reboot.c | 25 +++++++++++++++----------
 include/linux/efi.h           |  5 +++--
 2 files changed, 18 insertions(+), 12 deletions(-)
drivers/firmware/efi/reboot.c +15 -10
index ceae84c19d22..23a2fc68e9c9 100644
@@ -10,7 +10,7 @@ static struct sys_off_handler *efi_sys_off_handler;
 
 int efi_reboot_quirk_mode = -1;
 
-void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
+void efi_reboot(enum reboot_mode reboot_mode, const char *data)
 {
 	const char *str[] = { "cold", "warm", "shutdown", "platform" };
 	int efi_mode, cap_reset_mode;
@@ -18,14 +18,18 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
 	if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
 		return;
 
-	switch (reboot_mode) {
-	case REBOOT_WARM:
-	case REBOOT_SOFT:
-		efi_mode = EFI_RESET_WARM;
-		break;
-	default:
-		efi_mode = EFI_RESET_COLD;
-		break;
+	if (data) {
+		efi_mode = EFI_RESET_PLATFORM_SPECIFIC;
+	} else {
+		switch (reboot_mode) {
+		case REBOOT_WARM:
+		case REBOOT_SOFT:
+			efi_mode = EFI_RESET_WARM;
+			break;
+		default:
+			efi_mode = EFI_RESET_COLD;
+			break;
+		}
 	}
 
 	/*
@@ -43,7 +47,8 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
 		efi_mode = cap_reset_mode;
 	}
 
-	efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
+	efi.reset_system(efi_mode, EFI_SUCCESS, sizeof(data),
+			 (efi_char16_t *)data);
 }
 
 bool __weak efi_poweroff_required(void)
include/linux/efi.h +3 -2
index a98cc39e7aaa..5324db1518b6 100644
@@ -256,6 +256,7 @@ typedef union efi_boot_services efi_boot_services_t;
 #define EFI_RESET_COLD 0
 #define EFI_RESET_WARM 1
 #define EFI_RESET_SHUTDOWN 2
+#define EFI_RESET_PLATFORM_SPECIFIC 3
 
 /*
  * EFI Runtime Services table
@@ -874,7 +875,7 @@ static inline bool efi_enabled(int feature)
 {
 	return test_bit(feature, &efi.flags) != 0;
 }
-extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
+extern void efi_reboot(enum reboot_mode reboot_mode, const char *data);
 
 bool __pure __efi_soft_reserve_enabled(void);
 
@@ -895,7 +896,7 @@ static inline bool efi_enabled(int feature)
 	return false;
 }
 static inline void
-efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
+efi_reboot(enum reboot_mode reboot_mode, const char *data) {}
 
 static inline bool efi_soft_reserve_enabled(void)
 {
Signature · 1 line
2.48.1
author
#4 lore raw

PATCH 2/2 arm64: efi: Pass reboot cmd parameter to efi_reboot()

In reply to Sumit Garg

From: Sumit Garg <[email protected]>

EFI ResetSystem runtime service allows for platform specific reset type allowing the OS to pass reset data for the UEFI implementation to take corresponding action. So lets pass the reboot cmd parameter for the EFI driver to determine whether it's a platform specific reset requested or not.

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/process.c +1 -1
index fba7ca102a8c..51784986c568 100644
@@ -136,7 +136,7 @@ void machine_restart(char *cmd)
 	 * ResetSystem().
 	 */
 	if (efi_enabled(EFI_RUNTIME_SERVICES))
-		efi_reboot(reboot_mode, NULL);
+		efi_reboot(reboot_mode, cmd);
 
 	/* Now call the architecture specific reboot code. */
 	do_kernel_restart(cmd);
Signature · 1 line
2.48.1
maintainer
#5 lore raw

Re: [PATCH 2/2] arm64: efi: Pass reboot cmd parameter to efi_reboot()

Quoted 19 lines · Sumit Garg

From: Sumit Garg <[email protected]>

EFI ResetSystem runtime service allows for platform specific reset type allowing the OS to pass reset data for the UEFI implementation to take corresponding action. So lets pass the reboot cmd parameter for the EFI driver to determine whether it's a platform specific reset requested or not.

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/process.c +0 -0
index fba7ca102a8c..51784986c568 100644

arch/arm64/kernel/process.c void machine_restart(char *cmd) · line 140

Quoted 6 lines
arch/arm64/kernel/process.c +1 -1
@@ -136,7 +136,7 @@ void machine_restart(char *cmd)
         * ResetSystem().
         */
        if (efi_enabled(EFI_RUNTIME_SERVICES))
-               efi_reboot(reboot_mode, NULL);
+               efi_reboot(reboot_mode, cmd);
 

I agree with the general principle. However, there are already existing callers of kernel_restart() that would end up passing a random string to efi_reboot(), resulting in platform specific reset with undefined result.

E.g.,

$ git grep kernel_restart\(\"
drivers/md/dm-verity-target.c:          kernel_restart("dm-verity
device corrupted");
drivers/md/dm-verity-target.c:  kernel_restart("dm-verity device has
I/O error");
drivers/memory/emif.c:                  kernel_restart("SDRAM
Over-temp Emergency restart");
Quoted 5 lines
arch/arm64/kernel/process.c +0 -1
        /* Now call the architecture specific reboot code. */
        do_kernel_restart(cmd);
--

2.48.1

author
#6 lore raw

Re: [PATCH 2/2] arm64: efi: Pass reboot cmd parameter to efi_reboot()

Quoted 15 lines · Ard Biesheuvel
Quoted 14 lines · Sumit Garg

From: Sumit Garg <[email protected]>

EFI ResetSystem runtime service allows for platform specific reset type allowing the OS to pass reset data for the UEFI implementation to take corresponding action. So lets pass the reboot cmd parameter for the EFI driver to determine whether it's a platform specific reset requested or not.

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

arch/arm64/kernel/process.c void machine_restart(char *cmd) · line 140

Quoted 11 lines
arch/arm64/kernel/process.c +1 -1
index fba7ca102a8c..51784986c568 100644
@@ -136,7 +136,7 @@ void machine_restart(char *cmd)
         * ResetSystem().
         */
        if (efi_enabled(EFI_RUNTIME_SERVICES))
-               efi_reboot(reboot_mode, NULL);
+               efi_reboot(reboot_mode, cmd);
 

I agree with the general principle. However, there are already existing callers of kernel_restart() that would end up passing a random string to efi_reboot(), resulting in platform specific reset with undefined result.

Yeah true but the UEFI spec says:

"If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs."

So, in these cases the UEFI implementation can fallback to normal reset optionally logging the reset data being passed. Does that sounds reasonable to you?

-Sumit

Quoted 17 lines

E.g.,

$ git grep kernel_restart\(\"
drivers/md/dm-verity-target.c:          kernel_restart("dm-verity
device corrupted");
drivers/md/dm-verity-target.c:  kernel_restart("dm-verity device has
I/O error");
drivers/memory/emif.c:                  kernel_restart("SDRAM
Over-temp Emergency restart");
Quoted 5 lines
arch/arm64/kernel/process.c +0 -1
        /* Now call the architecture specific reboot code. */
        do_kernel_restart(cmd);
--

2.48.1

maintainer
#7 lore raw

Re: [PATCH 2/2] arm64: efi: Pass reboot cmd parameter to efi_reboot()

Quoted 36 lines · Sumit Garg
Quoted 15 lines · Ard Biesheuvel
Quoted 14 lines · Sumit Garg

From: Sumit Garg <[email protected]>

EFI ResetSystem runtime service allows for platform specific reset type allowing the OS to pass reset data for the UEFI implementation to take corresponding action. So lets pass the reboot cmd parameter for the EFI driver to determine whether it's a platform specific reset requested or not.

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

arch/arm64/kernel/process.c void machine_restart(char *cmd) · line 140

Quoted 11 lines
arch/arm64/kernel/process.c +1 -1
index fba7ca102a8c..51784986c568 100644
@@ -136,7 +136,7 @@ void machine_restart(char *cmd)
         * ResetSystem().
         */
        if (efi_enabled(EFI_RUNTIME_SERVICES))
-               efi_reboot(reboot_mode, NULL);
+               efi_reboot(reboot_mode, cmd);
 

I agree with the general principle. However, there are already existing callers of kernel_restart() that would end up passing a random string to efi_reboot(), resulting in platform specific reset with undefined result.

Yeah true but the UEFI spec says:

Quoted 8 lines

"If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs."

So, in these cases the UEFI implementation can fallback to normal reset optionally logging the reset data being passed. Does that sounds reasonable to you?

What the UEFI spec says might deviate from how real platforms in the field will behave when being passed a reset type that nobody ever tried passing before.

maintainer
#8 lore raw

Re: [PATCH 2/2] arm64: efi: Pass reboot cmd parameter to efi_reboot()

Quoted 42 lines · Ard Biesheuvel
Quoted 40 lines · Sumit Garg
Quoted 15 lines · Ard Biesheuvel
Quoted 14 lines · Sumit Garg

From: Sumit Garg <[email protected]>

EFI ResetSystem runtime service allows for platform specific reset type allowing the OS to pass reset data for the UEFI implementation to take corresponding action. So lets pass the reboot cmd parameter for the EFI driver to determine whether it's a platform specific reset requested or not.

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

arch/arm64/kernel/process.c void machine_restart(char *cmd) · line 140

Quoted 11 lines
arch/arm64/kernel/process.c +1 -1
index fba7ca102a8c..51784986c568 100644
@@ -136,7 +136,7 @@ void machine_restart(char *cmd)
         * ResetSystem().
         */
        if (efi_enabled(EFI_RUNTIME_SERVICES))
-               efi_reboot(reboot_mode, NULL);
+               efi_reboot(reboot_mode, cmd);
 

I agree with the general principle. However, there are already existing callers of kernel_restart() that would end up passing a random string to efi_reboot(), resulting in platform specific reset with undefined result.

Yeah true but the UEFI spec says:

"If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs."

Quoted 8 lines
Quoted 4 lines

So, in these cases the UEFI implementation can fallback to normal reset optionally logging the reset data being passed. Does that sounds reasonable to you?

What the UEFI spec says might deviate from how real platforms in the field will behave when being passed a reset type that nobody ever tried passing before.

Also, the GUID is expected to follow an unbounded NULL terminated UTF-16 string in memory, so we could easily cause a crash by doing this if \0\0 doesn't appear in the memory following the string.

author
#9 lore raw

Re: [PATCH 2/2] arm64: efi: Pass reboot cmd parameter to efi_reboot()

Quoted 43 lines · Ard Biesheuvel
Quoted 42 lines · Ard Biesheuvel
Quoted 40 lines · Sumit Garg
Quoted 15 lines · Ard Biesheuvel
Quoted 14 lines · Sumit Garg

From: Sumit Garg <[email protected]>

EFI ResetSystem runtime service allows for platform specific reset type allowing the OS to pass reset data for the UEFI implementation to take corresponding action. So lets pass the reboot cmd parameter for the EFI driver to determine whether it's a platform specific reset requested or not.

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

arch/arm64/kernel/process.c void machine_restart(char *cmd) · line 140

Quoted 11 lines
arch/arm64/kernel/process.c +1 -1
index fba7ca102a8c..51784986c568 100644
@@ -136,7 +136,7 @@ void machine_restart(char *cmd)
         * ResetSystem().
         */
        if (efi_enabled(EFI_RUNTIME_SERVICES))
-               efi_reboot(reboot_mode, NULL);
+               efi_reboot(reboot_mode, cmd);
 

I agree with the general principle. However, there are already existing callers of kernel_restart() that would end up passing a random string to efi_reboot(), resulting in platform specific reset with undefined result.

Yeah true but the UEFI spec says:

"If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs."

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

So, in these cases the UEFI implementation can fallback to normal reset optionally logging the reset data being passed. Does that sounds reasonable to you?

What the UEFI spec says might deviate from how real platforms in the field will behave when being passed a reset type that nobody ever tried passing before.

I suppose from OS point of view, we need to follow the UEFI specification. However, there will be scope for quirks later if the real world problems occur. Currently, in case of EFI reboot we are just ignoring the reboot cmd parameter.

If you have in mind any sanity checks we should do here then feel free to propose and I can try to implement them.

Quoted 4 lines

Also, the GUID is expected to follow an unbounded NULL terminated UTF-16 string in memory, so we could easily cause a crash by doing this if \0\0 doesn't appear in the memory following the string.

Okay I see, would following change on top of this patchset address this concern?

drivers/firmware/efi/reboot.c +9 -2
@@ -5,6 +5,7 @@
  */
 #include <linux/efi.h>
 #include <linux/reboot.h>
+#include <linux/ucs2_string.h>
 
 static struct sys_off_handler *efi_sys_off_handler;
 
@@ -14,11 +15,18 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *data)
 {
        const char *str[] = { "cold", "warm", "shutdown", "platform" };
        int efi_mode, cap_reset_mode;
+       unsigned long reset_data_sz = 0;
+       efi_char16_t *reset_data = NULL;
 
        if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
                return;
 
        if (data) {
+               reset_data_sz = ucs2_strlen(data) * sizeof(efi_char16_t);
+               reset_data = kzalloc(reset_data_sz + 2, GFP_KERNEL);
+               memcpy(reset_data, data, reset_data_sz);
+               reset_data_sz += 2;
+
                efi_mode = EFI_RESET_PLATFORM_SPECIFIC;
        } else {
                switch (reboot_mode) {
@@ -47,8 +55,7 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *data)
                efi_mode = cap_reset_mode;
        }
 
-       efi.reset_system(efi_mode, EFI_SUCCESS, sizeof(data),
-                        (efi_char16_t *)data);
+       efi.reset_system(efi_mode, EFI_SUCCESS, reset_data_sz, reset_data);
 }
 
 bool __weak efi_poweroff_required(void)

-Sumit

maintainer
#10 lore raw

Re: [PATCH 2/2] arm64: efi: Pass reboot cmd parameter to efi_reboot()

Quoted 82 lines · Sumit Garg
Quoted 43 lines · Ard Biesheuvel
Quoted 42 lines · Ard Biesheuvel
Quoted 40 lines · Sumit Garg
Quoted 15 lines · Ard Biesheuvel
Quoted 14 lines · Sumit Garg

From: Sumit Garg <[email protected]>

EFI ResetSystem runtime service allows for platform specific reset type allowing the OS to pass reset data for the UEFI implementation to take corresponding action. So lets pass the reboot cmd parameter for the EFI driver to determine whether it's a platform specific reset requested or not.

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

arch/arm64/kernel/process.c void machine_restart(char *cmd) · line 140

Quoted 11 lines
arch/arm64/kernel/process.c +1 -1
index fba7ca102a8c..51784986c568 100644
@@ -136,7 +136,7 @@ void machine_restart(char *cmd)
         * ResetSystem().
         */
        if (efi_enabled(EFI_RUNTIME_SERVICES))
-               efi_reboot(reboot_mode, NULL);
+               efi_reboot(reboot_mode, cmd);
 

I agree with the general principle. However, there are already existing callers of kernel_restart() that would end up passing a random string to efi_reboot(), resulting in platform specific reset with undefined result.

Yeah true but the UEFI spec says:

"If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs."

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

So, in these cases the UEFI implementation can fallback to normal reset optionally logging the reset data being passed. Does that sounds reasonable to you?

What the UEFI spec says might deviate from how real platforms in the field will behave when being passed a reset type that nobody ever tried passing before.

I suppose from OS point of view, we need to follow the UEFI specification. However, there will be scope for quirks later if the real world problems occur. Currently, in case of EFI reboot we are just ignoring the reboot cmd parameter.

If you have in mind any sanity checks we should do here then feel free to propose and I can try to implement them.

Quoted 4 lines

Also, the GUID is expected to follow an unbounded NULL terminated UTF-16 string in memory, so we could easily cause a crash by doing this if \0\0 doesn't appear in the memory following the string.

Okay I see, would following change on top of this patchset address this concern?

drivers/firmware/efi/reboot.c +1 -0
@@ -5,6 +5,7 @@
  */
 #include <linux/efi.h>
 #include <linux/reboot.h>
+#include <linux/ucs2_string.h>
 
 static struct sys_off_handler *efi_sys_off_handler;
 
@@ -14,11 +15,18 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *data)
 {

drivers/firmware/efi/reboot.c void efi_reboot(enum reboot_mode reboot_mode, const char *data) · line 25

Quoted 10 lines
drivers/firmware/efi/reboot.c +3 -0
        const char *str[] = { "cold", "warm", "shutdown", "platform" };
        int efi_mode, cap_reset_mode;
+       unsigned long reset_data_sz = 0;
+       efi_char16_t *reset_data = NULL;
 
        if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
                return;
 
        if (data) {
+               reset_data_sz = ucs2_strlen(data) * sizeof(efi_char16_t);

You can't just run ucs2_strlen() on an arbitrary buffer.

drivers/firmware/efi/reboot.c void efi_reboot(enum reboot_mode reboot_mode, const char *data) · line 29

Quoted 4 lines
drivers/firmware/efi/reboot.c +4 -0
+               reset_data = kzalloc(reset_data_sz + 2, GFP_KERNEL);
+               memcpy(reset_data, data, reset_data_sz);
+               reset_data_sz += 2;
+

What happened to the GUID? It comes after the UTF-16 string, no?

drivers/firmware/efi/reboot.c void efi_reboot(enum reboot_mode reboot_mode, const char *data) · line 60

Quoted 12 lines
drivers/firmware/efi/reboot.c +1 -2
                efi_mode = EFI_RESET_PLATFORM_SPECIFIC;
        } else {
                switch (reboot_mode) {
@@ -47,8 +55,7 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *data)
                efi_mode = cap_reset_mode;
        }
 
-       efi.reset_system(efi_mode, EFI_SUCCESS, sizeof(data),
-                        (efi_char16_t *)data);
+       efi.reset_system(efi_mode, EFI_SUCCESS, reset_data_sz, reset_data);
 }
 

I think the main issue here is tying machine_restart(), which takes a u8[] argument, to efi_reboot(), which takes a (u16[]) + L"\0" + GUID buffer. So the change to efi_reboot() looks fine to me, we just cannot call it directly from machine_restart() as you are suggesting.

Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] efi/reboot: Add support for EFI_RESET_PLATFORM_SPECIFIC

In reply to Sumit Garg
Quoted 17 lines · Sumit Garg

From: Sumit Garg <[email protected]>

UEFI specification provides support for EfiResetPlatformSpecific reset type as follows:

"
ResetSystem:

Calling this interface with ResetType of EfiResetPlatformSpecific causes a system-wide reset. The exact type of the reset is defined by the EFI_GUID that follows the Null-terminated Unicode string passed into ResetData. If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs.
"

Quoted 6 lines

Lets use the ResetData to pass the platform specific reboot command issued and leave it's interpretation to UEFI implementation following the specification.

---

Konrad

maintainer
#3 lore raw

Re: [PATCH 1/2] efi/reboot: Add support for EFI_RESET_PLATFORM_SPECIFIC

In reply to Sumit Garg
Quoted 69 lines · Sumit Garg

From: Sumit Garg <[email protected]>

UEFI specification provides support for EfiResetPlatformSpecific reset type as follows:

"
ResetSystem:

Calling this interface with ResetType of EfiResetPlatformSpecific causes a system-wide reset. The exact type of the reset is defined by the EFI_GUID that follows the Null-terminated Unicode string passed into ResetData. If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs.
"

Lets use the ResetData to pass the platform specific reboot command issued and leave it's interpretation to UEFI implementation following the specification.

---
 drivers/firmware/efi/reboot.c | 25 +++++++++++++++----------
 include/linux/efi.h           |  5 +++--
 2 files changed, 18 insertions(+), 12 deletions(-)
drivers/firmware/efi/reboot.c +13 -9
index ceae84c19d22..23a2fc68e9c9 100644
@@ -10,7 +10,7 @@ static struct sys_off_handler *efi_sys_off_handler;
 
 int efi_reboot_quirk_mode = -1;
 
-void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
+void efi_reboot(enum reboot_mode reboot_mode, const char *data)
 {
        const char *str[] = { "cold", "warm", "shutdown", "platform" };
        int efi_mode, cap_reset_mode;
@@ -18,14 +18,18 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
        if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
                return;
 
-       switch (reboot_mode) {
-       case REBOOT_WARM:
-       case REBOOT_SOFT:
-               efi_mode = EFI_RESET_WARM;
-               break;
-       default:
-               efi_mode = EFI_RESET_COLD;
-               break;
+       if (data) {
+               efi_mode = EFI_RESET_PLATFORM_SPECIFIC;
+       } else {
+               switch (reboot_mode) {
+               case REBOOT_WARM:
+               case REBOOT_SOFT:
+                       efi_mode = EFI_RESET_WARM;
+                       break;
+               default:
+                       efi_mode = EFI_RESET_COLD;
+                       break;
+               }
        }
 
        /*

drivers/firmware/efi/reboot.c void efi_reboot(enum reboot_mode reboot_mode, const char *__unused) · line 50

Quoted 5 lines
drivers/firmware/efi/reboot.c +1 -1
@@ -43,7 +47,8 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
                efi_mode = cap_reset_mode;
        }
 
-       efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
+       efi.reset_system(efi_mode, EFI_SUCCESS, sizeof(data),

You cannot use sizeof() here - it will return the size of a pointer to const char.

Quoted 37 lines
drivers/firmware/efi/reboot.c +1 -0
+                        (efi_char16_t *)data);
 }
 
 bool __weak efi_poweroff_required(void)
include/linux/efi.h +3 -3
index a98cc39e7aaa..5324db1518b6 100644
@@ -256,6 +256,7 @@ typedef union efi_boot_services efi_boot_services_t;
 #define EFI_RESET_COLD 0
 #define EFI_RESET_WARM 1
 #define EFI_RESET_SHUTDOWN 2
+#define EFI_RESET_PLATFORM_SPECIFIC 3
 
 /*
  * EFI Runtime Services table
@@ -874,7 +875,7 @@ static inline bool efi_enabled(int feature)
 {
        return test_bit(feature, &efi.flags) != 0;
 }
-extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
+extern void efi_reboot(enum reboot_mode reboot_mode, const char *data);
 
 bool __pure __efi_soft_reserve_enabled(void);
 
@@ -895,7 +896,7 @@ static inline bool efi_enabled(int feature)
        return false;
 }
 static inline void
-efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
+efi_reboot(enum reboot_mode reboot_mode, const char *data) {}
 
 static inline bool efi_soft_reserve_enabled(void)
 {
--

2.48.1

author
#11 lore raw

Re: [PATCH 2/2] arm64: efi: Pass reboot cmd parameter to efi_reboot()

In reply to Ard Biesheuvel
Quoted 96 lines · Ard Biesheuvel
Quoted 82 lines · Sumit Garg
Quoted 43 lines · Ard Biesheuvel
Quoted 42 lines · Ard Biesheuvel
Quoted 40 lines · Sumit Garg
Quoted 15 lines · Ard Biesheuvel
Quoted 14 lines · Sumit Garg

From: Sumit Garg <[email protected]>

EFI ResetSystem runtime service allows for platform specific reset type allowing the OS to pass reset data for the UEFI implementation to take corresponding action. So lets pass the reboot cmd parameter for the EFI driver to determine whether it's a platform specific reset requested or not.

---
 arch/arm64/kernel/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

arch/arm64/kernel/process.c void machine_restart(char *cmd) · line 140

Quoted 11 lines
arch/arm64/kernel/process.c +1 -1
index fba7ca102a8c..51784986c568 100644
@@ -136,7 +136,7 @@ void machine_restart(char *cmd)
         * ResetSystem().
         */
        if (efi_enabled(EFI_RUNTIME_SERVICES))
-               efi_reboot(reboot_mode, NULL);
+               efi_reboot(reboot_mode, cmd);
 

I agree with the general principle. However, there are already existing callers of kernel_restart() that would end up passing a random string to efi_reboot(), resulting in platform specific reset with undefined result.

Yeah true but the UEFI spec says:

"If the platform does not recognize the EFI_GUID in ResetData the platform must pick a supported reset type to perform. The platform may optionally log the parameters from any non-normal reset that occurs."

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

So, in these cases the UEFI implementation can fallback to normal reset optionally logging the reset data being passed. Does that sounds reasonable to you?

What the UEFI spec says might deviate from how real platforms in the field will behave when being passed a reset type that nobody ever tried passing before.

I suppose from OS point of view, we need to follow the UEFI specification. However, there will be scope for quirks later if the real world problems occur. Currently, in case of EFI reboot we are just ignoring the reboot cmd parameter.

If you have in mind any sanity checks we should do here then feel free to propose and I can try to implement them.

Quoted 4 lines

Also, the GUID is expected to follow an unbounded NULL terminated UTF-16 string in memory, so we could easily cause a crash by doing this if \0\0 doesn't appear in the memory following the string.

Okay I see, would following change on top of this patchset address this concern?

drivers/firmware/efi/reboot.c +1 -0
@@ -5,6 +5,7 @@
  */
 #include <linux/efi.h>
 #include <linux/reboot.h>
+#include <linux/ucs2_string.h>
 
 static struct sys_off_handler *efi_sys_off_handler;
 
@@ -14,11 +15,18 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *data)
 {

drivers/firmware/efi/reboot.c void efi_reboot(enum reboot_mode reboot_mode, const char *data) · line 25

Quoted 10 lines
drivers/firmware/efi/reboot.c +3 -0
        const char *str[] = { "cold", "warm", "shutdown", "platform" };
        int efi_mode, cap_reset_mode;
+       unsigned long reset_data_sz = 0;
+       efi_char16_t *reset_data = NULL;
 
        if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
                return;
 
        if (data) {
+               reset_data_sz = ucs2_strlen(data) * sizeof(efi_char16_t);

You can't just run ucs2_strlen() on an arbitrary buffer.

Quoted 6 lines

drivers/firmware/efi/reboot.c void efi_reboot(enum reboot_mode reboot_mode, const char *data) · line 29

Quoted 4 lines
drivers/firmware/efi/reboot.c +4 -0
+               reset_data = kzalloc(reset_data_sz + 2, GFP_KERNEL);
+               memcpy(reset_data, data, reset_data_sz);
+               reset_data_sz += 2;
+

What happened to the GUID? It comes after the UTF-16 string, no?

Ah, I missed putting the GUID here.

Quoted 8 lines
Quoted 8 lines
drivers/firmware/efi/reboot.c +0 -0
                efi_mode = EFI_RESET_PLATFORM_SPECIFIC;
        } else {
                switch (reboot_mode) {
@@ -47,8 +55,7 @@ void efi_reboot(enum reboot_mode reboot_mode, const char *data)
                efi_mode = cap_reset_mode;
        }
 
Quoted 10 lines

drivers/firmware/efi/reboot.c void efi_reboot(enum reboot_mode reboot_mode, const char *data) · line 60

Quoted 5 lines
drivers/firmware/efi/reboot.c +1 -2
-       efi.reset_system(efi_mode, EFI_SUCCESS, sizeof(data),
-                        (efi_char16_t *)data);
+       efi.reset_system(efi_mode, EFI_SUCCESS, reset_data_sz, reset_data);
 }
 

I think the main issue here is tying machine_restart(), which takes a u8[] argument, to efi_reboot(), which takes a (u16[]) + L"\0" + GUID buffer. So the change to efi_reboot() looks fine to me, we just cannot call it directly from machine_restart() as you are suggesting.

It mostly looks like the concerns you are highlighing are related to random commands being passed to UEFI platform specific reset API. I suppose this can be addressed using following allow list (based on analysis done in patch-set [1]) for platform specific reset types. Your views?

static const efi_platform_reset_type_t platform_reset_types[] = {

        {EFI_RESET_BOOTLOADER_GUID,                     L"bootloader"           },
        {EFI_RESET_DM_VERITY_GUID,                      L"dm-verity-device-corrupted"   },
        {EFI_RESET_EDL_GUID,                            L"edl"                  },
        {EFI_RESET_FASTBOOT_GUID,                       L"fastboot"             },
        {EFI_RESET_LOADER_GUID,                         L"loader"               },
        {EFI_RESET_REBOOT_AB_UPDATE_GUID,               L"reboot-ab-update"     },
        {EFI_RESET_RECOVERY_GUID,                       L"recovery"             },
        {EFI_RESET_RESCUE_GUID,                         L"rescue"               },
        {EFI_RESET_SHUTDOWN_THERMAL_GUID,               L"shutdown-thermal"     },
        {EFI_RESET_SHUTDOWN_THERMAL_BATTERY_GUID,       L"shutdown-thermal-battery"     },

}

[1] https://lore.kernel.org/all/20251109-arm-psci-system_reset2-vendor-reboots-v17-0-46e085bca4cc@oss.qualcomm.com/

-Sumit