From nobody Mon Sep 16 19:18:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) 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 1719237786765508.0407197358411; Mon, 24 Jun 2024 07:03:06 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7A6821353; Mon, 24 Jun 2024 10:03:05 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E4D3F135D; Mon, 24 Jun 2024 10:02:45 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7D20810F5; Mon, 24 Jun 2024 10:02:42 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 EB50ADB6 for ; Mon, 24 Jun 2024 10:02:41 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-471-VsXoU6EEMWq2PCGVEZa84w-1; Mon, 24 Jun 2024 10:02:39 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A89AF1955E7F for ; Mon, 24 Jun 2024 14:02:38 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 671F33000219 for ; Mon, 24 Jun 2024 14:02:37 +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=3.0 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719237761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GJeu5GpT8qVDcreNvvTfS3mKSbYyuyOWbr+Dj46uyI8=; b=JXmN1IcWrUE9dJwBLxOf7ZaF7uQmG1cozj2q4u5ebCWCLEOyW6GgXpRkmde5ev3tIbcgS8 MdiclcWBvRf5ULacLkQEe8tNMyuXN60r+8PWAFlUg8t9aORQfcBXSFXBDh9qxmddqm91Zi eaG1dVH7QQSOI+LdfLw9qL6Jhvvg+zM= X-MC-Unique: VsXoU6EEMWq2PCGVEZa84w-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH] qemu: Fix migration with disabled vmx-* CPU features Date: Mon, 24 Jun 2024 16:02:34 +0200 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4UF33NRT6SOSMIWR6FZ744KGRPYXU6NO X-Message-ID-Hash: 4UF33NRT6SOSMIWR6FZ744KGRPYXU6NO 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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1719237787494100001 Content-Type: text/plain; charset="utf-8" When starting a domain on a host which lacks a vmx-* CPU feature which is expected to be enabled by the CPU model specified in the domain XML, libvirt properly marks such feature as disabled in the active domain XML. But migrating the domain to a similar host which lacks the same vmx-* feature will fail with libvirt reporting the feature as missing. This is because of a bug in the hack ensuring backward compatibility libvirt running on the destination thinks the missing feature is expected to be enabled. https://issues.redhat.com/browse/RHEL-40899 Fixes: v10.1.0-85-g5fbfa5ab8a Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/cpu/cpu_x86.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 7a70eed9e7..fcbce0ec46 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -3021,10 +3021,7 @@ virCPUx86UpdateLive(virCPUDef *cpu, if (!(map =3D virCPUx86GetMap())) return -1; =20 - if (!(model =3D x86ModelFromCPU(cpu, map, -1))) - return -1; - - if (hostPassthrough && + if (!(model =3D x86ModelFromCPU(cpu, map, -1)) || !(modelDisabled =3D x86ModelFromCPU(cpu, map, VIR_CPU_FEATURE_DISA= BLE))) return -1; =20 @@ -3037,12 +3034,19 @@ virCPUx86UpdateLive(virCPUDef *cpu, for (i =3D 0; i < map->nfeatures; i++) { virCPUx86Feature *feature =3D map->features[i]; virCPUFeaturePolicy expected =3D VIR_CPU_FEATURE_LAST; + bool explicit =3D false; + bool ignore =3D false; =20 - if (x86DataIsSubset(&model->data, &feature->data)) + if (x86DataIsSubset(&model->data, &feature->data)) { + explicit =3D true; expected =3D VIR_CPU_FEATURE_REQUIRE; - else if (!hostPassthrough || - x86DataIsSubset(&modelDisabled->data, &feature->data)) + } else if (x86DataIsSubset(&modelDisabled->data, &feature->data)) { + explicit =3D true; + expected =3D VIR_CPU_FEATURE_DISABLE; + } else if (!hostPassthrough) { + /* implicitly disabled */ expected =3D VIR_CPU_FEATURE_DISABLE; + } =20 if (x86DataIsSubset(&enabled, &feature->data) && x86DataIsSubset(&disabled, &feature->data)) { @@ -3052,30 +3056,36 @@ virCPUx86UpdateLive(virCPUDef *cpu, return -1; } =20 + /* Features enabled or disabled by the hypervisor are ignored by + * check=3D'full' in case they were added to the model later and n= ot + * explicitly mentioned in the CPU definition. This matches how li= bvirt + * behaved before the features were added. + */ + if (!explicit && + g_strv_contains((const char **) model->addedFeatures, feature-= >name)) + ignore =3D true; + if (expected =3D=3D VIR_CPU_FEATURE_DISABLE && x86DataIsSubset(&enabled, &feature->data)) { VIR_DEBUG("Feature '%s' enabled by the hypervisor", feature->n= ame); =20 - /* Extra features enabled by the hypervisor are ignored by - * check=3D'full' in case they were added to the model later f= or - * backward compatibility with the older definition of the mod= el. - */ - if (cpu->check =3D=3D VIR_CPU_CHECK_FULL && - !g_strv_contains((const char **) model->addedFeatures, fea= ture->name)) { + if (cpu->check =3D=3D VIR_CPU_CHECK_FULL && !ignore) virBufferAsprintf(&bufAdded, "%s,", feature->name); - } else { + else virCPUDefUpdateFeature(cpu, feature->name, VIR_CPU_FEATURE= _REQUIRE); - } } =20 if (x86DataIsSubset(&disabled, &feature->data) || (expected =3D=3D VIR_CPU_FEATURE_REQUIRE && !x86DataIsSubset(&enabled, &feature->data))) { VIR_DEBUG("Feature '%s' disabled by the hypervisor", feature->= name); - if (cpu->check =3D=3D VIR_CPU_CHECK_FULL) + + if (cpu->check =3D=3D VIR_CPU_CHECK_FULL && !ignore) { virBufferAsprintf(&bufRemoved, "%s,", feature->name); - else + } else { virCPUDefUpdateFeature(cpu, feature->name, VIR_CPU_FEATURE= _DISABLE); + x86DataSubtract(&disabled, &feature->data); + } } } =20 --=20 2.45.1