qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/loongarch: Set cpuid CSR register only once with kvm mode
@ 2024-01-15  8:51 Bibo Mao
  2024-01-24  2:00 ` gaosong
  0 siblings, 1 reply; 2+ messages in thread
From: Bibo Mao @ 2024-01-15  8:51 UTC (permalink / raw)
  To: Song Gao; +Cc: qemu-devel

CSR cpuid register is used for routing irq to different vcpus, its
value is kept unchanged since poweron. So it is not necessary to
set CSR cpuid register after system resets, and it is only set at
vm creation stage.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 target/loongarch/kvm/kvm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
index 84bcdf5f86..2230f029d0 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -250,7 +250,7 @@ static int kvm_loongarch_get_csr(CPUState *cs)
     return ret;
 }
 
-static int kvm_loongarch_put_csr(CPUState *cs)
+static int kvm_loongarch_put_csr(CPUState *cs, int level)
 {
     int ret = 0;
     LoongArchCPU *cpu = LOONGARCH_CPU(cs);
@@ -322,8 +322,11 @@ static int kvm_loongarch_put_csr(CPUState *cs)
     ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_RVACFG),
                            &env->CSR_RVACFG);
 
-    ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CPUID),
+    /* CPUID is constant after poweron, it should be set only once */
+    if (level >= KVM_PUT_FULL_STATE) {
+        ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CPUID),
                            &env->CSR_CPUID);
+    }
 
     ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG1),
                            &env->CSR_PRCFG1);
@@ -598,7 +601,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)
         return ret;
     }
 
-    ret = kvm_loongarch_put_csr(cs);
+    ret = kvm_loongarch_put_csr(cs, level);
     if (ret) {
         return ret;
     }

base-commit: 977542ded7e6b28d2bc077bcda24568c716e393c
-- 
2.39.3



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] target/loongarch: Set cpuid CSR register only once with kvm mode
  2024-01-15  8:51 [PATCH] target/loongarch: Set cpuid CSR register only once with kvm mode Bibo Mao
@ 2024-01-24  2:00 ` gaosong
  0 siblings, 0 replies; 2+ messages in thread
From: gaosong @ 2024-01-24  2:00 UTC (permalink / raw)
  To: Bibo Mao; +Cc: qemu-devel

在 2024/1/15 下午4:51, Bibo Mao 写道:
> CSR cpuid register is used for routing irq to different vcpus, its
> value is kept unchanged since poweron. So it is not necessary to
> set CSR cpuid register after system resets, and it is only set at
> vm creation stage.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   target/loongarch/kvm/kvm.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)

Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
> index 84bcdf5f86..2230f029d0 100644
> --- a/target/loongarch/kvm/kvm.c
> +++ b/target/loongarch/kvm/kvm.c
> @@ -250,7 +250,7 @@ static int kvm_loongarch_get_csr(CPUState *cs)
>       return ret;
>   }
>   
> -static int kvm_loongarch_put_csr(CPUState *cs)
> +static int kvm_loongarch_put_csr(CPUState *cs, int level)
>   {
>       int ret = 0;
>       LoongArchCPU *cpu = LOONGARCH_CPU(cs);
> @@ -322,8 +322,11 @@ static int kvm_loongarch_put_csr(CPUState *cs)
>       ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_RVACFG),
>                              &env->CSR_RVACFG);
>   
> -    ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CPUID),
> +    /* CPUID is constant after poweron, it should be set only once */
> +    if (level >= KVM_PUT_FULL_STATE) {
> +        ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CPUID),
>                              &env->CSR_CPUID);
> +    }
>   
>       ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG1),
>                              &env->CSR_PRCFG1);
> @@ -598,7 +601,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)
>           return ret;
>       }
>   
> -    ret = kvm_loongarch_put_csr(cs);
> +    ret = kvm_loongarch_put_csr(cs, level);
>       if (ret) {
>           return ret;
>       }
>
> base-commit: 977542ded7e6b28d2bc077bcda24568c716e393c



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-24  2:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-15  8:51 [PATCH] target/loongarch: Set cpuid CSR register only once with kvm mode Bibo Mao
2024-01-24  2:00 ` gaosong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).