From nobody Sun Sep 28 17:12:46 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=canonical.com ARC-Seal: i=1; a=rsa-sha256; t=1757505592; cv=none; d=zohomail.com; s=zohoarc; b=R46JVvebWaL4mJQcnPIHHnbT5MDmJwLyo1yf3Bs1UTHSyHLC4zLEFGH7fOF1XdWGkI3dHOIyIH8XY/u/bNL0QUslM6iaCrJQnOJz9nKF5pGQ2+0fGP+vA+ch3+3SsJv3azLEmLK68oj86RC8ES+KFqeW4+BGej/7DhU1Y+cDq84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757505592; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=fUzSuTBMtGi3wZGGhv3ZitxmAY7aNwFeIHVAOlgI/PI=; b=e7+d7R1aD049+5KPegcIPLSjgxjqYpAYmQYlYyi1MjrhkhuQnK/0sQ5ZSIiudew6tnzJmi8/C3RjWBwYphpPTLfWnJffbSh0px92H/jCyiOgUcWRli/Fp4HOrB54vIZ94voz7p48N/DgYxuLSKqlN0heZB8wSBcXeyMwxRxi1hY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757505592669812.9074833310566; Wed, 10 Sep 2025 04:59:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwJTp-0005zc-J3; Wed, 10 Sep 2025 07:59:20 -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 1uwJTZ-0005s1-0K for qemu-devel@nongnu.org; Wed, 10 Sep 2025 07:59:02 -0400 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwJTJ-0001wi-8p for qemu-devel@nongnu.org; Wed, 10 Sep 2025 07:58:59 -0400 Received: from localhost.localdomain (unknown [10.101.192.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id A168540D36 for ; Wed, 10 Sep 2025 11:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1757505507; bh=fUzSuTBMtGi3wZGGhv3ZitxmAY7aNwFeIHVAOlgI/PI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fPAfs4+0XYKWgHXzLnZR5rDpLsZgG0J2JOws2SPb8rpLX2WDcNTUcBcZSgRACXJQe LeLMemPQ+mjr69qJyRMipCiSDMiao1F1WpEVasS7fiFCdIZqDynxzBy0vTUalJSUbY ksKPig+UulCoYBmvDBggpeRQHxjyCdvx3wLHmet9yFVkh980dYcG46Uw2201VSf1E1 cLDNha8p9J/H//lKxxkc5pWY21X4DMWeSXwO6WjcheWfz6sUS4LETm4rqeJTCUCNm/ aYCzKAsU16JAkc8U2AyttY49kYOQM9Dubu1F/51poK3gFx1+jfT66YE7im+6YMxb1y G63ISeGefA4Fw== From: Hector Cao To: qemu-devel@nongnu.org Subject: [PATCH 1/2] target/i386: add compatibility property for arch_capabilities Date: Wed, 10 Sep 2025 13:57:32 +0200 Message-ID: <20250910115733.21149-2-hector.cao@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250910115733.21149-1-hector.cao@canonical.com> References: <20250910115733.21149-1-hector.cao@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=185.125.188.120; envelope-from=hector.cao@canonical.com; helo=smtp-relay-canonical-0.canonical.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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-ZohoMail-DKIM: pass (identity @canonical.com) X-ZM-MESSAGEID: 1757505594956116600 Content-Type: text/plain; charset="utf-8" Prior to v10.1, if requested by user, arch-capabilities is always on despite the fact that CPUID advertises it to be off/unvailable. this causes a migration issue for VMs that are run on a machine without arch-capabilities and expect this feature to be present on the destination host with QEMU 10.1. This commit add a compatibility property to restore the legacy behavior for all machines with version prior to 10.1 Signed-off-by: Hector Cao --- hw/core/machine.c | 1 + migration/migration.h | 12 ++++++++++++ migration/options.c | 3 +++ target/i386/kvm/kvm.c | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 38c949c4f2..8ad5d79cb3 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -45,6 +45,7 @@ GlobalProperty hw_compat_10_0[] =3D { { "vfio-pci", "x-migration-load-config-after-iter", "off" }, { "ramfb", "use-legacy-x86-rom", "true"}, { "vfio-pci-nohotplug", "use-legacy-x86-rom", "true" }, + { "migration", "arch-cap-always-on", "true" }, }; const size_t hw_compat_10_0_len =3D G_N_ELEMENTS(hw_compat_10_0); =20 diff --git a/migration/migration.h b/migration/migration.h index 01329bf824..5124ff3636 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -510,6 +510,18 @@ struct MigrationState { bool rdma_migration; =20 GSource *hup_source; + + /* + * This variable allows to keep the backward compatibility with QEMU (= <10.1) + * on the arch-capabilities detection. + * With the commit d3a2413 (since 10.1), the arch-capabilities feature= is gated + * with the CPUID bit (CPUID_7_0_EDX_ARCH_CAPABILITIES) instead of bei= ng always + * enabled when user requests for it. this new behavior breaks migrati= on of VMs + * created and run with older QEMU on machines without IA32_ARCH_CAPAB= ILITIES MSR, + * those VMs might have arch-capabilities enabled and break when migra= ting + * to a host with QEMU 10.1 with error : missing feature arch-capabili= ties + */ + bool arch_cap_always_on; }; =20 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state, diff --git a/migration/options.c b/migration/options.c index 4e923a2e07..3a80dba9c5 100644 --- a/migration/options.c +++ b/migration/options.c @@ -203,6 +203,9 @@ const Property migration_properties[] =3D { MIGRATION_CAPABILITY_SWITCHOVER_ACK), DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT), DEFINE_PROP_MIG_CAP("mapped-ram", MIGRATION_CAPABILITY_MAPPED_RAM), + + DEFINE_PROP_BOOL("arch-cap-always-on", MigrationState, + arch_cap_always_on, false), }; const size_t migration_properties_count =3D ARRAY_SIZE(migration_propertie= s); =20 diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 306430a052..e2ec4e6de5 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -42,6 +42,7 @@ #include "xen-emu.h" #include "hyperv.h" #include "hyperv-proto.h" +#include "migration/migration.h" =20 #include "gdbstub/enums.h" #include "qemu/host-utils.h" @@ -438,6 +439,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint= 32_t function, uint32_t ret =3D 0; uint32_t cpuid_1_edx, unused; uint64_t bitmask; + MigrationState *ms =3D migrate_get_current(); =20 cpuid =3D get_supported_cpuid(s); =20 @@ -508,7 +510,8 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint= 32_t function, * mcahines at all, do not show the fake ARCH_CAPABILITIES MSR that * KVM sets up. */ - if (!has_msr_arch_capabs || !(edx & CPUID_7_0_EDX_ARCH_CAPABILITIE= S)) { + if (!has_msr_arch_capabs + || (!(edx & CPUID_7_0_EDX_ARCH_CAPABILITIES) && (!ms->arch_cap= _always_on))) { ret &=3D ~CPUID_7_0_EDX_ARCH_CAPABILITIES; } } else if (function =3D=3D 7 && index =3D=3D 1 && reg =3D=3D R_EAX) { --=20 2.45.2 From nobody Sun Sep 28 17:12:46 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=canonical.com ARC-Seal: i=1; a=rsa-sha256; t=1757505582; cv=none; d=zohomail.com; s=zohoarc; b=j/6kyYmlZ4vNsc0dykAInyAn8/yDzylGmaqk1uElItNPZ+HNx6+87VDxtHDPfDZXQZITrFnTI3++sFBJQtTZ8H8RCOVcor6RtImoe+Dr4o9lpbTWcBLjRsx8tZCny7rIApXoKnXRQpPDave71B6EINAcUNV6O1xyuTyj+VfFd44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757505582; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=QURLz3Q90l7SA0BCrdBjAfZ2Iv5nr6PTw1OPi/HIog4=; b=Eyk9oIE3Udh5R05iOF4c5kye1nqGjeaeTWBuiq8ovmM8aAaPTxkovbLImkIQhR5s/l4d2b9j8TmLWvHcV2PYc/QAJ4ZK3SpYzvPZDcAWNEoJwcXmVz63NIThD5OjuywHk/q41x9TiU/zzsJDCTalA7IWk4FqnNtfeeerv/BPJF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175750558183140.11065320922046; Wed, 10 Sep 2025 04:59:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uwJTl-0005ug-5X; Wed, 10 Sep 2025 07:59:13 -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 1uwJTW-0005rn-Mg for qemu-devel@nongnu.org; Wed, 10 Sep 2025 07:59:00 -0400 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uwJTQ-0001wv-36 for qemu-devel@nongnu.org; Wed, 10 Sep 2025 07:58:58 -0400 Received: from localhost.localdomain (unknown [10.101.192.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 60F0F40D39 for ; Wed, 10 Sep 2025 11:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1757505509; bh=QURLz3Q90l7SA0BCrdBjAfZ2Iv5nr6PTw1OPi/HIog4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sKKMhDyRCR7jkXfPBw8Hrx3ePcu4eDMv9JVWyp38ewphNpqaAunURS0FqdK2k1ye8 4KkzicM4zdon67T79CIRB+z7CfC8tE43PVgzRonwGwQAwa7o6vJvZB0YtoWjZQ2P/C jobAtP1ptdeAqrYU0v750W0rxPpfb3xJ19BQwpZIFzxeDfd+QS4KdSnxGc7PLp5sEp WotwNOR9HtcgDD5U9Z0Mkxdq/jhW87g8a4GX9Ceoo1optxrHmqWgZxaIfcMaEw6S2r jRb9F4eQQxEA11d3GiN9MSjZcIYgXGJyE4S4bpbnTu9iF3kAUES2zLfiWI19Jdo1Es YI6Iarn9K2Agw== From: Hector Cao To: qemu-devel@nongnu.org Subject: [PATCH 2/2] target/i386: add compatibility property for pdcm feature Date: Wed, 10 Sep 2025 13:57:33 +0200 Message-ID: <20250910115733.21149-3-hector.cao@canonical.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250910115733.21149-1-hector.cao@canonical.com> References: <20250910115733.21149-1-hector.cao@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=185.125.188.120; envelope-from=hector.cao@canonical.com; helo=smtp-relay-canonical-0.canonical.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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-ZohoMail-DKIM: pass (identity @canonical.com) X-ZM-MESSAGEID: 1757505585303116600 Content-Type: text/plain; charset="utf-8" The pdcm feature is supposed to be disabled when PMU is not available. Up until v10.1, pdcm feature is enabled even when PMU is off. This behavior has been fixed but this change breaks the migration of VMs that are run with QEMU < 10.0 and expect the pdcm feature to be enabled on the destination host. This commit restores the legacy behavior for machines with version prior to 10.1 to allow the migration from older QEMU to QEMU 10.1. Signed-off-by: Hector Cao --- hw/core/machine.c | 1 + migration/migration.h | 11 +++++++++++ migration/options.c | 3 +++ target/i386/cpu.c | 17 ++++++++++++++--- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 8ad5d79cb3..535184c221 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -46,6 +46,7 @@ GlobalProperty hw_compat_10_0[] =3D { { "ramfb", "use-legacy-x86-rom", "true"}, { "vfio-pci-nohotplug", "use-legacy-x86-rom", "true" }, { "migration", "arch-cap-always-on", "true" }, + { "migration", "pdcm-on-even-without-pmu", "true" }, }; const size_t hw_compat_10_0_len =3D G_N_ELEMENTS(hw_compat_10_0); =20 diff --git a/migration/migration.h b/migration/migration.h index 5124ff3636..7d5b2aa042 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -522,6 +522,17 @@ struct MigrationState { * to a host with QEMU 10.1 with error : missing feature arch-capabili= ties */ bool arch_cap_always_on; + + /* + * This variable allows to keep the backward compatibility with QEMU (= <10.1) + * on the pdcm feature detection. The pdcm feature should be disabled = when + * PMU is not available. Prio to 10.1, there is a bug and pdcm can sti= ll be + * enabled even if PMU is off. This behavior has been fixed by the com= mit + * e68ec29 (since 10.1). + * This new behavior breaks migration of VMs that expect, with the QEMU + * (since 10.1), pdcm to be disabled. + */ + bool pdcm_on_even_without_pmu; }; =20 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state, diff --git a/migration/options.c b/migration/options.c index 3a80dba9c5..a2a95dfcc4 100644 --- a/migration/options.c +++ b/migration/options.c @@ -206,6 +206,9 @@ const Property migration_properties[] =3D { =20 DEFINE_PROP_BOOL("arch-cap-always-on", MigrationState, arch_cap_always_on, false), + + DEFINE_PROP_BOOL("pdcm-on-even-without-pmu", MigrationState, + pdcm_on_even_without_pmu, false), }; const size_t migration_properties_count =3D ARRAY_SIZE(migration_propertie= s); =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6d85149e6e..1f0f2c8dbf 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -51,6 +51,8 @@ #include "disas/capstone.h" #include "cpu-internal.h" =20 +#include "migration/migration.h" + static void x86_cpu_realizefn(DeviceState *dev, Error **errp); static void x86_cpu_get_supported_cpuid(uint32_t func, uint32_t index, uint32_t *eax, uint32_t *ebx, @@ -7839,6 +7841,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, uint32_t signature[3]; X86CPUTopoInfo *topo_info =3D &env->topo_info; uint32_t threads_per_pkg; + MigrationState *ms =3D migrate_get_current(); =20 threads_per_pkg =3D x86_threads_per_pkg(topo_info); =20 @@ -7894,6 +7897,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, /* Fixup overflow: max value for bits 23-16 is 255. */ *ebx |=3D MIN(num, 255) << 16; } + if (ms->pdcm_on_even_without_pmu) { + if (!cpu->enable_pmu) { + *ecx &=3D ~CPUID_EXT_PDCM; + } + } break; case 2: { /* cache info: needed for Pentium Pro compatibility */ const CPUCaches *caches; @@ -8892,6 +8900,7 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **err= p) FeatureWord w; int i; GList *l; + MigrationState *ms =3D migrate_get_current(); =20 for (l =3D plus_features; l; l =3D l->next) { const char *prop =3D l->data; @@ -8944,9 +8953,11 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **er= rp) } } =20 - /* PDCM is fixed1 bit for TDX */ - if (!cpu->enable_pmu && !is_tdx_vm()) { - env->features[FEAT_1_ECX] &=3D ~CPUID_EXT_PDCM; + if (!ms->pdcm_on_even_without_pmu) { + /* PDCM is fixed1 bit for TDX */ + if (!cpu->enable_pmu && !is_tdx_vm()) { + env->features[FEAT_1_ECX] &=3D ~CPUID_EXT_PDCM; + } } =20 for (i =3D 0; i < ARRAY_SIZE(feature_dependencies); i++) { --=20 2.45.2