linux: fstat related changes in Linux 6.11
v3 cover linux: fstat related changes in Linux 6.11
Kernel 6.11 adds back fstat and newfstatat in commit 7697a0fe0154 ("LoongArch: Define __ARCH_WANT_NEW_STAT in unistd.h") for loongarch. With kernel headers from 6.11, make update-syscall-lists will generate the following diffs:
Quoted 13 lines
sysdeps/unix/sysv/linux/loongarch/arch-syscall.h +1
-0@@ -59,6 +59,7 @@#define __NR_fsmount 432#define __NR_fsopen 430#define __NR_fspick 433 +#define __NR_fstat 80#define __NR_fstatfs 44#define __NR_fsync 82#define __NR_ftruncate 46
sysdeps/unix/sysv/linux/loongarch/arch-syscall.h line 173
Quoted 7 lines
sysdeps/unix/sysv/linux/loongarch/arch-syscall.h +1
-0@@ -166,6 +167,7 @@#define __NR_munmap 215#define __NR_name_to_handle_at 264#define __NR_nanosleep 101 +#define __NR_newfstatat 79#define __NR_nfsservctl 42#define __NR_open_by_handle_at 265#define __NR_open_tree 428
With the changes, the compiled libraries will unexpectedly include calls to these two syscalls, and be incompatible withi the previous kernel versions.
This series addresses this issue by removing the two definitions if the targeted kernel version is below 6.10.6. I have tested this patch along with the change to arch-syscall.h with or without the configuration option --enable-kernel=6.10.6.
Kernel 6.11 also adds support for passing NULL to statx(fd, NULL, AT_EMPTY_PATH), which improves the performance. This series utilize this feature when statx is used to implement fstat, on some 32-bit platforms and on loongarch with targeting kernel version below 6.10.6.
---
Changes in v3:
- Changed the starting version where fstat/newfstatat are supported to 6.10.6.
- Add a new patch to this series, addressing the support of statx(fd, NULL, AT_EMPTY_PATH).
- Link to v2: https://sourceware.org/pipermail/libc-alpha/2024-August/159300.html
Changes in v2:
- Improve commit message for better patch handling
- Link to v1: https://sourceware.org/pipermail/libc-alpha/2024-August/159295.html
---
Miao Wang (2):
Loongarch: adapt for the re-introduction of fstat and newfstatat in 6.11
linux: Add linux statx(fd, NULL, AT_EMPTY_PATH) support
sysdeps/unix/sysv/linux/fstatat64.c | 9 +++- sysdeps/unix/sysv/linux/fxstat64.c | 4 +- sysdeps/unix/sysv/linux/kernel-features.h | 5 ++ .../unix/sysv/linux/loongarch/kernel-features.h | 27 +++++++++++ sysdeps/unix/sysv/linux/loongarch/sysdep.h | 5 ++ sysdeps/unix/sysv/linux/statx_empty_path.h | 53 ++++++++++++++++++++++ 6 files changed, 99 insertions(+), 4 deletions(-)
---
base-commit: 2eee835eca960c9d4119279804214b7a1ed5d156
change-id: 20240820-loong-fstat-f57f8be48575
Best regards,
Signature · 1 line
Miao Wang <[email protected]>
PATCH v3 1/2 Loongarch: adapt for the re-introduction of fstat and newfstatat in 6.11
In Linux 6.11, fstat and newfstatat are added back. We need to include this change in kernel-features.h to avoid producing libraries incompatible with previous linux versions with new headers.
The definition of the two syscalls will be removed when the targeted kernel version is below 6.10.6 in loongarch/sysdep.h, since the feature has already been backported to 6.10.6 in the stable tree.
--- .../unix/sysv/linux/loongarch/kernel-features.h | 27 ++++++++++++++++++++++ sysdeps/unix/sysv/linux/loongarch/sysdep.h | 5 ++++ 2 files changed, 32 insertions(+)
sysdeps/unix/sysv/linux/loongarch/kernel-features.h new file +27 -0
@@ -0,0 +1,27 @@ +/* Set flags signalling availability of kernel features based on given +kernel version number. Loongarch version. +Copyright (C) 2024 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include_next <kernel-features.h> + +#define __ASSUME_LOONGARCH_NEWSTAT 1 + +/* No support for fstat or newfstatat before 6.10.6. */ +#if __LINUX_KERNEL_VERSION <0x060a06 +# undef __ASSUME_LOONGARCH_NEWSTAT +#endif
sysdeps/unix/sysv/linux/loongarch/sysdep.h +5 -0
@@ -109,6 +109,11 @@#undef SYS_ify#define SYS_ify (syscall_name) __NR_##syscall_name +#ifndef __ASSUME_LOONGARCH_NEWSTAT +#undef __NR_fstat +#undef __NR_newfstatat +#endif +#ifndef __ASSEMBLER__#define VDSO_NAME "LINUX_5.10"
Signature · 1 line
2.43.0
PATCH v3 2/2 linux: Add linux statx(fd, NULL, AT_EMPTY_PATH) support
In reply to Miao WangLinux supports passing NULL instead of an empty string as the second parameter when AT_EMPTY_PATH is set in the flags, starting from 6.11, which brings a performance gain since it is much more efficient to detect a NULL parameter than to detect an empty string in the kernel. We utilize this feature if statx is used for fstat, when glibc is compiled to target kernel versions afterwards, and dynamically probe the kernel support of it, when targeting previous versions.
--- sysdeps/unix/sysv/linux/fstatat64.c | 9 +++-- sysdeps/unix/sysv/linux/fxstat64.c | 4 +-- sysdeps/unix/sysv/linux/kernel-features.h | 5 +++ sysdeps/unix/sysv/linux/statx_empty_path.h | 53 ++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-)
sysdeps/unix/sysv/linux/fstatat64.c +7 -2
@@ -39,6 +39,7 @@ _Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t),#endif #if FSTATAT_USE_STATX +#include <statx_empty_path.h> static inline int fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf,
@@ -47,8 +48,12 @@ fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf,/* 32-bit kABI with default 64-bit time_t, e.g. arc, riscv32. Also 64-bit time_t support is done through statx syscall. */ struct statx tmp; -int r =INTERNAL_SYSCALL_CALL (statx, fd, file,AT_NO_AUTOMOUNT | flag, -STATX_BASIC_STATS , &tmp); +int r; +if ((flag &AT_EMPTY_PATH ) && (file ==NULL || *file =='\0' )) + r =__statx_empty_path (fd,AT_NO_AUTOMOUNT | flag, &tmp); +else + r =INTERNAL_SYSCALL_CALL (statx, fd, file,AT_NO_AUTOMOUNT | flag, +STATX_BASIC_STATS , &tmp);if (r !=0 )return r;
sysdeps/unix/sysv/linux/fxstat64.c +2 -2
@@ -25,6 +25,7 @@#include <xstatconv.h> #include <statx_cp.h> #include <shlib-compat.h> +#include <statx_empty_path.h> #if LIB_COMPAT (libc,GLIBC_2_0 ,GLIBC_2_33 )
@@ -53,8 +54,7 @@ ___fxstat64 (int vers, int fd, struct stat64 *buf)# else /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ struct statx tmp; -int r =INLINE_SYSCALL_CALL (statx, fd,"" ,AT_EMPTY_PATH , -STATX_BASIC_STATS , &tmp); +int r =__statx_empty_path (fd,AT_EMPTY_PATH , &tmp);if (r ==0 )__cp_stat64_statx (buf, &tmp);return r;
sysdeps/unix/sysv/linux/kernel-features.h +5 -0
@@ -257,4 +257,9 @@# define __ASSUME_FCHMODAT2 0#endif +/* statx(fd, NULL, AT_EMPTY_PATH) was introduced in Linux 6.11. */ +#if __LINUX_KERNEL_VERSION >=0x060b00 +# define __ASSUME_STATX_NULL_PATH 1 +#endif +#endif /* kernel-features.h */
sysdeps/unix/sysv/linux/statx_empty_path.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.43.0