From nobody Sun Feb 8 20:17:35 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 1710263563107637.151740110893; Tue, 12 Mar 2024 10:12:43 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BD8092113; Tue, 12 Mar 2024 13:12:41 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 114501F43; Tue, 12 Mar 2024 13:07:27 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D3EEA1A98; Tue, 12 Mar 2024 13:07:12 -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 4C68D1A98 for ; Tue, 12 Mar 2024 13:07:12 -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-304-yeotrBQ7NruDxdu3scrblA-1; Tue, 12 Mar 2024 13:07:10 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 12189800269 for ; Tue, 12 Mar 2024 17:07:09 +0000 (UTC) Received: from orkuz (unknown [10.45.224.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id C837FC017A2 for ; Tue, 12 Mar 2024 17:07:08 +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.8 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: yeotrBQ7NruDxdu3scrblA-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH 04/22] qemu: domain: Drop added features from migratable CPU Date: Tue, 12 Mar 2024 18:06:44 +0100 Message-ID: <2a42ad12a0de0d16b59351821cda203e1c36e86b.1710262622.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 3KK4WM4CZXV7M5PYQHTJVJONCZBB34UA X-Message-ID-Hash: 3KK4WM4CZXV7M5PYQHTJVJONCZBB34UA 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: 1710263564632100001 Features marked with added=3D'yes' in CPU model definitions have to be removed before migration, otherwise older libvirt would complain about unknown CPU features. We only do this for features that were enabled for a given CPU model even with older libvirt, which just ignored the features. And only for features we added ourselves when updating CPU definition during domain startup, that is we do not remove features which were explicitly mentioned by a user. That said, this is not the safest thing we could do, but it's effectively the same thing we did before the affected features were added: we ignored them completely on both sides of migration. Signed-off-by: Jiri Denemark Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 50 ++++++++++++++++++++++++++++++-- src/qemu/qemu_domain.h | 3 +- src/qemu/qemu_migration_cookie.c | 5 +++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 31a6509166..535612000d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -66,6 +66,7 @@ #include "backup_conf.h" #include "virutil.h" #include "virsecureerase.h" +#include "cpu/cpu_x86.h" =20 #include #include @@ -6643,10 +6644,36 @@ qemuDomainDefCopy(virQEMUDriver *driver, } =20 =20 +typedef struct { + const char * const *added; + GStrv keep; +} qemuDomainDropAddedCPUFeaturesData; + + +static bool +qemuDomainDropAddedCPUFeatures(const char *name, + virCPUFeaturePolicy policy G_GNUC_UNUSED, + void *opaque) +{ + qemuDomainDropAddedCPUFeaturesData *data =3D opaque; + + if (!g_strv_contains(data->added, name)) + return true; + + if (data->keep && g_strv_contains((const char **) data->keep, name)) + return true; + + return false; +} + + int qemuDomainMakeCPUMigratable(virArch arch, - virCPUDef *cpu) + virCPUDef *cpu, + virCPUDef *origCPU) { + qemuDomainDropAddedCPUFeaturesData data =3D { 0 }; + if (cpu->mode !=3D VIR_CPU_MODE_CUSTOM || !cpu->model || !ARCH_IS_X86(arch)) @@ -6664,6 +6691,25 @@ qemuDomainMakeCPUMigratable(virArch arch, return -1; } =20 + if (virCPUx86GetAddedFeatures(cpu->model, &data.added) < 0) + return -1; + + /* Drop features marked as added in a cpu model, but only + * when they are not mentioned in origCPU, i.e., when they were not + * explicitly mentioned by the user. + */ + if (data.added) { + g_auto(GStrv) keep =3D NULL; + + if (origCPU) { + keep =3D virCPUDefListFeatures(origCPU); + data.keep =3D keep; + } + + if (virCPUDefFilterFeatures(cpu, qemuDomainDropAddedCPUFeatures, &= data) < 0) + return -1; + } + return 0; } =20 @@ -6843,7 +6889,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriver *driver, } =20 if (def->cpu && - qemuDomainMakeCPUMigratable(def->os.arch, def->cpu) < 0) + qemuDomainMakeCPUMigratable(def->os.arch, def->cpu, origCPU) <= 0) return -1; =20 /* Old libvirt doesn't understand