[PATCH v3] linux: Add linux statx(fd, NULL, AT_EMPTY_PATH) support
Xi Ruoyao
xry111@xry111.site
Wed Aug 28 00:21:33 GMT 2024
On Wed, 2024-08-28 at 04:13 +0800, Miao Wang via B4 Relay wrote:
/* snip */
> ---
> Changes in v3:
> - Fixed build error and failure to set errno in fxstat64.
> - Utilize tri-state supported flag to eliminate possible data read
Oh-oh, no... I thought I'd been clear "don't do it" but it seems I
wasn't clear.
/* snip */
> + static int statx_null_path_supported = -1;
> + int r;
> + int supported = statx_null_path_supported;
> + if (__glibc_unlikely (supported == -1))
If two threads are calling fstat at the same time when supported is
still -1, this normal load may happen at the same time with the atomic
store:
/* snip */
> + atomic_store_relaxed (&statx_null_path_supported, 1);
That's a data race and invoking an undefined behavior.
Even "harmless" data races are not allowed in Glibc code base nowadays,
see https://sourceware.org/glibc/wiki/Consensus#Standards_we_use. And
I'm not sure if this one is so harmless (on every supported
architectures).
To implement this optimization for LA464 (and Alpha, AFAIK) we need to
write assembly. And IMO it's not worthy to do it (the syscall will take
much more time than a barrier anyway).
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
More information about the Libc-alpha
mailing list