kernel/kexec_file.c
Source file repositories/reference/linux-study-clean/kernel/kexec_file.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/kexec_file.c- Extension
.c- Size
- 32319 bytes
- Lines
- 1262
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/capability.hlinux/mm.hlinux/file.hlinux/slab.hlinux/kexec.hlinux/memblock.hlinux/mutex.hlinux/list.hlinux/fs.hlinux/ima.hcrypto/sha2.hlinux/elf.hlinux/elfcore.hlinux/kernel.hlinux/kernel_read_file.hlinux/syscalls.hlinux/vmalloc.hlinux/dma-map-ops.hkexec_internal.h
Detected Declarations
syscall kexec_file_loadfunction set_kexec_sig_enforcedfunction check_ima_segment_indexfunction check_ima_segment_indexfunction kexec_image_probe_defaultfunction kexec_image_post_load_cleanup_defaultfunction kimage_file_post_load_cleanupfunction kexec_kernel_verify_pe_sigfunction kexec_image_verify_sigfunction kimage_validate_signaturefunction kexec_post_loadfunction kimage_file_prepare_segmentsfunction kimage_file_alloc_initfunction locate_mem_hole_top_downfunction locate_mem_hole_bottom_upfunction locate_mem_hole_callbackfunction kexec_walk_memblockfunction locate_mem_hole_callbackfunction for_each_free_mem_rangefunction kexec_walk_memblockfunction kexec_walk_resourcesfunction kexec_alloc_contigfunction kexec_locate_mem_holefunction kexec_add_bufferfunction kexec_calculate_store_digestsfunction kexec_purgatory_setup_kbuffunction kexec_purgatory_setup_sechdrsfunction kexec_apply_relocationsfunction kexec_load_purgatoryfunction kexec_purgatory_get_set_symbol
Annotated Snippet
SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
unsigned long, cmdline_len, const char __user *, cmdline_ptr,
unsigned long, flags)
{
int image_type = (flags & KEXEC_FILE_ON_CRASH) ?
KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT;
struct kimage **dest_image, *image;
int ret = 0, i;
/* We only trust the superuser with rebooting the system. */
if (!kexec_load_permitted(image_type))
return -EPERM;
/* Make sure we have a legal set of flags */
if (flags != (flags & KEXEC_FILE_FLAGS))
return -EINVAL;
image = NULL;
if (!kexec_trylock())
return -EBUSY;
#ifdef CONFIG_CRASH_DUMP
if (image_type == KEXEC_TYPE_CRASH) {
dest_image = &kexec_crash_image;
if (kexec_crash_image)
arch_kexec_unprotect_crashkres();
} else
#endif
dest_image = &kexec_image;
if (flags & KEXEC_FILE_UNLOAD)
goto exchange;
/*
* In case of crash, new kernel gets loaded in reserved region. It is
* same memory where old crash kernel might be loaded. Free any
* current crash dump kernel before we corrupt it.
*/
if (flags & KEXEC_FILE_ON_CRASH)
kimage_free(xchg(&kexec_crash_image, NULL));
ret = kimage_file_alloc_init(&image, kernel_fd, initrd_fd, cmdline_ptr,
cmdline_len, flags);
if (ret)
goto out;
#ifdef CONFIG_CRASH_HOTPLUG
if ((flags & KEXEC_FILE_ON_CRASH) && arch_crash_hotplug_support(image, flags))
image->hotplug_support = 1;
#endif
ret = machine_kexec_prepare(image);
if (ret)
goto out;
/*
* Some architecture(like S390) may touch the crash memory before
* machine_kexec_prepare(), we must copy vmcoreinfo data after it.
*/
ret = kimage_crash_copy_vmcoreinfo(image);
if (ret)
goto out;
ret = kexec_calculate_store_digests(image);
if (ret)
goto out;
kexec_dprintk("nr_segments = %lu\n", image->nr_segments);
for (i = 0; i < image->nr_segments; i++) {
struct kexec_segment *ksegment;
ksegment = &image->segment[i];
kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
i, ksegment->buf, ksegment->bufsz, ksegment->mem,
ksegment->memsz);
ret = kimage_load_segment(image, i);
if (ret)
goto out;
}
kimage_terminate(image);
ret = kexec_post_load(image, flags);
if (ret)
goto out;
kexec_dprintk("kexec_file_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
image->type, image->start, image->head, flags);
Annotation
- Immediate include surface: `linux/capability.h`, `linux/mm.h`, `linux/file.h`, `linux/slab.h`, `linux/kexec.h`, `linux/memblock.h`, `linux/mutex.h`, `linux/list.h`.
- Detected declarations: `syscall kexec_file_load`, `function set_kexec_sig_enforced`, `function check_ima_segment_index`, `function check_ima_segment_index`, `function kexec_image_probe_default`, `function kexec_image_post_load_cleanup_default`, `function kimage_file_post_load_cleanup`, `function kexec_kernel_verify_pe_sig`, `function kexec_image_verify_sig`, `function kimage_validate_signature`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: core implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.