From nobody Mon Feb 9 10:32:21 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1713357471257178.08880043877252; Wed, 17 Apr 2024 05:37:51 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 361B31BD2; Wed, 17 Apr 2024 08:37:50 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C1C411B54; Wed, 17 Apr 2024 08:36:47 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1376A1AD5; Wed, 17 Apr 2024 08:36:42 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 097891C08 for ; Wed, 17 Apr 2024 08:36:28 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-Y65vjcULOwCbulGvXmrS0g-1; Wed, 17 Apr 2024 08:36:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id E488588CE81 for ; Wed, 17 Apr 2024 12:36:25 +0000 (UTC) Received: from orkuz (unknown [10.45.224.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B5D21121306 for ; Wed, 17 Apr 2024 12:36:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: Y65vjcULOwCbulGvXmrS0g-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH v2 1/4] qemu: Fix migration with custom XML Date: Wed, 17 Apr 2024 14:36:08 +0200 Message-ID: <05ac016ff3a3cd54fc85748f8f081c2449a23af4.1713357265.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: E5SDQ3IJWCD4HLZS4JQZED55LEMOS32F X-Message-ID-Hash: E5SDQ3IJWCD4HLZS4JQZED55LEMOS32F X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1713357472116100001 Ages ago origCPU in domain private data was introduced to provide backward compatibility when migrating to an old libvirt, which did not support fetching updated CPU definition from QEMU. Thus origCPU will contain the original CPU definition before such update. But only if the update actually changed anything. Let's always fill origCPU with the original definition when starting a domain so that we can rely on it being always set, even if it matches the updated definition. This fixes migration or save operations with custom domain XML after commit v10.1.0-88-g14d3517410, which expected origCPU to be always set to the CPU definition from inactive XML to check features explicitly requested by a user. https://issues.redhat.com/browse/RHEL-30622 Signed-off-by: Jiri Denemark Tested-by: Han Han Reviewed-by: Peter Krempa --- Notes: Version 2: - virCPUDefCopy never returns NULL - do not remove !*origCPU check in qemuDomainFixupCPUs - make sure origCPU is set when reconnecting to running domains src/qemu/qemu_domain.c | 33 ++++++++++++++++++++------------- src/qemu/qemu_process.c | 19 +++++++------------ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6b869797a8..d91c7d478b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10995,12 +10995,13 @@ virSaveCookieCallbacks virQEMUDriverDomainSaveCoo= kie =3D { * @vm: domain which is being started * @cpu: CPU updated when the domain was running previously (before migrat= ion, * snapshot, or save) - * @origCPU: where to store the original CPU from vm->def in case @cpu was - * used instead + * @origCPU: where to store the original CPU from vm->def * - * Replace the CPU definition with the updated one when QEMU is new enough= to - * allow us to check extra features it is about to enable or disable when - * starting a domain. The original CPU is stored in @origCPU. + * Save the original CPU definition from inactive XML in @origCPU so that = we + * can safely update it and still be able to check what exactly a user ask= ed + * for. The domain definition will either contain a copy of the original C= PU + * definition or a copy of @cpu in case the domain was already running and + * we're just restoring a saved state or preparing for incoming migration. * * Returns 0 on success, -1 on error. */ @@ -11013,18 +11014,24 @@ qemuDomainUpdateCPU(virDomainObj *vm, =20 *origCPU =3D NULL; =20 - if (!cpu || !vm->def->cpu || - !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSIO= N) || - virCPUDefIsEqual(vm->def->cpu, cpu, false)) + if (!vm->def->cpu) return 0; =20 - if (!(cpu =3D virCPUDefCopy(cpu))) - return -1; + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSIO= N)) + return 0; + + /* nothing to do if only topology part of CPU def is used */ + if (vm->def->cpu->mode =3D=3D VIR_CPU_MODE_CUSTOM && !vm->def->cpu->mo= del) + return 0; + + VIR_DEBUG("Replacing CPU definition"); =20 - VIR_DEBUG("Replacing CPU def with the updated one"); + *origCPU =3D g_steal_pointer(&vm->def->cpu); =20 - *origCPU =3D vm->def->cpu; - vm->def->cpu =3D cpu; + if (cpu) + vm->def->cpu =3D virCPUDefCopy(cpu); + else + vm->def->cpu =3D virCPUDefCopy(*origCPU); =20 return 0; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index e4bcb628cf..f3e295ccf0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4437,8 +4437,6 @@ qemuProcessUpdateLiveGuestCPU(virDomainObj *vm, virCPUData *disabled) { virDomainDef *def =3D vm->def; - qemuDomainObjPrivate *priv =3D vm->privateData; - g_autoptr(virCPUDef) orig =3D NULL; int rc; =20 if (!enabled) @@ -4449,19 +4447,11 @@ qemuProcessUpdateLiveGuestCPU(virDomainObj *vm, !def->cpu->model)) return 0; =20 - orig =3D virCPUDefCopy(def->cpu); - - if ((rc =3D virCPUUpdateLive(def->os.arch, def->cpu, enabled, disabled= )) < 0) { + if ((rc =3D virCPUUpdateLive(def->os.arch, def->cpu, enabled, disabled= )) < 0) return -1; - } else if (rc =3D=3D 0) { - /* Store the original CPU in priv if QEMU changed it and we didn't - * get the original CPU via migration, restore, or snapshot revert. - */ - if (!priv->origCPU && !virCPUDefIsEqual(def->cpu, orig, false)) - priv->origCPU =3D g_steal_pointer(&orig); =20 + if (rc =3D=3D 0) def->cpu->check =3D VIR_CPU_CHECK_FULL; - } =20 return 0; } @@ -9147,6 +9137,11 @@ qemuProcessReconnect(void *opaque) =20 qemuDomainVcpuPersistOrder(obj->def); =20 + /* Make sure priv->origCPU is always set. */ + if (!priv->origCPU && + qemuDomainUpdateCPU(obj, NULL, &priv->origCPU) < 0) + goto error; + if (qemuProcessRefreshCPU(driver, obj) < 0) goto error; =20 --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org