From nobody Thu Apr 2 22:41:21 2026 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=1774525503; cv=none; d=zohomail.com; s=zohoarc; b=fhHTyBHq+gx5Oq/wXKNNp8+c5aaWOjJEY7x8Bvl8Ej9jbMlKP7G1Tqgm7MHPdy0ywn1qCM29GS0T4ab2AVM16x4qwbncPFv98+Z3T/gC+rmMxLWt8fYG7fqtEbW2g7oEz5XzwwYL3xAVnNFWJJ7UObWHcUMZiOu00vZasl+69J4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774525503; 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=IdISdbVF6NhMKGbWE267mZeDWgrmLt+zFMGSAgKLeDY=; b=kYuX9h5dy4NooVeyzkkodX9gYkO81PPBOpiesr/HJaD4XGuNlM+814eIw5qnDgJCTuI2YyLUDRf9QCTfVQq+AI49Wu/5dxRLIZyPLb1cyYLlrQN+H5wszXZtNBmuGer6cJMFBxqq1QeZAqt64KlCbnxMeZT7SPVtijslwZsbDwM= 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 177452550358821.63014734872729; Thu, 26 Mar 2026 04:45:03 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 8F4C33F931; Thu, 26 Mar 2026 07:45:02 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 75F534181C; Thu, 26 Mar 2026 07:44:24 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 84B293F328; Thu, 26 Mar 2026 07:44:20 -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 662E941812 for ; Thu, 26 Mar 2026 07:43:50 -0400 (EDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-292-nSX-grXNM1OOMy4c16hAjQ-1; Thu, 26 Mar 2026 07:43:47 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48534941525so14012455e9.2 for ; Thu, 26 Mar 2026 04:43:47 -0700 (PDT) Received: from wheatley.localdomain ([213.175.46.86]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-487208ca5b0sm46954505e9.2.2026.03.26.04.43.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 04:43:45 -0700 (PDT) Received: from wheatley.pinto-pinecone.ts.net (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 1C51A19E19E04 for ; Thu, 26 Mar 2026 12:43:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1774525430; 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=IdISdbVF6NhMKGbWE267mZeDWgrmLt+zFMGSAgKLeDY=; b=PWzT2qZYBD3duKc1FIu3EscsA3XHNgmuP845+0U3LHEU/LNcFoFxOClQiu9Nc2MwGKdNxa ohIiTpGMB9c66f3tXmxXogLth2zk0VUAxb30vaquEhorgzQy2WTtDygr5w0Czkz3+j7NJy bkjI0ebvPnjngqB9n7XoXlUvDPWwWDc= X-MC-Unique: nSX-grXNM1OOMy4c16hAjQ-1 X-Mimecast-MFC-AGG-ID: nSX-grXNM1OOMy4c16hAjQ_1774525426 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774525426; x=1775130226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=IdISdbVF6NhMKGbWE267mZeDWgrmLt+zFMGSAgKLeDY=; b=TQorf3SbFM6R41nieifA3SGjS2dDZ89XwzcICPEcsIGjsmifUSZtPg0UEJ/rqLewlp ixpDIn8n+s/WBzQrHn7rFZT0z0fFr0NV9RlDn9hwb9QYTY2CCIoCkrV9G6TkwBz7nr1C t6PokICP7XD1wSKCpxM5Hs8ijbFNq/tV6F7sjMtVlNMc8Dzz9Be/H4hMqKYjeCJwuVGU A4CfYPgyIyC+0CXIu6vZ8aj96XXvCSOBjw6d6a9RO2Cr8mvtlE+0jQAWHeLHkHrPAgTQ +4P4dSrOhuw7K3R6hHX30bZkkBPcR0yswiGFBe+r7iijxkQvEuKCov7ZJrkOfDN7l67p WefQ== X-Gm-Message-State: AOJu0Ywnfaevvp/gLW/aV2n9Xg3xBBiavF4eqfF7kZmqopm3mXgwe7bd wq5FiDmoX0/9ygyOfpvMa7D0noxmlxhNtre1nBUgfMm5Tvr1bEJzGcYi03d+hgdCK12bcA5DI1W 6B0PG1rWHmVyuolxGwBMgPjGd9snCuBlD0evQNJ9MJejxtq7bSpU+He4CnheEekMWcL+Hto9834 nNZiFKIcGH0DO+WoVhyD2zE5czQV2UIk3rob8hkxW582g= X-Gm-Gg: ATEYQzxWp0sg8COnW4c9N0P3kQQVYQhg6VTh0Wx5vUZv0HZf5yzq++6svzQJKNOnflC TCfAjRxW0/VYs4XC82JUeW25EaYv45iUpxjJBZjD9pqJ0iyF2+Xe4eBe1fFQzcnhCTuRJcb4bDg MVQN1zGLWrs6j0K+sAj4EPbnmdLSg7lKOAY+tFTP59z1n6QVsaNAN+j/G8/l2hM25OY4gbWBh5r gJzPcimiwu8Qitwp/G95jsmuwl2vqmNLbTEKM9Nq4T0zzBlgq6RrSzTM5OrWdn0vbAks4fGFBnr Sb/acgMLEGkLcUYH2pYHlmJNBYWj2+WZQC53xx18bAC9Xoatd89aKzNB2MKD27qRRt93KdaygH5 Na7hJSuvuHaLc1IdkpNFCaA== X-Received: by 2002:a05:600d:8449:b0:485:39d4:2dd9 with SMTP id 5b1f17b1804b1-487160afe8cmr81560235e9.33.1774525426269; Thu, 26 Mar 2026 04:43:46 -0700 (PDT) X-Received: by 2002:a05:600d:8449:b0:485:39d4:2dd9 with SMTP id 5b1f17b1804b1-487160afe8cmr81559805e9.33.1774525425734; Thu, 26 Mar 2026 04:43:45 -0700 (PDT) To: devel@lists.libvirt.org Subject: [PATCH 1/3] tests: Extend virhostcputest to check virHostCPUGetMap Date: Thu, 26 Mar 2026 12:43:34 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: uVg53a3-pRbV_LwSaAHl33x0eZMxuM8wnevHFK1rTXg_1774525426 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: Y47BY2HA2OH34FXMSVJ7D2542F2BOATT X-Message-ID-Hash: Y47BY2HA2OH34FXMSVJ7D2542F2BOATT X-MailFrom: mkletzan@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: Martin Kletzander via Devel Reply-To: Martin Kletzander X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1774525507120154100 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Martin Kletzander This commit goes through all virhostcpudata subdirectories and checks that `virHostCPUGetMap()` returns valid data for each one of them. Signed-off-by: Martin Kletzander Reviewed-by: J=C3=A1n Tomko --- tests/virhostcputest.c | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 4e65e5febf93..4b31b7944484 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -244,11 +244,41 @@ linuxTestNodeCPUStats(const void *data) } =20 =20 +static int +linuxTestHostCPUGetMap(const void *data G_GNUC_UNUSED) +{ + g_autofree unsigned char *cpumap =3D NULL; + + int ncpus =3D virHostCPUGetMap(&cpumap, NULL, 0); + + g_autoptr(virBitmap) actual =3D virBitmapNewData(cpumap, VIR_DIV_UP(nc= pus, 8)); + g_autoptr(virBitmap) expected =3D NULL; + + if (virFileReadValueBitmap(&expected, "%s/cpu/online", SYSFS_SYSTEM_PA= TH) < 0) + return -1; + + if (!virBitmapEqual(actual, expected)) { + g_autofree char *expected_str =3D virBitmapFormat(expected); + g_autofree char *actual_str =3D virBitmapFormat(actual); + fprintf(stderr, + "Bitmaps are different\nexpected: %s\nactual: %s\n", + expected_str, actual_str); + return -1; + } + + return 0; +} + + static int mymain(void) { int ret =3D 0; size_t i; + int rc =3D 0; + struct dirent *ent =3D NULL; + g_autofree char *datadir =3D g_strdup_printf("%s/virhostcpudata", abs_= srcdir); + g_autoptr(DIR) dir =3D NULL; const struct linuxTestHostCPUData nodeData[] =3D { {"test1", VIR_ARCH_X86_64}, {"test1", VIR_ARCH_PPC}, @@ -300,6 +330,33 @@ mymain(void) DO_TEST_CPU_STATS("24cpu", 24, false); DO_TEST_CPU_STATS("24cpu", 25, true); =20 + /* Tests for virHostCPUGetMap() with each data subdirectory. */ + if (virDirOpen(&dir, datadir) < 0) + return -1; + + while ((rc =3D virDirRead(dir, &ent, datadir)) > 0) { + struct stat sb; + g_autofree char *path =3D g_strdup_printf("%s/%s", datadir, ent->d= _name); + + if (stat(path, &sb) < 0) { + fprintf(stderr, "Cannot stat %s\n", path); + return -1; + } + + if (!S_ISDIR(sb.st_mode)) + continue; + + virFileWrapperAddPrefix(SYSFS_SYSTEM_PATH, path); + if (virTestRun(ent->d_name, linuxTestHostCPUGetMap, NULL) < 0) + ret =3D -1; + virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH); + } + + if (rc < 0) { + fprintf(stderr, "Error reading %s\n", SYSFS_SYSTEM_PATH); + return -1; + } + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.53.0 From nobody Thu Apr 2 22:41:21 2026 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=1774525546; cv=none; d=zohomail.com; s=zohoarc; b=MonyNPWwKvS51kugz1Bji/xvXTJ/K+gYvUFAEpzOZOQCx9Cv9BerdDPJAajDfJLrXHUBRHMMj7hox1bSqJJnKdCgmSiEw2Rc0dgUeUOqcSc88Rdzei9Wi4KUf1IP8PIW50YxkpbSlkVKVTb/BN/4nYkvYGOfiB7KagoN1bxMhxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774525546; 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=lBjQ7W7rsf2q6aMYeVra/2d01zIBF434EAmXapY6U98=; b=lRmdp7C3dX+X7qHpd3F0da47/kOO/5UITjZfgUGMiiJYcfKfFPBg/ccHIqxKU3JdWo1IDA6uGpQTIO00mqYxGspX0HxQveQlg79gOnkBQL9jEdJsuHYV3Ja0BMOHlH8oeIGsLpu8cLZjfBVsp2fc5UBAdAffCbasS1Q6Y1JFWuM= 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 1774525546408109.75181570332131; Thu, 26 Mar 2026 04:45:46 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 63EB03F88F; Thu, 26 Mar 2026 07:45:45 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id A205D418D3; Thu, 26 Mar 2026 07:44:25 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id AE7D43F328; Thu, 26 Mar 2026 07:44:20 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 3BB5F41822 for ; Thu, 26 Mar 2026 07:43:57 -0400 (EDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-401-aEh_qweaP4WKgBJdZrsczA-1; Thu, 26 Mar 2026 07:43:55 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43b86de58d9so749560f8f.0 for ; Thu, 26 Mar 2026 04:43:54 -0700 (PDT) Received: from wheatley.localdomain ([213.175.46.86]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b919df903sm7861344f8f.30.2026.03.26.04.43.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 04:43:52 -0700 (PDT) Received: from wheatley.pinto-pinecone.ts.net (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 184EB19E19E05 for ; Thu, 26 Mar 2026 12:43:52 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1774525436; 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=lBjQ7W7rsf2q6aMYeVra/2d01zIBF434EAmXapY6U98=; b=irWV/Q4Z3JP48Seun8nTZ7PAVVIr3fDx2xgQMv+CZWh1zSecRXwCH3nM26nOg4zqcygxvj ATGN6Y7qLr0r8dGfPjDNXFadMDX82JboxArz6DxOpR1sTWquSH63dkbaAMzrm3cS9Chdtz StgWCtYMrZRO9mH3i+O+g2j27tAmWYk= X-MC-Unique: aEh_qweaP4WKgBJdZrsczA-1 X-Mimecast-MFC-AGG-ID: aEh_qweaP4WKgBJdZrsczA_1774525434 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774525433; x=1775130233; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=lBjQ7W7rsf2q6aMYeVra/2d01zIBF434EAmXapY6U98=; b=eAtn8RbIanTE+9+Zr/dmdfKrv6HhKnhSdC6RNQdHLfqrsd56oUrRw3ocTyyRv0UHS6 tCHG962hdjEB/4MtY62h2+460qjhN2tdXH31nz69nTqFov9F9jpgJG3kr2Zzf8ledFcC MRRNjyG+iDTiAOpuTZP9NLe9kkI+hFfWSpwv7VNuwsZMEvQf9CFtk78TIA26emA+lI6N lNgU2m3Z5lepp+zjGSEgPEI+siHlKQ+PvHa3HJ4IIVDJiRRVgZpPLvWcM+Js5R0I1f2o iL2MKOz9fQkvO1Z+sEpAhHMvqDOuHr1lpxt9ra34kvWE1QqGB5MjlYT/JfPCQezKUmK+ xqVQ== X-Gm-Message-State: AOJu0YynzJEFYb5bM7rv/XA1buRjFKepYEIrJZavRM2IKLaimXniOEmb aMdVrxo/CugV8rDcmik8lfgOXYyXBn8PiA1JD3pJJj9nZJHE1uLJHHkWCH7UHor6mPddRCvWjfB 4wlfj7jZyGwY6JZm16wERc9qvg4Sb0cvNT5MtcxHc6RZpzQZCs7en8Rkp6b7aTJYeNEKrPx0Nau f2W3e+ofkNPHoP/PSbbQD3R956bkOXGONdWYSxd1d+gUA= X-Gm-Gg: ATEYQzzoZAjdnywSbM6gLiM1i3640U9XVNq2uOcPGkntU3L1AgoeYP7Ryiq5HwgbMh5 YymAUlUDeSD6Ks7Cmr3vjxlImQvrQ7gAvc7HtTsy4JyZFMkp6Inhc1ZhN3+zq7gjEHGmNY+9hw3 1tbqAaJxXAq6IiPbwOtwISpChpArfu5gICA1glEavaBt/GEndZuj2evJpcT0yb02L14QIbdoi6p spjhRm80XiavquLVc9OcQPMmqxbAaTUrxkMlhghAJh+bkUJ3gDGQYPj+/zNF0niFzVSTIK+dZs2 pAcS+auXJA6k+Cmj6UiKEeRHPddrFEOEZCBdysZcMjfDivN/EaxeB2urexXdICdtPczRdqiVuVo 7CqrBhn5E7993lIwWIW/oBw== X-Received: by 2002:a05:6000:2892:b0:43b:50d6:4f00 with SMTP id ffacd0b85a97d-43b88a0d20fmr10670171f8f.30.1774525433434; Thu, 26 Mar 2026 04:43:53 -0700 (PDT) X-Received: by 2002:a05:6000:2892:b0:43b:50d6:4f00 with SMTP id ffacd0b85a97d-43b88a0d20fmr10670137f8f.30.1774525432849; Thu, 26 Mar 2026 04:43:52 -0700 (PDT) To: devel@lists.libvirt.org Subject: [PATCH 2/3] virhostcpu: Fix potential use of unallocated memory Date: Thu, 26 Mar 2026 12:43:35 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: W5CD_7lUszzTFEZeYJJGC9YX0WcYgwpYldTSCDQM8c4_1774525434 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: F66D6EVWKUPXWJ3QPDIIUX7ZGEFDPKXO X-Message-ID-Hash: F66D6EVWKUPXWJ3QPDIIUX7ZGEFDPKXO X-MailFrom: mkletzan@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: Martin Kletzander via Devel Reply-To: Martin Kletzander X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1774525548097158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Felix Huettner In case of a host that has a large number of cpus offline the count of host cpus and the last bit set in the virHostCPUGetOnlineBitmap might diverge significantly. This can e.g. be the case when disabling smt via /sys/devices/system/cpu/smt/control. On the host this looks like: ``` $ cat /sys/devices/system/cpu/present 0-255 $ cat /sys/devices/system/cpu/online 0-127 ``` However in this case virBitmapToData previously only allocated 16 bytes for the output bitmap. This is becase the last set bit is on the 15th byte. Users of virHostCPUGetMap however rely on the "cpumap" containing enough space for all existing cpus (so they would expect 32 bytes in this case). E.g. cmdNodeCpuMap relies on this for its output. It will then actually read 32 bytes from the start of the "cpumap" address where in this case the last 16 of these bytes are uninitialized. This manifests itself in flapping outputs of "virsh nodecpumap --pretty" li= ke: ``` $ virsh nodecpumap --pretty CPUs present: 256 CPUs online: 128 CPU map: 0-127,192,194,202 $ virsh nodecpumap --pretty CPUs present: 256 CPUs online: 128 CPU map: 0-127,192,194,197 $ virsh nodecpumap --pretty CPUs present: 256 CPUs online: 128 CPU map: 0-127,192,194,196-197 ``` This in turn potentially causes users of this data to report wrong cpu counts. Note that this only seems to happen with at least 256 physical cpus where at least 128 are offline. We fix this by preallocating the expected bitmap size. Signed-off-by: Felix Huettner Reviewed-by: Martin Kletzander Reviewed-by: J=C3=A1n Tomko --- src/util/virhostcpu.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 8688b6ec67a6..870338edad0a 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1148,28 +1148,26 @@ virHostCPUGetMap(unsigned char **cpumap, unsigned int flags) { g_autoptr(virBitmap) cpus =3D NULL; - int ret =3D -1; - int dummy; + int ncpus =3D virHostCPUGetCount(); =20 virCheckFlags(0, -1); =20 if (!cpumap && !online) - return virHostCPUGetCount(); + return ncpus; =20 if (!(cpus =3D virHostCPUGetOnlineBitmap())) - goto cleanup; + return -1; + + if (cpumap) { + int len =3D (ncpus + CHAR_BIT) / CHAR_BIT; + *cpumap =3D g_new0(unsigned char, len); + virBitmapToDataBuf(cpus, *cpumap, len); + } =20 - if (cpumap) - virBitmapToData(cpus, cpumap, &dummy); if (online) *online =3D virBitmapCountBits(cpus); =20 - ret =3D virHostCPUGetCount(); - - cleanup: - if (ret < 0 && cpumap) - VIR_FREE(*cpumap); - return ret; + return ncpus; } =20 =20 --=20 2.53.0 From nobody Thu Apr 2 22:41:21 2026 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=1774525579; cv=none; d=zohomail.com; s=zohoarc; b=RX7f4+Aqq8Yo7wYuS4oeIylQNYhvut8Gi+7Zpdhnh1NcPpbZl2qCQhzdqb8/qK3q3+jUGAf0cXb+tkNEOPYhrl5l87ipnQGJfrC0Mr3n1yW9nQwkuvOD5eWuHExw1MKT2bEwBF2VTqjGe4IVRKmHDDGAZadKsoV69Xgum4AApiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774525579; 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=SGTVDoH4iSL0symcimmgzCGLTBhTGjH1MP/Nb7P1PfM=; b=HaZ1AY0yUrZvEF75amC5BIgpZzsQ78bA2ZNJKnsfXyUK0PzTEw8GulH9fvRBHdMFrZBLJFCTTB6erXywfp/vdKr6y3wW5kUgBBSvOU+Uy7c4N7nQqt/IBGDULLAq3E/SddXuBPvThd7XSHqI/cK5bKr5rOVzHZw3oFpwKtrTCMw= 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 1774525579270514.5038836254422; Thu, 26 Mar 2026 04:46:19 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 713B33F349; Thu, 26 Mar 2026 07:46:18 -0400 (EDT) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id B632B4193B; Thu, 26 Mar 2026 07:44:27 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CCDBC3F328; Thu, 26 Mar 2026 07:44:20 -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 B47B2417EA for ; Thu, 26 Mar 2026 07:43:56 -0400 (EDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-132-jIv5-nICOVWsYJ15mpX6Lw-1; Thu, 26 Mar 2026 07:43:55 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-439b8bc43aeso604284f8f.1 for ; Thu, 26 Mar 2026 04:43:55 -0700 (PDT) Received: from wheatley.localdomain ([213.175.37.14]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b9192e533sm8688707f8f.2.2026.03.26.04.43.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 04:43:53 -0700 (PDT) Received: from wheatley.pinto-pinecone.ts.net (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id C83CE19E19E06 for ; Thu, 26 Mar 2026 12:43:52 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1774525436; 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=SGTVDoH4iSL0symcimmgzCGLTBhTGjH1MP/Nb7P1PfM=; b=iZh+T40oKCELNmNOsOM44gzXhza4ST8+0UGZAD5ZEbo2H0SczDafWVZNQs1TEOUdfw+RfP hCsnmnu6XJ6kxJPTDGO73kKiAn+fw7BOfc/qRcsPjydotZX9PV+jmOwQc0uk7jfLr8GAAG bB7Q5j00vGnhCgtyHCQhaDsxSEFZ55w= X-MC-Unique: jIv5-nICOVWsYJ15mpX6Lw-1 X-Mimecast-MFC-AGG-ID: jIv5-nICOVWsYJ15mpX6Lw_1774525434 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774525434; x=1775130234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=SGTVDoH4iSL0symcimmgzCGLTBhTGjH1MP/Nb7P1PfM=; b=kTHAEkZBTA3Ikyhvc/slNPY+NgAWWNNkpAFVqtBvb5SXrTflLg74fq2wclOWlS33c1 8WU1PBv+cK2Fi3vkCBMxSnK0TCv5QRaEyjJa6mOuvkBYg5YqfUOBP47ZMhEOc0KJRxzR 65TXjy3GDwoBdLpRgYxtiqGd/FUDFMOmWdD8MtOfhxdVP9hVMwUyjHnpqa567+WwMyAe 9M96iM1RH1ve959bqGnJufMJ7G4Qmoy/F+BjSwCpCf6/Ja3WrvNO9nMlLrQe/SHo2kNC JdcBHAH6BmkfwJmhy1LDfXjIYLKSK6qwgR2HE0RmrfSY4Bs716Y3yj/11844T7QSokG1 d6CQ== X-Gm-Message-State: AOJu0Yw6MaQymGk4EWqNjMarHR4vgbKtuKG8w5Zr6ja96ZhKcEdwA7MD BEWG0ZRp50ZS4hkW38I05qC1pjIlmFHxFn8S2GygndRs3vCEJ+i/Svok5DPownbrRhr9qdQJYKU +tHF7gI8Ov93lIvUctJo+0bOxViowFzx7aGUPqoyNSq1uU95tU7HeuMYGoNHUatow0bbkJ2M2pJ H3cd8tTHDfiaKy4nRiBeuS0wL6wq6XPWhaM1DrJELs7DY= X-Gm-Gg: ATEYQzx+1vwE+bke9MCWw0K+cXR/+FjRMYw51y2bsHp1tJLZ5at4qgV2vd6OxWwIC+C DjV67YPNKXsWrhTsTJ3uFTh9Alt59TD3W0WaOvrwpX2fi1LfxvVrPCQ5l34nTxEo7C/jn2sI/XK 0HivbRQSkt8DhphzhdwweiGjD2p4HYD/jKyhFKzJwijyewWyjT4XW2H7BVp/D7MmEvHKOzmXfWO VfAOhDL2bNBXFoU8Hw/IaR9cQkHZz4jM5IEiHPjjDJyb/LFiANw9qlMN3hgyaDpl3R76Rg2eU03 gOXqeje6JzyMw0wd/a1v0uAoGQ2EUG1oQQJqFSUuVnwbpJHSbW/SYQVsC6siNlB68f4/i6RUKs/ ScedfgtWhqJXV2fLnxYuWVA== X-Received: by 2002:a5d:5d02:0:b0:439:b486:ba6b with SMTP id ffacd0b85a97d-43b88a3dbf6mr10812071f8f.39.1774525433948; Thu, 26 Mar 2026 04:43:53 -0700 (PDT) X-Received: by 2002:a5d:5d02:0:b0:439:b486:ba6b with SMTP id ffacd0b85a97d-43b88a3dbf6mr10812024f8f.39.1774525433457; Thu, 26 Mar 2026 04:43:53 -0700 (PDT) To: devel@lists.libvirt.org Subject: [PATCH 3/3] tests/virhostcpudata: Add test case with many offline CPUs Date: Thu, 26 Mar 2026 12:43:36 +0100 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: CMCN0YEkr2jHxfSMHFcIDn5Bz3Rv_QD7m0Ix4GjpxOI_1774525434 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4CGKWFTCXGBI7A77SURQPIQKJYP3O26P X-Message-ID-Hash: 4CGKWFTCXGBI7A77SURQPIQKJYP3O26P X-MailFrom: mkletzan@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: Martin Kletzander via Devel Reply-To: Martin Kletzander X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1774525580404158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Martin Kletzander Signed-off-by: Martin Kletzander Reviewed-by: J=C3=A1n Tomko --- tests/virhostcpudata/linux-many-offline/cpu/online | 1 + tests/virhostcpudata/linux-many-offline/cpu/present | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/virhostcpudata/linux-many-offline/cpu/online create mode 100644 tests/virhostcpudata/linux-many-offline/cpu/present diff --git a/tests/virhostcpudata/linux-many-offline/cpu/online b/tests/vir= hostcpudata/linux-many-offline/cpu/online new file mode 100644 index 000000000000..fb812ed1df3c --- /dev/null +++ b/tests/virhostcpudata/linux-many-offline/cpu/online @@ -0,0 +1 @@ +0-127 diff --git a/tests/virhostcpudata/linux-many-offline/cpu/present b/tests/vi= rhostcpudata/linux-many-offline/cpu/present new file mode 100644 index 000000000000..8d232c7839e8 --- /dev/null +++ b/tests/virhostcpudata/linux-many-offline/cpu/present @@ -0,0 +1 @@ +0-255 --=20 2.53.0