arch/loongarch/kvm/vcpu.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kvm/vcpu.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kvm/vcpu.c- Extension
.c- Size
- 48719 bytes
- Lines
- 1899
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- 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.
- 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.
- 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/kvm_host.hasm/fpu.hasm/lbt.hasm/loongarch.hasm/setup.hasm/time.hasm/timex.htrace.h
Detected Declarations
function kvm_save_host_pmufunction kvm_restore_host_pmufunction kvm_save_guest_pmufunction kvm_restore_guest_pmufunction kvm_own_pmufunction kvm_lose_pmufunction kvm_update_stolen_timefunction kvm_check_requestsfunction kvm_late_check_requestsfunction kvm_enter_guest_checkfunction kvm_pre_enter_guestfunction kvm_handle_exitfunction kvm_arch_vcpu_runnablefunction kvm_arch_vcpu_should_kickfunction kvm_arch_vcpu_in_kernelfunction kvm_arch_vcpu_get_ipfunction Interruptfunction kvm_arch_vcpu_preempted_in_kernelfunction kvm_arch_vcpu_faultfunction kvm_arch_vcpu_ioctl_translatefunction kvm_cpu_has_pending_timerfunction kvm_arch_vcpu_dump_regsfunction kvm_arch_vcpu_ioctl_get_mpstatefunction kvm_arch_vcpu_ioctl_set_mpstatefunction kvm_arch_vcpu_ioctl_set_guest_debugfunction kvm_set_cpuidfunction kvm_drop_cpuidfunction _kvm_getcsrfunction _kvm_setcsrfunction _kvm_get_cpucfg_maskfunction kvm_check_cpucfgfunction kvm_get_one_regfunction kvm_get_regfunction kvm_set_one_regfunction kvm_set_regfunction kvm_arch_vcpu_ioctl_get_sregsfunction kvm_arch_vcpu_ioctl_set_sregsfunction kvm_arch_vcpu_ioctl_get_regsfunction kvm_arch_vcpu_ioctl_set_regsfunction kvm_vcpu_ioctl_enable_capfunction kvm_loongarch_cpucfg_has_attrfunction kvm_loongarch_pvtime_has_attrfunction kvm_loongarch_vcpu_has_attrfunction kvm_loongarch_cpucfg_get_attrfunction kvm_loongarch_pvtime_get_attrfunction kvm_loongarch_vcpu_get_attrfunction kvm_loongarch_cpucfg_set_attrfunction kvm_loongarch_pvtime_set_attr
Annotated Snippet
if (kvm_gfn_to_hva_cache_init(vcpu->kvm, ghc, gpa, sizeof(*st))) {
ghc->gpa = INVALID_GPA;
return;
}
}
st = (struct kvm_steal_time __user *)ghc->hva;
if (kvm_guest_has_pv_feature(vcpu, KVM_FEATURE_PREEMPT)) {
unsafe_put_user(0, &st->preempted, out);
vcpu->arch.st.preempted = 0;
}
unsafe_get_user(version, &st->version, out);
if (version & 1)
version += 1; /* first time write, random junk */
version += 1;
unsafe_put_user(version, &st->version, out);
smp_wmb();
unsafe_get_user(steal, &st->steal, out);
steal += current->sched_info.run_delay - vcpu->arch.st.last_steal;
vcpu->arch.st.last_steal = current->sched_info.run_delay;
unsafe_put_user(steal, &st->steal, out);
smp_wmb();
version += 1;
unsafe_put_user(version, &st->version, out);
out:
mark_page_dirty_in_slot(vcpu->kvm, ghc->memslot, gpa_to_gfn(ghc->gpa));
}
/*
* kvm_check_requests - check and handle pending vCPU requests
*
* Return: RESUME_GUEST if we should enter the guest
* RESUME_HOST if we should exit to userspace
*/
static int kvm_check_requests(struct kvm_vcpu *vcpu)
{
if (!kvm_request_pending(vcpu))
return RESUME_GUEST;
if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
vcpu->arch.vpid = 0; /* Drop vpid for this vCPU */
if (kvm_dirty_ring_check_request(vcpu))
return RESUME_HOST;
if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))
kvm_update_stolen_time(vcpu);
return RESUME_GUEST;
}
static void kvm_late_check_requests(struct kvm_vcpu *vcpu)
{
lockdep_assert_irqs_disabled();
if (!kvm_request_pending(vcpu))
return;
if (kvm_check_request(KVM_REQ_PMU, vcpu)) {
kvm_own_pmu(vcpu);
vcpu->arch.aux_inuse |= KVM_LARCH_PMU;
}
if (kvm_check_request(KVM_REQ_TLB_FLUSH_GPA, vcpu))
if (vcpu->arch.flush_gpa != INVALID_GPA) {
kvm_flush_tlb_gpa(vcpu, vcpu->arch.flush_gpa);
vcpu->arch.flush_gpa = INVALID_GPA;
}
if (kvm_check_request(KVM_REQ_FPU_LOAD, vcpu)) {
if (kvm_guest_has_lasx(&vcpu->arch))
kvm_own_lasx(vcpu);
else if (kvm_guest_has_lsx(&vcpu->arch))
kvm_own_lsx(vcpu);
else if (kvm_guest_has_fpu(&vcpu->arch))
kvm_own_fpu(vcpu);
}
if (kvm_check_request(KVM_REQ_LBT_LOAD, vcpu))
kvm_own_lbt(vcpu);
}
/*
* Check and handle pending signal and vCPU requests etc
* Run with irq enabled and preempt enabled
*
Annotation
- Immediate include surface: `linux/kvm_host.h`, `asm/fpu.h`, `asm/lbt.h`, `asm/loongarch.h`, `asm/setup.h`, `asm/time.h`, `asm/timex.h`, `trace.h`.
- Detected declarations: `function kvm_save_host_pmu`, `function kvm_restore_host_pmu`, `function kvm_save_guest_pmu`, `function kvm_restore_guest_pmu`, `function kvm_own_pmu`, `function kvm_lose_pmu`, `function kvm_update_stolen_time`, `function kvm_check_requests`, `function kvm_late_check_requests`, `function kvm_enter_guest_check`.
- Atlas domain: Architecture Layer / arch/loongarch.
- 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.