@samitouri / QOSamiQemu / commits / 1b80f1009d

target/i386: add compat for migrating error code

If cpu->env.has_error_code is true, backwards migration of a VM from a QEMU binary with commit 27535e9cca to a QEMU binary without commit 27535e9cca will fail: > kvm: error while loading state for instance 0x0 of device 'cpu' In practice, wrongly setting the error code to 0 on the target is often unproblematic, so additionally checking error_code != 0 in cpu_errcode_needed() is not enough to mitigate the issue. Instead, add proper machine version compat handling. Cc: qemu-stable@nongnu.org Fixes: 27535e9cca ("target/i386: Add support for save/load of exception error code") Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20260310154348.495332-1-f.ebner@proxmox.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Fiona Ebner committed Mar 10, 2026 at 16:43 UTC 1b80f1009dcaf19b4a82a63ab4e52833374e31cc
4 files changed +4 -1
hw/i386/pc.c
+1
@@ -78,6 +78,7 @@ const size_t pc_compat_10_2_len = G_N_ELEMENTS(pc_compat_10_2);
78
79 GlobalProperty pc_compat_10_1[] = {
80 { "mch", "extended-tseg-mbytes", "16" },
81 + { TYPE_X86_CPU, "x-migrate-error-code", "false" },
82 };
83 const size_t pc_compat_10_1_len = G_N_ELEMENTS(pc_compat_10_1);
84
target/i386/cpu.c
+1
@@ -10651,6 +10651,7 @@ static const Property x86_cpu_properties[] = {
10651 DEFINE_PROP_BOOL("tcg-cpuid", X86CPU, expose_tcg, true),
10652 DEFINE_PROP_BOOL("x-migrate-smi-count", X86CPU, migrate_smi_count,
10653 true),
10654 + DEFINE_PROP_BOOL("x-migrate-error-code", X86CPU, migrate_error_code, true),
10655 /*
10656 * lecacy_cache defaults to true unless the CPU model provides its
10657 * own cache information (see x86_cpu_load_def()).
target/i386/cpu.h
+1
@@ -2361,6 +2361,7 @@ struct ArchCPU {
2361 bool expose_tcg;
2362 bool migratable;
2363 bool migrate_smi_count;
2364 + bool migrate_error_code;
2365 uint32_t apic_id;
2366
2367 /* Enables publishing of TSC increment and Local APIC bus frequencies to
target/i386/machine.c
+1 -1
@@ -466,7 +466,7 @@ static bool cpu_errcode_needed(void *opaque)
466 {
467 X86CPU *cpu = opaque;
468
469 - return cpu->env.has_error_code != 0;
469 + return cpu->env.has_error_code != 0 && cpu->migrate_error_code;
470 }
471
472 static const VMStateDescription vmstate_error_code = {