arch/x86/hyperv/ivm.c
Source file repositories/reference/linux-study-clean/arch/x86/hyperv/ivm.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/hyperv/ivm.c- Extension
.c- Size
- 24180 bytes
- Lines
- 947
- 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.
- 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/bitfield.hlinux/types.hlinux/slab.hlinux/cpu.hlinux/export.hasm/svm.hasm/sev.hasm/io.hasm/coco.hasm/mem_encrypt.hasm/set_memory.hasm/mshyperv.hasm/hypervisor.hasm/mtrr.hasm/io_apic.hasm/realmode.hasm/e820/api.hasm/desc.hasm/msr.hasm/segment.huapi/asm/vmx.h
Detected Declarations
struct hv_enc_pfn_regionfunction hv_ghcb_hypercallfunction rd_ghcb_msrfunction wr_ghcb_msrfunction hv_ghcb_hv_callfunction hv_ghcb_terminatefunction hv_ghcb_negotiate_protocolfunction hv_ghcb_msr_writefunction hv_ghcb_msr_readfunction snp_set_vmsafunction snp_cleanup_vmsafunction hv_snp_boot_apfunction hv_snp_hypercallfunction hv_ghcb_msr_writefunction hv_tdx_msr_writefunction hv_tdx_msr_readfunction hv_tdx_hypercallfunction hv_tdx_msr_writefunction hv_ivm_msr_writefunction hv_ivm_msr_readfunction hv_list_enc_addfunction list_for_each_entryfunction notfunction hv_list_enc_removefunction list_for_each_entry_safefunction hv_vtom_kexec_beginfunction hv_vtom_kexec_finishfunction list_for_each_entryfunction hv_mark_gpa_visibilityfunction set_memory_encryptedfunction hv_vtom_set_host_visibilityfunction hv_vtom_tlb_flush_requiredfunction hv_vtom_cache_flush_requiredfunction hv_is_private_mmiofunction hv_vtom_initfunction hv_get_isolation_typefunction hv_is_isolation_supportedfunction hv_isolation_type_snpfunction hv_isolation_type_tdxexport hv_get_isolation_type
Annotated Snippet
struct hv_enc_pfn_region {
struct list_head list;
u64 pfn;
int count;
};
static LIST_HEAD(hv_list_enc);
static DEFINE_RAW_SPINLOCK(hv_list_enc_lock);
static int hv_list_enc_add(const u64 *pfn_list, int count)
{
struct hv_enc_pfn_region *ent;
unsigned long flags;
u64 pfn;
int i;
for (i = 0; i < count; i++) {
pfn = pfn_list[i];
raw_spin_lock_irqsave(&hv_list_enc_lock, flags);
/* Check if the PFN already exists in some region first */
list_for_each_entry(ent, &hv_list_enc, list) {
if ((ent->pfn <= pfn) && (ent->pfn + ent->count - 1 >= pfn))
/* Nothing to do - pfn is already in the list */
goto unlock_done;
}
/*
* Check if the PFN is adjacent to an existing region. Growing
* a region can make it adjacent to another one but merging is
* not (yet) implemented for simplicity. A PFN cannot be added
* to two regions to keep the logic in hv_list_enc_remove()
* correct.
*/
list_for_each_entry(ent, &hv_list_enc, list) {
if (ent->pfn + ent->count == pfn) {
/* Grow existing region up */
ent->count++;
goto unlock_done;
} else if (pfn + 1 == ent->pfn) {
/* Grow existing region down */
ent->pfn--;
ent->count++;
goto unlock_done;
}
}
raw_spin_unlock_irqrestore(&hv_list_enc_lock, flags);
/* No adjacent region found -- create a new one */
ent = kzalloc_obj(struct hv_enc_pfn_region);
if (!ent)
return -ENOMEM;
ent->pfn = pfn;
ent->count = 1;
raw_spin_lock_irqsave(&hv_list_enc_lock, flags);
list_add(&ent->list, &hv_list_enc);
unlock_done:
raw_spin_unlock_irqrestore(&hv_list_enc_lock, flags);
}
return 0;
}
static int hv_list_enc_remove(const u64 *pfn_list, int count)
{
struct hv_enc_pfn_region *ent, *t;
struct hv_enc_pfn_region new_region;
unsigned long flags;
u64 pfn;
int i;
for (i = 0; i < count; i++) {
pfn = pfn_list[i];
raw_spin_lock_irqsave(&hv_list_enc_lock, flags);
list_for_each_entry_safe(ent, t, &hv_list_enc, list) {
if (pfn == ent->pfn + ent->count - 1) {
/* Removing tail pfn */
ent->count--;
if (!ent->count) {
list_del(&ent->list);
kfree(ent);
}
goto unlock_done;
} else if (pfn == ent->pfn) {
/* Removing head pfn */
ent->count--;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/types.h`, `linux/slab.h`, `linux/cpu.h`, `linux/export.h`, `asm/svm.h`, `asm/sev.h`, `asm/io.h`.
- Detected declarations: `struct hv_enc_pfn_region`, `function hv_ghcb_hypercall`, `function rd_ghcb_msr`, `function wr_ghcb_msr`, `function hv_ghcb_hv_call`, `function hv_ghcb_terminate`, `function hv_ghcb_negotiate_protocol`, `function hv_ghcb_msr_write`, `function hv_ghcb_msr_read`, `function snp_set_vmsa`.
- 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.