kernel/crash_core.c
Source file repositories/reference/linux-study-clean/kernel/crash_core.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/crash_core.c- Extension
.c- Size
- 19049 bytes
- Lines
- 701
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/buildid.hlinux/init.hlinux/utsname.hlinux/vmalloc.hlinux/sizes.hlinux/kexec.hlinux/memory.hlinux/mm.hlinux/cpuhotplug.hlinux/memblock.hlinux/kmemleak.hlinux/crash_core.hlinux/reboot.hlinux/btf.hlinux/objtool.hlinux/delay.hlinux/panic.hasm/page.hasm/sections.hkallsyms_internal.hkexec_internal.h
Detected Declarations
function kimage_crash_copy_vmcoreinfofunction kexec_should_crashfunction kexec_crash_loadedfunction crash_cma_clear_pending_dmafunction __crash_kexecfunction crash_kexecfunction crash_resource_sizefunction crash_prepare_elf64_headersfunction crash_exclude_mem_rangefunction crash_get_memory_sizefunction __crash_shrink_memoryfunction crash_shrink_memoryfunction crash_save_cpufunction crash_notes_memory_initfunction crash_check_hotplug_supportfunction crash_handle_hotplug_eventfunction crash_memhp_notifierfunction crash_cpuhp_onlinefunction crash_cpuhp_offlinefunction crash_hotplug_initmodule init crash_notes_memory_initmodule init crash_hotplug_initexport kexec_crash_loadedexport crash_exclude_mem_range
Annotated Snippet
subsys_initcall(crash_notes_memory_init);
#endif /*CONFIG_CRASH_DUMP*/
#ifdef CONFIG_CRASH_HOTPLUG
#undef pr_fmt
#define pr_fmt(fmt) "crash hp: " fmt
/*
* Different than kexec/kdump loading/unloading/jumping/shrinking which
* usually rarely happen, there will be many crash hotplug events notified
* during one short period, e.g one memory board is hot added and memory
* regions are online. So mutex lock __crash_hotplug_lock is used to
* serialize the crash hotplug handling specifically.
*/
static DEFINE_MUTEX(__crash_hotplug_lock);
#define crash_hotplug_lock() mutex_lock(&__crash_hotplug_lock)
#define crash_hotplug_unlock() mutex_unlock(&__crash_hotplug_lock)
/*
* This routine utilized when the crash_hotplug sysfs node is read.
* It reflects the kernel's ability/permission to update the kdump
* image directly.
*/
int crash_check_hotplug_support(void)
{
int rc = 0;
crash_hotplug_lock();
/* Obtain lock while reading crash information */
if (!kexec_trylock()) {
if (!kexec_in_progress)
pr_info("kexec_trylock() failed, kdump image may be inaccurate\n");
crash_hotplug_unlock();
return 0;
}
if (kexec_crash_image) {
rc = kexec_crash_image->hotplug_support;
}
/* Release lock now that update complete */
kexec_unlock();
crash_hotplug_unlock();
return rc;
}
/*
* To accurately reflect hot un/plug changes of CPU and Memory resources
* (including onling and offlining of those resources), the relevant
* kexec segments must be updated with latest CPU and Memory resources.
*
* Architectures must ensure two things for all segments that need
* updating during hotplug events:
*
* 1. Segments must be large enough to accommodate a growing number of
* resources.
* 2. Exclude the segments from SHA verification.
*
* For example, on most architectures, the elfcorehdr (which is passed
* to the crash kernel via the elfcorehdr= parameter) must include the
* new list of CPUs and memory. To make changes to the elfcorehdr, it
* should be large enough to permit a growing number of CPU and Memory
* resources. One can estimate the elfcorehdr memory size based on
* NR_CPUS_DEFAULT and CRASH_MAX_MEMORY_RANGES. The elfcorehdr is
* excluded from SHA verification by default if the architecture
* supports crash hotplug.
*/
static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu, void *arg)
{
struct kimage *image;
crash_hotplug_lock();
/* Obtain lock while changing crash information */
if (!kexec_trylock()) {
if (!kexec_in_progress)
pr_info("kexec_trylock() failed, kdump image may be inaccurate\n");
crash_hotplug_unlock();
return;
}
/* Check kdump is not loaded */
if (!kexec_crash_image)
goto out;
image = kexec_crash_image;
/* Check that kexec segments update is permitted */
if (!image->hotplug_support)
goto out;
Annotation
- Immediate include surface: `linux/buildid.h`, `linux/init.h`, `linux/utsname.h`, `linux/vmalloc.h`, `linux/sizes.h`, `linux/kexec.h`, `linux/memory.h`, `linux/mm.h`.
- Detected declarations: `function kimage_crash_copy_vmcoreinfo`, `function kexec_should_crash`, `function kexec_crash_loaded`, `function crash_cma_clear_pending_dma`, `function __crash_kexec`, `function crash_kexec`, `function crash_resource_size`, `function crash_prepare_elf64_headers`, `function crash_exclude_mem_range`, `function crash_get_memory_size`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.