From nobody Sat Feb 7 06:57:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1571153744; cv=none; d=zoho.com; s=zohoarc; b=bLoLE3N8Nt7609pzJIx4y03UHnHahQjWZTBxPvtb4jnsncCpe5RUGslkVuLwrymOYcJVgxu7kDAl6JWA76TTqSelbzTqJWJsvMKk//a4tZicvmUeVMEn9RUKWtAhk2lgXIgk5f7YkoYJNkX5WTfVzx22J/nLWM5OQiw9uW1IMis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571153744; 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=HAF010+M3Y3MDRHg3JUlyNSj8ZyNOWnM7CLo4whDi90=; b=HCwc3Fd8EM/9nJ3dW/gyvz6ODp4lUQBlrWngFQaBopyTOdQv4OvwCSf5am6Qp9Ld9nGP7DtwwCToD3VyzhpMD1/DpmwhhuXxMGyV0lTATCJKgsIa5OIGxQr5ypFlzQAuSLx6vpzxoFTEyn0HRoZesFKqHXgzcPzmHzYuFd+q2ZQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1571153744841100.92967034959747; Tue, 15 Oct 2019 08:35:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BB9F302C08E; Tue, 15 Oct 2019 15:35:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F61C60C80; Tue, 15 Oct 2019 15:35:43 +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 C755662D10; Tue, 15 Oct 2019 15:35:42 +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 x9FFZEla024626 for ; Tue, 15 Oct 2019 11:35:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE8D45D6B0; Tue, 15 Oct 2019 15:35:14 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.188]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DB3F5D6A9 for ; Tue, 15 Oct 2019 15:35:14 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 2B83E101A8A; Tue, 15 Oct 2019 17:35:09 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 15 Oct 2019 17:34:41 +0200 Message-Id: <675aa339fe8214acd99c46938c520f5437c4b1a3.1571152057.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 Subject: [libvirt] [PATCH v2 05/31] qemu: Copy CPU models in virQEMUCapsGetCPUDefinitions 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 15 Oct 2019 15:35:43 +0000 (UTC) Rather than returning a direct pointer the list stored in qemuCaps the function now creates a new copy of the CPU models list. The main purpose of this seemingly useless change is to update callers to free the result returned by virQEMUCapsGetCPUDefinitions because the internals of this function will change significantly in the following patches. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- Notes: Version 2: - no change src/qemu/qemu_capabilities.c | 23 ++++++++++++++++++----- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_process.c | 7 +++++-- tests/cputest.c | 1 - 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 14939fc91d..a40bf99aa3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1891,10 +1891,17 @@ virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps, virDomainVirtType type) { + virDomainCapsCPUModelsPtr cpuModels; + if (type =3D=3D VIR_DOMAIN_VIRT_KVM) - return qemuCaps->kvmCPUModels; + cpuModels =3D qemuCaps->kvmCPUModels; else - return qemuCaps->tcgCPUModels; + cpuModels =3D qemuCaps->tcgCPUModels; + + if (!cpuModels) + return NULL; + + return virDomainCapsCPUModelsCopy(cpuModels); } =20 =20 @@ -3125,6 +3132,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps, virCPUDefPtr cpu, bool migratable) { + VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels =3D NULL; virCPUDataPtr data =3D NULL; int ret =3D -1; =20 @@ -3134,7 +3142,9 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps, if (!(data =3D virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratab= le))) goto cleanup; =20 - if (cpuDecode(cpu, data, virQEMUCapsGetCPUDefinitions(qemuCaps, type))= < 0) + cpuModels =3D virQEMUCapsGetCPUDefinitions(qemuCaps, type); + + if (cpuDecode(cpu, data, cpuModels) < 0) goto cleanup; =20 ret =3D 0; @@ -3217,10 +3227,13 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, if ((rc =3D virQEMUCapsInitCPUModel(qemuCaps, type, cpu, false)) < 0) { goto error; } else if (rc =3D=3D 1) { + VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels =3D NULL; + VIR_DEBUG("No host CPU model info from QEMU; probing host CPU dire= ctly"); =20 - hostCPU =3D virQEMUCapsProbeHostCPU(hostArch, - virQEMUCapsGetCPUDefinitions(qem= uCaps, type)); + cpuModels =3D virQEMUCapsGetCPUDefinitions(qemuCaps, type); + hostCPU =3D virQEMUCapsProbeHostCPU(hostArch, cpuModels); + if (!hostCPU || virCPUDefCopyModelFilter(cpu, hostCPU, true, virQEMUCapsCPUFilterFeatures, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6ce6348593..15c69667a5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13913,7 +13913,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, virQEMUCapsPtr qemuCaps =3D NULL; virArch arch; virDomainVirtType virttype; - virDomainCapsCPUModelsPtr cpuModels; + VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels =3D NULL; bool migratable; virCPUDefPtr cpu =3D NULL; char *cpustr =3D NULL; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 9c50c4a1d8..58192612b0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6122,6 +6122,8 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, =20 /* nothing to update for host-passthrough */ if (def->cpu->mode !=3D VIR_CPU_MODE_HOST_PASSTHROUGH) { + VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels =3D NULL; + if (def->cpu->check =3D=3D VIR_CPU_CHECK_PARTIAL && virCPUCompare(caps->host.arch, virQEMUCapsGetHostModel(qemuCaps, def->virtType, @@ -6134,8 +6136,9 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, VIR_QEMU_CAPS_HOST_CPU_MI= GRATABLE)) < 0) return -1; =20 - if (virCPUTranslate(def->os.arch, def->cpu, - virQEMUCapsGetCPUDefinitions(qemuCaps, def->vi= rtType)) < 0) + cpuModels =3D virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType= ); + + if (virCPUTranslate(def->os.arch, def->cpu, cpuModels) < 0) return -1; =20 def->cpu->fallback =3D VIR_CPU_FALLBACK_FORBID; diff --git a/tests/cputest.c b/tests/cputest.c index 7f47e3b601..3aa8fd7bf3 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -551,7 +551,6 @@ cpuTestGetCPUModels(const struct data *data, return -1; =20 *models =3D virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM= ); - virObjectRef(*models); =20 virObjectUnref(qemuCaps); =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list