From: Tao Cui <cui.tao@linux.dev>
To: qemu-devel@nongnu.org
Cc: "Song Gao" <gaosong@loongson.cn>,
"Bibo Mao" <maobibo@loongson.cn>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@mailo.com>,
"Tao Cui" <cuitao@kylinos.cn>
Subject: [PATCH v2 3/3] target/loongarch: add no_pv_feature compat flag
Date: Fri, 10 Jul 2026 08:50:29 +0800 [thread overview]
Message-ID: <20260710005029.345378-4-cui.tao@linux.dev> (raw)
In-Reply-To: <20260710005029.345378-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
Advertising pv features to the guest affects the migration stream. Add a
no_pv_feature compat flag so the behavior can be gated per machine version:
LoongArchCPU gets a bool field, and the virt machine gains a
LoongArchVirtMachineClass field that defaults the CPU flag per version.
kvm_cpu_check_pv_features() skips populating pv features when the flag is
set. The 11.1 machine type keeps pv advertisement off (no_pv_feature is
true, preserving the previous behavior); from the new 11.2 machine type it
is on by default.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
hw/loongarch/virt.c | 14 +++++++++++++-
include/hw/loongarch/virt.h | 9 ++++++++-
target/loongarch/cpu.h | 1 +
target/loongarch/kvm/kvm.c | 5 +++++
4 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 6693dea647..53c84c8def 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -955,6 +955,8 @@ static void virt_init(MachineState *machine)
machine->cpu_type);
exit(EXIT_FAILURE);
}
+ LOONGARCH_CPU(cpuobj)->no_pv_feature =
+ LOONGARCH_VIRT_MACHINE_GET_CLASS(lvms)->no_pv_feature;
qdev_realize_and_unref(DEVICE(cpuobj), NULL, &error_fatal);
}
virt_check_dmsi(machine);
@@ -1584,6 +1586,7 @@ static const TypeInfo virt_machine_info = {
.parent = TYPE_MACHINE,
.abstract = true,
.instance_size = sizeof(LoongArchVirtMachineState),
+ .class_size = sizeof(LoongArchVirtMachineClass),
.class_init = virt_class_init,
.instance_init = virt_initfn,
.instance_finalize = virt_instance_finalize,
@@ -1601,6 +1604,15 @@ static void machvirt_machine_init(void)
type_init(machvirt_machine_init);
static void virt_machine_11_1_options(MachineClass *mc)
+{
+ LoongArchVirtMachineClass *vmc = LOONGARCH_VIRT_MACHINE_CLASS(mc);
+
+ /* pv feature advertisement is enabled from 11.2; keep 11.1 unchanged */
+ vmc->no_pv_feature = true;
+}
+DEFINE_VIRT_MACHINE(11, 1)
+
+static void virt_machine_11_2_options(MachineClass *mc)
{
}
-DEFINE_VIRT_MACHINE_AS_LATEST(11, 1)
+DEFINE_VIRT_MACHINE_AS_LATEST(11, 2)
diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
index d39a9bbf5d..cf8d9e1fd2 100644
--- a/include/hw/loongarch/virt.h
+++ b/include/hw/loongarch/virt.h
@@ -130,8 +130,15 @@ struct LoongArchVirtMachineState {
bool highmem_mmio;
};
+struct LoongArchVirtMachineClass {
+ MachineClass parent_obj;
+
+ bool no_pv_feature; /* compat: 11.1 and older do not advertise pv features */
+};
+
#define TYPE_LOONGARCH_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
-OBJECT_DECLARE_SIMPLE_TYPE(LoongArchVirtMachineState, LOONGARCH_VIRT_MACHINE)
+OBJECT_DECLARE_TYPE(LoongArchVirtMachineState, LoongArchVirtMachineClass,
+ LOONGARCH_VIRT_MACHINE)
void virt_acpi_setup(LoongArchVirtMachineState *lvms);
void virt_fdt_setup(LoongArchVirtMachineState *lvms);
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index ad30c73167..11bbb5f36e 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -447,6 +447,7 @@ struct ArchCPU {
OnOffAuto msgint;
OnOffAuto kvm_pv_ipi;
OnOffAuto kvm_steal_time;
+ bool no_pv_feature; /* compat: do not advertise KVM pv features */
int32_t socket_id; /* socket-id of this CPU */
int32_t core_id; /* core-id of this CPU */
int32_t thread_id; /* thread-id of this CPU */
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
index c557ee3c3d..878914928b 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -1119,6 +1119,11 @@ static int kvm_cpu_check_pv_features(CPUState *cs, Error **errp)
CPULoongArchState *env = cpu_env(cs);
bool kvm_supported;
+ /* compat: older machine types do not advertise pv features to the guest */
+ if (cpu->no_pv_feature) {
+ return 0;
+ }
+
kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_PV_IPI);
if (cpu->kvm_pv_ipi == ON_OFF_AUTO_ON) {
if (!kvm_supported) {
--
2.43.0
next prev parent reply other threads:[~2026-07-10 0:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 0:50 [PATCH v2 0/3] target/loongarch: advertise pv features per vCPU Tao Cui
2026-07-10 0:50 ` [PATCH v2 1/3] target/loongarch/kvm: " Tao Cui
2026-07-10 2:58 ` Bibo Mao
2026-07-10 8:09 ` Tao Cui
2026-07-10 8:44 ` Bibo Mao
2026-07-10 12:46 ` Tao Cui
2026-07-13 1:00 ` Bibo Mao
2026-07-10 0:50 ` [PATCH v2 2/3] target/loongarch: migrate pv_features in the vCPU VMState Tao Cui
2026-07-10 3:02 ` Bibo Mao
2026-07-10 3:15 ` Bibo Mao
2026-07-10 8:22 ` Tao Cui
2026-07-10 0:50 ` Tao Cui [this message]
2026-07-10 3:09 ` [PATCH v2 3/3] target/loongarch: add no_pv_feature compat flag Bibo Mao
2026-07-10 8:28 ` Tao Cui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260710005029.345378-4-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=cuitao@kylinos.cn \
--cc=gaosong@loongson.cn \
--cc=jiaxun.yang@flygoat.com \
--cc=maobibo@loongson.cn \
--cc=pbonzini@redhat.com \
--cc=philmd@mailo.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.