arch/riscv/kernel/machine_kexec.c
Source file repositories/reference/linux-study-clean/arch/riscv/kernel/machine_kexec.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kernel/machine_kexec.c- Extension
.c- Size
- 5421 bytes
- Lines
- 183
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kexec.hasm/kexec.hlinux/smp.hasm/cacheflush.hasm/barrier.hasm/page.hlinux/libfdt.hasm/set_memory.hlinux/compiler.hlinux/cpu.hlinux/reboot.hlinux/interrupt.hlinux/irq.h
Detected Declarations
function Copyrightfunction machine_kexec_cleanupfunction machine_crash_shutdownfunction machine_kexec
Annotated Snippet
if (unlikely(riscv_kexec_relocate_size > control_code_buffer_sz)) {
pr_err("Relocation code doesn't fit within a control page\n");
return -EINVAL;
}
memcpy(control_code_buffer, riscv_kexec_relocate,
riscv_kexec_relocate_size);
/* Mark the control page executable */
set_memory_x((unsigned long) control_code_buffer, 1);
}
return 0;
}
/*
* machine_kexec_cleanup - Cleanup any leftovers from
* machine_kexec_prepare
*
* This function is called by kimage_free to handle any arch-specific
* allocations done on machine_kexec_prepare. Since we didn't do any
* allocations there, this is just an empty function. Note that the
* control buffer is freed by kimage_free.
*/
void
machine_kexec_cleanup(struct kimage *image)
{
}
/*
* machine_shutdown - Prepare for a kexec reboot
*
* This function is called by kernel_kexec just before machine_kexec
* below. Its goal is to prepare the rest of the system (the other
* harts and possibly devices etc) for a kexec reboot.
*/
void machine_shutdown(void)
{
/*
* No more interrupts on this hart
* until we are back up.
*/
local_irq_disable();
#if defined(CONFIG_HOTPLUG_CPU)
smp_shutdown_nonboot_cpus(smp_processor_id());
#endif
}
/*
* machine_crash_shutdown - Prepare to kexec after a kernel crash
*
* This function is called by crash_kexec just before machine_kexec
* and its goal is to shutdown non-crashing cpus and save registers.
*/
void
machine_crash_shutdown(struct pt_regs *regs)
{
local_irq_disable();
/* shutdown non-crashing cpus */
crash_smp_send_stop();
crash_save_cpu(regs, smp_processor_id());
machine_kexec_mask_interrupts();
pr_info("Starting crashdump kernel...\n");
}
/*
* machine_kexec - Jump to the loaded kimage
*
* This function is called by kernel_kexec which is called by the
* reboot system call when the reboot cmd is LINUX_REBOOT_CMD_KEXEC,
* or by crash_kernel which is called by the kernel's arch-specific
* trap handler in case of a kernel panic. It's the final stage of
* the kexec process where the pre-loaded kimage is ready to be
* executed. We assume at this point that all other harts are
* suspended and this hart will be the new boot hart.
*/
void __noreturn
machine_kexec(struct kimage *image)
{
struct kimage_arch *internal = &image->arch;
unsigned long jump_addr = (unsigned long) image->start;
unsigned long first_ind_entry = (unsigned long) &image->head;
unsigned long this_cpu_id = __smp_processor_id();
unsigned long this_hart_id = cpuid_to_hartid_map(this_cpu_id);
Annotation
- Immediate include surface: `linux/kexec.h`, `asm/kexec.h`, `linux/smp.h`, `asm/cacheflush.h`, `asm/barrier.h`, `asm/page.h`, `linux/libfdt.h`, `asm/set_memory.h`.
- Detected declarations: `function Copyright`, `function machine_kexec_cleanup`, `function machine_crash_shutdown`, `function machine_kexec`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.