* [PATCH 0/2] target/loongarch: PV TLB flush advertisement
@ 2026-06-15 8:52 Tao Cui
2026-06-15 8:52 ` [PATCH 1/2] linux-headers: Add LoongArch PV TLB flush definitions Tao Cui
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Tao Cui @ 2026-06-15 8:52 UTC (permalink / raw)
To: qemu-devel
Cc: Song Gao, Paolo Bonzini, Michael S . Tsirkin, Cornelia Huck, kvm,
Tao Cui
From: Tao Cui <cuitao@kylinos.cn>
Advertise the LoongArch paravirtual TLB flush feature (KVM_FEATURE_PV_TLB_FLUSH)
to the guest when the host KVM supports it. This pairs with the corresponding
KVM/guest-kernel PV TLB flush series posted to the kernel.
Patch 1 syncs the UAPI definitions into linux-headers.
Patch 2 adds the probe, the CPUCFG feature advertisement, and a
kvm-pv-tlb-flush CPU property (on/off/auto, default auto).
The feature is only advertised when the host actually supports it, so a
guest never observes KVM_FEATURE_PV_TLB_FLUSH on a host that cannot
service PV TLB flush requests.
Tao Cui (2):
linux-headers: Add LoongArch PV TLB flush definitions
target/loongarch: Enable PV TLB flush advertisement to the guest
linux-headers/asm-loongarch/kvm.h | 1 +
linux-headers/asm-loongarch/kvm_para.h | 1 +
target/loongarch/cpu.h | 2 ++
target/loongarch/kvm/kvm.c | 38 ++++++++++++++++++++++++++
target/loongarch/loongarch-qmp-cmds.c | 4 +--
5 files changed, 44 insertions(+), 2 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] linux-headers: Add LoongArch PV TLB flush definitions
2026-06-15 8:52 [PATCH 0/2] target/loongarch: PV TLB flush advertisement Tao Cui
@ 2026-06-15 8:52 ` Tao Cui
2026-06-15 8:52 ` [PATCH 2/2] target/loongarch: Enable PV TLB flush advertisement to the guest Tao Cui
2026-06-15 9:20 ` [PATCH 0/2] target/loongarch: PV TLB flush advertisement gaosong
2 siblings, 0 replies; 4+ messages in thread
From: Tao Cui @ 2026-06-15 8:52 UTC (permalink / raw)
To: qemu-devel
Cc: Song Gao, Paolo Bonzini, Michael S . Tsirkin, Cornelia Huck, kvm,
Tao Cui
From: Tao Cui <cuitao@kylinos.cn>
Sync the LoongArch PV TLB flush definitions from the kernel:
KVM_LOONGARCH_VM_FEAT_PV_TLB_FLUSH VM feature and KVM_FEATURE_PV_TLB_FLUSH
guest feature.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
| 1 +
| 1 +
2 files changed, 2 insertions(+)
--git a/linux-headers/asm-loongarch/kvm.h b/linux-headers/asm-loongarch/kvm.h
index cd0b5c11ca..e4cd4bbf89 100644
--- a/linux-headers/asm-loongarch/kvm.h
+++ b/linux-headers/asm-loongarch/kvm.h
@@ -106,6 +106,7 @@ struct kvm_fpu {
#define KVM_LOONGARCH_VM_FEAT_PTW 8
#define KVM_LOONGARCH_VM_FEAT_MSGINT 9
#define KVM_LOONGARCH_VM_FEAT_PV_PREEMPT 10
+#define KVM_LOONGARCH_VM_FEAT_PV_TLB_FLUSH 11
/* Device Control API on vcpu fd */
#define KVM_LOONGARCH_VCPU_CPUCFG 0
--git a/linux-headers/asm-loongarch/kvm_para.h b/linux-headers/asm-loongarch/kvm_para.h
index 3fd87a096b..98494784ed 100644
--- a/linux-headers/asm-loongarch/kvm_para.h
+++ b/linux-headers/asm-loongarch/kvm_para.h
@@ -16,6 +16,7 @@
#define KVM_FEATURE_IPI 1
#define KVM_FEATURE_STEAL_TIME 2
#define KVM_FEATURE_PREEMPT 3
+#define KVM_FEATURE_PV_TLB_FLUSH 4
/* BIT 24 - 31 are features configurable by user space vmm */
#define KVM_FEATURE_VIRT_EXTIOI 24
#define KVM_FEATURE_USER_HCALL 25
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] target/loongarch: Enable PV TLB flush advertisement to the guest
2026-06-15 8:52 [PATCH 0/2] target/loongarch: PV TLB flush advertisement Tao Cui
2026-06-15 8:52 ` [PATCH 1/2] linux-headers: Add LoongArch PV TLB flush definitions Tao Cui
@ 2026-06-15 8:52 ` Tao Cui
2026-06-15 9:20 ` [PATCH 0/2] target/loongarch: PV TLB flush advertisement gaosong
2 siblings, 0 replies; 4+ messages in thread
From: Tao Cui @ 2026-06-15 8:52 UTC (permalink / raw)
To: qemu-devel
Cc: Song Gao, Paolo Bonzini, Michael S . Tsirkin, Cornelia Huck, kvm,
Tao Cui
From: Tao Cui <cuitao@kylinos.cn>
Probe the KVM_LOONGARCH_VM_FEAT_PV_TLB_FLUSH VM-level capability and, when
the host supports it, advertise KVM_FEATURE_PV_TLB_FLUSH to the guest by
including it in the CPUCFG_KVM_FEATURE feature mask handed to the kernel.
This mirrors the existing PV IPI / steal-time enablement. A new
kvm-pv-tlb-flush CPU property (on/off/auto, default auto) lets users
disable the feature, e.g. when migrating to a host that lacks it.
The feature is only advertised when the host actually supports it, so a
guest never observes KVM_FEATURE_PV_TLB_FLUSH on a host that cannot
service PV TLB flush requests (which would otherwise lead to stale TLBs).
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
target/loongarch/cpu.h | 2 ++
target/loongarch/kvm/kvm.c | 38 +++++++++++++++++++++++++++
target/loongarch/loongarch-qmp-cmds.c | 4 +--
3 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index ad30c73167..94e8f176f4 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -300,6 +300,7 @@ enum loongarch_features {
LOONGARCH_FEATURE_PMU,
LOONGARCH_FEATURE_PV_IPI,
LOONGARCH_FEATURE_STEALTIME,
+ LOONGARCH_FEATURE_PV_TLB_FLUSH,
LOONGARCH_FEATURE_PTW,
};
@@ -447,6 +448,7 @@ struct ArchCPU {
OnOffAuto msgint;
OnOffAuto kvm_pv_ipi;
OnOffAuto kvm_steal_time;
+ OnOffAuto kvm_pv_tlb_flush;
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 d6539c12ac..f91c388bf3 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -981,6 +981,12 @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
return (ret == 0);
+ case LOONGARCH_FEATURE_PV_TLB_FLUSH:
+ attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
+ attr.attr = KVM_LOONGARCH_VM_FEAT_PV_TLB_FLUSH;
+ ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
+ return (ret == 0);
+
case LOONGARCH_FEATURE_PTW:
attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
attr.attr = KVM_LOONGARCH_VM_FEAT_PTW;
@@ -1150,6 +1156,20 @@ static int kvm_cpu_check_pv_features(CPUState *cs, Error **errp)
env->pv_features |= BIT(KVM_FEATURE_STEAL_TIME);
}
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_PV_TLB_FLUSH);
+ if (cpu->kvm_pv_tlb_flush == ON_OFF_AUTO_ON) {
+ if (!kvm_supported) {
+ error_setg(errp, "'pv_tlb_flush' not supported by KVM host");
+ return -ENOTSUP;
+ }
+ } else if (cpu->kvm_pv_tlb_flush != ON_OFF_AUTO_AUTO) {
+ kvm_supported = false;
+ }
+
+ if (kvm_supported) {
+ env->pv_features |= BIT(KVM_FEATURE_PV_TLB_FLUSH);
+ }
+
if (object_dynamic_cast(OBJECT(ms), TYPE_LOONGARCH_VIRT_MACHINE)) {
LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(ms);
@@ -1266,6 +1286,18 @@ static void kvm_steal_time_set(Object *obj, bool value, Error **errp)
cpu->kvm_steal_time = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
}
+static bool kvm_pv_tlb_flush_get(Object *obj, Error **errp)
+{
+ return LOONGARCH_CPU(obj)->kvm_pv_tlb_flush != ON_OFF_AUTO_OFF;
+}
+
+static void kvm_pv_tlb_flush_set(Object *obj, bool value, Error **errp)
+{
+ LoongArchCPU *cpu = LOONGARCH_CPU(obj);
+
+ cpu->kvm_pv_tlb_flush = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
+}
+
void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
{
cpu->lbt = ON_OFF_AUTO_AUTO;
@@ -1291,6 +1323,12 @@ void kvm_loongarch_cpu_post_init(LoongArchCPU *cpu)
kvm_steal_time_set);
object_property_set_description(OBJECT(cpu), "kvm-steal-time",
"Set off to disable KVM steal time.");
+
+ cpu->kvm_pv_tlb_flush = ON_OFF_AUTO_AUTO;
+ object_property_add_bool(OBJECT(cpu), "kvm-pv-tlb-flush",
+ kvm_pv_tlb_flush_get, kvm_pv_tlb_flush_set);
+ object_property_set_description(OBJECT(cpu), "kvm-pv-tlb-flush",
+ "Set off to disable KVM PV TLB flush.");
}
int kvm_arch_destroy_vcpu(CPUState *cs)
diff --git a/target/loongarch/loongarch-qmp-cmds.c b/target/loongarch/loongarch-qmp-cmds.c
index f053f22bb8..5f372d85a9 100644
--- a/target/loongarch/loongarch-qmp-cmds.c
+++ b/target/loongarch/loongarch-qmp-cmds.c
@@ -41,8 +41,8 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
}
static const char *cpu_model_advertised_features[] = {
- "lsx", "lasx", "lbt", "pmu", "kvm-pv-ipi", "kvm-steal-time", "msgint",
- "ptw", NULL
+ "lsx", "lasx", "lbt", "pmu", "kvm-pv-ipi", "kvm-steal-time",
+ "kvm-pv-tlb-flush", "msgint", "ptw", NULL
};
CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] target/loongarch: PV TLB flush advertisement
2026-06-15 8:52 [PATCH 0/2] target/loongarch: PV TLB flush advertisement Tao Cui
2026-06-15 8:52 ` [PATCH 1/2] linux-headers: Add LoongArch PV TLB flush definitions Tao Cui
2026-06-15 8:52 ` [PATCH 2/2] target/loongarch: Enable PV TLB flush advertisement to the guest Tao Cui
@ 2026-06-15 9:20 ` gaosong
2 siblings, 0 replies; 4+ messages in thread
From: gaosong @ 2026-06-15 9:20 UTC (permalink / raw)
To: Tao Cui, qemu-devel
Cc: Paolo Bonzini, Michael S . Tsirkin, Cornelia Huck, kvm, Tao Cui,
bibo mao
在 2026/6/15 下午4:52, Tao Cui 写道:
> From: Tao Cui <cuitao@kylinos.cn>
>
> Advertise the LoongArch paravirtual TLB flush feature (KVM_FEATURE_PV_TLB_FLUSH)
> to the guest when the host KVM supports it. This pairs with the corresponding
> KVM/guest-kernel PV TLB flush series posted to the kernel.
>
> Patch 1 syncs the UAPI definitions into linux-headers.
Hi, you should use scripts/update-linux-headers.sh to update the
linux-headers.
Thanks.
Song Gao
> Patch 2 adds the probe, the CPUCFG feature advertisement, and a
> kvm-pv-tlb-flush CPU property (on/off/auto, default auto).
>
> The feature is only advertised when the host actually supports it, so a
> guest never observes KVM_FEATURE_PV_TLB_FLUSH on a host that cannot
> service PV TLB flush requests.
> Tao Cui (2):
> linux-headers: Add LoongArch PV TLB flush definitions
> target/loongarch: Enable PV TLB flush advertisement to the guest
>
> linux-headers/asm-loongarch/kvm.h | 1 +
> linux-headers/asm-loongarch/kvm_para.h | 1 +
> target/loongarch/cpu.h | 2 ++
> target/loongarch/kvm/kvm.c | 38 ++++++++++++++++++++++++++
> target/loongarch/loongarch-qmp-cmds.c | 4 +--
> 5 files changed, 44 insertions(+), 2 deletions(-)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-15 9:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-15 8:52 [PATCH 0/2] target/loongarch: PV TLB flush advertisement Tao Cui
2026-06-15 8:52 ` [PATCH 1/2] linux-headers: Add LoongArch PV TLB flush definitions Tao Cui
2026-06-15 8:52 ` [PATCH 2/2] target/loongarch: Enable PV TLB flush advertisement to the guest Tao Cui
2026-06-15 9:20 ` [PATCH 0/2] target/loongarch: PV TLB flush advertisement gaosong
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.