From nobody Sun Apr 28 06:43:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1665479196; cv=none; d=zohomail.com; s=zohoarc; b=AkXAVovvu7HUSL0bCpQlfHEogb6QX2Uf4SN6CThDUpISlSCzJEsL/gg9VFNeidMogbaVCsE25G245q6juRgQf+MijYXV8ddxUIJXkJFZLuZymNcD1Nh6lkzsm6UQTDvLssEL8PPjmiuCh6C9R1HZ21RAOrdbszad0OZGhLQJoKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665479196; h=Content-Type:Content-Transfer-Encoding:Cc: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=kA9+H0wk402bEFRN+xGEPmxUujMUR3ag4MsdEOk5bBA=; b=hE0KbuxwZZEMC9+clKRDZ8gHI8Wj221ydZZq+BSYM+8+l8/97LwjnVEiI0pYyr31qq9MW0qzP3nLjUwdJxgG8sed5VTbHzH4ZFy3GYSyuuVgLj/x6TigTDLGxE++dmgW5xLTxxVxOkXegxa1NGUqyDbLUKSCOZn3DeLbH7F2828= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1665479196356110.00159499938582; Tue, 11 Oct 2022 02:06:36 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-262-dy5v5WSLNGO5OeoSnOBW_A-1; Tue, 11 Oct 2022 05:06:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02A48299E740; Tue, 11 Oct 2022 09:06:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E43199E70; Tue, 11 Oct 2022 09:06:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 82C091946A45; Tue, 11 Oct 2022 09:06:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DC2AB19465A0 for ; Tue, 11 Oct 2022 09:06:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BF0C61121319; Tue, 11 Oct 2022 09:06:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2588F1121314; Tue, 11 Oct 2022 09:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665479195; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=kA9+H0wk402bEFRN+xGEPmxUujMUR3ag4MsdEOk5bBA=; b=RcY2v7I0D2WafPz0t/Xx7qhYY1pAhMyam9yimRvr/0Lnr+XLW8QAn4liiWthJBotIYrUF8 SnD6bDRyG6tGy7QPgeEq7+NqifqDFT+jCBxQe0jpuFN5SfGdw6nrhr9h52bPB5MG6S0dt8 LHMqDDf4ekWh+FLgutPttbC+QrBbpX0= X-MC-Unique: dy5v5WSLNGO5OeoSnOBW_A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/2] conf: define autoptr func for virCapsHostCacheBankFree Date: Tue, 11 Oct 2022 10:06:20 +0100 Message-Id: <20221011090621.1712993-2-berrange@redhat.com> In-Reply-To: <20221011090621.1712993-1-berrange@redhat.com> References: <20221011090621.1712993-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665479198309100003 This lets us simplify the cleanup paths when populating the host cache bank information in capabilities XML. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko Tested-by: Alex Benn=C3=A9e --- src/conf/capabilities.c | 34 ++++++++++++++-------------------- src/conf/capabilities.h | 3 +++ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1a7ebf4a13..d693d38f3c 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -2150,9 +2150,7 @@ virCapabilitiesInitCaches(virCaps *caps) size_t i =3D 0; g_autoptr(virBitmap) cpus =3D NULL; ssize_t pos =3D -1; - int ret =3D -1; struct dirent *ent =3D NULL; - virCapsHostCacheBank *bank =3D NULL; const virResctrlMonitorType montype =3D VIR_RESCTRL_MONITOR_TYPE_CACHE; const char *prefix =3D virResctrlMonitorPrefixTypeToString(montype); =20 @@ -2172,10 +2170,11 @@ virCapabilitiesInitCaches(virCaps *caps) int rv =3D -1; g_autoptr(DIR) dirp =3D NULL; g_autofree char *path =3D g_strdup_printf("%s/cpu/cpu%zd/cache/", = SYSFS_SYSTEM_PATH, pos); + g_autoptr(virCapsHostCacheBank) bank =3D NULL; =20 rv =3D virDirOpenIfExists(&dirp, path); if (rv < 0) - goto cleanup; + return -1; =20 if (!dirp) continue; @@ -2191,7 +2190,7 @@ virCapabilitiesInitCaches(virCaps *caps) if (virFileReadValueUint(&level, "%s/cpu/cpu%zd/cache/%s/level", SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; + return -1; =20 if (level < cache_min_level) continue; @@ -2202,33 +2201,33 @@ virCapabilitiesInitCaches(virCaps *caps) if (virFileReadValueUint(&bank->id, "%s/cpu/cpu%zd/cache/%s/id", SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; + return -1; =20 if (virFileReadValueUint(&bank->level, "%s/cpu/cpu%zd/cache/%s/level", SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) - goto cleanup; + return -1; =20 if (virFileReadValueString(&type, "%s/cpu/cpu%zd/cache/%s/type", SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) - goto cleanup; + return -1; =20 if (virFileReadValueScaledInt(&bank->size, "%s/cpu/cpu%zd/cache/%s/size", SYSFS_SYSTEM_PATH, pos, ent->d_n= ame) < 0) - goto cleanup; + return -1; =20 if (virFileReadValueBitmap(&bank->cpus, "%s/cpu/cpu%zd/cache/%s/shared_cpu_= list", SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) - goto cleanup; + return -1; =20 kernel_type =3D virCacheKernelTypeFromString(type); if (kernel_type < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown cache type '%s'"), type); - goto cleanup; + return -1; } =20 bank->type =3D kernel_type; @@ -2244,15 +2243,13 @@ virCapabilitiesInitCaches(virCaps *caps) bank->size, &bank->ncontrols, &bank->controls) < 0) - goto cleanup; + return -1; =20 VIR_APPEND_ELEMENT(caps->host.cache.banks, caps->host.cach= e.nbanks, bank); } - - g_clear_pointer(&bank, virCapsHostCacheBankFree); } if (rv < 0) - goto cleanup; + return -1; } =20 /* Sort the array in order for the tests to be predictable. This way = we can @@ -2264,16 +2261,13 @@ virCapabilitiesInitCaches(virCaps *caps) } =20 if (virCapabilitiesInitResctrlMemory(caps) < 0) - goto cleanup; + return -1; =20 if (virResctrlInfoGetMonitorPrefix(caps->host.resctrl, prefix, &caps->host.cache.monitor) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCapsHostCacheBankFree(bank); - return ret; + return 0; } =20 =20 diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 6fe7818b2e..ef6e8ab685 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -137,6 +137,9 @@ struct _virCapsHostCacheBank { virResctrlInfoPerCache **controls; }; =20 +void virCapsHostCacheBankFree(virCapsHostCacheBank *ptr); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCapsHostCacheBank, virCapsHostCacheBankFr= ee); + struct _virCapsHostCache { size_t nbanks; virCapsHostCacheBank **banks; --=20 2.37.3 From nobody Sun Apr 28 06:43:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1665479200; cv=none; d=zohomail.com; s=zohoarc; b=dve1c/kR6IfIQFdetuQY9lR3pv6fY3nlYcNP9rLv9p1kTCNk/I1odzDbD/VJKCLIOMsMIGIcKm032uwCi9EcylqdbeY2qJiF5iyu10QZbrZBeyCU+msK8h6UIXauTwbYZu9fe2pn1Fdr+SvOAxEtQlXsVQIoHFKl7JYQwzMHw7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665479200; h=Content-Type:Content-Transfer-Encoding:Cc: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=aHw6k5nJvK7DEt7bjLyvPgNAck4ylEKZWP8BVMgC8Wo=; b=OfWx3JDvM02ZPhmQlg3kw7OpIW9UnAQ5eKRosBQN/v1fohjG0EeViDnWWzeAOcPiBJW5+1Z256DMbOTlSAlUzhzk8sUbFoJrVtTmrZ3vNklkCS4+j+Noui2aJZyHFXD13Zs0xT5zBjlx9NYKyaJ2P4LQZXA+rNLE6T4mejSXk4c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1665479199994982.8858923767253; Tue, 11 Oct 2022 02:06:39 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-2xftkT4cOSmy4cSHKomkBw-1; Tue, 11 Oct 2022 05:06:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6F582862FE3; Tue, 11 Oct 2022 09:06:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D630414A809; Tue, 11 Oct 2022 09:06:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 148D81946A61; Tue, 11 Oct 2022 09:06:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B87E719465A0 for ; Tue, 11 Oct 2022 09:06:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AA6621121319; Tue, 11 Oct 2022 09:06:25 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 017F61121314; Tue, 11 Oct 2022 09:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665479198; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=aHw6k5nJvK7DEt7bjLyvPgNAck4ylEKZWP8BVMgC8Wo=; b=G0AdL7u9z7a3DG53Ofh7AtGghq0/zibWtiXseM2Uhl40Jq8FK4hYhD/BCGkNKE/LHK2TGC JObEvUWi+mMACwrjdJTX0hmap0xirYuma2L3SNlXvpH8aAFGVK/8hfxQqlVJtVDD2ugbGs 2ShaYscO1LgWdQ9aJOJfsIGkdmYXYck= X-MC-Unique: 2xftkT4cOSmy4cSHKomkBw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/2] conf: skip resource cache init if sysfs files are missing Date: Tue, 11 Oct 2022 10:06:21 +0100 Message-Id: <20221011090621.1712993-3-berrange@redhat.com> In-Reply-To: <20221011090621.1712993-1-berrange@redhat.com> References: <20221011090621.1712993-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665479200305100005 On aarch64 the 'id' file is not present for CPU cache information in sysfs. This causes the local stateful hypervisor drivers to fail to initialize capabilities: virStateInitialize:657 : Initialisation of cloud-hypervisor state driver fa= iled: no error The 'no error' is because the 'virFileReadValueNNN' methods return ret=3D=3D-2, with no error raised, when the requeted file does not exist. None of the callers were checking for this scenario when populating capabilities. The most graceful way to handle this is to skip the cache bank in question. This fixes failure to launch libvirt drivers on certain aarch64 hardware. Fixes: https://gitlab.com/libvirt/libvirt/-/issues/389 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko Tested-by: Alex Benn=C3=A9e --- src/conf/capabilities.c | 56 ++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index d693d38f3c..a79547f6ca 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -2183,6 +2183,7 @@ virCapabilitiesInitCaches(virCaps *caps) g_autofree char *type =3D NULL; int kernel_type; unsigned int level; + int ret; =20 if (!STRPREFIX(ent->d_name, "index")) continue; @@ -2198,29 +2199,54 @@ virCapabilitiesInitCaches(virCaps *caps) bank =3D g_new0(virCapsHostCacheBank, 1); bank->level =3D level; =20 - if (virFileReadValueUint(&bank->id, - "%s/cpu/cpu%zd/cache/%s/id", - SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) + ret =3D virFileReadValueUint(&bank->id, + "%s/cpu/cpu%zd/cache/%s/id", + SYSFS_SYSTEM_PATH, pos, ent->d_name= ); + if (ret =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'id' missing", pos, ent->d_nam= e); + continue; + } + if (ret < 0) return -1; =20 - if (virFileReadValueUint(&bank->level, - "%s/cpu/cpu%zd/cache/%s/level", - SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) + ret =3D virFileReadValueUint(&bank->level, + "%s/cpu/cpu%zd/cache/%s/level", + SYSFS_SYSTEM_PATH, pos, ent->d_name= ); + if (ret =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'level' missing", pos, ent->d_= name); + continue; + } + if (ret < 0) return -1; =20 - if (virFileReadValueString(&type, - "%s/cpu/cpu%zd/cache/%s/type", - SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) + ret =3D virFileReadValueString(&type, + "%s/cpu/cpu%zd/cache/%s/type", + SYSFS_SYSTEM_PATH, pos, ent->d_na= me); + if (ret =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'type' missing", pos, ent->d_n= ame); + continue; + } + if (ret < 0) return -1; =20 - if (virFileReadValueScaledInt(&bank->size, - "%s/cpu/cpu%zd/cache/%s/size", - SYSFS_SYSTEM_PATH, pos, ent->d_n= ame) < 0) + ret =3D virFileReadValueScaledInt(&bank->size, + "%s/cpu/cpu%zd/cache/%s/size", + SYSFS_SYSTEM_PATH, pos, ent->d= _name); + if (ret =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'size' missing", pos, ent->d_n= ame); + continue; + } + if (ret < 0) return -1; =20 - if (virFileReadValueBitmap(&bank->cpus, - "%s/cpu/cpu%zd/cache/%s/shared_cpu_= list", - SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) + ret =3D virFileReadValueBitmap(&bank->cpus, + "%s/cpu/cpu%zd/cache/%s/shared_cp= u_list", + SYSFS_SYSTEM_PATH, pos, ent->d_na= me); + if (ret =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'shared_cpu_list' missing", po= s, ent->d_name); + continue; + } + if (ret < 0) return -1; =20 kernel_type =3D virCacheKernelTypeFromString(type); --=20 2.37.3