arch/x86/hyperv/hv_init.c
Source file repositories/reference/linux-study-clean/arch/x86/hyperv/hv_init.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/hyperv/hv_init.c- Extension
.c- Size
- 21037 bytes
- Lines
- 746
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/efi.hlinux/types.hlinux/bitfield.hlinux/io.hasm/apic.hasm/desc.hasm/e820/api.hasm/sev.hasm/hypervisor.hhyperv/hvhdk.hasm/mshyperv.hasm/msr.hasm/idtentry.hasm/set_memory.hlinux/kexec.hlinux/version.hlinux/vmalloc.hlinux/mm.hlinux/slab.hlinux/kernel.hlinux/cpuhotplug.hlinux/syscore_ops.hclocksource/hyperv_timer.hlinux/highmem.hlinux/export.h
Detected Declarations
function __hv_hyperfailfunction hv_std_hypercallfunction hv_set_hypercall_pgfunction hv_set_hypercall_pgfunction hyperv_init_ghcbfunction hv_cpu_initfunction hv_apic_eoi_writefunction hv_reenlightenment_notifyfunction hyperv_stop_tsc_emulationfunction hv_reenlightenment_availablefunction set_hv_tscchange_cbfunction clear_hv_tscchange_cbfunction hv_cpu_diefunction hv_pci_initfunction E820_TYPE_PRAMfunction hv_suspendfunction hv_resumefunction hv_stimer_setup_percpu_clockevfunction hyperv_initfunction hyperv_cleanupfunction hyperv_report_panicfunction hv_is_hyperv_initializedfunction hv_apicid_to_vp_indexexport hv_hypercall_pgexport hv_vp_assist_pageexport hyperv_stop_tsc_emulationexport set_hv_tscchange_cbexport clear_hv_tscchange_cbexport hyperv_report_panicexport hv_is_hyperv_initializedexport hv_apicid_to_vp_index
Annotated Snippet
if (!*hvp) {
*hvp = __vmalloc(PAGE_SIZE, GFP_KERNEL | __GFP_ZERO);
/*
* Hyper-V should never specify a VM that is a Confidential
* VM and also running in the root partition. Root partition
* is blocked to run in Confidential VM. So only decrypt assist
* page in non-root partition here.
*/
if (*hvp && !ms_hyperv.paravisor_present && hv_isolation_type_snp()) {
WARN_ON_ONCE(set_memory_decrypted((unsigned long)(*hvp), 1));
memset(*hvp, 0, PAGE_SIZE);
}
}
if (*hvp)
msr.pfn = vmalloc_to_pfn(*hvp);
}
if (!WARN_ON(!(*hvp))) {
msr.enable = 1;
wrmsrq(HV_X64_MSR_VP_ASSIST_PAGE, msr.as_uint64);
}
/* Allow Hyper-V stimer vector to be injected from Hypervisor. */
if (ms_hyperv.misc_features & HV_STIMER_DIRECT_MODE_AVAILABLE)
apic_update_vector(cpu, HYPERV_STIMER0_VECTOR, true);
return hyperv_init_ghcb();
}
static void (*hv_reenlightenment_cb)(void);
static void hv_reenlightenment_notify(struct work_struct *dummy)
{
struct hv_tsc_emulation_status emu_status;
rdmsrq(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
/* Don't issue the callback if TSC accesses are not emulated */
if (hv_reenlightenment_cb && emu_status.inprogress)
hv_reenlightenment_cb();
}
static DECLARE_DELAYED_WORK(hv_reenlightenment_work, hv_reenlightenment_notify);
void hyperv_stop_tsc_emulation(void)
{
u64 freq;
struct hv_tsc_emulation_status emu_status;
rdmsrq(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
emu_status.inprogress = 0;
wrmsrq(HV_X64_MSR_TSC_EMULATION_STATUS, *(u64 *)&emu_status);
rdmsrq(HV_X64_MSR_TSC_FREQUENCY, freq);
tsc_khz = div64_u64(freq, 1000);
}
EXPORT_SYMBOL_GPL(hyperv_stop_tsc_emulation);
static inline bool hv_reenlightenment_available(void)
{
/*
* Check for required features and privileges to make TSC frequency
* change notifications work.
*/
return ms_hyperv.features & HV_ACCESS_FREQUENCY_MSRS &&
ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE &&
ms_hyperv.features & HV_ACCESS_REENLIGHTENMENT;
}
DEFINE_IDTENTRY_SYSVEC(sysvec_hyperv_reenlightenment)
{
apic_eoi();
inc_irq_stat(HYPERV_REENLIGHTENMENT);
schedule_delayed_work(&hv_reenlightenment_work, HZ/10);
}
void set_hv_tscchange_cb(void (*cb)(void))
{
struct hv_reenlightenment_control re_ctrl = {
.vector = HYPERV_REENLIGHTENMENT_VECTOR,
.enabled = 1,
};
struct hv_tsc_emulation_control emu_ctrl = {.enabled = 1};
if (!hv_reenlightenment_available()) {
pr_warn("reenlightenment support is unavailable\n");
return;
}
Annotation
- Immediate include surface: `linux/efi.h`, `linux/types.h`, `linux/bitfield.h`, `linux/io.h`, `asm/apic.h`, `asm/desc.h`, `asm/e820/api.h`, `asm/sev.h`.
- Detected declarations: `function __hv_hyperfail`, `function hv_std_hypercall`, `function hv_set_hypercall_pg`, `function hv_set_hypercall_pg`, `function hyperv_init_ghcb`, `function hv_cpu_init`, `function hv_apic_eoi_write`, `function hv_reenlightenment_notify`, `function hyperv_stop_tsc_emulation`, `function hv_reenlightenment_available`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.