arch/riscv/kvm/vcpu.c
Source file repositories/reference/linux-study-clean/arch/riscv/kvm/vcpu.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kvm/vcpu.c- Extension
.c- Size
- 25629 bytes
- Lines
- 985
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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/bitops.hlinux/errno.hlinux/err.hlinux/kdebug.hlinux/module.hlinux/percpu.hlinux/vmalloc.hlinux/sched/signal.hlinux/fs.hlinux/kvm_host.hasm/cacheflush.hasm/kvm_mmu.hasm/kvm_nacl.hasm/kvm_vcpu_vector.htrace.h
Detected Declarations
function kvm_riscv_vcpu_context_resetfunction kvm_riscv_reset_vcpufunction kvm_arch_vcpu_precreatefunction kvm_arch_vcpu_createfunction kvm_arch_vcpu_postcreatefunction kvm_arch_vcpu_destroyfunction kvm_cpu_has_pending_timerfunction kvm_arch_vcpu_runnablefunction kvm_arch_vcpu_should_kickfunction kvm_arch_vcpu_in_kernelfunction kvm_arch_vcpu_get_ipfunction kvm_arch_vcpu_faultfunction kvm_arch_vcpu_unlocked_ioctlfunction kvm_arch_vcpu_ioctlfunction kvm_arch_vcpu_ioctl_get_sregsfunction kvm_arch_vcpu_ioctl_set_sregsfunction kvm_arch_vcpu_ioctl_get_fpufunction kvm_arch_vcpu_ioctl_set_fpufunction kvm_arch_vcpu_ioctl_translatefunction kvm_arch_vcpu_ioctl_get_regsfunction kvm_arch_vcpu_ioctl_set_regsfunction kvm_riscv_vcpu_flush_interruptsfunction kvm_riscv_vcpu_sync_interruptsfunction kvm_riscv_vcpu_set_interruptfunction kvm_riscv_vcpu_unset_interruptfunction kvm_riscv_vcpu_has_interruptsfunction __kvm_riscv_vcpu_power_offfunction kvm_riscv_vcpu_power_offfunction __kvm_riscv_vcpu_power_onfunction kvm_riscv_vcpu_power_onfunction kvm_riscv_vcpu_stoppedfunction kvm_arch_vcpu_ioctl_get_mpstatefunction kvm_arch_vcpu_ioctl_set_mpstatefunction kvm_arch_vcpu_ioctl_set_guest_debugfunction kvm_arch_vcpu_loadfunction kvm_arch_vcpu_putfunction kvm_riscv_check_vcpu_requestsfunction kvm_riscv_update_hvipfunction kvm_riscv_vcpu_swap_in_guest_statefunction kvm_riscv_vcpu_swap_in_host_statefunction kvm_riscv_vcpu_enter_exitfunction kvm_arch_vcpu_ioctl_run
Annotated Snippet
if (hvip & (1UL << IRQ_VS_SOFT)) {
if (!test_and_set_bit(IRQ_VS_SOFT,
v->irqs_pending_mask))
set_bit(IRQ_VS_SOFT, v->irqs_pending);
} else {
if (!test_and_set_bit(IRQ_VS_SOFT,
v->irqs_pending_mask))
clear_bit(IRQ_VS_SOFT, v->irqs_pending);
}
}
/* Sync up the HVIP.LCOFIP bit changes (only clear) by the guest */
if ((csr->hvip ^ hvip) & (1UL << IRQ_PMU_OVF)) {
if (!(hvip & (1UL << IRQ_PMU_OVF)) &&
!test_and_set_bit(IRQ_PMU_OVF, v->irqs_pending_mask))
clear_bit(IRQ_PMU_OVF, v->irqs_pending);
}
/* Sync-up AIA high interrupts */
kvm_riscv_vcpu_aia_sync_interrupts(vcpu);
/* Sync-up timer CSRs */
kvm_riscv_vcpu_timer_sync(vcpu);
}
int kvm_riscv_vcpu_set_interrupt(struct kvm_vcpu *vcpu, unsigned int irq)
{
/*
* We only allow VS-mode software, timer, and external
* interrupts when irq is one of the local interrupts
* defined by RISC-V privilege specification.
*/
if (irq < IRQ_LOCAL_MAX &&
irq != IRQ_VS_SOFT &&
irq != IRQ_VS_TIMER &&
irq != IRQ_VS_EXT &&
irq != IRQ_PMU_OVF)
return -EINVAL;
set_bit(irq, vcpu->arch.irqs_pending);
smp_mb__before_atomic();
set_bit(irq, vcpu->arch.irqs_pending_mask);
kvm_vcpu_kick(vcpu);
return 0;
}
int kvm_riscv_vcpu_unset_interrupt(struct kvm_vcpu *vcpu, unsigned int irq)
{
/*
* We only allow VS-mode software, timer, counter overflow and external
* interrupts when irq is one of the local interrupts
* defined by RISC-V privilege specification.
*/
if (irq < IRQ_LOCAL_MAX &&
irq != IRQ_VS_SOFT &&
irq != IRQ_VS_TIMER &&
irq != IRQ_VS_EXT &&
irq != IRQ_PMU_OVF)
return -EINVAL;
clear_bit(irq, vcpu->arch.irqs_pending);
smp_mb__before_atomic();
set_bit(irq, vcpu->arch.irqs_pending_mask);
return 0;
}
bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, u64 mask)
{
unsigned long ie;
ie = ((vcpu->arch.guest_csr.vsie & VSIP_VALID_MASK)
<< VSIP_TO_HVIP_SHIFT) & (unsigned long)mask;
ie |= vcpu->arch.guest_csr.vsie & ~IRQ_LOCAL_MASK &
(unsigned long)mask;
if (READ_ONCE(vcpu->arch.irqs_pending[0]) & ie)
return true;
/* Check AIA high interrupts */
return kvm_riscv_vcpu_aia_has_interrupts(vcpu, mask);
}
void __kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu)
{
WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_STOPPED);
kvm_make_request(KVM_REQ_SLEEP, vcpu);
kvm_vcpu_kick(vcpu);
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/errno.h`, `linux/err.h`, `linux/kdebug.h`, `linux/module.h`, `linux/percpu.h`, `linux/vmalloc.h`, `linux/sched/signal.h`.
- Detected declarations: `function kvm_riscv_vcpu_context_reset`, `function kvm_riscv_reset_vcpu`, `function kvm_arch_vcpu_precreate`, `function kvm_arch_vcpu_create`, `function kvm_arch_vcpu_postcreate`, `function kvm_arch_vcpu_destroy`, `function kvm_cpu_has_pending_timer`, `function kvm_arch_vcpu_runnable`, `function kvm_arch_vcpu_should_kick`, `function kvm_arch_vcpu_in_kernel`.
- Atlas domain: Architecture Layer / arch/riscv.
- 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.