From nobody Sun Feb 8 20:23:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1605901204; cv=none; d=zohomail.com; s=zohoarc; b=bAhsRQr4KwhVM9qq6ybAZq/bSA3Uq7/+uIEQz1a32J439DwiuVHazWrr6TmsEHNWNxcSM0gW6ebOjVTBAh3168vbXchPw+wTFllcKMwH7t6YeIx7h0bmDTAqTZdaZHYywEojzZFPqJVoXoK5hRULNPJax4OhUUNpnUdAr5uGvvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605901204; 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=FhIazNmVOeLsE5wClTB/qpqgVA2PgquuBlnfG/7mJnk=; b=Dd/4t1xUzdhzHn7Lk9f73JeKjg7k2DJJn4GtckfwWveBgVND/P2g7yZhofmDJ/DR/HJ+Mg9/dBmqN8rCb2NCWhK72MDolSTUlTyz2ShxDVAXmAjog/B6Db4XNY+eY0t2qtL094RJwwmHBKwzb/7/8P3cSPIm+SVw48FCBW3HN1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605901204697503.5510865247196; Fri, 20 Nov 2020 11:40:04 -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-304-FoFEdE4tMIWZ2w80Ad8lMw-1; Fri, 20 Nov 2020 14:39:33 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D41DD100A646; Fri, 20 Nov 2020 19:39:27 +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 B2EF66085D; Fri, 20 Nov 2020 19:39:27 +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 7ED1E1809CA4; Fri, 20 Nov 2020 19:39:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AKJdD8h023263 for ; Fri, 20 Nov 2020 14:39:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1F4D11E5; Fri, 20 Nov 2020 19:39:13 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.40.194.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDA1D13470 for ; Fri, 20 Nov 2020 19:39:09 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id E39A62437F1; 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=1605901203; 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=FhIazNmVOeLsE5wClTB/qpqgVA2PgquuBlnfG/7mJnk=; b=hXcDdpdZv7dMcMMS8nkvcVteAFTbK/oLj8hxbRbglJnPXl1TedbNzteg5frCaxTtzykaOh GuAbisKTgLmFhHEf/iOKJKLCILtLfPuuwbXEgzyn6My2k1asfyHffTLir/0FpBlfq20Fj2 0Bm7ERETbuSlguzFhfXvicBFwf2GX4o= X-MC-Unique: FoFEdE4tMIWZ2w80Ad8lMw-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH 4/8] cpu: Run arch specific code for virCPUUpdate for all custom CPUs Date: Fri, 20 Nov 2020 20:39:03 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.13 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" Until now, the function returned immediately when the guest CPU definition did not use optional features or minimum match. Clearly, there's nothing to be updated according to the host CPU in this case, but the arch specific code may still want to do some compatibility updates based on the model and features used in the guest CPU definition. Signed-off-by: Jiri Denemark --- src/cpu/cpu.c | 52 +++++++++++++++++++++++++-------------------- src/cpu/cpu.h | 3 ++- src/cpu/cpu_arm.c | 5 +++-- src/cpu/cpu_ppc64.c | 3 ++- src/cpu/cpu_s390.c | 6 +++++- src/cpu/cpu_x86.c | 6 +++++- 6 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index bf94811960..44094bd0df 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -538,12 +538,11 @@ virCPUBaseline(virArch arch, * @guest: guest CPU definition to be updated * @host: host CPU definition * - * Updates @guest CPU definition according to @host CPU. This is required = to - * support guest CPU definitions specified relatively to host CPU, such as - * CPUs with VIR_CPU_MODE_CUSTOM and optional features or - * VIR_CPU_MATCH_MINIMUM, or CPUs with VIR_CPU_MODE_HOST_MODEL. - * When the guest CPU was not specified relatively, the function does noth= ing - * and returns success. + * Updates @guest CPU definition possibly taking @host CPU into account. T= his + * is required for maintaining compatibility with older libvirt releases o= r to + * support guest CPU definitions specified relatively to host CPU, such as= CPUs + * with VIR_CPU_MODE_CUSTOM and optional features or VIR_CPU_MATCH_MINIMUM= , or + * CPUs with VIR_CPU_MODE_HOST_MODEL. * * Returns 0 on success, -1 on error. */ @@ -553,6 +552,7 @@ virCPUUpdate(virArch arch, const virCPUDef *host) { struct cpuArchDriver *driver; + bool relative; =20 VIR_DEBUG("arch=3D%s, guest=3D%p mode=3D%s model=3D%s, host=3D%p model= =3D%s", virArchToString(arch), guest, virCPUModeTypeToString(guest->= mode), @@ -561,30 +561,36 @@ virCPUUpdate(virArch arch, if (!(driver =3D cpuGetSubDriver(arch))) return -1; =20 - if (guest->mode =3D=3D VIR_CPU_MODE_HOST_PASSTHROUGH) + switch ((virCPUMode) guest->mode) { + case VIR_CPU_MODE_HOST_PASSTHROUGH: return 0; =20 - if (guest->mode =3D=3D VIR_CPU_MODE_CUSTOM && - guest->match !=3D VIR_CPU_MATCH_MINIMUM) { - size_t i; - bool optional =3D false; + case VIR_CPU_MODE_HOST_MODEL: + relative =3D true; + break; =20 - for (i =3D 0; i < guest->nfeatures; i++) { - if (guest->features[i].policy =3D=3D VIR_CPU_FEATURE_OPTIONAL)= { - optional =3D true; - break; + case VIR_CPU_MODE_CUSTOM: + if (guest->match =3D=3D VIR_CPU_MATCH_MINIMUM) { + relative =3D true; + } else { + size_t i; + + relative =3D false; + for (i =3D 0; i < guest->nfeatures; i++) { + if (guest->features[i].policy =3D=3D VIR_CPU_FEATURE_OPTIO= NAL) { + relative =3D true; + break; + } } } + break; =20 - if (!optional) - return 0; + case VIR_CPU_MODE_LAST: + default: + virReportEnumRangeError(virCPUMode, guest->mode); + return -1; } =20 - /* We get here if guest CPU is either - * - host-model - * - custom with minimum match - * - custom with optional features - */ if (!driver->update) { virReportError(VIR_ERR_NO_SUPPORT, _("cannot update guest CPU for %s architecture"), @@ -592,7 +598,7 @@ virCPUUpdate(virArch arch, return -1; } =20 - if (driver->update(guest, host) < 0) + if (driver->update(guest, host, relative) < 0) return -1; =20 VIR_DEBUG("model=3D%s", NULLSTR(guest->model)); diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index cc2d132275..ff4fb7e103 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -79,7 +79,8 @@ typedef virCPUDefPtr =20 typedef int (*virCPUArchUpdate)(virCPUDefPtr guest, - const virCPUDef *host); + const virCPUDef *host, + bool relative); =20 typedef int (*virCPUArchUpdateLive)(virCPUDefPtr cpu, diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 31997b59cd..8a408a324a 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -415,11 +415,12 @@ virCPUarmGetMap(void) =20 static int virCPUarmUpdate(virCPUDefPtr guest, - const virCPUDef *host) + const virCPUDef *host, + bool relative) { g_autoptr(virCPUDef) updated =3D NULL; =20 - if (guest->mode !=3D VIR_CPU_MODE_HOST_MODEL) + if (!relative || guest->mode !=3D VIR_CPU_MODE_HOST_MODEL) return 0; =20 if (!host) { diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index 555eeecbe7..d71d147207 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -614,7 +614,8 @@ virCPUppc64GetHost(virCPUDefPtr cpu, =20 static int virCPUppc64Update(virCPUDefPtr guest, - const virCPUDef *host G_GNUC_UNUSED) + const virCPUDef *host G_GNUC_UNUSED, + bool relative G_GNUC_UNUSED) { /* * - host-passthrough doesn't even get here diff --git a/src/cpu/cpu_s390.c b/src/cpu/cpu_s390.c index c1c5686244..17321dc04a 100644 --- a/src/cpu/cpu_s390.c +++ b/src/cpu/cpu_s390.c @@ -43,11 +43,15 @@ virCPUs390Compare(virCPUDefPtr host G_GNUC_UNUSED, =20 static int virCPUs390Update(virCPUDefPtr guest, - const virCPUDef *host) + const virCPUDef *host, + bool relative) { g_autoptr(virCPUDef) updated =3D NULL; size_t i; =20 + if (!relative) + return 0; + if (guest->mode =3D=3D VIR_CPU_MODE_CUSTOM) { if (guest->match =3D=3D VIR_CPU_MATCH_MINIMUM) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 0e533c62e1..72f17070e1 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2936,12 +2936,16 @@ x86UpdateHostModel(virCPUDefPtr guest, =20 static int virCPUx86Update(virCPUDefPtr guest, - const virCPUDef *host) + const virCPUDef *host, + bool relative) { g_autoptr(virCPUx86Model) model =3D NULL; virCPUx86MapPtr map; size_t i; =20 + if (!relative) + return 0; + if (!host) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unknown host CPU model")); --=20 2.29.2