arch/loongarch/kernel/machine_kexec_file.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/machine_kexec_file.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kernel/machine_kexec_file.c- Extension
.c- Size
- 6670 bytes
- Lines
- 240
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- 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/ioport.hlinux/kernel.hlinux/kexec.hlinux/memblock.hlinux/slab.hlinux/string.hlinux/types.hlinux/vmalloc.hasm/bootinfo.h
Detected Declarations
function arch_kimage_file_post_load_cleanupfunction cmdline_add_loaderfunction cmdline_add_initrdfunction prepare_elf_headersfunction cmdline_add_memfunction cmdline_add_elfcorehdrfunction load_other_segments
Annotated Snippet
if (ret < 0) {
pr_err("Preparing elf core header failed\n");
goto out_err;
}
kbuf.buffer = headers;
kbuf.bufsz = headers_sz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
kbuf.memsz = headers_sz;
kbuf.buf_align = SZ_64K; /* largest supported page size */
kbuf.buf_max = ULONG_MAX;
kbuf.top_down = true;
ret = kexec_add_buffer(&kbuf);
if (ret < 0) {
vfree(headers);
goto out_err;
}
image->elf_headers = headers;
image->elf_load_addr = kbuf.mem;
image->elf_headers_sz = headers_sz;
kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
/* Add the mem=size@start parameter to the command line */
cmdline_add_mem(&cmdline_tmplen, modified_cmdline);
/* Add the elfcorehdr=size@start parameter to the command line */
cmdline_add_elfcorehdr(image, &cmdline_tmplen, modified_cmdline, headers_sz);
}
#endif
/* Load initrd */
if (initrd) {
kbuf.buffer = initrd;
kbuf.bufsz = initrd_len;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
kbuf.memsz = initrd_len;
kbuf.buf_align = 0;
/* within 1GB-aligned window of up to 32GB in size */
kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + (unsigned long)SZ_1G * 32;
kbuf.top_down = false;
ret = kexec_add_buffer(&kbuf);
if (ret < 0)
goto out_err;
initrd_load_addr = kbuf.mem;
kexec_dprintk("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
initrd_load_addr, kbuf.bufsz, kbuf.memsz);
/* Add the initrd=start,size parameter to the command line */
cmdline_add_initrd(image, &cmdline_tmplen, modified_cmdline, initrd_load_addr);
}
if (cmdline_len + cmdline_tmplen > COMMAND_LINE_SIZE) {
pr_err("Appending command line exceeds COMMAND_LINE_SIZE\n");
ret = -EINVAL;
goto out_err;
}
memcpy(modified_cmdline + cmdline_tmplen, cmdline, cmdline_len);
cmdline = modified_cmdline;
image->arch.cmdline_ptr = (unsigned long)cmdline;
return 0;
out_err:
image->nr_segments = orig_segments;
kfree(modified_cmdline);
return ret;
}
Annotation
- Immediate include surface: `linux/ioport.h`, `linux/kernel.h`, `linux/kexec.h`, `linux/memblock.h`, `linux/slab.h`, `linux/string.h`, `linux/types.h`, `linux/vmalloc.h`.
- Detected declarations: `function arch_kimage_file_post_load_cleanup`, `function cmdline_add_loader`, `function cmdline_add_initrd`, `function prepare_elf_headers`, `function cmdline_add_mem`, `function cmdline_add_elfcorehdr`, `function load_other_segments`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: source 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.