From nobody Sun Feb 8 21:53:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605901179; cv=none; d=zohomail.com; s=zohoarc; b=XF8Edthp3/1EyMTD27p2QcsxraVBAjFBhps4gAmyLyZHUSOXwlhjQG6n0Qdn42AOFIiSNOhrdedyN68KdAgm7Gz0XwT1HoMPFlcnlFxnMoYEVj2aWEG5fwP4CGzTxS1wpgKNDlZ4D0La3Hk+HJUSEpeOB1D45QFUjfVWJmqx+ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605901179; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BIJfuoLLZXW1XXLi5xuhwZlBXJcxeuY/Nt9ML8gnfdA=; b=PMJWPLurnApwzBTvwWCQJtgGlypeV4Q9NkWjvj9oos6+RRiWBLL+cGVrS5+90nqCVDwlqrW9KVNe+2KUARtOgPPjQnzpGCK9OE3I6Gwf6VBnSiNEqMrXBjWIyGLdfEEvnNDVVBDgYHcTPw3h+kTbAZDVr5yR7ZyOiN76SgOIqAw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605901179247795.9904500664778; Fri, 20 Nov 2020 11:39:39 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-500-176Jnvn_MoOuyEZE1LBiYw-1; Fri, 20 Nov 2020 14:39:36 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ABB19100A643; Fri, 20 Nov 2020 19:39:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D1465D9D5; Fri, 20 Nov 2020 19:39:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 593931809CA8; Fri, 20 Nov 2020 19:39:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AKJdH9S023300 for ; Fri, 20 Nov 2020 14:39:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 38C585D6CF; Fri, 20 Nov 2020 19:39:17 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.40.194.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D5F7A5D6BA for ; Fri, 20 Nov 2020 19:39:13 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id E93692437F5; Fri, 20 Nov 2020 20:39:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605901178; h=from:from:sender:sender: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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BIJfuoLLZXW1XXLi5xuhwZlBXJcxeuY/Nt9ML8gnfdA=; b=KjGAUOr5Nunr+bEql3a5Dky3hzz2hXXQ7TYHknp5JNKTFGRi+kRX5B6jdzQFWtQjvSb0oy 8BAgdelH6kpbtOkcp1Ow5h09q58exxo+9+ikPHF5hVgvhsg08kq7muLi61CkJu2XRHkgRY hTusmiXcD5AGATyMzptaFxMK6qiGL4U= X-MC-Unique: 176Jnvn_MoOuyEZE1LBiYw-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH 7/8] cpu_x86: Make sure removed features are always mentioned in CPU def Date: Fri, 20 Nov 2020 20:39:06 +0100 Message-Id: <58712dd056ce8945a314fbd56871a1a1a16a82c7.1605900836.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" For backward compatibility with older versions of libvirt CPU models in our CPU map are mostly immutable. We only changed them in a few specific cases after showing it was safe. Sometimes QEMU developers realize a specific feature should not be part of a particular (or any) CPU model because it can never be enabled automatically without further configuration. But we couldn't follow them because doing so would break migration to older libvirt. If QEMU drops feature F from CPU model M because F could not be enabled automatically anyway, asking for M would never enable F. Even with older QEMU versions. Naively removing F from libvirt's definition of M would seem to work nicely on a single host. Libvirt would consider M to be compatible with hosts CPU that do not support F. However, trying to migrate domains using M without explicitly enabling or disabling F could fail, because older libvirt would think F was enabled (it is part of M there), but QEMU reports it as disabled once started. Thus we can remove such feature from a libvirt's CPU model, but we have to make sure any CPU definition using the affected model will always explicitly mention the state of the removed feature. https://bugzilla.redhat.com/show_bug.cgi?id=3D1798004 Signed-off-by: Jiri Denemark --- src/cpu/cpu_x86.c | 58 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 40bf5b68d0..2422e258ec 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -804,11 +804,37 @@ x86DataAddSignature(virCPUx86Data *data, } =20 =20 +/* + * Disables features removed from the CPU @model unless they are already + * mentioned in @cpu to make sure these features will always be explicitly + * listed in the CPU definition. + */ +static int +virCPUx86DisableRemovedFeatures(virCPUDefPtr cpu, + virCPUx86ModelPtr model) +{ + char **feat =3D model->removedFeatures; + + if (!feat) + return 0; + + while (*feat) { + if (virCPUDefAddFeatureIfMissing(cpu, *feat, VIR_CPU_FEATURE_DISAB= LE) < 0) + return -1; + + feat++; + } + + return 0; +} + + static virCPUDefPtr x86DataToCPU(const virCPUx86Data *data, virCPUx86ModelPtr model, virCPUx86MapPtr map, - virDomainCapsCPUModelPtr hvModel) + virDomainCapsCPUModelPtr hvModel, + virCPUType cpuType) { g_autoptr(virCPUDef) cpu =3D NULL; g_auto(virCPUx86Data) copy =3D VIR_CPU_X86_DATA_INIT; @@ -851,6 +877,13 @@ x86DataToCPU(const virCPUx86Data *data, x86DataToCPUFeatures(cpu, VIR_CPU_FEATURE_DISABLE, &modelData, map= )) return NULL; =20 + if (cpuType =3D=3D VIR_CPU_TYPE_GUEST) { + if (virCPUx86DisableRemovedFeatures(cpu, model) < 0) + return NULL; + } + + cpu->type =3D cpuType; + return g_steal_pointer(&cpu); } =20 @@ -2197,9 +2230,9 @@ x86Decode(virCPUDefPtr cpu, continue; } =20 - if (!(cpuCandidate =3D x86DataToCPU(&data, candidate, map, hvModel= ))) + if (!(cpuCandidate =3D x86DataToCPU(&data, candidate, map, hvModel, + cpu->type))) return -1; - cpuCandidate->type =3D cpu->type; =20 if ((rc =3D x86DecodeUseCandidate(model, cpuModel, candidate, cpuCandidate, @@ -2962,6 +2995,7 @@ virCPUx86Update(virCPUDefPtr guest, bool relative) { g_autoptr(virCPUx86Model) model =3D NULL; + virCPUx86ModelPtr guestModel; virCPUx86MapPtr map; size_t i; =20 @@ -2998,6 +3032,15 @@ virCPUx86Update(virCPUDefPtr guest, } } =20 + if (!(guestModel =3D x86ModelFind(map, guest->model))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown CPU model %s"), guest->model); + return -1; + } + + if (virCPUx86DisableRemovedFeatures(guest, guestModel) < 0) + return -1; + return 0; } =20 @@ -3067,6 +3110,9 @@ virCPUx86UpdateLive(virCPUDefPtr cpu, } } =20 + if (virCPUx86DisableRemovedFeatures(cpu, model) < 0) + return -1; + virBufferTrim(&bufAdded, ","); virBufferTrim(&bufRemoved, ","); =20 @@ -3190,6 +3236,7 @@ virCPUx86ExpandFeatures(virCPUDefPtr cpu) } =20 model =3D x86ModelCopy(model); + if (x86DataToCPUFeatures(expanded, host ? -1 : VIR_CPU_FEATURE_REQUIRE, &model->data, map) < 0) return -1; @@ -3206,6 +3253,11 @@ virCPUx86ExpandFeatures(virCPUDefPtr cpu) return -1; } =20 + if (!host) { + if (virCPUx86DisableRemovedFeatures(expanded, model) < 0) + return -1; + } + virCPUDefFreeModel(cpu); =20 return virCPUDefCopyModel(cpu, expanded, false); --=20 2.29.2