* [PATCH] target/loongarch/kvm: set pv features per vCPU in kvm_arch_init_vcpu
@ 2026-06-25 1:53 Tao Cui
2026-06-25 3:14 ` Bibo Mao
0 siblings, 1 reply; 2+ messages in thread
From: Tao Cui @ 2026-06-25 1:53 UTC (permalink / raw)
To: qemu-devel
Cc: Song Gao, Bibo Mao, Paolo Bonzini, Philippe Mathieu-Daudé,
Tao Cui
From: Tao Cui <cuitao@kylinos.cn>
kvm_set_pv_features() programs the KVM_FEATURE cpucfg attribute, which is a
per-vCPU setting. It was called from kvm_arch_put_registers() under a
function-local static guard, so it ran only once for the whole VM and only
the first vCPU actually got its pv features pushed to KVM.
Move the call to kvm_arch_init_vcpu(), which runs once per vCPU, right
after the pv features are computed, and drop the static guard.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
target/loongarch/kvm/kvm.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
index d6539c12ac..985812c828 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -816,7 +816,6 @@ int kvm_arch_get_registers(CPUState *cs, Error **errp)
int kvm_arch_put_registers(CPUState *cs, KvmPutState level, Error **errp)
{
int ret;
- static int once;
ret = kvm_loongarch_put_regs_core(cs);
if (ret) {
@@ -843,14 +842,6 @@ int kvm_arch_put_registers(CPUState *cs, KvmPutState level, Error **errp)
return ret;
}
- if (!once) {
- ret = kvm_set_pv_features(cs);
- if (ret) {
- return ret;
- }
- once = 1;
- }
-
if (level >= KVM_PUT_FULL_STATE) {
/*
* only KVM_PUT_FULL_STATE is required, kvm kernel will clear
@@ -1209,6 +1200,12 @@ int kvm_arch_init_vcpu(CPUState *cs)
return ret;
}
+ /* pv_features is a per-vCPU attribute; set it here, once per vCPU. */
+ ret = kvm_set_pv_features(cs);
+ if (ret < 0) {
+ return ret;
+ }
+
ret = kvm_cpu_check_ptw(cs, &local_err);
if (ret < 0) {
error_report_err(local_err);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] target/loongarch/kvm: set pv features per vCPU in kvm_arch_init_vcpu
2026-06-25 1:53 [PATCH] target/loongarch/kvm: set pv features per vCPU in kvm_arch_init_vcpu Tao Cui
@ 2026-06-25 3:14 ` Bibo Mao
0 siblings, 0 replies; 2+ messages in thread
From: Bibo Mao @ 2026-06-25 3:14 UTC (permalink / raw)
To: Tao Cui, qemu-devel
Cc: Song Gao, Paolo Bonzini, Philippe Mathieu-Daudé, Tao Cui
On 2026/6/25 上午9:53, Tao Cui wrote:
> From: Tao Cui <cuitao@kylinos.cn>
>
> kvm_set_pv_features() programs the KVM_FEATURE cpucfg attribute, which is a
> per-vCPU setting. It was called from kvm_arch_put_registers() under a
> function-local static guard, so it ran only once for the whole VM and only
> the first vCPU actually got its pv features pushed to KVM.
>
> Move the call to kvm_arch_init_vcpu(), which runs once per vCPU, right
> after the pv features are computed, and drop the static guard.
>
> Signed-off-by: Tao Cui <cuitao@kylinos.cn>
> ---
> target/loongarch/kvm/kvm.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
> index d6539c12ac..985812c828 100644
> --- a/target/loongarch/kvm/kvm.c
> +++ b/target/loongarch/kvm/kvm.c
> @@ -816,7 +816,6 @@ int kvm_arch_get_registers(CPUState *cs, Error **errp)
> int kvm_arch_put_registers(CPUState *cs, KvmPutState level, Error **errp)
> {
> int ret;
> - static int once;
>
> ret = kvm_loongarch_put_regs_core(cs);
> if (ret) {
> @@ -843,14 +842,6 @@ int kvm_arch_put_registers(CPUState *cs, KvmPutState level, Error **errp)
> return ret;
> }
>
> - if (!once) {
> - ret = kvm_set_pv_features(cs);
> - if (ret) {
> - return ret;
> - }
> - once = 1;
> - }
> -
> if (level >= KVM_PUT_FULL_STATE) {
> /*
> * only KVM_PUT_FULL_STATE is required, kvm kernel will clear
> @@ -1209,6 +1200,12 @@ int kvm_arch_init_vcpu(CPUState *cs)
> return ret;
> }
>
> + /* pv_features is a per-vCPU attribute; set it here, once per vCPU. */
> + ret = kvm_set_pv_features(cs);
> + if (ret < 0) {
> + return ret;
> + }
I prefer the old method. The pv_features is one vCPU state instead, and
it will be added in vCPU VMState if migration is supported on different
host kernel version.
Here is host feature detection, not vCPU state setting.
Regards
Bibo Mao
> +
> ret = kvm_cpu_check_ptw(cs, &local_err);
> if (ret < 0) {
> error_report_err(local_err);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-25 3:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25 1:53 [PATCH] target/loongarch/kvm: set pv features per vCPU in kvm_arch_init_vcpu Tao Cui
2026-06-25 3:14 ` Bibo Mao
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.