efi: arm64: abort boot on pending SError
Subsystems (2)
PATCH 1/2 efi: arm64: abort boot on pending SError
It is the firmware's job to clear any pending SErrors before entering the kernel. On UEFI, we can fail gracefully rather than panic during early boot, so check for this condition in the stub.
--- drivers/firmware/efi/libstub/arm64-stub.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/firmware/efi/libstub/arm64-stub.c +8 -1
@@ -20,7 +20,14 @@ extern bool __nokaslr;efi_status_t check_platform_features (efi_system_table_t *sys_table_arg) { -u64 tg; +u64 tg, isr; + +/* check for a pending SError */ + asm ("mrs %0, isr_el1" :"=r" (isr)); +if (isr &BIT (8 )) { +pr_efi_err (sys_table_arg,"Pending SError detected -- aborting\n" ); +return EFI_LOAD_ERROR ; + }/* UEFI mandates support for 4 KB granularity, no need to check */ if (IS_ENABLED (CONFIG_ARM64_4K_PAGES ))
Signature · 1 line
2.7.4
PATCH 2/2 arm64: document that pending SErrors are not allowed at kernel entry
Our current strategy to deal with pending SErrors at boot is to panic. So let's mention in our boot protocol documentation that no SErrors should be pending when handing over to the kernel.
--- Documentation/arm64/booting.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Documentation/arm64/booting.txt +3 -2
@@ -154,8 +154,9 @@ Before jumping into the kernel, the following conditions must be met: x3 = 0 (reserved for future use) - CPU mode - All forms of interrupts must be masked in PSTATE.DAIF (Debug, SError, - IRQ and FIQ). + All forms of exceptions must be masked in PSTATE.DAIF (Debug, SError, + IRQ and FIQ), and any pending SError exceptions must be taken by the + boot loader or firmware before handing over to the kernel. The CPU must be in either EL2 (RECOMMENDED in order to have access to the virtualisation extensions) or non-secure EL1.
Signature · 1 line
2.7.4
PATCH 2/2 arm64: document that pending SErrors are not allowed at kernel entry
Quoted 14 lines · Ard Biesheuvel
Our current strategy to deal with pending SErrors at boot is to panic. So let's mention in our boot protocol documentation that no SErrors should be pending when handing over to the kernel.
Signed-off-by Ard Biesheuvel <[email protected]>--- Documentation/arm64/booting.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Documentation/arm64/booting.txt +0
-0
Documentation/arm64/booting.txt Before jumping into the kernel, the following conditions must be met: · line 159
Quoted 8 lines
Documentation/arm64/booting.txt +3
-2@@ -154,8 +154,9 @@ Before jumping into the kernel, the following conditions must be met: x3 = 0 (reserved for future use) - CPU mode - All forms of interrupts must be masked in PSTATE.DAIF (Debug, SError, - IRQ and FIQ). + All forms of exceptions must be masked in PSTATE.DAIF (Debug, SError, + IRQ and FIQ), and any pending SError exceptions must be taken by the + boot loader or firmware before handing over to the kernel.
That can be read to mean that a loader should silently swallow SError, which isn't quite what we want (that no SError ever occurs). I don't have a better wording to suggest, unfortunately. :/
As with patch 1, I'm not sure what this means for CPER and friends.
Thanks,
Mark.
Quoted 6 lines
Documentation/arm64/booting.txt +0
-0The CPU must be in either EL2 (RECOMMENDED in order to have access to the virtualisation extensions) or non-secure EL1.Signature · 1 line
2.7.4
PATCH 2/2 arm64: document that pending SErrors are not allowed at kernel entry
Quoted 17 lines · Mark Rutland
Quoted 16 lines · Ard Biesheuvel
Our current strategy to deal with pending SErrors at boot is to panic. So let's mention in our boot protocol documentation that no SErrors should be pending when handing over to the kernel.
Signed-off-by Ard Biesheuvel <[email protected]>--- Documentation/arm64/booting.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Documentation/arm64/booting.txt +0
-0@@ -154,8 +154,9 @@ Before jumping into the kernel, the following conditions must be met: x3 = 0 (reserved for future use)
Quoted 11 lines
Documentation/arm64/booting.txt Before jumping into the kernel, the following conditions must be met: · line 159
Quoted 6 lines
Documentation/arm64/booting.txt +3
-2- CPU mode - All forms of interrupts must be masked in PSTATE.DAIF (Debug, SError, - IRQ and FIQ). + All forms of exceptions must be masked in PSTATE.DAIF (Debug, SError, + IRQ and FIQ), and any pending SError exceptions must be taken by the + boot loader or firmware before handing over to the kernel.That can be read to mean that a loader should silently swallow SError, which isn't quite what we want (that no SError ever occurs). I don't have a better wording to suggest, unfortunately. :/
I don't think it is up to us to mandate how the firmware should be dealing with early SErrors, as long as none are pending when we enter the kernel.
PATCH 1/2 efi: arm64: abort boot on pending SError
In reply to Ard BiesheuvelQuoted 5 lines · Ard Biesheuvel
It is the firmware's job to clear any pending SErrors before entering the kernel. On UEFI, we can fail gracefully rather than panic during early boot, so check for this condition in the stub.
Signed-off-by Ard Biesheuvel <[email protected]>
An SError could be triggered either asynchronously by FW, or as a result of our actions at any point after this, e.g. due to the filesystem accesses made to load an initrd.
So in practice, is checking here useful? Have we seen FW with masked but pending SError at the point we enter the stub rather than that SError being triggered later,?
I'm also not sure what this means for CPER, which may use SError to signal to the OS. It's possible that the UEFI implementation polls ISR_EL1 itself, and handles SError appropriately internally, or that the OS can later deal with the SError based on CPER and friends.
Quoted 9 lines
--- drivers/firmware/efi/libstub/arm64-stub.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/firmware/efi/libstub/arm64-stub.c +0
-0
drivers/firmware/efi/libstub/arm64-stub.c extern bool __nokaslr; · line 26
Quoted 8 lines
drivers/firmware/efi/libstub/arm64-stub.c +4
-1@@ -20,7 +20,14 @@ extern bool __nokaslr;efi_status_t check_platform_features (efi_system_table_t *sys_table_arg) { -u64 tg; +u64 tg, isr; + +/* check for a pending SError */ + asm ("mrs %0, isr_el1" :"=r" (isr));
I think you can use read_sysreg(isr_el1) here, given that the read_sysreg helper is a macro function, and we already include sysreg.h here.
drivers/firmware/efi/libstub/arm64-stub.c extern bool __nokaslr; · line 27
Quoted 1 line
drivers/firmware/efi/libstub/arm64-stub.c +1
-0+if (isr &BIT (8 )) {
Perhaps add:
#define ISR_EL1_A_BIT BIT(8)
to sysreg.h?
drivers/firmware/efi/libstub/arm64-stub.c extern bool __nokaslr; · line 30
Quoted 3 lines
drivers/firmware/efi/libstub/arm64-stub.c +3
-0+pr_efi_err (sys_table_arg,"Pending SError detected -- aborting\n" ); +return EFI_LOAD_ERROR ; + }
Otherwise, code-wise this looks fine, but as above I'm not sure if this is the right thiing to do. :/
Thanks,
Mark.
Quoted 6 lines
drivers/firmware/efi/libstub/arm64-stub.c +0
-0/* UEFI mandates support for 4 KB granularity, no need to check */ if (IS_ENABLED (CONFIG_ARM64_4K_PAGES ))Signature · 1 line
2.7.4
PATCH 1/2 efi: arm64: abort boot on pending SError
Quoted 7 lines · Mark Rutland
Quoted 5 lines · Ard Biesheuvel
It is the firmware's job to clear any pending SErrors before entering the kernel. On UEFI, we can fail gracefully rather than panic during early boot, so check for this condition in the stub.
Signed-off-by Ard Biesheuvel <[email protected]>
Quoted 8 lines
An SError could be triggered either asynchronously by FW, or as a result of our actions at any point after this, e.g. due to the filesystem accesses made to load an initrd.
So in practice, is checking here useful? Have we seen FW with masked but pending SError at the point we enter the stub rather than that SError being triggered later,?
Yes. EDK2 keeps SError masked throughout its execution by default, and so any condition that triggered an SError up till this point is likely to still be pending, and blow up the kernel as soon as it unmasks it.
Quoted 5 lines
I'm also not sure what this means for CPER, which may use SError to signal to the OS. It's possible that the UEFI implementation polls
ISR_EL1itself, and handles SError appropriately internally, or that the OS can later deal with the SError based on CPER and friends.
Currently, the kernel panics on an SError, and so what the kernel should do once we start dealing with them in a more sophisticated way is hypothetical at the moment. Once that code arrives, it may revert this change, but for now, being dropped back into the UEFI shell does sound more appealing than panic early imo.
Quoted 10 lines
Quoted 10 lines
--- drivers/firmware/efi/libstub/arm64-stub.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/firmware/efi/libstub/arm64-stub.c +0
-0@@ -20,7 +20,14 @@ extern bool __nokaslr;
Quoted 12 lines
drivers/firmware/efi/libstub/arm64-stub.c extern bool __nokaslr; · line 26
Quoted 7 lines
drivers/firmware/efi/libstub/arm64-stub.c +4
-1efi_status_t check_platform_features (efi_system_table_t *sys_table_arg) { -u64 tg; +u64 tg, isr; + +/* check for a pending SError */ + asm ("mrs %0, isr_el1" :"=r" (isr));I think you can use
read_sysreg(isr_el1)here, given that theread_sysreghelper is a macro function, and we already includesysreg.hhere.
OK
Quoted 8 lines
drivers/firmware/efi/libstub/arm64-stub.c extern bool __nokaslr; · line 27
Quoted 1 line
drivers/firmware/efi/libstub/arm64-stub.c +1
-0+if (isr &BIT (8 )) {Perhaps add:
#define
ISR_EL1_A_BITBIT(8)to
sysreg.h?
OK
Quoted 7 lines
drivers/firmware/efi/libstub/arm64-stub.c extern bool __nokaslr; · line 30
Quoted 3 lines
drivers/firmware/efi/libstub/arm64-stub.c +3
-0+pr_efi_err (sys_table_arg,"Pending SError detected -- aborting\n" ); +return EFI_LOAD_ERROR ; + }Otherwise, code-wise this looks fine, but as above I'm not sure if this is the right thiing to do. :/
Yes, let's clear that up first.
Signature · 1 line
Ard,
PATCH 1/2 efi: arm64: abort boot on pending SError
Quoted 12 lines · Ard Biesheuvel
Quoted 11 lines · Mark Rutland
Quoted 5 lines · Ard Biesheuvel
It is the firmware's job to clear any pending SErrors before entering the kernel. On UEFI, we can fail gracefully rather than panic during early boot, so check for this condition in the stub.
Signed-off-by Ard Biesheuvel <[email protected]>An SError could be triggered either asynchronously by FW, or as a result of our actions at any point after this, e.g. due to the filesystem accesses made to load an initrd.
Quoted 7 lines
Quoted 3 lines
So in practice, is checking here useful? Have we seen FW with masked but pending SError at the point we enter the stub rather than that SError being triggered later,?
Yes. EDK2 keeps SError masked throughout its execution by default, and so any condition that triggered an SError up till this point is likely to still be pending, and blow up the kernel as soon as it unmasks it.
Ok.
Quoted 10 lines
Quoted 4 lines
I'm also not sure what this means for CPER, which may use SError to signal to the OS. It's possible that the UEFI implementation polls
ISR_EL1itself, and handles SError appropriately internally, or that the OS can later deal with the SError based on CPER and friends.Currently, the kernel panics on an SError, and so what the kernel should do once we start dealing with them in a more sophisticated way is hypothetical at the moment. Once that code arrives, it may revert this change, but for now, being dropped back into the UEFI shell does sound more appealing than panic early imo.
Logging something while the UART is available is certainly appealing.
As you say, we can change this later if/when we have more advanced SError handling. So modulo my prior comments, I guess this is fine for now.
Thanks,
Mark.
PATCH 1/2 efi: arm64: abort boot on pending SError
Quoted 28 lines · Mark Rutland
Quoted 12 lines · Ard Biesheuvel
Quoted 11 lines · Mark Rutland
Quoted 5 lines · Ard Biesheuvel
It is the firmware's job to clear any pending SErrors before entering the kernel. On UEFI, we can fail gracefully rather than panic during early boot, so check for this condition in the stub.
Signed-off-by Ard Biesheuvel <[email protected]>An SError could be triggered either asynchronously by FW, or as a result of our actions at any point after this, e.g. due to the filesystem accesses made to load an initrd.
Quoted 7 lines
Quoted 3 lines
So in practice, is checking here useful? Have we seen FW with masked but pending SError at the point we enter the stub rather than that SError being triggered later,?
Yes. EDK2 keeps SError masked throughout its execution by default, and so any condition that triggered an SError up till this point is likely to still be pending, and blow up the kernel as soon as it unmasks it.
Ok.
Quoted 5 lines
Quoted 4 lines
I'm also not sure what this means for CPER, which may use SError to signal to the OS. It's possible that the UEFI implementation polls
ISR_EL1itself, and handles SError appropriately internally, or that the OS can later deal with the SError based on CPER and friends.
Quoted 8 lines
Quoted 5 lines
Currently, the kernel panics on an SError, and so what the kernel should do once we start dealing with them in a more sophisticated way is hypothetical at the moment. Once that code arrives, it may revert this change, but for now, being dropped back into the UEFI shell does sound more appealing than panic early imo.
Logging something while the UART is available is certainly appealing.
Not just the UART, the graphical console as well, if the system has one.
Quoted 4 lines
As you say, we can change this later if/when we have more advanced SError handling. So modulo my prior comments, I guess this is fine for now.
OK, thanks.