arch/x86/kernel/kvmclock.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/kvmclock.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/kvmclock.c- Extension
.c- Size
- 9401 bytes
- Lines
- 373
- 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.
- 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/clocksource.hlinux/kvm_para.hasm/pvclock.hasm/msr.hasm/apic.hlinux/percpu.hlinux/hardirq.hlinux/cpuhotplug.hlinux/sched.hlinux/sched/clock.hlinux/mm.hlinux/slab.hlinux/set_memory.hlinux/cc_platform.hasm/hypervisor.hasm/timer.hasm/x86_init.hasm/kvmclock.h
Detected Declarations
function parse_no_kvmclockfunction parse_no_kvmclock_vsyscallfunction kvm_get_wallclockfunction kvm_set_wallclockfunction kvm_clock_readfunction kvm_clock_get_cyclesfunction kvm_clock_get_cycles_snapshotfunction kvm_sched_clock_readfunction kvm_sched_clock_initfunction kvm_get_tsc_khzfunction kvm_get_preset_lpjfunction kvm_check_and_clear_guest_pausedfunction kvm_cs_enablefunction kvm_register_clockfunction kvm_save_sched_clock_statefunction kvm_setup_secondary_clockfunction kvmclock_disablefunction kvmclock_init_memfunction kvm_setup_vsyscall_timeinfofunction kvmclock_setup_percpufunction kvmclock_init
Annotated Snippet
if (r) {
__free_pages(p, order);
hvclock_mem = NULL;
pr_warn("kvmclock: set_memory_decrypted() failed. Disabling\n");
return;
}
}
memset(hvclock_mem, 0, PAGE_SIZE << order);
}
static int __init kvm_setup_vsyscall_timeinfo(void)
{
if (!kvm_para_available() || !kvmclock || nopv)
return 0;
kvmclock_init_mem();
#ifdef CONFIG_X86_64
if (per_cpu(hv_clock_per_cpu, 0) && kvmclock_vsyscall) {
u8 flags;
flags = pvclock_read_flags(&hv_clock_boot[0].pvti);
if (!(flags & PVCLOCK_TSC_STABLE_BIT))
return 0;
kvm_clock.vdso_clock_mode = VDSO_CLOCKMODE_PVCLOCK;
}
#endif
return 0;
}
early_initcall(kvm_setup_vsyscall_timeinfo);
static int kvmclock_setup_percpu(unsigned int cpu)
{
struct pvclock_vsyscall_time_info *p = per_cpu(hv_clock_per_cpu, cpu);
/*
* The per cpu area setup replicates CPU0 data to all cpu
* pointers. So carefully check. CPU0 has been set up in init
* already.
*/
if (!cpu || (p && p != per_cpu(hv_clock_per_cpu, 0)))
return 0;
/* Use the static page for the first CPUs, allocate otherwise */
if (cpu < HVC_BOOT_ARRAY_SIZE)
p = &hv_clock_boot[cpu];
else if (hvclock_mem)
p = hvclock_mem + cpu - HVC_BOOT_ARRAY_SIZE;
else
return -ENOMEM;
per_cpu(hv_clock_per_cpu, cpu) = p;
return p ? 0 : -ENOMEM;
}
void __init kvmclock_init(void)
{
u8 flags;
if (!kvm_para_available() || !kvmclock)
return;
if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE2)) {
msr_kvm_system_time = MSR_KVM_SYSTEM_TIME_NEW;
msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK_NEW;
} else if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)) {
msr_kvm_system_time = MSR_KVM_SYSTEM_TIME;
msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK;
} else {
return;
}
if (cpuhp_setup_state(CPUHP_BP_PREPARE_DYN, "kvmclock:setup_percpu",
kvmclock_setup_percpu, NULL) < 0) {
return;
}
pr_info("kvm-clock: Using msrs %x and %x",
msr_kvm_system_time, msr_kvm_wall_clock);
this_cpu_write(hv_clock_per_cpu, &hv_clock_boot[0]);
kvm_register_clock("primary cpu clock");
pvclock_set_pvti_cpu0_va(hv_clock_boot);
if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT))
pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT);
Annotation
- Immediate include surface: `linux/clocksource.h`, `linux/kvm_para.h`, `asm/pvclock.h`, `asm/msr.h`, `asm/apic.h`, `linux/percpu.h`, `linux/hardirq.h`, `linux/cpuhotplug.h`.
- Detected declarations: `function parse_no_kvmclock`, `function parse_no_kvmclock_vsyscall`, `function kvm_get_wallclock`, `function kvm_set_wallclock`, `function kvm_clock_read`, `function kvm_clock_get_cycles`, `function kvm_clock_get_cycles_snapshot`, `function kvm_sched_clock_read`, `function kvm_sched_clock_init`, `function kvm_get_tsc_khz`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
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.