From nobody Tue Apr 7 20:09:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773245644593158.38405259592253; Wed, 11 Mar 2026 09:14:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0M9x-0000ea-21; Wed, 11 Mar 2026 12:11:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w0M9K-0000Fm-0V; Wed, 11 Mar 2026 12:11:08 -0400 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w0M9G-0007tM-UU; Wed, 11 Mar 2026 12:11:05 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 74E74874F7; Wed, 11 Mar 2026 17:10:59 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, mst@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, zhao1.liu@intel.com, peterx@redhat.com, farosas@suse.de, wangxinxin.wang@huawei.com Subject: [PATCH v3] target/i386: add compat for migrating error code Date: Wed, 11 Mar 2026 17:10:13 +0100 Message-ID: <20260311161053.704233-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1773245423859 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, HEXHASH_WORD=2.999, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1773245649731154100 Content-Type: text/plain; charset="utf-8" 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 !=3D 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 err= or code") Signed-off-by: Fiona Ebner Reviewed-by: Zhao Liu --- Changes in v3: * Add comment above compatibility flag. * Add R-b trailer from Zaho Liu. hw/i386/pc.c | 1 + target/i386/cpu.c | 1 + target/i386/cpu.h | 5 +++++ target/i386/machine.c | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index addf602da0..4b53b5be4a 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -78,6 +78,7 @@ const size_t pc_compat_10_2_len =3D G_N_ELEMENTS(pc_compa= t_10_2); =20 GlobalProperty pc_compat_10_1[] =3D { { "mch", "extended-tseg-mbytes", "16" }, + { TYPE_X86_CPU, "x-migrate-error-code", "false" }, }; const size_t pc_compat_10_1_len =3D G_N_ELEMENTS(pc_compat_10_1); =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0a29ff805f..abf129c7d5 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -10561,6 +10561,7 @@ static const Property x86_cpu_properties[] =3D { DEFINE_PROP_BOOL("tcg-cpuid", X86CPU, expose_tcg, true), DEFINE_PROP_BOOL("x-migrate-smi-count", X86CPU, migrate_smi_count, true), + DEFINE_PROP_BOOL("x-migrate-error-code", X86CPU, migrate_error_code, t= rue), /* * lecacy_cache defaults to true unless the CPU model provides its * own cache information (see x86_cpu_load_def()). diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 5a62aa6157..e88cdadb18 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2361,6 +2361,11 @@ struct ArchCPU { bool expose_tcg; bool migratable; bool migrate_smi_count; + /* + * Compatibility bits for old machine types. + * If true, allow including env.error_code in migration stream. + */ + bool migrate_error_code; uint32_t apic_id; =20 /* Enables publishing of TSC increment and Local APIC bus frequencies = to diff --git a/target/i386/machine.c b/target/i386/machine.c index c913961281..48a2a4b319 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -466,7 +466,7 @@ static bool cpu_errcode_needed(void *opaque) { X86CPU *cpu =3D opaque; =20 - return cpu->env.has_error_code !=3D 0; + return cpu->env.has_error_code !=3D 0 && cpu->migrate_error_code; } =20 static const VMStateDescription vmstate_error_code =3D { --=20 2.47.3