From 8773410a9d5aff3f222c7ab063170248df88bfbd Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 6 Sep 2025 10:50:31 +0200 Subject: [PATCH] BUG/MINOR: cpu_topo: work around a small bug in musl's CPU_ISSET() As found in GH issue #3103, CPU_ISSET() on musl 1.25 doesn't match the man page which says it's returning an int. The reason is pretty simple, it's a macro that operates on the bits directly and returns the result of the bit field applied to the mask as an unsigned long. Bits above 31 will simply be dropped if returned as an int, which causes CPUs 32..63 to appear as absent from cpu_sets. The fix is trivial, it consists in just comparing the result against zero (i.e. turning it to a boolean), but before it's merged and deployed we'll have to face such deployments, so better implement the same workaround in the code here since we have access to the raw long value. This workaround should be backported to 3.0. (cherry picked from commit 75bd9255dd04d9247f1e555023cc45f5e17936ca) Signed-off-by: Christopher Faulet (cherry picked from commit 3847df920f4610c5b03061b9f3da6ca295fda228) Signed-off-by: Christopher Faulet (cherry picked from commit ac35ac8af7232002a0692ea03b25129fd9dd7edb) Signed-off-by: Christopher Faulet --- src/cpuset.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cpuset.c b/src/cpuset.c index a20b81a..63e23c0 100644 --- a/src/cpuset.c +++ b/src/cpuset.c @@ -81,7 +81,10 @@ int ha_cpuset_isset(const struct hap_cpuset *set, int cpu) return 0; #if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET) - return CPU_ISSET(cpu, &set->cpuset); + /* Turn to boolean because musl directly returns the mask as a + * a long instead of an int, hence loses bits 32+. + */ + return !!CPU_ISSET(cpu, &set->cpuset); #elif defined(CPUSET_USE_ULONG) return !!(set->cpuset & (0x1 << cpu)); -- 1.7.10.4