arch/loongarch/kvm/exit.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kvm/exit.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kvm/exit.c- Extension
.c- Size
- 23375 bytes
- Lines
- 972
- 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.
- 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/err.hlinux/errno.hlinux/kvm_host.hlinux/module.hlinux/preempt.hlinux/vmalloc.htrace/events/kvm.hasm/fpu.hasm/inst.hasm/loongarch.hasm/mmzone.hasm/numa.hasm/time.hasm/tlb.hasm/kvm_csr.hasm/kvm_vcpu.htrace.h
Detected Declarations
function Copyrightfunction kvm_emu_read_csrfunction kvm_emu_write_csrfunction kvm_emu_xchg_csrfunction kvm_handle_csrfunction kvm_emu_iocsrfunction kvm_complete_iocsr_readfunction kvm_emu_idlefunction kvm_trap_handle_gsprfunction kvm_handle_gsprfunction kvm_emu_mmio_readfunction kvm_complete_mmio_readfunction kvm_emu_mmio_writefunction kvm_handle_rdwr_faultfunction kvm_handle_read_faultfunction kvm_handle_write_faultfunction kvm_complete_user_servicefunction kvm_handle_fpu_disabledfunction kvm_save_notifyfunction kvm_handle_lsx_disabledfunction kvm_handle_lasx_disabledfunction kvm_handle_lbt_disabledfunction kvm_send_pv_ipifunction kvm_handle_servicefunction kvm_handle_hypercallfunction kvm_fault_nifunction kvm_handle_fault
Annotated Snippet
if (kvm_guest_has_pmu(&vcpu->arch)) {
vcpu->arch.pc -= 4;
kvm_make_request(KVM_REQ_PMU, vcpu);
return EMULATE_DONE;
}
}
/* Process CSR ops */
switch (rj) {
case 0: /* process csrrd */
val = kvm_emu_read_csr(vcpu, csrid);
vcpu->arch.gprs[rd] = val;
break;
case 1: /* process csrwr */
val = vcpu->arch.gprs[rd];
val = kvm_emu_write_csr(vcpu, csrid, val);
vcpu->arch.gprs[rd] = val;
break;
default: /* process csrxchg */
val = vcpu->arch.gprs[rd];
csr_mask = vcpu->arch.gprs[rj];
val = kvm_emu_xchg_csr(vcpu, csrid, csr_mask, val);
vcpu->arch.gprs[rd] = val;
}
return EMULATE_DONE;
}
int kvm_emu_iocsr(larch_inst inst, struct kvm_run *run, struct kvm_vcpu *vcpu)
{
int idx, ret;
unsigned long *val;
u32 addr, rd, rj, opcode;
/*
* Each IOCSR with different opcode
*/
rd = inst.reg2_format.rd;
rj = inst.reg2_format.rj;
opcode = inst.reg2_format.opcode;
addr = vcpu->arch.gprs[rj];
run->iocsr_io.phys_addr = addr;
run->iocsr_io.is_write = 0;
val = &vcpu->arch.gprs[rd];
/* LoongArch is Little endian */
switch (opcode) {
case iocsrrdb_op:
run->iocsr_io.len = 1;
break;
case iocsrrdh_op:
run->iocsr_io.len = 2;
break;
case iocsrrdw_op:
run->iocsr_io.len = 4;
break;
case iocsrrdd_op:
run->iocsr_io.len = 8;
break;
case iocsrwrb_op:
run->iocsr_io.len = 1;
run->iocsr_io.is_write = 1;
break;
case iocsrwrh_op:
run->iocsr_io.len = 2;
run->iocsr_io.is_write = 1;
break;
case iocsrwrw_op:
run->iocsr_io.len = 4;
run->iocsr_io.is_write = 1;
break;
case iocsrwrd_op:
run->iocsr_io.len = 8;
run->iocsr_io.is_write = 1;
break;
default:
return EMULATE_FAIL;
}
if (run->iocsr_io.is_write) {
idx = srcu_read_lock(&vcpu->kvm->srcu);
ret = kvm_io_bus_write(vcpu, KVM_IOCSR_BUS, addr, run->iocsr_io.len, val);
srcu_read_unlock(&vcpu->kvm->srcu, idx);
if (ret == 0)
ret = EMULATE_DONE;
else {
ret = EMULATE_DO_IOCSR;
/* Save data and let user space to write it */
memcpy(run->iocsr_io.data, val, run->iocsr_io.len);
}
Annotation
- Immediate include surface: `linux/err.h`, `linux/errno.h`, `linux/kvm_host.h`, `linux/module.h`, `linux/preempt.h`, `linux/vmalloc.h`, `trace/events/kvm.h`, `asm/fpu.h`.
- Detected declarations: `function Copyright`, `function kvm_emu_read_csr`, `function kvm_emu_write_csr`, `function kvm_emu_xchg_csr`, `function kvm_handle_csr`, `function kvm_emu_iocsr`, `function kvm_complete_iocsr_read`, `function kvm_emu_idle`, `function kvm_trap_handle_gspr`, `function kvm_handle_gspr`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: source 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.