From nobody Sun Apr 28 07:42:06 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=1665420486; cv=none; d=zohomail.com; s=zohoarc; b=NiuoU2JHDOFbn+2j6HuMVKyzo1fI57SVD7PqYS2tvWmjwkTpY+GDlZ609O599o4w5CFwhtQT1KbUDLljqZBW7EMFOKXwQrLTaFr84bMm1bjsZ05LDwoNL5tDkxH8yvcK6hbW0oxPgT+wQFff2z1BDeLemop1h650q7jA6bdVuk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665420486; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=7eiC1VcVLkilgRN62IQxAztJRDS668j4JwBVc7r6X7U=; b=CpAnyO3RbWx/hgW0kdaHZ5Dst+VjSDpwQwFiL6ADrsDQLEAtGAmy5IQbC1gbp/cbPTF2q/AUKFeBKdlmeOExRoLewmMq5T6aYN9wJgWERBaSKNctwudPhI4M10EGl2DoIH3kB6FtuG2e6NdIWWlrErMMwuPHQUTlZEYigGBcAxQ= 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 1665420486136747.3822166965832; Mon, 10 Oct 2022 09:48:06 -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-45-QlCAbiMOPLyXk4H-0kkG5A-1; Mon, 10 Oct 2022 12:48:02 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 521C3185A7AB; Mon, 10 Oct 2022 16:47:59 +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 8D0EDC68E5E; Mon, 10 Oct 2022 16:47:58 +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 1F9641946A49; Mon, 10 Oct 2022 16:47:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 520BC19465A0 for ; Mon, 10 Oct 2022 16:47:57 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3C984477F5F; Mon, 10 Oct 2022 16:47:57 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56BE4477F5C; Mon, 10 Oct 2022 16:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665420484; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7eiC1VcVLkilgRN62IQxAztJRDS668j4JwBVc7r6X7U=; b=iLsMTVO5Xof2Ol88RDIBIKlSgbg7XtKTAUHM0kEY3QQgZTsk1ZYE0pIEICRNPO5MVMP6sM sLHY4oZwq6xN+ITPjTpD1dcAmU3O4J+1UWanYt3rNHIGrM0wvmfaEWtoNDlEhf6aCnOq/9 v87O9T5jKp83RHE41W5Qtt2mOfpOayc= X-MC-Unique: QlCAbiMOPLyXk4H-0kkG5A-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] conf: skip resource cache init if sysfs files are missing Date: Mon, 10 Oct 2022 17:47:53 +0100 Message-Id: <20221010164753.1701971-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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.8 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: 1665420488453100001 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 Tested-by: Alex Benn=C3=A9e --- src/conf/capabilities.c | 57 ++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1a7ebf4a13..ae63515fd3 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -2184,6 +2184,7 @@ virCapabilitiesInitCaches(virCaps *caps) g_autofree char *type =3D NULL; int kernel_type; unsigned int level; + int err; =20 if (!STRPREFIX(ent->d_name, "index")) continue; @@ -2199,29 +2200,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) + err =3D virFileReadValueUint(&bank->id, + "%s/cpu/cpu%zd/cache/%s/id", + SYSFS_SYSTEM_PATH, pos, ent->d_name= ); + if (err =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'id' missing", pos, ent->d_nam= e); + goto skip_cache; + } + if (err < 0) goto cleanup; =20 - if (virFileReadValueUint(&bank->level, - "%s/cpu/cpu%zd/cache/%s/level", - SYSFS_SYSTEM_PATH, pos, ent->d_name) = < 0) + err =3D virFileReadValueUint(&bank->level, + "%s/cpu/cpu%zd/cache/%s/level", + SYSFS_SYSTEM_PATH, pos, ent->d_name= ); + if (err =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'level' missing", pos, ent->d_= name); + goto skip_cache; + } + if (err < 0) goto cleanup; =20 - if (virFileReadValueString(&type, - "%s/cpu/cpu%zd/cache/%s/type", - SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) + err =3D virFileReadValueString(&type, + "%s/cpu/cpu%zd/cache/%s/type", + SYSFS_SYSTEM_PATH, pos, ent->d_na= me); + if (err =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'type' missing", pos, ent->d_n= ame); + goto skip_cache; + } + if (err < 0) goto cleanup; =20 - if (virFileReadValueScaledInt(&bank->size, - "%s/cpu/cpu%zd/cache/%s/size", - SYSFS_SYSTEM_PATH, pos, ent->d_n= ame) < 0) + err =3D virFileReadValueScaledInt(&bank->size, + "%s/cpu/cpu%zd/cache/%s/size", + SYSFS_SYSTEM_PATH, pos, ent->d= _name); + if (err =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'size' missing", pos, ent->d_n= ame); + goto skip_cache; + } + if (err < 0) goto cleanup; =20 - if (virFileReadValueBitmap(&bank->cpus, - "%s/cpu/cpu%zd/cache/%s/shared_cpu_= list", - SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) + err =3D virFileReadValueBitmap(&bank->cpus, + "%s/cpu/cpu%zd/cache/%s/shared_cp= u_list", + SYSFS_SYSTEM_PATH, pos, ent->d_na= me); + if (err =3D=3D -2) { + VIR_DEBUG("CPU %zd cache %s 'shared_cpu_list' missing", po= s, ent->d_name); + goto skip_cache; + } + if (err < 0) goto cleanup; =20 kernel_type =3D virCacheKernelTypeFromString(type); @@ -2249,6 +2275,7 @@ virCapabilitiesInitCaches(virCaps *caps) VIR_APPEND_ELEMENT(caps->host.cache.banks, caps->host.cach= e.nbanks, bank); } =20 + skip_cache: g_clear_pointer(&bank, virCapsHostCacheBankFree); } if (rv < 0) --=20 2.37.3