Commit 56d81acd2b for qemu.org
commit 56d81acd2bc750900da7239b4e5c6f8d0d3a2640
Author: Bibo Mao <maobibo@loongson.cn>
Date: Tue Nov 17 10:04:57 2026 +0800
Revert "target/loongarch: Remove TLB entry in vmstate"
This reverts commit 9e771d547b72d1eecd962725fad7508af3b97183.
The reverted change drops the vmstate_tlb fields on the assumption that
LoongArch guests can rebuild TLB entries from scratch. That assumption is
functionally valid, but the change was not gated behind a new machine type,
so it altered the migration stream layout of the already-released
virt-11.1 machine. As a result, migration from QEMU 11.1 to current
master fails.
With the revert applied, migration succeeds with:
(receiver, current master)
qemu-system-loongarch64 -M virt-11.1 -m 256M -display none \
-incoming "exec:cat /tmp/loongarch-virt-11.1.mig" -monitor stdio
using the stream produced by QEMU 11.1 (sender):
qemu-system-loongarch64 -M virt-11.1 -m 256M -display none -monitor stdio
(qemu) migrate "exec:cat > /tmp/loongarch-virt-11.1.mig"
Revert restores the virt-11.1 migration layout. If the TLB-dropping
optimisation is still desirable, it should be re-introduced behind a new
machine type (e.g. virt-11.2) so that existing guests remain migratable.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4879
Tested-by: Karl Mehltretter <kmehltretter@gmail.com>
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
diff --git a/target/loongarch/machine.c b/target/loongarch/machine.c
index 4acab2a4a3..957dc2ed71 100644
--- a/target/loongarch/machine.c
+++ b/target/loongarch/machine.c
@@ -175,6 +175,38 @@ static const VMStateDescription vmstate_pmu = {
},
};
+#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
+static bool tlb_needed(void *opaque)
+{
+ return tcg_enabled();
+}
+
+/* TLB state */
+static const VMStateDescription vmstate_tlb_entry = {
+ .name = "cpu/tlb_entry",
+ .version_id = 0,
+ .minimum_version_id = 0,
+ .fields = (const VMStateField[]) {
+ VMSTATE_UINT64(tlb_misc, LoongArchTLB),
+ VMSTATE_UINT64(tlb_entry0, LoongArchTLB),
+ VMSTATE_UINT64(tlb_entry1, LoongArchTLB),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static const VMStateDescription vmstate_tlb = {
+ .name = "cpu/tlb",
+ .version_id = 0,
+ .minimum_version_id = 0,
+ .needed = tlb_needed,
+ .fields = (const VMStateField[]) {
+ VMSTATE_STRUCT_ARRAY(env.tlb, LoongArchCPU, LOONGARCH_TLB_MAX,
+ 0, vmstate_tlb_entry, LoongArchTLB),
+ VMSTATE_END_OF_LIST()
+ }
+};
+#endif
+
/* LoongArch CPU state */
const VMStateDescription vmstate_loongarch_cpu = {
.name = "cpu",
@@ -251,6 +283,9 @@ const VMStateDescription vmstate_loongarch_cpu = {
&vmstate_fpu,
&vmstate_lsx,
&vmstate_lasx,
+#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
+ &vmstate_tlb,
+#endif
&vmstate_lbt,
&vmstate_msgint,
&vmstate_pmu,