Skip to content

Commit fecd903

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Add ecode parameter for exception handlers
For some KVM exception types, they share the same exception handler. To show the difference, ecode (exception code) is added as a new parameter in exception handlers. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent a5806cd commit fecd903

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

arch/loongarch/include/asm/kvm_vcpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define KVM_LOONGSON_IRQ_NUM_MASK 0xffff
3838

3939
typedef union loongarch_instruction larch_inst;
40-
typedef int (*exit_handle_fn)(struct kvm_vcpu *);
40+
typedef int (*exit_handle_fn)(struct kvm_vcpu *, int);
4141

4242
int kvm_emu_mmio_read(struct kvm_vcpu *vcpu, larch_inst inst);
4343
int kvm_emu_mmio_write(struct kvm_vcpu *vcpu, larch_inst inst);

arch/loongarch/kvm/exit.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static int kvm_trap_handle_gspr(struct kvm_vcpu *vcpu)
341341
* 2) Execute CACOP/IDLE instructions;
342342
* 3) Access to unimplemented CSRs/IOCSRs.
343343
*/
344-
static int kvm_handle_gspr(struct kvm_vcpu *vcpu)
344+
static int kvm_handle_gspr(struct kvm_vcpu *vcpu, int ecode)
345345
{
346346
int ret = RESUME_GUEST;
347347
enum emulation_result er = EMULATE_DONE;
@@ -705,12 +705,12 @@ static int kvm_handle_rdwr_fault(struct kvm_vcpu *vcpu, bool write)
705705
return ret;
706706
}
707707

708-
static int kvm_handle_read_fault(struct kvm_vcpu *vcpu)
708+
static int kvm_handle_read_fault(struct kvm_vcpu *vcpu, int ecode)
709709
{
710710
return kvm_handle_rdwr_fault(vcpu, false);
711711
}
712712

713-
static int kvm_handle_write_fault(struct kvm_vcpu *vcpu)
713+
static int kvm_handle_write_fault(struct kvm_vcpu *vcpu, int ecode)
714714
{
715715
return kvm_handle_rdwr_fault(vcpu, true);
716716
}
@@ -726,11 +726,12 @@ int kvm_complete_user_service(struct kvm_vcpu *vcpu, struct kvm_run *run)
726726
/**
727727
* kvm_handle_fpu_disabled() - Guest used fpu however it is disabled at host
728728
* @vcpu: Virtual CPU context.
729+
* @ecode: Exception code.
729730
*
730731
* Handle when the guest attempts to use fpu which hasn't been allowed
731732
* by the root context.
732733
*/
733-
static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu)
734+
static int kvm_handle_fpu_disabled(struct kvm_vcpu *vcpu, int ecode)
734735
{
735736
struct kvm_run *run = vcpu->run;
736737

@@ -783,11 +784,12 @@ static long kvm_save_notify(struct kvm_vcpu *vcpu)
783784
/*
784785
* kvm_handle_lsx_disabled() - Guest used LSX while disabled in root.
785786
* @vcpu: Virtual CPU context.
787+
* @ecode: Exception code.
786788
*
787789
* Handle when the guest attempts to use LSX when it is disabled in the root
788790
* context.
789791
*/
790-
static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcpu)
792+
static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcpu, int ecode)
791793
{
792794
if (kvm_own_lsx(vcpu))
793795
kvm_queue_exception(vcpu, EXCCODE_INE, 0);
@@ -798,19 +800,20 @@ static int kvm_handle_lsx_disabled(struct kvm_vcpu *vcpu)
798800
/*
799801
* kvm_handle_lasx_disabled() - Guest used LASX while disabled in root.
800802
* @vcpu: Virtual CPU context.
803+
* @ecode: Exception code.
801804
*
802805
* Handle when the guest attempts to use LASX when it is disabled in the root
803806
* context.
804807
*/
805-
static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu)
808+
static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu, int ecode)
806809
{
807810
if (kvm_own_lasx(vcpu))
808811
kvm_queue_exception(vcpu, EXCCODE_INE, 0);
809812

810813
return RESUME_GUEST;
811814
}
812815

813-
static int kvm_handle_lbt_disabled(struct kvm_vcpu *vcpu)
816+
static int kvm_handle_lbt_disabled(struct kvm_vcpu *vcpu, int ecode)
814817
{
815818
if (kvm_own_lbt(vcpu))
816819
kvm_queue_exception(vcpu, EXCCODE_INE, 0);
@@ -872,7 +875,7 @@ static void kvm_handle_service(struct kvm_vcpu *vcpu)
872875
kvm_write_reg(vcpu, LOONGARCH_GPR_A0, ret);
873876
}
874877

875-
static int kvm_handle_hypercall(struct kvm_vcpu *vcpu)
878+
static int kvm_handle_hypercall(struct kvm_vcpu *vcpu, int ecode)
876879
{
877880
int ret;
878881
larch_inst inst;
@@ -932,16 +935,14 @@ static int kvm_handle_hypercall(struct kvm_vcpu *vcpu)
932935
/*
933936
* LoongArch KVM callback handling for unimplemented guest exiting
934937
*/
935-
static int kvm_fault_ni(struct kvm_vcpu *vcpu)
938+
static int kvm_fault_ni(struct kvm_vcpu *vcpu, int ecode)
936939
{
937-
unsigned int ecode, inst;
938-
unsigned long estat, badv;
940+
unsigned int inst;
941+
unsigned long badv;
939942

940943
/* Fetch the instruction */
941944
inst = vcpu->arch.badi;
942945
badv = vcpu->arch.badv;
943-
estat = vcpu->arch.host_estat;
944-
ecode = (estat & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
945946
kvm_err("ECode: %d PC=%#lx Inst=0x%08x BadVaddr=%#lx ESTAT=%#lx\n",
946947
ecode, vcpu->arch.pc, inst, badv, read_gcsr_estat());
947948
kvm_arch_vcpu_dump_regs(vcpu);
@@ -966,5 +967,5 @@ static exit_handle_fn kvm_fault_tables[EXCCODE_INT_START] = {
966967

967968
int kvm_handle_fault(struct kvm_vcpu *vcpu, int fault)
968969
{
969-
return kvm_fault_tables[fault](vcpu);
970+
return kvm_fault_tables[fault](vcpu, fault);
970971
}

0 commit comments

Comments
 (0)