|
|
Message-ID: <20261019001258.GZ23438@brightrain.aerifal.cx> Date: Sun, 18 Oct 2026 20:12:58 -0400 From: Rich Felker <dalias@...c.org> To: unnoticed-hassle <unnoticed-hassle@...ton.me> Cc: "musl@...ts.openwall.com" <musl@...ts.openwall.com> Subject: Re: aarch64/SVE: sysconf(_SC_NPROCESSORS_ONLN) returns a wrong value because the compiler keeps sve predicate state live across the inline svc 0 syscall On Sun, Oct 18, 2026 at 11:50:58PM +0000, unnoticed-hassle wrote: > OS: Gentoo Linux > Arch: armv9.2-a > Compiler: Clang 23.1.3+polly > Libc: Musl v1.2.6 > > Hi! > > I would like to report a defect in musl on aarch64 that leads to silently > incorrect results when the library is built with the vector extensions > enabled. > > On arm64 Linux the kernel zeroes the SVE state that is not shared with FPSIMD on > return from a syscall: the high bits of Z0 through Z31, all of P0 through P15, > and FFR. The aarch64 syscall wrappers in musl list only "memory" and "cc" in the > clobber list of the inline "svc 0" assembly, so the compiler may keep SVE values > live across the syscall and read them back after the kernel has already zeroed > them, producing incorrect results. This is observable with > clang >= 21 at -O2 -march=armv8-a+sve, which hoists "ptrue p0.s" above the > syscall and then uses a predicated "cnt", so the popcount forsysconf(_SC_NPROCESSORS_ONLN) sums whole mask bytes instead of counting bits. Yes, this has been discussed in the thread on the riscv clobbers: https://www.openwall.com/lists/musl/2026/10/04/1 but it wasn't expected that there would be affected code. Unfortunately, the gcc/clang asm constraints for aarch64 do not provide any way to flag that the SVE state is clobbered but the shared part of the state is not. So until that's fixed on the compiler side (needs cooperation between gcc, clang, and arm folks), there is no clean solution to this. The recommended action right now is to build for a non-SVE target. I'll see if we can get a patch in for this bugfix release to mitigate the problem, but it's probably going to be something like blocking inlining of all syscalls if the predefined macros indicate SVE is available. Which is a rather bad tradeoff, I think, since there's very little SVE is useful for in libc. Rich
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.