Skip to content

Commit 372631b

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Add hypercall instruction emulation
On LoongArch system, there is a hypercall instruction special for virtualization. When system executes this instruction on host side, there is an illegal instruction exception reported, however it will trap into host when it is executed in VM mode. When hypercall is emulated, A0 register is set with value KVM_HCALL_INVALID_CODE, rather than inject EXCCODE_INE invalid instruction exception. So VM can continue to executing the next code. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 316863c commit 372631b

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

arch/loongarch/include/asm/Kbuild

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ generic-y += poll.h
2626
generic-y += param.h
2727
generic-y += posix_types.h
2828
generic-y += resource.h
29-
generic-y += kvm_para.h

arch/loongarch/include/asm/kvm_para.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_LOONGARCH_KVM_PARA_H
3+
#define _ASM_LOONGARCH_KVM_PARA_H
4+
5+
/*
6+
* LoongArch hypercall return code
7+
*/
8+
#define KVM_HCALL_SUCCESS 0
9+
#define KVM_HCALL_INVALID_CODE -1UL
10+
#define KVM_HCALL_INVALID_PARAMETER -2UL
11+
12+
static inline unsigned int kvm_arch_para_features(void)
13+
{
14+
return 0;
15+
}
16+
17+
static inline unsigned int kvm_arch_para_hints(void)
18+
{
19+
return 0;
20+
}
21+
22+
static inline bool kvm_check_and_clear_guest_paused(void)
23+
{
24+
return false;
25+
}
26+
27+
#endif /* _ASM_LOONGARCH_KVM_PARA_H */

arch/loongarch/kvm/exit.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,16 @@ static int kvm_handle_lasx_disabled(struct kvm_vcpu *vcpu)
685685
return RESUME_GUEST;
686686
}
687687

688+
static int kvm_handle_hypercall(struct kvm_vcpu *vcpu)
689+
{
690+
update_pc(&vcpu->arch);
691+
692+
/* Treat it as noop intruction, only set return value */
693+
vcpu->arch.gprs[LOONGARCH_GPR_A0] = KVM_HCALL_INVALID_CODE;
694+
695+
return RESUME_GUEST;
696+
}
697+
688698
/*
689699
* LoongArch KVM callback handling for unimplemented guest exiting
690700
*/
@@ -716,6 +726,7 @@ static exit_handle_fn kvm_fault_tables[EXCCODE_INT_START] = {
716726
[EXCCODE_LSXDIS] = kvm_handle_lsx_disabled,
717727
[EXCCODE_LASXDIS] = kvm_handle_lasx_disabled,
718728
[EXCCODE_GSPR] = kvm_handle_gspr,
729+
[EXCCODE_HVC] = kvm_handle_hypercall,
719730
};
720731

721732
int kvm_handle_fault(struct kvm_vcpu *vcpu, int fault)

0 commit comments

Comments
 (0)