Skip to content

Commit 71f4fb8

Browse files
zhaotianrui-loongsonchenhuacai
authored andcommitted
LoongArch: KVM: Implement kvm exception vectors
Implement kvm exception vectors, using kvm_fault_tables array to save the handle function pointers and it is used when vcpu handle guest exit. Reviewed-by: Bibo Mao <[email protected]> Tested-by: Huacai Chen <[email protected]> Signed-off-by: Tianrui Zhao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 37cdfc6 commit 71f4fb8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

arch/loongarch/kvm/exit.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,3 +658,39 @@ static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu)
658658

659659
return RESUME_GUEST;
660660
}
661+
662+
/*
663+
* LoongArch KVM callback handling for unimplemented guest exiting
664+
*/
665+
static int kvm_fault_ni(struct kvm_vcpu *vcpu)
666+
{
667+
unsigned int ecode, inst;
668+
unsigned long estat, badv;
669+
670+
/* Fetch the instruction */
671+
inst = vcpu->arch.badi;
672+
badv = vcpu->arch.badv;
673+
estat = vcpu->arch.host_estat;
674+
ecode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
675+
kvm_err("ECode: %d PC=%#lx Inst=0x%08x BadVaddr=%#lx ESTAT=%#lx\n",
676+
ecode, vcpu->arch.pc, inst, badv, read_gcsr_estat());
677+
kvm_arch_vcpu_dump_regs(vcpu);
678+
kvm_queue_exception(vcpu, EXCCODE_INE, 0);
679+
680+
return RESUME_GUEST;
681+
}
682+
683+
static exit_handle_fn kvm_fault_tables[EXCCODE_INT_START] = {
684+
[0 ... EXCCODE_INT_START - 1] = kvm_fault_ni,
685+
[EXCCODE_TLBI] = kvm_handle_read_fault,
686+
[EXCCODE_TLBL] = kvm_handle_read_fault,
687+
[EXCCODE_TLBS] = kvm_handle_write_fault,
688+
[EXCCODE_TLBM] = kvm_handle_write_fault,
689+
[EXCCODE_FPDIS] = kvm_handle_fpu_disabled,
690+
[EXCCODE_GSPR] = kvm_handle_gspr,
691+
};
692+
693+
int kvm_handle_fault(struct kvm_vcpu *vcpu, int fault)
694+
{
695+
return kvm_fault_tables[fault](vcpu);
696+
}

0 commit comments

Comments
 (0)