Skip to content

Commit f41c8bd

Browse files
zhaotianrui-loongsonchenhuacai
authored andcommitted
LoongArch: KVM: Implement handle idle exception
Implement kvm handle LoongArch vcpu idle exception, using kvm_vcpu_block to emulate it. 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 81efe04 commit f41c8bd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

arch/loongarch/kvm/exit.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,23 @@ int kvm_complete_iocsr_read(struct kvm_vcpu *vcpu, struct kvm_run *run)
194194

195195
return er;
196196
}
197+
198+
int kvm_emu_idle(struct kvm_vcpu *vcpu)
199+
{
200+
++vcpu->stat.idle_exits;
201+
trace_kvm_exit_idle(vcpu, KVM_TRACE_EXIT_IDLE);
202+
203+
if (!kvm_arch_vcpu_runnable(vcpu)) {
204+
/*
205+
* Switch to the software timer before halt-polling/blocking as
206+
* the guest's timer may be a break event for the vCPU, and the
207+
* hypervisor timer runs only when the CPU is in guest mode.
208+
* Switch before halt-polling so that KVM recognizes an expired
209+
* timer before blocking.
210+
*/
211+
kvm_save_timer(vcpu);
212+
kvm_vcpu_block(vcpu);
213+
}
214+
215+
return EMULATE_DONE;
216+
}

0 commit comments

Comments
 (0)