virt/kvm/async_pf.c
Source file repositories/reference/linux-study-clean/virt/kvm/async_pf.c
File Facts
- System
- Linux kernel
- Corpus path
virt/kvm/async_pf.c- Extension
.c- Size
- 6335 bytes
- Lines
- 242
- Domain
- Kernel Services
- Bucket
- virt
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kvm_host.hlinux/slab.hlinux/module.hlinux/mmu_context.hlinux/sched/mm.hasync_pf.htrace/events/kvm.h
Detected Declarations
function kvm_async_pf_initfunction kvm_async_pf_deinitfunction kvm_async_pf_vcpu_initfunction async_pf_executefunction kvm_destroy_vmfunction kvm_flush_and_free_async_pf_workfunction kvm_clear_async_pf_completion_queuefunction kvm_check_async_pf_completionfunction kvm_setup_async_pffunction kvm_async_pf_wakeup_all
Annotated Snippet
kvm_arch_can_dequeue_async_page_present(vcpu)) {
spin_lock(&vcpu->async_pf.lock);
work = list_first_entry(&vcpu->async_pf.done, typeof(*work),
link);
list_del(&work->link);
spin_unlock(&vcpu->async_pf.lock);
kvm_arch_async_page_ready(vcpu, work);
if (!IS_ENABLED(CONFIG_KVM_ASYNC_PF_SYNC))
kvm_arch_async_page_present(vcpu, work);
list_del(&work->queue);
vcpu->async_pf.queued--;
kvm_flush_and_free_async_pf_work(work);
}
}
/*
* Try to schedule a job to handle page fault asynchronously. Returns 'true' on
* success, 'false' on failure (page fault has to be handled synchronously).
*/
bool kvm_setup_async_pf(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
unsigned long hva, struct kvm_arch_async_pf *arch)
{
struct kvm_async_pf *work;
if (vcpu->async_pf.queued >= ASYNC_PF_PER_VCPU)
return false;
/* Arch specific code should not do async PF in this case */
if (unlikely(kvm_is_error_hva(hva)))
return false;
/*
* do alloc nowait since if we are going to sleep anyway we
* may as well sleep faulting in page
*/
work = kmem_cache_zalloc(async_pf_cache, GFP_NOWAIT);
if (!work)
return false;
work->wakeup_all = false;
work->vcpu = vcpu;
work->cr2_or_gpa = cr2_or_gpa;
work->addr = hva;
work->arch = *arch;
INIT_WORK(&work->work, async_pf_execute);
list_add_tail(&work->queue, &vcpu->async_pf.queue);
vcpu->async_pf.queued++;
work->notpresent_injected = kvm_arch_async_page_not_present(vcpu, work);
schedule_work(&work->work);
return true;
}
int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu)
{
struct kvm_async_pf *work;
bool first;
if (!list_empty_careful(&vcpu->async_pf.done))
return 0;
work = kmem_cache_zalloc(async_pf_cache, GFP_ATOMIC);
if (!work)
return -ENOMEM;
work->wakeup_all = true;
INIT_LIST_HEAD(&work->queue); /* for list_del to work */
spin_lock(&vcpu->async_pf.lock);
first = list_empty(&vcpu->async_pf.done);
list_add_tail(&work->link, &vcpu->async_pf.done);
spin_unlock(&vcpu->async_pf.lock);
if (!IS_ENABLED(CONFIG_KVM_ASYNC_PF_SYNC) && first)
kvm_arch_async_page_present_queued(vcpu);
vcpu->async_pf.queued++;
return 0;
}
Annotation
- Immediate include surface: `linux/kvm_host.h`, `linux/slab.h`, `linux/module.h`, `linux/mmu_context.h`, `linux/sched/mm.h`, `async_pf.h`, `trace/events/kvm.h`.
- Detected declarations: `function kvm_async_pf_init`, `function kvm_async_pf_deinit`, `function kvm_async_pf_vcpu_init`, `function async_pf_execute`, `function kvm_destroy_vm`, `function kvm_flush_and_free_async_pf_work`, `function kvm_clear_async_pf_completion_queue`, `function kvm_check_async_pf_completion`, `function kvm_setup_async_pf`, `function kvm_async_pf_wakeup_all`.
- Atlas domain: Kernel Services / virt.
- 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.