diff mbox series

target/loongarch/kvm: Add vCPU reset function

Message ID 20240822022827.2273534-1-maobibo@loongson.cn
State New
Headers show
Series target/loongarch/kvm: Add vCPU reset function | expand

Commit Message

Bibo Mao Aug. 22, 2024, 2:28 a.m. UTC
KVM provides interface KVM_REG_LOONGARCH_VCPU_RESET to reset vCPU,
it can be used to clear internal state about kvm kernel. vCPU reset
function is added here for kvm mode.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 target/loongarch/cpu.c               | 2 +-
 target/loongarch/kvm/kvm.c           | 5 ++++-
 target/loongarch/kvm/kvm_loongarch.h | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

Comments

gaosong Sept. 9, 2024, 2:26 a.m. UTC | #1
在 2024/8/22 上午10:28, Bibo Mao 写道:
> KVM provides interface KVM_REG_LOONGARCH_VCPU_RESET to reset vCPU,
> it can be used to clear internal state about kvm kernel. vCPU reset
> function is added here for kvm mode.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   target/loongarch/cpu.c               | 2 +-
>   target/loongarch/kvm/kvm.c           | 5 ++++-
>   target/loongarch/kvm/kvm_loongarch.h | 2 +-
>   3 files changed, 6 insertions(+), 3 deletions(-)
> 
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks
Song Gao
> diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
> index 5e85b9dbef..6a5f856bd6 100644
> --- a/target/loongarch/cpu.c
> +++ b/target/loongarch/cpu.c
> @@ -563,7 +563,7 @@ static void loongarch_cpu_reset_hold(Object *obj, ResetType type)
>       memset(env->tlb, 0, sizeof(env->tlb));
>   #endif
>       if (kvm_enabled()) {
> -        kvm_arch_reset_vcpu(env);
> +        kvm_arch_reset_vcpu(cs);
>       }
>   #endif
>   
> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
> index e1be6a6959..4786cd5efa 100644
> --- a/target/loongarch/kvm/kvm.c
> +++ b/target/loongarch/kvm/kvm.c
> @@ -476,9 +476,12 @@ static int kvm_loongarch_put_regs_fp(CPUState *cs)
>       return ret;
>   }
>   
> -void kvm_arch_reset_vcpu(CPULoongArchState *env)
> +void kvm_arch_reset_vcpu(CPUState *cs)
>   {
> +    CPULoongArchState *env = cpu_env(cs);
> +
>       env->mp_state = KVM_MP_STATE_RUNNABLE;
> +    kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, 0);
>   }
>   
>   static int kvm_loongarch_get_mpstate(CPUState *cs)
> diff --git a/target/loongarch/kvm/kvm_loongarch.h b/target/loongarch/kvm/kvm_loongarch.h
> index d945b6bb82..1051a341ec 100644
> --- a/target/loongarch/kvm/kvm_loongarch.h
> +++ b/target/loongarch/kvm/kvm_loongarch.h
> @@ -11,6 +11,6 @@
>   #define QEMU_KVM_LOONGARCH_H
>   
>   int  kvm_loongarch_set_interrupt(LoongArchCPU *cpu, int irq, int level);
> -void kvm_arch_reset_vcpu(CPULoongArchState *env);
> +void kvm_arch_reset_vcpu(CPUState *cs);
>   
>   #endif
>
diff mbox series

Patch

diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 5e85b9dbef..6a5f856bd6 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -563,7 +563,7 @@  static void loongarch_cpu_reset_hold(Object *obj, ResetType type)
     memset(env->tlb, 0, sizeof(env->tlb));
 #endif
     if (kvm_enabled()) {
-        kvm_arch_reset_vcpu(env);
+        kvm_arch_reset_vcpu(cs);
     }
 #endif
 
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
index e1be6a6959..4786cd5efa 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -476,9 +476,12 @@  static int kvm_loongarch_put_regs_fp(CPUState *cs)
     return ret;
 }
 
-void kvm_arch_reset_vcpu(CPULoongArchState *env)
+void kvm_arch_reset_vcpu(CPUState *cs)
 {
+    CPULoongArchState *env = cpu_env(cs);
+
     env->mp_state = KVM_MP_STATE_RUNNABLE;
+    kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, 0);
 }
 
 static int kvm_loongarch_get_mpstate(CPUState *cs)
diff --git a/target/loongarch/kvm/kvm_loongarch.h b/target/loongarch/kvm/kvm_loongarch.h
index d945b6bb82..1051a341ec 100644
--- a/target/loongarch/kvm/kvm_loongarch.h
+++ b/target/loongarch/kvm/kvm_loongarch.h
@@ -11,6 +11,6 @@ 
 #define QEMU_KVM_LOONGARCH_H
 
 int  kvm_loongarch_set_interrupt(LoongArchCPU *cpu, int irq, int level);
-void kvm_arch_reset_vcpu(CPULoongArchState *env);
+void kvm_arch_reset_vcpu(CPUState *cs);
 
 #endif