diff options
author | Tianrui Zhao <zhaotianrui@loongson.cn> | 2023-10-02 10:01:28 +0800 |
---|---|---|
committer | Huacai Chen <chenhuacai@loongson.cn> | 2023-10-02 10:01:28 +0800 |
commit | f41c8bdbbdbe73343d4842e580c6ab9db9d84171 (patch) | |
tree | 34d044c8b85dc9f7fc6bf652a3dae57b566f5e6f /arch/loongarch | |
parent | 81efe043a35113ec1352f6eb2b954d02aac368db (diff) | |
download | lwn-f41c8bdbbdbe73343d4842e580c6ab9db9d84171.tar.gz lwn-f41c8bdbbdbe73343d4842e580c6ab9db9d84171.zip |
LoongArch: KVM: Implement handle idle exception
Implement kvm handle LoongArch vcpu idle exception, using kvm_vcpu_block
to emulate it.
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Tested-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Diffstat (limited to 'arch/loongarch')
-rw-r--r-- | arch/loongarch/kvm/exit.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/arch/loongarch/kvm/exit.c b/arch/loongarch/kvm/exit.c index 7e729dd9e915..d4d7e74f72af 100644 --- a/arch/loongarch/kvm/exit.c +++ b/arch/loongarch/kvm/exit.c @@ -194,3 +194,23 @@ int kvm_complete_iocsr_read(struct kvm_vcpu *vcpu, struct kvm_run *run) return er; } + +int kvm_emu_idle(struct kvm_vcpu *vcpu) +{ + ++vcpu->stat.idle_exits; + trace_kvm_exit_idle(vcpu, KVM_TRACE_EXIT_IDLE); + + if (!kvm_arch_vcpu_runnable(vcpu)) { + /* + * Switch to the software timer before halt-polling/blocking as + * the guest's timer may be a break event for the vCPU, and the + * hypervisor timer runs only when the CPU is in guest mode. + * Switch before halt-polling so that KVM recognizes an expired + * timer before blocking. + */ + kvm_save_timer(vcpu); + kvm_vcpu_block(vcpu); + } + + return EMULATE_DONE; +} |