[PATCH v2] Loongarch: adapt for the re-introduction of fstat and newfstatat in 6.11

Xi Ruoyao xry111@xry111.site
Tue Aug 20 15:06:31 GMT 2024


On Tue, 2024-08-20 at 22:12 +0800, Miao Wang via B4 Relay wrote:
> From: Miao Wang <shankerwangmiao@gmail.com>
> 
> 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.11 in loongarch/sysdep.h.
> 
> Signed-off-by: Miao Wang <shankerwangmiao@gmail.com>

You should resolve the previous review comments before sending a new
version.  If you don't agree with 6.10.6 then fine to leave the code
unchanged but you need to explain the reason in the commit message.  And
to me "I think the backport is questionable" isn't a good reason (i.e.
we need the reason it's questionable, not just "it's questionable").

And before you start to say "downstream distros may think the backport
is questionable and revert it," no.  Glibc does not support non-Linus
trees.  If you must patch the kernel in some way Glibc cannot expect
it's your own job to fix up your Glibc fork as well.

> ---
> Kernel 6.11 adds back fstat and newfstatat in commit 7697a0fe0154
> ("LoongArch: Define __ARCH_WANT_NEW_STAT in unistd.h"). With kernel
> headers from 6.11, make update-syscall-lists will generate the
> following
> diffs:
> 
> > diff --git a/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
> > b/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
> > index 8bb82448a7..7e732256fd 100644
> > --- a/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
> > +++ b/sysdeps/unix/sysv/linux/loongarch/arch-syscall.h
> > @@ -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
> > @@ -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 that changed, the compiled libraries will unexpectedly include
> calls to these two syscalls, and be incompatible with previous kernel
> versions.
> 
> This patch addresses this issue by removing the two definitions if the
> targeted kernel version is below 6.11. I have tested this patch along
> with the change to arch-syscall.h with or without the configuration
> option --enable-kernel=6.11.
> ---
> Changes in v2:
> - Improve commit message for better patch handling
> - Link to v1:
> https://sourceware.org/pipermail/libc-alpha/2024-August/159295.html
> ---
>  .../unix/sysv/linux/loongarch/kernel-features.h    | 27
> ++++++++++++++++++++++
>  sysdeps/unix/sysv/linux/loongarch/sysdep.h         |  5 ++++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/sysdeps/unix/sysv/linux/loongarch/kernel-features.h
> b/sysdeps/unix/sysv/linux/loongarch/kernel-features.h
> new file mode 100644
> index 0000000000..c0e7ccb5de
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/loongarch/kernel-features.h
> @@ -0,0 +1,27 @@
> +/* Set flags signalling availability of kernel features based on
> given
> +   kernel version number.  Loongarch version.
> +   Copyright (C) 2024-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.11.  */
> +#if __LINUX_KERNEL_VERSION < 0x060b00
> +# undef __ASSUME_LOONGARCH_NEWSTAT
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> index eb0ba790da..1fdf18197f 100644
> --- a/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h
> @@ -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"
> 
> ---
> base-commit: 2eee835eca960c9d4119279804214b7a1ed5d156
> change-id: 20240820-loong-fstat-f57f8be48575
> 
> Best regards,

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University


More information about the Libc-alpha mailing list