This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit ccf9e61653099b46ef6af40c4a9912fba46f0649 Author: hujun5 <[email protected]> AuthorDate: Wed Jul 22 12:27:11 2026 +0800 arch/arm64: add panic notifier to switch back to non-secure world When the secure world (TEE) panics, the CPU stalls in S-EL1 and the non-secure world (REE) can never resume to finish its coredump or recovery. Register a reboot notifier that issues an SMC (ARM_SMCCC_NUTTX_TEE_IDLE) on SYS_HALT to yield the CPU back to the REE via EL3, mirroring the existing arm32 arm_panic_switch_nsec_register mechanism. Signed-off-by: hujun5 <[email protected]> --- arch/arm64/src/common/arm64_initialize.c | 59 ++++++++++++++++++++++++++++++++ arch/arm64/src/common/arm64_internal.h | 6 ++++ 2 files changed, 65 insertions(+) diff --git a/arch/arm64/src/common/arm64_initialize.c b/arch/arm64/src/common/arm64_initialize.c index eab3fd99950..ff4e7b07eb8 100644 --- a/arch/arm64/src/common/arm64_initialize.c +++ b/arch/arm64/src/common/arm64_initialize.c @@ -37,6 +37,7 @@ #include <nuttx/net/tun.h> #include <nuttx/net/telnet.h> #include <nuttx/panic_notifier.h> +#include <nuttx/reboot_notifier.h> #include <nuttx/power/pm.h> #include <arch/chip/chip.h> @@ -56,6 +57,11 @@ static struct notifier_block g_fpu_panic_block; #endif +#ifdef CONFIG_ARCH_TRUSTZONE_SECURE +static DEFINE_PER_CPU_BSS(struct notifier_block, g_panic_switch_nsec_nb); +#define g_panic_switch_nsec_nb this_cpu_var(g_panic_switch_nsec_nb) +#endif + /**************************************************************************** * Public Data ****************************************************************************/ @@ -91,6 +97,53 @@ static int arm64_panic_disable_fpu(struct notifier_block *block, } #endif +/**************************************************************************** + * Name: arm64_panic_switch_nsec + * + * Description: + * Reboot notifier callback for TrustZone Secure world. On SYS_HALT + * (panic), issue an SMC to yield CPU back to the non-secure world so + * the REE can finish its coredump or recovery sequence. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_TRUSTZONE_SECURE +static int arm64_panic_switch_nsec(struct notifier_block *block, + unsigned long action, void *data) +{ + if (action == SYS_HALT) + { + struct arm_smccc_res res; + + /* Yield CPU to non-secure world via EL3. This is the same SMC + * used in idle; EL3 will switch context to the REE. + */ + + arm_smccc_smc(ARM_SMCCC_NUTTX_TEE_IDLE, + 0, 0, 0, 0, 0, 0, 0, &res); + } + + return 0; +} + +/**************************************************************************** + * Name: arm64_panic_switch_nsec_register + * + * Description: + * Register a reboot notifier that switches to the non-secure world + * when the secure world panics, so the REE can finish its coredump + * or recovery sequence. + * + ****************************************************************************/ + +void arm64_panic_switch_nsec_register(void) +{ + g_panic_switch_nsec_nb.notifier_call = arm64_panic_switch_nsec; + g_panic_switch_nsec_nb.priority = INT_MIN; + register_reboot_notifier(&g_panic_switch_nsec_nb); +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -170,4 +223,10 @@ void up_initialize(void) #endif #endif + + /* Register the panic notifier that switches to the non-secure world on a + * secure-world crash, so the REE can finish coredump / recovery. + */ + + arm64_panic_switch_nsec_register(); } diff --git a/arch/arm64/src/common/arm64_internal.h b/arch/arm64/src/common/arm64_internal.h index 9674860624a..b1c21687e6f 100644 --- a/arch/arm64/src/common/arm64_internal.h +++ b/arch/arm64/src/common/arm64_internal.h @@ -389,6 +389,12 @@ void arm64_stack_color(void *stackbase, size_t nbytes); int arm64_enable_dbgmonitor(void); #endif +#ifdef CONFIG_ARCH_TRUSTZONE_SECURE +void arm64_panic_switch_nsec_register(void); +#else +# define arm64_panic_switch_nsec_register() +#endif + #ifdef CONFIG_SMP void arm64_timer_secondary_init(void); #endif
