arch/x86/kvm/vmx/nested.c
Source file repositories/reference/linux-study-clean/arch/x86/kvm/vmx/nested.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/vmx/nested.c- Extension
.c- Size
- 238932 bytes
- Lines
- 7503
- 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/objtool.hlinux/percpu.hasm/debugreg.hasm/mmu_context.hasm/msr.hx86.hcpuid.hhyperv.hmmu.hnested.hpmu.hposted_intr.hsgx.htrace.hvmx.hsmm.hx86_ops.hvmcs_shadow_fields.h
Detected Declarations
struct shadow_vmcs_fieldfunction init_vmcs_shadow_fieldsfunction instructionfunction nested_vmx_failInvalidfunction nested_vmx_failValidfunction nested_vmx_failfunction nested_vmx_abortfunction vmx_control_verifyfunction vmx_control_msrfunction vmx_disable_shadow_vmcsfunction nested_release_evmcsfunction nested_evmcs_handle_vmclearfunction vmx_sync_vmcs_host_statefunction vmx_switch_vmcsfunction nested_put_vmcs12_pagesfunction free_nestedfunction free_nestedfunction nested_ept_root_matchesfunction nested_ept_invalidate_addrfunction nested_ept_inject_page_faultfunction nested_ept_mbec_enabledfunction nested_ept_new_eptpfunction nested_ept_init_mmu_contextfunction nested_ept_uninit_mmu_contextfunction nested_vmx_is_page_fault_vmexitfunction nested_vmx_is_exception_vmexitfunction nested_vmx_check_io_bitmap_controlsfunction nested_vmx_check_msr_bitmap_controlsfunction nested_vmx_check_tpr_shadow_controlsfunction nested_vmx_disable_intercept_for_x2apic_msrfunction enable_x2apic_msr_interceptsfunction nested_vmx_set_intercept_for_msrfunction nested_vmx_merge_pmu_msr_bitmapsfunction nested_vmx_prepare_msr_bitmapfunction KVMfunction nested_cache_shadow_vmcs12function nested_flush_cached_shadow_vmcs12function nested_exit_intr_ack_setfunction nested_vmx_check_apic_access_controlsfunction nested_vmx_check_apicv_controlsfunction nested_vmx_max_atomic_switch_msrsfunction nested_vmx_check_msr_switchfunction nested_vmx_check_exit_msr_switch_controlsfunction nested_vmx_check_entry_msr_switch_controlsfunction nested_vmx_check_pml_controlsfunction nested_vmx_check_unrestricted_guest_controlsfunction nested_vmx_check_mode_based_ept_exec_controlsfunction nested_vmx_check_shadow_vmcs_controls
Annotated Snippet
struct shadow_vmcs_field {
u16 encoding;
u16 offset;
};
static struct shadow_vmcs_field shadow_read_only_fields[] = {
#define SHADOW_FIELD_RO(x, y) { x, offsetof(struct vmcs12, y) },
#include "vmcs_shadow_fields.h"
};
static int max_shadow_read_only_fields =
ARRAY_SIZE(shadow_read_only_fields);
static struct shadow_vmcs_field shadow_read_write_fields[] = {
#define SHADOW_FIELD_RW(x, y) { x, offsetof(struct vmcs12, y) },
#include "vmcs_shadow_fields.h"
};
static int max_shadow_read_write_fields =
ARRAY_SIZE(shadow_read_write_fields);
static void init_vmcs_shadow_fields(void)
{
int i, j;
memset(vmx_vmread_bitmap, 0xff, PAGE_SIZE);
memset(vmx_vmwrite_bitmap, 0xff, PAGE_SIZE);
for (i = j = 0; i < max_shadow_read_only_fields; i++) {
struct shadow_vmcs_field entry = shadow_read_only_fields[i];
u16 field = entry.encoding;
if (vmcs_field_width(field) == VMCS_FIELD_WIDTH_U64 &&
(i + 1 == max_shadow_read_only_fields ||
shadow_read_only_fields[i + 1].encoding != field + 1))
pr_err("Missing field from shadow_read_only_field %x\n",
field + 1);
if (get_vmcs12_field_offset(field) < 0)
continue;
clear_bit(field, vmx_vmread_bitmap);
if (field & 1)
#ifdef CONFIG_X86_64
continue;
#else
entry.offset += sizeof(u32);
#endif
shadow_read_only_fields[j++] = entry;
}
max_shadow_read_only_fields = j;
for (i = j = 0; i < max_shadow_read_write_fields; i++) {
struct shadow_vmcs_field entry = shadow_read_write_fields[i];
u16 field = entry.encoding;
if (vmcs_field_width(field) == VMCS_FIELD_WIDTH_U64 &&
(i + 1 == max_shadow_read_write_fields ||
shadow_read_write_fields[i + 1].encoding != field + 1))
pr_err("Missing field from shadow_read_write_field %x\n",
field + 1);
WARN_ONCE(field >= GUEST_ES_AR_BYTES &&
field <= GUEST_TR_AR_BYTES,
"Update vmcs12_write_any() to drop reserved bits from AR_BYTES");
if (get_vmcs12_field_offset(field) < 0)
continue;
/*
* KVM emulates PML and the VMX preemption timer irrespective
* of hardware support, but shadowing their related VMCS fields
* requires hardware support as the CPU will reject VMWRITEs to
* fields that don't exist.
*/
switch (field) {
case GUEST_PML_INDEX:
if (!cpu_has_vmx_pml())
continue;
break;
case VMX_PREEMPTION_TIMER_VALUE:
if (!cpu_has_vmx_preemption_timer())
continue;
break;
default:
break;
}
clear_bit(field, vmx_vmwrite_bitmap);
clear_bit(field, vmx_vmread_bitmap);
if (field & 1)
#ifdef CONFIG_X86_64
continue;
Annotation
- Immediate include surface: `linux/objtool.h`, `linux/percpu.h`, `asm/debugreg.h`, `asm/mmu_context.h`, `asm/msr.h`, `x86.h`, `cpuid.h`, `hyperv.h`.
- Detected declarations: `struct shadow_vmcs_field`, `function init_vmcs_shadow_fields`, `function instruction`, `function nested_vmx_failInvalid`, `function nested_vmx_failValid`, `function nested_vmx_fail`, `function nested_vmx_abort`, `function vmx_control_verify`, `function vmx_control_msr`, `function vmx_disable_shadow_vmcs`.
- 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.