arch/x86/kvm/vmx/vmx.c
Source file repositories/reference/linux-study-clean/arch/x86/kvm/vmx/vmx.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/vmx/vmx.c- Extension
.c- Size
- 261660 bytes
- Lines
- 8858
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/highmem.hlinux/hrtimer.hlinux/kernel.hlinux/kvm_host.hlinux/module.hlinux/moduleparam.hlinux/mod_devicetable.hlinux/mm.hlinux/objtool.hlinux/sched.hlinux/sched/smt.hlinux/slab.hlinux/tboot.hlinux/trace_events.hasm/apic.hasm/asm.hasm/cpu.hasm/cpu_device_id.hasm/cpuid/api.hasm/debugreg.hasm/desc.hasm/fpu/api.hasm/fpu/xstate.hasm/fred.hasm/idtentry.hasm/io.hasm/irq_remapping.hasm/reboot.hasm/perf_event.hasm/mmu_context.hasm/mshyperv.hasm/msr.h
Detected Declarations
function __vmx_setup_l1d_flushfunction vmx_setup_l1d_flushfunction vmx_cleanup_l1d_flushfunction vmentry_l1d_flush_parsefunction vmentry_l1d_flush_setfunction vmx_initfunction vmentry_l1d_flush_getfunction vmx_l1d_flushfunction vmx_setup_l1d_flushfunction vmx_cleanup_l1d_flushfunction vmx_l1d_flushfunction vmentry_l1d_flush_getfunction vmx_disable_fb_clearfunction vmx_enable_fb_clearfunction vmx_update_fb_clear_disfunction vmread_errorfunction vmread_error_trampoline2function vmwrite_errorfunction vmclear_errorfunction vmptrld_errorfunction invvpid_errorfunction invept_errorfunction hv_enable_l2_tlb_flushfunction hv_init_evmcsfunction for_each_online_cpufunction hv_reset_evmcsfunction hv_init_evmcsfunction cpu_has_broken_vmx_preemption_timerfunction cpu_need_virtualize_apic_accessesfunction vmx_set_guest_uret_msrfunction vmx_emergency_disable_virtualization_cpufunction list_for_each_entryfunction __loaded_vmcs_clearfunction loaded_vmcs_clearfunction vmx_segment_cache_test_setfunction vmx_read_guest_seg_selectorfunction vmx_read_guest_seg_basefunction vmx_read_guest_seg_limitfunction vmx_read_guest_seg_arfunction vmx_update_exception_bitmapfunction msr_write_interceptedfunction __vmx_vcpu_enter_flagsfunction clear_atomic_switch_msr_specialfunction vmx_find_loadstore_msr_slotfunction vmx_remove_auto_msrfunction clear_atomic_switch_msrfunction add_atomic_switch_msr_specialfunction vmx_add_auto_msr
Annotated Snippet
switch (l1tf_mitigation) {
case L1TF_MITIGATION_OFF:
l1tf = VMENTER_L1D_FLUSH_NEVER;
break;
case L1TF_MITIGATION_AUTO:
case L1TF_MITIGATION_FLUSH_NOWARN:
case L1TF_MITIGATION_FLUSH:
case L1TF_MITIGATION_FLUSH_NOSMT:
l1tf = VMENTER_L1D_FLUSH_COND;
break;
case L1TF_MITIGATION_FULL:
case L1TF_MITIGATION_FULL_FORCE:
l1tf = VMENTER_L1D_FLUSH_ALWAYS;
break;
}
} else if (l1tf_mitigation == L1TF_MITIGATION_FULL_FORCE) {
l1tf = VMENTER_L1D_FLUSH_ALWAYS;
}
if (l1tf != VMENTER_L1D_FLUSH_NEVER && !vmx_l1d_flush_pages &&
!boot_cpu_has(X86_FEATURE_FLUSH_L1D)) {
/*
* This allocation for vmx_l1d_flush_pages is not tied to a VM
* lifetime and so should not be charged to a memcg.
*/
page = alloc_pages(GFP_KERNEL, L1D_CACHE_ORDER);
if (!page)
return -ENOMEM;
vmx_l1d_flush_pages = page_address(page);
/*
* Initialize each page with a different pattern in
* order to protect against KSM in the nested
* virtualization case.
*/
for (i = 0; i < 1u << L1D_CACHE_ORDER; ++i) {
memset(vmx_l1d_flush_pages + i * PAGE_SIZE, i + 1,
PAGE_SIZE);
}
}
l1tf_vmx_mitigation = l1tf;
if (l1tf != VMENTER_L1D_FLUSH_NEVER)
static_branch_enable(&vmx_l1d_should_flush);
else
static_branch_disable(&vmx_l1d_should_flush);
if (l1tf == VMENTER_L1D_FLUSH_COND)
static_branch_enable(&vmx_l1d_flush_cond);
else
static_branch_disable(&vmx_l1d_flush_cond);
return 0;
}
static int vmx_setup_l1d_flush(void)
{
/*
* Hand the parameter mitigation value in which was stored in the pre
* module init parser. If no parameter was given, it will contain
* 'auto' which will be turned into the default 'cond' mitigation mode.
*/
return __vmx_setup_l1d_flush(vmentry_l1d_flush_param);
}
static void vmx_cleanup_l1d_flush(void)
{
if (vmx_l1d_flush_pages) {
free_pages((unsigned long)vmx_l1d_flush_pages, L1D_CACHE_ORDER);
vmx_l1d_flush_pages = NULL;
}
/* Restore state so sysfs ignores VMX */
l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_AUTO;
}
static int vmentry_l1d_flush_parse(const char *s)
{
unsigned int i;
if (s) {
for (i = 0; i < ARRAY_SIZE(vmentry_l1d_param); i++) {
if (vmentry_l1d_param[i].for_parse &&
sysfs_streq(s, vmentry_l1d_param[i].option))
return i;
}
}
return -EINVAL;
}
static int vmentry_l1d_flush_set(const char *s, const struct kernel_param *kp)
Annotation
- Immediate include surface: `linux/highmem.h`, `linux/hrtimer.h`, `linux/kernel.h`, `linux/kvm_host.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/mod_devicetable.h`, `linux/mm.h`.
- Detected declarations: `function __vmx_setup_l1d_flush`, `function vmx_setup_l1d_flush`, `function vmx_cleanup_l1d_flush`, `function vmentry_l1d_flush_parse`, `function vmentry_l1d_flush_set`, `function vmx_init`, `function vmentry_l1d_flush_get`, `function vmx_l1d_flush`, `function vmx_setup_l1d_flush`, `function vmx_cleanup_l1d_flush`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.