arch/x86/kernel/cpu/bugs.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/bugs.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/bugs.c- Extension
.c- Size
- 107719 bytes
- Lines
- 3738
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/cpu.hlinux/module.hlinux/nospec.hlinux/prctl.hlinux/sched/smt.hlinux/pgtable.hlinux/bpf.hlinux/kvm_types.hasm/spec-ctrl.hasm/cmdline.hasm/bugs.hasm/processor.hasm/processor-flags.hasm/fpu/api.hasm/msr.hasm/vmx.hasm/cpu_device_id.hasm/e820/api.hasm/hypervisor.hasm/tlbflush.hasm/cpu.hcpu.h
Detected Declarations
enum taa_mitigationsenum mmio_mitigationsenum rfds_mitigationsenum srbds_mitigationsenum l1d_flush_mitigationsenum gds_mitigationsenum spectre_v1_mitigationenum its_mitigationenum retbleed_mitigationenum srso_mitigationenum tsa_mitigationsenum spectre_v2_mitigation_cmdenum spectre_v2_user_mitigation_cmdenum bhi_mitigationsenum vmscape_mitigationsfunction set_return_thunkfunction update_spec_ctrlfunction update_spec_ctrl_condfunction spec_ctrl_currentfunction cpu_print_attack_vectorsfunction x86_virt_spec_ctrlfunction x86_amd_ssb_disablefunction should_mitigate_vulnfunction mds_select_mitigationfunction mds_update_mitigationfunction mds_apply_mitigationfunction mds_cmdlinefunction taa_vulnerablefunction taa_select_mitigationfunction taa_update_mitigationfunction taa_apply_mitigationfunction tsx_async_abort_parse_cmdlinefunction mmio_select_mitigationfunction mmio_update_mitigationfunction mmio_apply_mitigationfunction mmio_stale_data_parse_cmdlinefunction verw_clears_cpu_reg_filefunction rfds_select_mitigationfunction rfds_update_mitigationfunction rfds_apply_mitigationfunction rfds_parse_cmdlinefunction update_srbds_msrfunction srbds_select_mitigationfunction srbds_apply_mitigationfunction srbds_parse_cmdlinefunction l1d_flush_select_mitigationfunction l1d_flush_parse_cmdlinefunction gds_ucode_mitigated
Annotated Snippet
else if (!strcmp(str, "full,nosmt")) {
mds_mitigation = MDS_MITIGATION_FULL;
mds_nosmt = true;
}
return 0;
}
early_param("mds", mds_cmdline);
#undef pr_fmt
#define pr_fmt(fmt) "TAA: " fmt
static bool taa_nosmt __ro_after_init;
static const char * const taa_strings[] = {
[TAA_MITIGATION_OFF] = "Vulnerable",
[TAA_MITIGATION_UCODE_NEEDED] = "Vulnerable: Clear CPU buffers attempted, no microcode",
[TAA_MITIGATION_VERW] = "Mitigation: Clear CPU buffers",
[TAA_MITIGATION_TSX_DISABLED] = "Mitigation: TSX disabled",
};
static bool __init taa_vulnerable(void)
{
return boot_cpu_has_bug(X86_BUG_TAA) && boot_cpu_has(X86_FEATURE_RTM);
}
static void __init taa_select_mitigation(void)
{
if (!boot_cpu_has_bug(X86_BUG_TAA)) {
taa_mitigation = TAA_MITIGATION_OFF;
return;
}
/* TSX previously disabled by tsx=off */
if (!boot_cpu_has(X86_FEATURE_RTM)) {
taa_mitigation = TAA_MITIGATION_TSX_DISABLED;
return;
}
/* Microcode will be checked in taa_update_mitigation(). */
if (taa_mitigation == TAA_MITIGATION_AUTO) {
if (should_mitigate_vuln(X86_BUG_TAA))
taa_mitigation = TAA_MITIGATION_VERW;
else
taa_mitigation = TAA_MITIGATION_OFF;
}
if (taa_mitigation != TAA_MITIGATION_OFF)
verw_clear_cpu_buf_mitigation_selected = true;
}
static void __init taa_update_mitigation(void)
{
if (!taa_vulnerable())
return;
if (verw_clear_cpu_buf_mitigation_selected)
taa_mitigation = TAA_MITIGATION_VERW;
if (taa_mitigation == TAA_MITIGATION_VERW) {
/* Check if the requisite ucode is available. */
if (!boot_cpu_has(X86_FEATURE_MD_CLEAR))
taa_mitigation = TAA_MITIGATION_UCODE_NEEDED;
/*
* VERW doesn't clear the CPU buffers when MD_CLEAR=1 and MDS_NO=1.
* A microcode update fixes this behavior to clear CPU buffers. It also
* adds support for MSR_IA32_TSX_CTRL which is enumerated by the
* ARCH_CAP_TSX_CTRL_MSR bit.
*
* On MDS_NO=1 CPUs if ARCH_CAP_TSX_CTRL_MSR is not set, microcode
* update is required.
*/
if ((x86_arch_cap_msr & ARCH_CAP_MDS_NO) &&
!(x86_arch_cap_msr & ARCH_CAP_TSX_CTRL_MSR))
taa_mitigation = TAA_MITIGATION_UCODE_NEEDED;
}
pr_info("%s\n", taa_strings[taa_mitigation]);
}
static void __init taa_apply_mitigation(void)
{
if (taa_mitigation == TAA_MITIGATION_VERW ||
taa_mitigation == TAA_MITIGATION_UCODE_NEEDED) {
/*
* TSX is enabled, select alternate mitigation for TAA which is
* the same as MDS. Enable MDS static branch to clear CPU buffers.
*
* For guests that can't determine whether the correct microcode is
Annotation
- Immediate include surface: `linux/init.h`, `linux/cpu.h`, `linux/module.h`, `linux/nospec.h`, `linux/prctl.h`, `linux/sched/smt.h`, `linux/pgtable.h`, `linux/bpf.h`.
- Detected declarations: `enum taa_mitigations`, `enum mmio_mitigations`, `enum rfds_mitigations`, `enum srbds_mitigations`, `enum l1d_flush_mitigations`, `enum gds_mitigations`, `enum spectre_v1_mitigation`, `enum its_mitigation`, `enum retbleed_mitigation`, `enum srso_mitigation`.
- Atlas domain: Architecture Layer / arch/x86.
- 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.