arch/x86/kernel/kvm.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/kvm.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/kvm.c- Extension
.c- Size
- 29581 bytes
- Lines
- 1191
- 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.
- 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/context_tracking.hlinux/init.hlinux/irq.hlinux/kernel.hlinux/kvm_para.hlinux/cpu.hlinux/mm.hlinux/highmem.hlinux/hardirq.hlinux/notifier.hlinux/reboot.hlinux/hash.hlinux/sched.hlinux/slab.hlinux/kprobes.hlinux/nmi.hlinux/swait.hlinux/syscore_ops.hlinux/cc_platform.hlinux/efi.hlinux/kvm_types.hlinux/sched/cputime.hasm/timer.hasm/cpu.hasm/traps.hasm/desc.hasm/tlbflush.hasm/apic.hasm/apicdef.hasm/hypervisor.hasm/mtrr.hasm/tlb.h
Detected Declarations
struct kvm_task_sleep_nodefunction parse_no_kvmapffunction parse_no_stealaccfunction hlist_for_eachfunction kvm_async_pf_queue_taskfunction kvm_async_pf_task_wait_schedulefunction apf_task_wake_onefunction apf_task_wake_allfunction hlist_for_each_safefunction kvm_async_pf_task_wakefunction kvm_read_and_reset_apf_flagsfunction __kvm_handle_async_pffunction paravirt_ops_setupfunction kvm_register_steal_timefunction kvm_guest_apic_eoi_writefunction kvm_guest_cpu_initfunction kvm_pv_disable_apffunction kvm_disable_steal_timefunction kvm_steal_clockfunction __set_percpu_decryptedfunction sev_map_percpu_datafunction for_each_possible_cpufunction kvm_guest_cpu_offlinefunction kvm_cpu_onlinefunction pv_tlb_flush_supportedfunction pv_ipi_supportedfunction pv_sched_yield_supportedfunction __send_ipi_maskfunction for_each_cpufunction kvm_send_ipi_maskfunction kvm_send_ipi_mask_allbutselffunction setup_efi_kvm_sev_migrationfunction kvm_setup_pv_ipifunction kvm_smp_send_call_func_ipifunction kvm_flush_tlb_multifunction kvm_alloc_cpumaskfunction kvm_smp_prepare_boot_cpufunction kvm_cpu_down_preparefunction kvm_suspendfunction kvm_resumefunction kvm_pv_guest_cpu_rebootfunction kvm_pv_reboot_notifyfunction kvm_crash_shutdownfunction __kvm_vcpu_is_preemptedfunction kvm_guest_initfunction __kvm_cpuid_basefunction kvm_cpuid_basefunction kvm_para_available
Annotated Snippet
struct kvm_task_sleep_node {
struct hlist_node link;
struct swait_queue_head wq;
u32 token;
int cpu;
bool dummy;
};
static struct kvm_task_sleep_head {
raw_spinlock_t lock;
struct hlist_head list;
} async_pf_sleepers[KVM_TASK_SLEEP_HASHSIZE];
static struct kvm_task_sleep_node *_find_apf_task(struct kvm_task_sleep_head *b,
u32 token)
{
struct hlist_node *p;
hlist_for_each(p, &b->list) {
struct kvm_task_sleep_node *n =
hlist_entry(p, typeof(*n), link);
if (n->token == token)
return n;
}
return NULL;
}
static bool kvm_async_pf_queue_task(u32 token, struct kvm_task_sleep_node *n)
{
u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS);
struct kvm_task_sleep_head *b = &async_pf_sleepers[key];
struct kvm_task_sleep_node *e;
raw_spin_lock(&b->lock);
e = _find_apf_task(b, token);
if (e) {
struct kvm_task_sleep_node *dummy = NULL;
/*
* The entry can either be a 'dummy' entry (which is put on the
* list when wake-up happens ahead of APF handling completion)
* or a token from another task which should not be touched.
*/
if (e->dummy) {
hlist_del(&e->link);
dummy = e;
}
raw_spin_unlock(&b->lock);
kfree(dummy);
return false;
}
n->token = token;
n->cpu = smp_processor_id();
n->dummy = false;
init_swait_queue_head(&n->wq);
hlist_add_head(&n->link, &b->list);
raw_spin_unlock(&b->lock);
return true;
}
/*
* kvm_async_pf_task_wait_schedule - Wait for pagefault to be handled
* @token: Token to identify the sleep node entry
*
* Invoked from the async pagefault handling code or from the VM exit page
* fault handler. In both cases RCU is watching.
*/
void kvm_async_pf_task_wait_schedule(u32 token)
{
struct kvm_task_sleep_node n;
DECLARE_SWAITQUEUE(wait);
lockdep_assert_irqs_disabled();
if (!kvm_async_pf_queue_task(token, &n))
return;
for (;;) {
prepare_to_swait_exclusive(&n.wq, &wait, TASK_UNINTERRUPTIBLE);
if (hlist_unhashed(&n.link))
break;
local_irq_enable();
schedule();
local_irq_disable();
}
finish_swait(&n.wq, &wait);
Annotation
- Immediate include surface: `linux/context_tracking.h`, `linux/init.h`, `linux/irq.h`, `linux/kernel.h`, `linux/kvm_para.h`, `linux/cpu.h`, `linux/mm.h`, `linux/highmem.h`.
- Detected declarations: `struct kvm_task_sleep_node`, `function parse_no_kvmapf`, `function parse_no_stealacc`, `function hlist_for_each`, `function kvm_async_pf_queue_task`, `function kvm_async_pf_task_wait_schedule`, `function apf_task_wake_one`, `function apf_task_wake_all`, `function hlist_for_each_safe`, `function kvm_async_pf_task_wake`.
- 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.
- 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.