arch/arm64/kernel/hibernate.c
Source file repositories/reference/linux-study-clean/arch/arm64/kernel/hibernate.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kernel/hibernate.c- Extension
.c- Size
- 11755 bytes
- Lines
- 484
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpu.hlinux/kvm_host.hlinux/pm.hlinux/sched.hlinux/suspend.hlinux/utsname.hasm/barrier.hasm/cacheflush.hasm/cputype.hasm/daifflags.hasm/irqflags.hasm/kexec.hasm/memory.hasm/mmu_context.hasm/mte.hasm/sections.hasm/smp.hasm/smp_plat.hasm/suspend.hasm/sysreg.hasm/trans_pgd.hasm/virt.h
Detected Declarations
struct arch_hibernate_hdr_invariantsfunction arch_hdr_invariantsfunction pfn_is_nosavefunction save_processor_statefunction arch_hibernation_header_restorefunction create_safe_exec_pagefunction save_tagsfunction swsusp_mte_free_storagefunction swsusp_mte_save_tagsfunction for_each_populated_zonefunction swsusp_mte_restore_tagsfunction swsusp_mte_save_tagsfunction swsusp_mte_restore_tagsfunction swsusp_arch_suspend_exitfunction hibernate_resume_nonboot_cpu_disableexport arch_hibernation_header_saveexport arch_hibernation_header_restore
Annotated Snippet
struct arch_hibernate_hdr_invariants {
char uts_version[__NEW_UTS_LEN + 1];
};
/* These values need to be know across a hibernate/restore. */
static struct arch_hibernate_hdr {
struct arch_hibernate_hdr_invariants invariants;
/* These are needed to find the relocated kernel if built with kaslr */
phys_addr_t ttbr1_el1;
void (*reenter_kernel)(void);
/*
* We need to know where the __hyp_stub_vectors are after restore to
* re-configure el2.
*/
phys_addr_t __hyp_stub_vectors;
u64 sleep_cpu_mpidr;
} resume_hdr;
static inline void arch_hdr_invariants(struct arch_hibernate_hdr_invariants *i)
{
memset(i, 0, sizeof(*i));
memcpy(i->uts_version, init_utsname()->version, sizeof(i->uts_version));
}
int pfn_is_nosave(unsigned long pfn)
{
unsigned long nosave_begin_pfn = sym_to_pfn(&__nosave_begin);
unsigned long nosave_end_pfn = sym_to_pfn(&__nosave_end - 1);
return ((pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn)) ||
crash_is_nosave(pfn);
}
void notrace save_processor_state(void)
{
}
void notrace restore_processor_state(void)
{
}
int arch_hibernation_header_save(void *addr, unsigned int max_size)
{
struct arch_hibernate_hdr *hdr = addr;
if (max_size < sizeof(*hdr))
return -EOVERFLOW;
arch_hdr_invariants(&hdr->invariants);
hdr->ttbr1_el1 = __pa_symbol(swapper_pg_dir);
hdr->reenter_kernel = _cpu_resume;
/* We can't use __hyp_get_vectors() because kvm may still be loaded */
if (el2_reset_needed())
hdr->__hyp_stub_vectors = __pa_symbol(__hyp_stub_vectors);
else
hdr->__hyp_stub_vectors = 0;
/* Save the mpidr of the cpu we called cpu_suspend() on... */
if (sleep_cpu < 0) {
pr_err("Failing to hibernate on an unknown CPU.\n");
return -ENODEV;
}
hdr->sleep_cpu_mpidr = cpu_logical_map(sleep_cpu);
pr_info("Hibernating on CPU %d [mpidr:0x%llx]\n", sleep_cpu,
hdr->sleep_cpu_mpidr);
return 0;
}
EXPORT_SYMBOL(arch_hibernation_header_save);
int arch_hibernation_header_restore(void *addr)
{
int ret;
struct arch_hibernate_hdr_invariants invariants;
struct arch_hibernate_hdr *hdr = addr;
arch_hdr_invariants(&invariants);
if (memcmp(&hdr->invariants, &invariants, sizeof(invariants))) {
pr_crit("Hibernate image not generated by this kernel!\n");
return -EINVAL;
}
sleep_cpu = get_logical_index(hdr->sleep_cpu_mpidr);
pr_info("Hibernated on CPU %d [mpidr:0x%llx]\n", sleep_cpu,
hdr->sleep_cpu_mpidr);
if (sleep_cpu < 0) {
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/kvm_host.h`, `linux/pm.h`, `linux/sched.h`, `linux/suspend.h`, `linux/utsname.h`, `asm/barrier.h`, `asm/cacheflush.h`.
- Detected declarations: `struct arch_hibernate_hdr_invariants`, `function arch_hdr_invariants`, `function pfn_is_nosave`, `function save_processor_state`, `function arch_hibernation_header_restore`, `function create_safe_exec_page`, `function save_tags`, `function swsusp_mte_free_storage`, `function swsusp_mte_save_tags`, `function for_each_populated_zone`.
- Atlas domain: Architecture Layer / arch/arm64.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.