From 76cfb2738e2809895b1062468d80da773ebdaf6c Mon Sep 17 00:00:00 2001 From: Pratik-Kumar-Dhakar Date: Wed, 18 Nov 2026 22:57:43 +0530 Subject: [PATCH 1/2] CPUCache (Linux): skips offline CPUs The kernel removes `cpuX/cache/` when a CPU goes offline, so opendir() failed for that CPU and the whole module returned an error. Skip CPUs whose `online` file reads 0; a CPU without an `online` file (usually cpu0) is treated as online, as before. Fixes #2736 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + src/detection/cpucache/cpucache_linux.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff57fdab7..2148ee511a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Changes: Bugfixes: * Fixed libc version detection on FreeBSD without binutils installed, and on DragonFly BSD. (Libc, FreeBSD / DragonFly) +* Fixed CPU cache detection failing entirely when any CPU is offline. (#2736, CPUCache, Linux) # 2.71.0 diff --git a/src/detection/cpucache/cpucache_linux.c b/src/detection/cpucache/cpucache_linux.c index ff0551cbef..74c093409a 100644 --- a/src/detection/cpucache/cpucache_linux.c +++ b/src/detection/cpucache/cpucache_linux.c @@ -133,6 +133,19 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result) { } ffStrbufAppendS(&path, pathCpuEntry->d_name); + + // The kernel removes `cpuX/cache/` when a CPU goes offline. cpu0 usually has no `online` file + uint32_t cpuLen = path.length; + ffStrbufAppendS(&path, "/online"); + char online = '1'; + ffReadFileData(path.chars, sizeof(online), &online); + ffStrbufSubstrBefore(&path, cpuLen); + if (online == '0') { + FF_DEBUG("Skipping offline CPU \"%s\"", pathCpuEntry->d_name); + ffStrbufSubstrBefore(&path, baseLen); + continue; + } + const char* error = parseCpuCache(&path, result, &buffer, &added); if (error) { return error; From f34e5cb197cd9f18988587445e1324694e19b8d5 Mon Sep 17 00:00:00 2001 From: Pratik-Kumar-Dhakar Date: Thu, 19 Nov 2026 14:04:31 +0530 Subject: [PATCH 2/2] CPUCache (Linux): skips CPUs whose cache can't be read Instead of checking `cpuX/online`, drop the early return: a CPU without a readable `cache/` directory, such as an offline one, is skipped rather than failing the module. Co-Authored-By: Claude Opus 5.5 --- src/detection/cpucache/cpucache_linux.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/detection/cpucache/cpucache_linux.c b/src/detection/cpucache/cpucache_linux.c index 74c093409a..92fb63cf61 100644 --- a/src/detection/cpucache/cpucache_linux.c +++ b/src/detection/cpucache/cpucache_linux.c @@ -133,22 +133,10 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result) { } ffStrbufAppendS(&path, pathCpuEntry->d_name); - - // The kernel removes `cpuX/cache/` when a CPU goes offline. cpu0 usually has no `online` file - uint32_t cpuLen = path.length; - ffStrbufAppendS(&path, "/online"); - char online = '1'; - ffReadFileData(path.chars, sizeof(online), &online); - ffStrbufSubstrBefore(&path, cpuLen); - if (online == '0') { - FF_DEBUG("Skipping offline CPU \"%s\"", pathCpuEntry->d_name); - ffStrbufSubstrBefore(&path, baseLen); - continue; - } - + // Skip a CPU whose cache can't be read, e.g. an offline one: the kernel removes its `cache/` const char* error = parseCpuCache(&path, result, &buffer, &added); if (error) { - return error; + FF_DEBUG("Skipping \"%s\": %s", pathCpuEntry->d_name, error); } ffStrbufSubstrBefore(&path, baseLen); }