From 433587d1de8b9ac21ccbc99c067802ef2e7ac053 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Mon, 10 Oct 2022 17:45:02 +0100 Subject: [PATCH] conf: skip resource cache init if sysfs files are missing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 failed: no error The 'no error' is because the 'virFileReadValueNNN' methods return ret==-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 Tested-by: Alex Bennée Reviewed-by: Ján Tomko Signed-off-by: Daniel P. Berrangé --- 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 94e8b1f7a4..34770fc416 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -2191,6 +2191,7 @@ virCapabilitiesInitCaches(virCaps *caps) g_autofree char *type = NULL; int kernel_type; unsigned int level; + int ret; if (!STRPREFIX(ent->d_name, "index")) continue; @@ -2206,29 +2207,54 @@ virCapabilitiesInitCaches(virCaps *caps) bank = g_new0(virCapsHostCacheBank, 1); bank->level = level; - if (virFileReadValueUint(&bank->id, - "%s/cpu/cpu%zd/cache/%s/id", - SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0) + ret = virFileReadValueUint(&bank->id, + "%s/cpu/cpu%zd/cache/%s/id", + SYSFS_SYSTEM_PATH, pos, ent->d_name); + if (ret == -2) { + VIR_DEBUG("CPU %zd cache %s 'id' missing", pos, ent->d_name); + continue; + } + if (ret < 0) return -1; - if (virFileReadValueUint(&bank->level, - "%s/cpu/cpu%zd/cache/%s/level", - SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0) + ret = virFileReadValueUint(&bank->level, + "%s/cpu/cpu%zd/cache/%s/level", + SYSFS_SYSTEM_PATH, pos, ent->d_name); + if (ret == -2) { + VIR_DEBUG("CPU %zd cache %s 'level' missing", pos, ent->d_name); + continue; + } + if (ret < 0) return -1; - if (virFileReadValueString(&type, - "%s/cpu/cpu%zd/cache/%s/type", - SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0) + ret = virFileReadValueString(&type, + "%s/cpu/cpu%zd/cache/%s/type", + SYSFS_SYSTEM_PATH, pos, ent->d_name); + if (ret == -2) { + VIR_DEBUG("CPU %zd cache %s 'type' missing", pos, ent->d_name); + continue; + } + if (ret < 0) return -1; - if (virFileReadValueScaledInt(&bank->size, - "%s/cpu/cpu%zd/cache/%s/size", - SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0) + ret = virFileReadValueScaledInt(&bank->size, + "%s/cpu/cpu%zd/cache/%s/size", + SYSFS_SYSTEM_PATH, pos, ent->d_name); + if (ret == -2) { + VIR_DEBUG("CPU %zd cache %s 'size' missing", pos, ent->d_name); + continue; + } + if (ret < 0) return -1; - if (virFileReadValueBitmap(&bank->cpus, - "%s/cpu/cpu%zd/cache/%s/shared_cpu_list", - SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0) + ret = virFileReadValueBitmap(&bank->cpus, + "%s/cpu/cpu%zd/cache/%s/shared_cpu_list", + SYSFS_SYSTEM_PATH, pos, ent->d_name); + if (ret == -2) { + VIR_DEBUG("CPU %zd cache %s 'shared_cpu_list' missing", pos, ent->d_name); + continue; + } + if (ret < 0) return -1; kernel_type = virCacheKernelTypeFromString(type); -- 2.39.5