arch/x86/kernel/cpu/microcode/core.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/microcode/core.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/microcode/core.c- Extension
.c- Size
- 23973 bytes
- Lines
- 934
- Domain
- Architecture Layer
- Bucket
- arch/x86
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/stop_machine.hlinux/device/faux.hlinux/syscore_ops.hlinux/miscdevice.hlinux/capability.hlinux/firmware.hlinux/cpumask.hlinux/kernel.hlinux/delay.hlinux/mutex.hlinux/cpu.hlinux/nmi.hlinux/fs.hlinux/mm.hasm/apic.hasm/cpu_device_id.hasm/cpuid/api.hasm/perf_event.hasm/processor.hasm/cmdline.hasm/msr.hasm/setup.hinternal.h
Detected Declarations
struct microcode_ctrlenum sibling_ctrlfunction amd_check_current_patch_levelfunction microcode_loader_disabledfunction early_parse_cmdlinefunction load_ucode_bspfunction load_ucode_apfunction find_microcode_in_initrdfunction reload_early_microcodefunction wait_for_cpusfunction wait_for_ctrlfunction load_secondary_waitfunction load_secondaryfunction __load_primaryfunction for_each_cpufunction kick_offline_cpusfunction for_each_cpufunction release_offline_cpusfunction load_primaryfunction microcode_offline_nmi_handlerfunction microcode_update_handlerfunction microcode_nmi_handlerfunction load_cpus_stoppedfunction load_late_stop_cpusfunction setup_cpusfunction for_each_cpu_andfunction load_late_lockedfunction reload_storefunction version_showfunction processor_flags_showfunction microcode_fini_cpufunction microcode_bsp_resumefunction microcode_bsp_syscore_resumefunction mc_cpu_onlinefunction mc_cpu_down_prepfunction microcode_init
Annotated Snippet
struct microcode_ctrl {
enum sibling_ctrl ctrl;
enum ucode_state result;
unsigned int ctrl_cpu;
bool nmi_enabled;
};
DEFINE_STATIC_KEY_FALSE(microcode_nmi_handler_enable);
static DEFINE_PER_CPU(struct microcode_ctrl, ucode_ctrl);
static atomic_t late_cpus_in, offline_in_nmi;
static unsigned int loops_per_usec;
static cpumask_t cpu_offline_mask;
static noinstr bool wait_for_cpus(atomic_t *cnt)
{
unsigned int timeout, loops;
WARN_ON_ONCE(raw_atomic_dec_return(cnt) < 0);
for (timeout = 0; timeout < USEC_PER_SEC; timeout++) {
if (!raw_atomic_read(cnt))
return true;
for (loops = 0; loops < loops_per_usec; loops++)
cpu_relax();
/* If invoked directly, tickle the NMI watchdog */
if (!microcode_ops->use_nmi && !(timeout % USEC_PER_MSEC)) {
instrumentation_begin();
touch_nmi_watchdog();
instrumentation_end();
}
}
/* Prevent the late comers from making progress and let them time out */
raw_atomic_inc(cnt);
return false;
}
static noinstr bool wait_for_ctrl(void)
{
unsigned int timeout, loops;
for (timeout = 0; timeout < USEC_PER_SEC; timeout++) {
if (raw_cpu_read(ucode_ctrl.ctrl) != SCTRL_WAIT)
return true;
for (loops = 0; loops < loops_per_usec; loops++)
cpu_relax();
/* If invoked directly, tickle the NMI watchdog */
if (!microcode_ops->use_nmi && !(timeout % USEC_PER_MSEC)) {
instrumentation_begin();
touch_nmi_watchdog();
instrumentation_end();
}
}
return false;
}
/*
* Protected against instrumentation up to the point where the primary
* thread completed the update. See microcode_nmi_handler() for details.
*/
static noinstr bool load_secondary_wait(unsigned int ctrl_cpu)
{
/* Initial rendezvous to ensure that all CPUs have arrived */
if (!wait_for_cpus(&late_cpus_in)) {
raw_cpu_write(ucode_ctrl.result, UCODE_TIMEOUT);
return false;
}
/*
* Wait for primary threads to complete. If one of them hangs due
* to the update, there is no way out. This is non-recoverable
* because the CPU might hold locks or resources and confuse the
* scheduler, watchdogs etc. There is no way to safely evacuate the
* machine.
*/
if (wait_for_ctrl())
return true;
instrumentation_begin();
panic("Microcode load: Primary CPU %d timed out\n", ctrl_cpu);
instrumentation_end();
}
/*
* Protected against instrumentation up to the point where the primary
* thread completed the update. See microcode_nmi_handler() for details.
*/
Annotation
- Immediate include surface: `linux/stop_machine.h`, `linux/device/faux.h`, `linux/syscore_ops.h`, `linux/miscdevice.h`, `linux/capability.h`, `linux/firmware.h`, `linux/cpumask.h`, `linux/kernel.h`.
- Detected declarations: `struct microcode_ctrl`, `enum sibling_ctrl`, `function amd_check_current_patch_level`, `function microcode_loader_disabled`, `function early_parse_cmdline`, `function load_ucode_bsp`, `function load_ucode_ap`, `function find_microcode_in_initrd`, `function reload_early_microcode`, `function wait_for_cpus`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.