![]() |
|
Message-ID: <CA+R2L90X44yTMjcGdhdb2ztEQ5vFSEk32zJmCBkAT5UO6cdoeg@mail.gmail.com>
Date: Fri, 5 Sep 2025 21:23:47 +0200
From: rafamiga <rafamiga@...il.com>
To: musl@...ts.openwall.com
Subject: Discrepancy in include/sched.h – breaks haproxy's CPU topology discovery
While working on a fix for haproxy load balancer running in a
container built with musl a discrepancy was found in include/sched.h. Long
story short, on a 48 CPU system haproxy was reporting just 32 CPUs. I'm
forwarding findings to this list to let you know that a change might be
considered.
Original bug report: https://github.com/haproxy/haproxy/issues/3103
Citing the author (wtarreau):
Oh I think I found it! The issue is here in sched.h:
#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \
(((unsigned long *)(set))[(i)/8/sizeof(long)] op
(1UL<<((i)%(8*sizeof(long))))) )
but CPU_ISSET() is defined as:
#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
See ? It returns an unsigned long which is returned as-is by the macro.
However the man says that CPU_ISSET() must return an int. So in our case
it's returned as-is and truncated to the lowest 32 bits.
The fix for the lib would be simple:
-#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
+#define CPU_ISSET(i, set) (CPU_ISSET_S(i,sizeof(cpu_set_t),set) != 0)
It should be reported to the project.
--
rafamiga
Content of type "text/html" skipped
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.