[RFC PATCH 03/36] arm64: hibernate: mask DAIF before restoring hibernated kernel
Jinjie Ruan
ruanjinjie at huawei.com
Thu Jul 9 20:28:31 PDT 2026
On 7/9/2026 8:13 PM, Vladimir Murzin wrote:
> From: Ada Couprie Diaz <ada.coupriediaz at arm.com>
>
> The arm64 hibernate code manages the exception masking in an unsound
> way, leading to potential crashes and/or warnings during resume.
>
> When a hibernation image is saved in `swsusp_arch_suspend()`, all DAIF
> exceptions are masked (by virtue of `local_daif_save()`), and the
> suspended image is saved assuming that all DAIF exceptions will remain
> masked when the image is restored.
>
> When a hibernation image is resumed by `swsusp_arch_resume()`, only
> interrupts are masked (by virtue of `local_irq_save()` in
> `resume_target_kernel()`). When pseudo-NMI is enabled the DAIF.IF bits
> will be clear, and regardless of pseudo-NMI the DAIF.DA bits will be
> clear.
>
> This means that there are two problems:
>
> (1) It is possible to take Debug, SError, or pseudo-NMI exceptions
> during the resume process. This is unsafe, as during the resume
> process both the old ane new kernels will tranisently be in an
> inconsistent state, and swsusp_arch_suspend_exit() won't retain
> an executable mapping of any exception vectors.
>
> Any exception taken here will be fatal and silent.
>
> (2) When re-entering the resumed kernel, some DAIF bits will be clear
> unexpectedly. This permits Debug, SError, or pseudo-NMI exceptions
> to be taken for a short period while the resumed kernel is not yet
> in a consistent state.
>
> This is detected by CONFIG_ARM64_DEBUG_PRIORITY_MASKING.
>
> Avoid these issues by masking all DAIF exceptions during resume.
>
> Cc: stable at vger.kernel.org
> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz at arm.com>
> Signed-off-by: Vladimir Murzin <vladimir.murzin at arm.com>
> ---
> arch/arm64/kernel/hibernate.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
> index 9717568518ba..d0d9bd91e639 100644
> --- a/arch/arm64/kernel/hibernate.c
> +++ b/arch/arm64/kernel/hibernate.c
> @@ -405,6 +405,7 @@ int swsusp_arch_suspend(void)
> int __nocfi swsusp_arch_resume(void)
> {
> int rc;
> + unsigned long flags;
> void *zero_page;
> size_t exit_size;
> pgd_t *tmp_pg_dir;
> @@ -465,9 +466,21 @@ int __nocfi swsusp_arch_resume(void)
> if (el2_reset_needed())
> __hyp_set_vectors(el2_vectors);
>
> + /*
> + * It is necessary to mask all DAIF exceptions here as:
> + *
> + * - The copy of swsusp_arch_suspend_exit() in the hibernation
> + * text cannot handle taking any exceptions.
> + *
> + * - The suspended kernel masked all DAIF exceptions in
> + * swsusp_arch_resume(), and expects to be re-entered in the
> + * same state : with all DAIF exceptions masked.
> + */
> + flags = local_daif_save();
> hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1,
> resume_hdr.reenter_kernel, restore_pblist,
> resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page));
> + local_daif_restore(flags);
I believe that the local_daif_save() here is also unnecessary because
hibernate_exit() returns from the "return 0 branch" of
__cpu_suspend_enter() in swsusp_arch_suspend(), and before that,
local_daif_save() has already been called to mask all exceptions.
swsusp_arch_suspend(void)
-> flags = local_daif_save();
-> if (__cpu_suspend_enter(&state)) {
...
} else { // _cpu_resume <- hibernate_exit()
...
in_suspend = 0;
...
}
-> local_daif_restore(flags);
>
> return 0;
> }
More information about the linux-arm-kernel
mailing list