From nobody Fri Dec 12 15:15:59 2025 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1761827376; cv=none; d=zohomail.com; s=zohoarc; b=j3seb/5czKUEd0GW58n/VpLw3FKS1vWTnRRF9nI9JUY5jboaPV2DEyxa5Rl8BKq9vEppbaSJ1AFHfHVywcfo1OVqh90yxgxQBNegO9f+ESfGe3QhnVwVjzW1xL+HRZ1J9pD4ZG7yDSnfnWSsPEW91SoD/dX0i+Xirt+YZNBJH/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761827376; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=5GzGgXvYPsbH5/AzCwLZame+PSmZe5QmWL8hO2gHziE=; b=S+Xz7l/GPMy8zw1bNtEJ3f+OX/7/iCtopk5//RFMwt4MJC+evg2b5vnS/+GOw5b+xZ5TlSRGpBX0qMHL5SJpDkSD3cM1L4WHKDS5JuLyY5+XFbk4WJrnkrzblAXgXXK4/x2fefZfTpwbLIOscZo4nQ9FMKs9GYuWdIrW6p0ZOqQ= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1761827376042290.8481116783772; Thu, 30 Oct 2025 05:29:36 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CA72D41B99; Thu, 30 Oct 2025 08:29:32 -0400 (EDT) Received: from [172.19.199.29] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 8ADAE41C62; Thu, 30 Oct 2025 08:27:41 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id BE14C3F308; Thu, 30 Oct 2025 08:27:22 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E495641A35 for ; Thu, 30 Oct 2025 08:27:21 -0400 (EDT) Received: from mx-prod-mc-03.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-508-DNkKSC3NPl2Jd2AEAVGH4A-1; Thu, 30 Oct 2025 08:27:20 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 586151955F11 for ; Thu, 30 Oct 2025 12:27:19 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D765919560A2 for ; Thu, 30 Oct 2025 12:27:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761827241; 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: in-reply-to:in-reply-to:references:references; bh=5GzGgXvYPsbH5/AzCwLZame+PSmZe5QmWL8hO2gHziE=; b=VD48D8cE89fEW2fah+xoNd02Swi72KUKJdoDzs02XaBcUxxKNr2Nu4jLj/5uuUw/akCpVa X31W8TPTPsKjpys4zdBfcmHJDhiWwg5mrkSBcUfYS01YorqyXPtwZXO7KD7p3HsokMjcu8 9qj81t2AT/kIhDBNpEiK8yqW/fzxAF8= X-MC-Unique: DNkKSC3NPl2Jd2AEAVGH4A-1 X-Mimecast-MFC-AGG-ID: DNkKSC3NPl2Jd2AEAVGH4A_1761827239 To: devel@lists.libvirt.org Subject: [PATCH 1/6] cpu_conf: Make virCPUDefFilterFeatures return void Date: Thu, 30 Oct 2025 13:27:09 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: SbXg8pqRHEDvvhov88jcZiBgoiv9Ozf2E3f8uCBko88_1761827239 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LVNT2BEGJ2GSTOHOEQVOY6QXSG64GUKH X-Message-ID-Hash: LVNT2BEGJ2GSTOHOEQVOY6QXSG64GUKH X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jiri Denemark via Devel Reply-To: Jiri Denemark X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1761827379203154100 Content-Type: text/plain; charset="utf-8" From: Jiri Denemark The only thing that can fail inside virCPUDefFilterFeatures is VIR_DELETE_ELEMENT_INPLACE macro. The macro just calls virDeleteElementsN, which reports a warning when all elements to be removed are not within the array bounds and returns -1. The function succeeds otherwise. But since VIR_DELETE_ELEMENT_INPLACE sets the number of elements to be removed to 1 and we call it with i < cpu->nfeatures, the safety check in virDeleteElementsN will never fail. And even if we theoretically called it with wrong arguments, it just wouldn't do anything. Thus we can safely assume VIR_DELETE_ELEMENT_INPLACE always succeeds in virCPUDefFilterFeatures and avoid reporting any errors to simplify callers. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/conf/cpu_conf.c | 9 ++++----- src/conf/cpu_conf.h | 2 +- src/qemu/qemu_capabilities.c | 15 ++++++--------- src/qemu/qemu_domain.c | 3 +-- src/qemu/qemu_process.c | 5 ++--- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 31425783ba..7aeedf64f5 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -1017,7 +1017,7 @@ virCPUDefListExplicitFeatures(const virCPUDef *def) } =20 =20 -int +void virCPUDefFilterFeatures(virCPUDef *cpu, virCPUDefFeatureFilter filter, void *opaque) @@ -1031,11 +1031,10 @@ virCPUDefFilterFeatures(virCPUDef *cpu, } =20 VIR_FREE(cpu->features[i].name); - if (VIR_DELETE_ELEMENT_INPLACE(cpu->features, i, cpu->nfeatures) <= 0) - return -1; - } =20 - return 0; + /* Safe to ignore as an error is returned only for invalid argumen= ts */ + ignore_value(VIR_DELETE_ELEMENT_INPLACE(cpu->features, i, cpu->nfe= atures)); + } } =20 =20 diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 28e26303ef..cfb8f1a461 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -260,7 +260,7 @@ virCPUFeatureDef * virCPUDefFindFeature(const virCPUDef *def, const char *name); =20 -int +void virCPUDefFilterFeatures(virCPUDef *cpu, virCPUDefFeatureFilter filter, void *opaque); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 83946123be..2c966e7ef0 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4023,17 +4023,14 @@ virQEMUCapsInitHostCPUModel(virQEMUCaps *qemuCaps, =20 if (ARCH_IS_X86(qemuCaps->arch) && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_UNAVAILABLE_FEATURES)) { - if (cpu && - virCPUDefFilterFeatures(cpu, virCPUx86FeatureFilterDropMSR, NU= LL) < 0) - goto error; + if (cpu) + virCPUDefFilterFeatures(cpu, virCPUx86FeatureFilterDropMSR, NU= LL); =20 - if (migCPU && - virCPUDefFilterFeatures(migCPU, virCPUx86FeatureFilterDropMSR,= NULL) < 0) - goto error; + if (migCPU) + virCPUDefFilterFeatures(migCPU, virCPUx86FeatureFilterDropMSR,= NULL); =20 - if (fullCPU && - virCPUDefFilterFeatures(fullCPU, virCPUx86FeatureFilterDropMSR= , NULL) < 0) - goto error; + if (fullCPU) + virCPUDefFilterFeatures(fullCPU, virCPUx86FeatureFilterDropMSR= , NULL); } =20 if (virQEMUCapsTypeIsAccelerated(type)) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 375e0e441a..227eee3646 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5319,8 +5319,7 @@ qemuDomainMakeCPUMigratable(virArch arch, g_auto(GStrv) keep =3D virCPUDefListExplicitFeatures(origCPU); data.keep =3D keep; =20 - if (virCPUDefFilterFeatures(cpu, qemuDomainDropAddedCPUFeature= s, &data) < 0) - return -1; + virCPUDefFilterFeatures(cpu, qemuDomainDropAddedCPUFeatures, &= data); } } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 9926998f85..17eac5772b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6552,9 +6552,8 @@ qemuProcessUpdateGuestCPU(virDomainDef *def, def->cpu->fallback =3D VIR_CPU_FALLBACK_FORBID; } =20 - if (virCPUDefFilterFeatures(def->cpu, virQEMUCapsCPUFilterFeatures, - &def->os.arch) < 0) - return -1; + virCPUDefFilterFeatures(def->cpu, virQEMUCapsCPUFilterFeatures, + &def->os.arch); =20 if (def->cpu->deprecated_feats) { virCPUFeaturePolicy policy =3D VIR_CPU_FEATURE_REQUIRE; --=20 2.51.0