qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3] target/loongarch: fix vcpu reset command word issue
@ 2025-02-12  1:56 Xianglai Li
  2025-02-12  7:30 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 3+ messages in thread
From: Xianglai Li @ 2025-02-12  1:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bibo Mao, Philippe Mathieu-Daudé, Song Gao

When the KVM_REG_LOONGARCH_VCPU_RESET command word
is sent to the kernel through the kvm_set_one_reg interface,
the parameter source needs to be a legal address,
otherwise the kernel will return an error and the command word
will fail to be sent.

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
---
Cc: Bibo Mao <Maobibo@loongson.cn>
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Cc: Song Gao <gaosong@loongson.cn>
Cc: Xianglai Li <lixianglai@loongson.cn>

CHANGE:
V3<-V2:
 Optimize log output when function calls fail and exit the process
directly. 

V2<-V1:
  1.Sets the initial value of the variable and
  adds a function return value judgment and prints a log

 target/loongarch/kvm/kvm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
index a3f55155b0..27df02fa3a 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -581,9 +581,16 @@ static int kvm_loongarch_get_lbt(CPUState *cs)
 void kvm_arch_reset_vcpu(CPUState *cs)
 {
     CPULoongArchState *env = cpu_env(cs);
+    int ret = 0;
+    uint64_t unused = 0;
 
     env->mp_state = KVM_MP_STATE_RUNNABLE;
-    kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, 0);
+    ret = kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, &unused);
+    if (ret) {
+        error_report("Failed to set KVM_REG_LOONGARCH_VCPU_RESET: %s",
+                     strerror(errno));
+        exit(EXIT_FAILURE);
+    }
 }
 
 static int kvm_loongarch_get_mpstate(CPUState *cs)
-- 
2.39.1



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

* Re: [PATCH V3] target/loongarch: fix vcpu reset command word issue
  2025-02-12  1:56 [PATCH V3] target/loongarch: fix vcpu reset command word issue Xianglai Li
@ 2025-02-12  7:30 ` Philippe Mathieu-Daudé
  2025-02-20  1:42   ` bibo mao
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-02-12  7:30 UTC (permalink / raw)
  To: Xianglai Li, qemu-devel; +Cc: Bibo Mao, Song Gao

On 12/2/25 02:56, Xianglai Li wrote:
> When the KVM_REG_LOONGARCH_VCPU_RESET command word
> is sent to the kernel through the kvm_set_one_reg interface,
> the parameter source needs to be a legal address,
> otherwise the kernel will return an error and the command word
> will fail to be sent.
> 
> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
> ---
> Cc: Bibo Mao <Maobibo@loongson.cn>
> Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
> Cc: Song Gao <gaosong@loongson.cn>
> Cc: Xianglai Li <lixianglai@loongson.cn>
> 
> CHANGE:
> V3<-V2:
>   Optimize log output when function calls fail and exit the process
> directly.
> 
> V2<-V1:
>    1.Sets the initial value of the variable and
>    adds a function return value judgment and prints a log
> 
>   target/loongarch/kvm/kvm.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
> index a3f55155b0..27df02fa3a 100644
> --- a/target/loongarch/kvm/kvm.c
> +++ b/target/loongarch/kvm/kvm.c
> @@ -581,9 +581,16 @@ static int kvm_loongarch_get_lbt(CPUState *cs)
>   void kvm_arch_reset_vcpu(CPUState *cs)
>   {
>       CPULoongArchState *env = cpu_env(cs);
> +    int ret = 0;
> +    uint64_t unused = 0;
>   
>       env->mp_state = KVM_MP_STATE_RUNNABLE;
> -    kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, 0);
> +    ret = kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, &unused);
> +    if (ret) {
> +        error_report("Failed to set KVM_REG_LOONGARCH_VCPU_RESET: %s",
> +                     strerror(errno));
> +        exit(EXIT_FAILURE);
> +    }
>   }

Look good now, thanks!

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



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

* Re: [PATCH V3] target/loongarch: fix vcpu reset command word issue
  2025-02-12  7:30 ` Philippe Mathieu-Daudé
@ 2025-02-20  1:42   ` bibo mao
  0 siblings, 0 replies; 3+ messages in thread
From: bibo mao @ 2025-02-20  1:42 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Xianglai Li, qemu-devel; +Cc: Song Gao

On 2025/2/12 下午3:30, Philippe Mathieu-Daudé wrote:
> On 12/2/25 02:56, Xianglai Li wrote:
>> When the KVM_REG_LOONGARCH_VCPU_RESET command word
>> is sent to the kernel through the kvm_set_one_reg interface,
>> the parameter source needs to be a legal address,
>> otherwise the kernel will return an error and the command word
>> will fail to be sent.
>>
>> Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
>> ---
>> Cc: Bibo Mao <Maobibo@loongson.cn>
>> Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
>> Cc: Song Gao <gaosong@loongson.cn>
>> Cc: Xianglai Li <lixianglai@loongson.cn>
>>
>> CHANGE:
>> V3<-V2:
>>   Optimize log output when function calls fail and exit the process
>> directly.
>>
>> V2<-V1:
>>    1.Sets the initial value of the variable and
>>    adds a function return value judgment and prints a log
>>
>>   target/loongarch/kvm/kvm.c | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
>> index a3f55155b0..27df02fa3a 100644
>> --- a/target/loongarch/kvm/kvm.c
>> +++ b/target/loongarch/kvm/kvm.c
>> @@ -581,9 +581,16 @@ static int kvm_loongarch_get_lbt(CPUState *cs)
>>   void kvm_arch_reset_vcpu(CPUState *cs)
>>   {
>>       CPULoongArchState *env = cpu_env(cs);
>> +    int ret = 0;
>> +    uint64_t unused = 0;
>>       env->mp_state = KVM_MP_STATE_RUNNABLE;
>> -    kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, 0);
>> +    ret = kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, &unused);
>> +    if (ret) {
>> +        error_report("Failed to set KVM_REG_LOONGARCH_VCPU_RESET: %s",
>> +                     strerror(errno));
>> +        exit(EXIT_FAILURE);
>> +    }
>>   }
> 
> Look good now, thanks!
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Queued in loongarch-next.

Regards
Bibo Mao



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

end of thread, other threads:[~2025-02-20  1:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12  1:56 [PATCH V3] target/loongarch: fix vcpu reset command word issue Xianglai Li
2025-02-12  7:30 ` Philippe Mathieu-Daudé
2025-02-20  1:42   ` bibo mao

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).