* [PATCH v2 0/4] Add clone3 support for multiple architectures @ 2023-07-10 18:40 Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 1/4] s390x: Add the clone3 wrapper Adhemerval Zanella ` (3 more replies) 0 siblings, 4 replies; 9+ messages in thread From: Adhemerval Zanella @ 2023-07-10 18:40 UTC (permalink / raw) To: libc-alpha It enables the posix_spawn optimization on newer kernels. Changes from v1: - Fixed mips SETUP_GP64_STACK. - Undef __ASSUME_CLONE3 for arch that do not support clone3. Adhemerval Zanella (4): s390x: Add the clone3 wrapper arm: Add the clone3 wrapper mips: Add the clone3 wrapper linux: Undef __ASSUME_CLONE3 for alpha, ia64, nios2, sh, and sparc .../unix/sysv/linux/alpha/kernel-features.h | 3 + sysdeps/unix/sysv/linux/arm/clone3.S | 80 ++++++++++ sysdeps/unix/sysv/linux/arm/sysdep.h | 1 + .../unix/sysv/linux/ia64/kernel-features.h | 3 + sysdeps/unix/sysv/linux/mips/clone3.S | 139 ++++++++++++++++++ sysdeps/unix/sysv/linux/mips/sysdep.h | 2 + .../unix/sysv/linux/nios2/kernel-features.h | 23 +++ sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 81 ++++++++++ sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + sysdeps/unix/sysv/linux/sh/kernel-features.h | 3 + .../unix/sysv/linux/sparc/kernel-features.h | 3 + 11 files changed, 339 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/arm/clone3.S create mode 100644 sysdeps/unix/sysv/linux/mips/clone3.S create mode 100644 sysdeps/unix/sysv/linux/nios2/kernel-features.h create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S -- 2.34.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/4] s390x: Add the clone3 wrapper 2023-07-10 18:40 [PATCH v2 0/4] Add clone3 support for multiple architectures Adhemerval Zanella @ 2023-07-10 18:40 ` Adhemerval Zanella 2023-07-12 14:51 ` Stefan Liebler 2023-07-10 18:40 ` [PATCH v2 2/4] arm: " Adhemerval Zanella ` (2 subsequent siblings) 3 siblings, 1 reply; 9+ messages in thread From: Adhemerval Zanella @ 2023-07-10 18:40 UTC (permalink / raw) To: libc-alpha It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on s390x-linux-gnu. --- sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 81 +++++++++++++++++++ sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + 2 files changed, 82 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S new file mode 100644 index 0000000000..417fdcb785 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S @@ -0,0 +1,81 @@ +/* The clone3 syscall wrapper. Linux/s390x version. + Copyright (C) 2023 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 <sysdep.h> +#define _ERRNO_H 1 +#include <bits/errno.h> + +/* The userland implementation is: + int clone3 (struct clone_args *cl_args, size_t size, + int (*func)(void *arg), void *arg); + + the kernel entry is: + int clone3 (struct clone_args *cl_args, size_t size); + + The parameters are passed in registers from userland: + r2: cl_args + r3: size + r4: func + r5: arg */ + + .text +ENTRY(__clone3) + stg %r6, 48(%r15) + + /* Sanity check args. */ + ltgr %r2, %r2 + je error + ltgr %r6, %r4 + je error + + /* Do the system call, the kernel expects: + r1: system call number + r2: cl_args + r3: size */ + lghi %r1, SYS_ify(clone3) + svc 0 + ltgr %r2,%r2 /* check return code */ + jz thread_start + lg %r6, 48(%r15) + jgm SYSCALL_ERROR_LABEL + br %r14 +error: + lghi %r2,-EINVAL + jg SYSCALL_ERROR_LABEL +PSEUDO_END (__clone3) + + .align 4 + .type thread_start, %function +thread_start: + cfi_startproc + /* Mark r14 as undefined in order to stop unwinding here. */ + cfi_undefined (r14) + + /* func is in gpr 6, arg in gpr 5. */ + lgr %r2, %r5 + aghi %r15, -160 + xc 0(8,%r15),0(%r15) + basr %r14, %r6 + + DO_CALL (exit, 1) + cfi_endproc + .size thread_start, .-thread_start + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h index 3bde8ba19c..b099fea9c6 100644 --- a/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -72,6 +72,7 @@ #ifdef __s390x__ #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" +#define HAVE_CLONE3_WRAPPER 1 #else #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" -- 2.34.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] s390x: Add the clone3 wrapper 2023-07-10 18:40 ` [PATCH v2 1/4] s390x: Add the clone3 wrapper Adhemerval Zanella @ 2023-07-12 14:51 ` Stefan Liebler 2023-07-12 18:08 ` Adhemerval Zanella Netto 0 siblings, 1 reply; 9+ messages in thread From: Stefan Liebler @ 2023-07-12 14:51 UTC (permalink / raw) To: libc-alpha Hi Adhemerval, I have applied your patches and tested it on s390x. I've ensured that the wrapper is now used for pthread_create/posix_spawn and the testsuite runs fine. Nevertheless I have some minor comments: see below. And one more question: Is there a reason, why the wrapper is only added to s390x (64bit), but not for s390 (31bit)? Should there be an #undef __ASSUME_CLONE3? According to the kernel commit it is also available for compat-mode: "s390: wire up clone3 system call" https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=5518aed82d2abd97f8d3ec91d8ba455d939e8cd1 On 10.07.23 20:40, Adhemerval Zanella via Libc-alpha wrote: > It follows the internal signature: > > extern int clone3 (struct clone_args *__cl_args, size_t __size, > int (*__func) (void *__arg), void *__arg); > > Checked on s390x-linux-gnu. > --- > sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 81 +++++++++++++++++++ > sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + > 2 files changed, 82 insertions(+) > create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S > > diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S > new file mode 100644 > index 0000000000..417fdcb785 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S > @@ -0,0 +1,81 @@ > +/* The clone3 syscall wrapper. Linux/s390x version. > + Copyright (C) 2023 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 <sysdep.h> > +#define _ERRNO_H 1 > +#include <bits/errno.h> > + > +/* The userland implementation is: > + int clone3 (struct clone_args *cl_args, size_t size, > + int (*func)(void *arg), void *arg); > + > + the kernel entry is: > + int clone3 (struct clone_args *cl_args, size_t size); > + > + The parameters are passed in registers from userland: > + r2: cl_args > + r3: size > + r4: func > + r5: arg */ > + > + .text > +ENTRY(__clone3) > + stg %r6, 48(%r15) Add cfi_offset (%r6,-112) > + > + /* Sanity check args. */ > + ltgr %r2, %r2 > + je error > + ltgr %r6, %r4 > + je error > + > + /* Do the system call, the kernel expects: > + r1: system call number > + r2: cl_args > + r3: size */ > + lghi %r1, SYS_ify(clone3) > + svc 0 > + ltgr %r2,%r2 /* check return code */ > + jz thread_start > + lg %r6, 48(%r15) > + jgm SYSCALL_ERROR_LABEL > + br %r14 > +error: > + lghi %r2,-EINVAL > + jg SYSCALL_ERROR_LABEL > +PSEUDO_END (__clone3) > + > + .align 4 The ENTRY-macro from sysdep.h is using an alignment of 16 bytes. Can you please also use it here? > + .type thread_start, %function > +thread_start: > + cfi_startproc > + /* Mark r14 as undefined in order to stop unwinding here. */ > + cfi_undefined (r14) > + > + /* func is in gpr 6, arg in gpr 5. */ > + lgr %r2, %r5 > + aghi %r15, -160 > + xc 0(8,%r15),0(%r15) > + basr %r14, %r6 > + > + DO_CALL (exit, 1) > + cfi_endproc > + .size thread_start, .-thread_start If you want, you can use ASM_SIZE_DIRECTIVE (thread_start) from sysdep.h here, which is also used in END-macros. > + > +libc_hidden_def (__clone3) > +weak_alias (__clone3, clone3) > diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h > index 3bde8ba19c..b099fea9c6 100644 > --- a/sysdeps/unix/sysv/linux/s390/sysdep.h > +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h > @@ -72,6 +72,7 @@ > #ifdef __s390x__ > #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" > #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" > +#define HAVE_CLONE3_WRAPPER 1 > #else > #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" > #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" Thanks, Stefan ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] s390x: Add the clone3 wrapper 2023-07-12 14:51 ` Stefan Liebler @ 2023-07-12 18:08 ` Adhemerval Zanella Netto 2023-07-13 9:30 ` Stefan Liebler 0 siblings, 1 reply; 9+ messages in thread From: Adhemerval Zanella Netto @ 2023-07-12 18:08 UTC (permalink / raw) To: libc-alpha, Stefan Liebler On 12/07/23 11:51, Stefan Liebler via Libc-alpha wrote: > Hi Adhemerval, > > I have applied your patches and tested it on s390x. I've ensured that > the wrapper is now used for pthread_create/posix_spawn and the testsuite > runs fine. Nevertheless I have some minor comments: see below. > > And one more question: > Is there a reason, why the wrapper is only added to s390x (64bit), but > not for s390 (31bit)? Should there be an #undef __ASSUME_CLONE3? > According to the kernel commit it is also available for compat-mode: > "s390: wire up clone3 system call" > https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=5518aed82d2abd97f8d3ec91d8ba455d939e8cd1 Mainly because I could not test it properly: there is no easy access to s390x machine (such as on gcc build farm), there is no qemu-user support for 31-bit, and I saw strange results running s390 binaries on a s390x qemu vm. > > On 10.07.23 20:40, Adhemerval Zanella via Libc-alpha wrote: >> It follows the internal signature: >> >> extern int clone3 (struct clone_args *__cl_args, size_t __size, >> int (*__func) (void *__arg), void *__arg); >> >> Checked on s390x-linux-gnu. >> --- >> sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 81 +++++++++++++++++++ >> sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + >> 2 files changed, 82 insertions(+) >> create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >> >> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >> new file mode 100644 >> index 0000000000..417fdcb785 >> --- /dev/null >> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >> @@ -0,0 +1,81 @@ >> +/* The clone3 syscall wrapper. Linux/s390x version. >> + Copyright (C) 2023 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 <sysdep.h> >> +#define _ERRNO_H 1 >> +#include <bits/errno.h> >> + >> +/* The userland implementation is: >> + int clone3 (struct clone_args *cl_args, size_t size, >> + int (*func)(void *arg), void *arg); >> + >> + the kernel entry is: >> + int clone3 (struct clone_args *cl_args, size_t size); >> + >> + The parameters are passed in registers from userland: >> + r2: cl_args >> + r3: size >> + r4: func >> + r5: arg */ >> + >> + .text >> +ENTRY(__clone3) >> + stg %r6, 48(%r15) > Add cfi_offset (%r6,-112) > > >> + >> + /* Sanity check args. */ >> + ltgr %r2, %r2 >> + je error >> + ltgr %r6, %r4 >> + je error >> + >> + /* Do the system call, the kernel expects: >> + r1: system call number >> + r2: cl_args >> + r3: size */ >> + lghi %r1, SYS_ify(clone3) >> + svc 0 >> + ltgr %r2,%r2 /* check return code */ >> + jz thread_start >> + lg %r6, 48(%r15) >> + jgm SYSCALL_ERROR_LABEL >> + br %r14 >> +error: >> + lghi %r2,-EINVAL >> + jg SYSCALL_ERROR_LABEL >> +PSEUDO_END (__clone3) >> + >> + .align 4 > The ENTRY-macro from sysdep.h is using an alignment of 16 bytes. Can you > please also use it here? > >> + .type thread_start, %function >> +thread_start: >> + cfi_startproc >> + /* Mark r14 as undefined in order to stop unwinding here. */ >> + cfi_undefined (r14) >> + >> + /* func is in gpr 6, arg in gpr 5. */ >> + lgr %r2, %r5 >> + aghi %r15, -160 >> + xc 0(8,%r15),0(%r15) >> + basr %r14, %r6 >> + >> + DO_CALL (exit, 1) >> + cfi_endproc >> + .size thread_start, .-thread_start > If you want, you can use ASM_SIZE_DIRECTIVE (thread_start) from sysdep.h > here, which is also used in END-macros. >> + >> +libc_hidden_def (__clone3) >> +weak_alias (__clone3, clone3) >> diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h >> index 3bde8ba19c..b099fea9c6 100644 >> --- a/sysdeps/unix/sysv/linux/s390/sysdep.h >> +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h >> @@ -72,6 +72,7 @@ >> #ifdef __s390x__ >> #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" >> #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" >> +#define HAVE_CLONE3_WRAPPER 1 >> #else >> #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" >> #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" Updated patch below. From 74f79943014c4df13f2ce6d6ccd60b8b271319b3 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella <adhemerval.zanella@linaro.org> Date: Tue, 27 Sep 2022 17:00:27 -0300 Subject: [PATCH 1/9] s390x: Add the clone3 wrapper It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on s390x-linux-gnu. --- sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 82 +++++++++++++++++++ sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + 2 files changed, 83 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S new file mode 100644 index 0000000000..22e07fa450 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S @@ -0,0 +1,82 @@ +/* The clone3 syscall wrapper. Linux/s390x version. + Copyright (C) 2023 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 <sysdep.h> +#define _ERRNO_H 1 +#include <bits/errno.h> + +/* The userland implementation is: + int clone3 (struct clone_args *cl_args, size_t size, + int (*func)(void *arg), void *arg); + + the kernel entry is: + int clone3 (struct clone_args *cl_args, size_t size); + + The parameters are passed in registers from userland: + r2: cl_args + r3: size + r4: func + r5: arg */ + + .text +ENTRY(__clone3) + stg %r6, 48(%r15) + cfi_offset (%r6, -112) + + /* Sanity check args. */ + ltgr %r2, %r2 + je error + ltgr %r6, %r4 + je error + + /* Do the system call, the kernel expects: + r1: system call number + r2: cl_args + r3: size */ + lghi %r1, SYS_ify(clone3) + svc 0 + ltgr %r2,%r2 /* check return code */ + jz thread_start + lg %r6, 48(%r15) + jgm SYSCALL_ERROR_LABEL + br %r14 +error: + lghi %r2,-EINVAL + jg SYSCALL_ERROR_LABEL +PSEUDO_END (__clone3) + + .align 16 + .type thread_start, %function +thread_start: + cfi_startproc + /* Mark r14 as undefined in order to stop unwinding here. */ + cfi_undefined (r14) + + /* func is in gpr 6, arg in gpr 5. */ + lgr %r2, %r5 + aghi %r15, -160 + xc 0(8,%r15),0(%r15) + basr %r14, %r6 + + DO_CALL (exit, 1) + cfi_endproc + ASM_SIZE_DIRECTIVE (thread_start) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h index 3bde8ba19c..b099fea9c6 100644 --- a/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -72,6 +72,7 @@ #ifdef __s390x__ #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" +#define HAVE_CLONE3_WRAPPER 1 #else #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" -- 2.34.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] s390x: Add the clone3 wrapper 2023-07-12 18:08 ` Adhemerval Zanella Netto @ 2023-07-13 9:30 ` Stefan Liebler 2023-07-13 11:52 ` Adhemerval Zanella Netto 0 siblings, 1 reply; 9+ messages in thread From: Stefan Liebler @ 2023-07-13 9:30 UTC (permalink / raw) To: Adhemerval Zanella Netto, libc-alpha [-- Attachment #1: Type: text/plain, Size: 9533 bytes --] Hi Adhemerval, I had a further look into the implementation. And we can get rid of save/restore of r6 to stack at all. Despite of r2 (return-value), the syscall does not clobber the registers. Thus we can just keep func in r4 and arg in r5 and use both directly in thread_start. Furthermore I've added a clone3.S in s390-32 directory and define HAVE_CLONE3_WRAPPER to 1 for s390x(64bit)/s390(31bit). The testsuite runs fine for both modes. Both changes are within the patch-file attached (I'm not quite sure if my mail-client corrupts an inlined patch). Bye, Stefan On 12.07.23 20:08, Adhemerval Zanella Netto wrote: > > > On 12/07/23 11:51, Stefan Liebler via Libc-alpha wrote: >> Hi Adhemerval, >> >> I have applied your patches and tested it on s390x. I've ensured that >> the wrapper is now used for pthread_create/posix_spawn and the testsuite >> runs fine. Nevertheless I have some minor comments: see below. >> >> And one more question: >> Is there a reason, why the wrapper is only added to s390x (64bit), but >> not for s390 (31bit)? Should there be an #undef __ASSUME_CLONE3? >> According to the kernel commit it is also available for compat-mode: >> "s390: wire up clone3 system call" >> https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=5518aed82d2abd97f8d3ec91d8ba455d939e8cd1 > > Mainly because I could not test it properly: there is no easy access to > s390x machine (such as on gcc build farm), there is no qemu-user support > for 31-bit, and I saw strange results running s390 binaries on a s390x > qemu vm. > >> >> On 10.07.23 20:40, Adhemerval Zanella via Libc-alpha wrote: >>> It follows the internal signature: >>> >>> extern int clone3 (struct clone_args *__cl_args, size_t __size, >>> int (*__func) (void *__arg), void *__arg); >>> >>> Checked on s390x-linux-gnu. >>> --- >>> sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 81 +++++++++++++++++++ >>> sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + >>> 2 files changed, 82 insertions(+) >>> create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >>> >>> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >>> new file mode 100644 >>> index 0000000000..417fdcb785 >>> --- /dev/null >>> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >>> @@ -0,0 +1,81 @@ >>> +/* The clone3 syscall wrapper. Linux/s390x version. >>> + Copyright (C) 2023 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 <sysdep.h> >>> +#define _ERRNO_H 1 >>> +#include <bits/errno.h> >>> + >>> +/* The userland implementation is: >>> + int clone3 (struct clone_args *cl_args, size_t size, >>> + int (*func)(void *arg), void *arg); >>> + >>> + the kernel entry is: >>> + int clone3 (struct clone_args *cl_args, size_t size); >>> + >>> + The parameters are passed in registers from userland: >>> + r2: cl_args >>> + r3: size >>> + r4: func >>> + r5: arg */ >>> + >>> + .text >>> +ENTRY(__clone3) >>> + stg %r6, 48(%r15) >> Add cfi_offset (%r6,-112) >> >> >>> + >>> + /* Sanity check args. */ >>> + ltgr %r2, %r2 >>> + je error >>> + ltgr %r6, %r4 >>> + je error >>> + >>> + /* Do the system call, the kernel expects: >>> + r1: system call number >>> + r2: cl_args >>> + r3: size */ >>> + lghi %r1, SYS_ify(clone3) >>> + svc 0 >>> + ltgr %r2,%r2 /* check return code */ >>> + jz thread_start >>> + lg %r6, 48(%r15) >>> + jgm SYSCALL_ERROR_LABEL >>> + br %r14 >>> +error: >>> + lghi %r2,-EINVAL >>> + jg SYSCALL_ERROR_LABEL >>> +PSEUDO_END (__clone3) >>> + >>> + .align 4 >> The ENTRY-macro from sysdep.h is using an alignment of 16 bytes. Can you >> please also use it here? >> >>> + .type thread_start, %function >>> +thread_start: >>> + cfi_startproc >>> + /* Mark r14 as undefined in order to stop unwinding here. */ >>> + cfi_undefined (r14) >>> + >>> + /* func is in gpr 6, arg in gpr 5. */ >>> + lgr %r2, %r5 >>> + aghi %r15, -160 >>> + xc 0(8,%r15),0(%r15) >>> + basr %r14, %r6 >>> + >>> + DO_CALL (exit, 1) >>> + cfi_endproc >>> + .size thread_start, .-thread_start >> If you want, you can use ASM_SIZE_DIRECTIVE (thread_start) from sysdep.h >> here, which is also used in END-macros. >>> + >>> +libc_hidden_def (__clone3) >>> +weak_alias (__clone3, clone3) >>> diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h >>> index 3bde8ba19c..b099fea9c6 100644 >>> --- a/sysdeps/unix/sysv/linux/s390/sysdep.h >>> +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h >>> @@ -72,6 +72,7 @@ >>> #ifdef __s390x__ >>> #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" >>> #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" >>> +#define HAVE_CLONE3_WRAPPER 1 >>> #else >>> #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" >>> #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" > > Updated patch below. > > From 74f79943014c4df13f2ce6d6ccd60b8b271319b3 Mon Sep 17 00:00:00 2001 > From: Adhemerval Zanella <adhemerval.zanella@linaro.org> > Date: Tue, 27 Sep 2022 17:00:27 -0300 > Subject: [PATCH 1/9] s390x: Add the clone3 wrapper > > It follows the internal signature: > > extern int clone3 (struct clone_args *__cl_args, size_t __size, > int (*__func) (void *__arg), void *__arg); > > Checked on s390x-linux-gnu. > --- > sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 82 +++++++++++++++++++ > sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + > 2 files changed, 83 insertions(+) > create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S > > diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S > new file mode 100644 > index 0000000000..22e07fa450 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S > @@ -0,0 +1,82 @@ > +/* The clone3 syscall wrapper. Linux/s390x version. > + Copyright (C) 2023 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 <sysdep.h> > +#define _ERRNO_H 1 > +#include <bits/errno.h> > + > +/* The userland implementation is: > + int clone3 (struct clone_args *cl_args, size_t size, > + int (*func)(void *arg), void *arg); > + > + the kernel entry is: > + int clone3 (struct clone_args *cl_args, size_t size); > + > + The parameters are passed in registers from userland: > + r2: cl_args > + r3: size > + r4: func > + r5: arg */ > + > + .text > +ENTRY(__clone3) > + stg %r6, 48(%r15) > + cfi_offset (%r6, -112) > + > + /* Sanity check args. */ > + ltgr %r2, %r2 > + je error > + ltgr %r6, %r4 > + je error > + > + /* Do the system call, the kernel expects: > + r1: system call number > + r2: cl_args > + r3: size */ > + lghi %r1, SYS_ify(clone3) > + svc 0 > + ltgr %r2,%r2 /* check return code */ > + jz thread_start > + lg %r6, 48(%r15) > + jgm SYSCALL_ERROR_LABEL > + br %r14 > +error: > + lghi %r2,-EINVAL > + jg SYSCALL_ERROR_LABEL > +PSEUDO_END (__clone3) > + > + .align 16 > + .type thread_start, %function > +thread_start: > + cfi_startproc > + /* Mark r14 as undefined in order to stop unwinding here. */ > + cfi_undefined (r14) > + > + /* func is in gpr 6, arg in gpr 5. */ > + lgr %r2, %r5 > + aghi %r15, -160 > + xc 0(8,%r15),0(%r15) > + basr %r14, %r6 > + > + DO_CALL (exit, 1) > + cfi_endproc > + ASM_SIZE_DIRECTIVE (thread_start) > + > +libc_hidden_def (__clone3) > +weak_alias (__clone3, clone3) > diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h > index 3bde8ba19c..b099fea9c6 100644 > --- a/sysdeps/unix/sysv/linux/s390/sysdep.h > +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h > @@ -72,6 +72,7 @@ > #ifdef __s390x__ > #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" > #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" > +#define HAVE_CLONE3_WRAPPER 1 > #else > #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" > #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" [-- Attachment #2: 20230713_az_clone3.patch --] [-- Type: text/x-patch, Size: 5490 bytes --] commit 7da61096ec02165454aeaa7436fbe3ccb20b695c Author: Adhemerval Zanella <adhemerval.zanella@linaro.org> Date: Mon Jul 10 15:40:19 2023 -0300 s390x: Add the clone3 wrapper It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on s390x-linux-gnu. diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-32/clone3.S new file mode 100644 index 0000000000..bbe75ce893 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/s390-32/clone3.S @@ -0,0 +1,78 @@ +/* The clone3 syscall wrapper. Linux/s390x version. + Copyright (C) 2023 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 <sysdep.h> +#define _ERRNO_H 1 +#include <bits/errno.h> + +/* The userland implementation is: + int clone3 (struct clone_args *cl_args, size_t size, + int (*func)(void *arg), void *arg); + + the kernel entry is: + int clone3 (struct clone_args *cl_args, size_t size); + + The parameters are passed in registers from userland: + r2: cl_args + r3: size + r4: func + r5: arg */ + + .text +ENTRY(__clone3) + /* Sanity check args. */ + ltr %r2, %r2 + je error + ltr %r4, %r4 + je error + + /* Do the system call, the kernel expects: + r1: system call number + r2: cl_args + r3: size */ + lhi %r1, SYS_ify(clone3) + svc 0 + ltr %r2,%r2 /* check return code */ + jz thread_start + jm SYSCALL_ERROR_LABEL + br %r14 +error: + lhi %r2,-EINVAL + j SYSCALL_ERROR_LABEL +PSEUDO_END (__clone3) + + .align 16 + .type thread_start, %function +thread_start: + cfi_startproc + /* Mark r14 as undefined in order to stop unwinding here. */ + cfi_undefined (r14) + + /* func is in gpr 4, arg in gpr 5. */ + lr %r2, %r5 + ahi %r15, -96 + xc 0(4,%r15),0(%r15) + basr %r14, %r4 + + DO_CALL (exit, 1) + cfi_endproc + ASM_SIZE_DIRECTIVE (thread_start) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S new file mode 100644 index 0000000000..62800f8ef3 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S @@ -0,0 +1,78 @@ +/* The clone3 syscall wrapper. Linux/s390x version. + Copyright (C) 2023 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 <sysdep.h> +#define _ERRNO_H 1 +#include <bits/errno.h> + +/* The userland implementation is: + int clone3 (struct clone_args *cl_args, size_t size, + int (*func)(void *arg), void *arg); + + the kernel entry is: + int clone3 (struct clone_args *cl_args, size_t size); + + The parameters are passed in registers from userland: + r2: cl_args + r3: size + r4: func + r5: arg */ + + .text +ENTRY(__clone3) + /* Sanity check args. */ + ltgr %r2, %r2 + je error + ltgr %r4, %r4 + je error + + /* Do the system call, the kernel expects: + r1: system call number + r2: cl_args + r3: size */ + lghi %r1, SYS_ify(clone3) + svc 0 + ltgr %r2,%r2 /* check return code */ + jz thread_start + jgm SYSCALL_ERROR_LABEL + br %r14 +error: + lghi %r2,-EINVAL + jg SYSCALL_ERROR_LABEL +PSEUDO_END (__clone3) + + .align 16 + .type thread_start, %function +thread_start: + cfi_startproc + /* Mark r14 as undefined in order to stop unwinding here. */ + cfi_undefined (r14) + + /* func is in gpr 4, arg in gpr 5. */ + lgr %r2, %r5 + aghi %r15, -160 + xc 0(8,%r15),0(%r15) + basr %r14, %r4 + + DO_CALL (exit, 1) + cfi_endproc + ASM_SIZE_DIRECTIVE (thread_start) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h index 3bde8ba19c..b2621630f0 100644 --- a/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -79,4 +79,5 @@ #define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" #define HAVE_GETCPU_VSYSCALL "__kernel_getcpu" +#define HAVE_CLONE3_WRAPPER 1 #endif ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] s390x: Add the clone3 wrapper 2023-07-13 9:30 ` Stefan Liebler @ 2023-07-13 11:52 ` Adhemerval Zanella Netto 0 siblings, 0 replies; 9+ messages in thread From: Adhemerval Zanella Netto @ 2023-07-13 11:52 UTC (permalink / raw) To: Stefan Liebler, libc-alpha On 13/07/23 06:30, Stefan Liebler wrote: > Hi Adhemerval, > > I had a further look into the implementation. And we can get rid of > save/restore of r6 to stack at all. Despite of r2 (return-value), the > syscall does not clobber the registers. Thus we can just keep func in r4 > and arg in r5 and use both directly in thread_start. > > Furthermore I've added a clone3.S in s390-32 directory and define > HAVE_CLONE3_WRAPPER to 1 for s390x(64bit)/s390(31bit). > The testsuite runs fine for both modes. > > Both changes are within the patch-file attached (I'm not quite sure if > my mail-client corrupts an inlined patch). > > Bye, > Stefan LGTM, thanks for check the s390 version. I will install the patch. > > On 12.07.23 20:08, Adhemerval Zanella Netto wrote: >> >> >> On 12/07/23 11:51, Stefan Liebler via Libc-alpha wrote: >>> Hi Adhemerval, >>> >>> I have applied your patches and tested it on s390x. I've ensured that >>> the wrapper is now used for pthread_create/posix_spawn and the testsuite >>> runs fine. Nevertheless I have some minor comments: see below. >>> >>> And one more question: >>> Is there a reason, why the wrapper is only added to s390x (64bit), but >>> not for s390 (31bit)? Should there be an #undef __ASSUME_CLONE3? >>> According to the kernel commit it is also available for compat-mode: >>> "s390: wire up clone3 system call" >>> https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=5518aed82d2abd97f8d3ec91d8ba455d939e8cd1 >> >> Mainly because I could not test it properly: there is no easy access to >> s390x machine (such as on gcc build farm), there is no qemu-user support >> for 31-bit, and I saw strange results running s390 binaries on a s390x >> qemu vm. >> >>> >>> On 10.07.23 20:40, Adhemerval Zanella via Libc-alpha wrote: >>>> It follows the internal signature: >>>> >>>> extern int clone3 (struct clone_args *__cl_args, size_t __size, >>>> int (*__func) (void *__arg), void *__arg); >>>> >>>> Checked on s390x-linux-gnu. >>>> --- >>>> sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 81 +++++++++++++++++++ >>>> sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + >>>> 2 files changed, 82 insertions(+) >>>> create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >>>> >>>> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >>>> new file mode 100644 >>>> index 0000000000..417fdcb785 >>>> --- /dev/null >>>> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >>>> @@ -0,0 +1,81 @@ >>>> +/* The clone3 syscall wrapper. Linux/s390x version. >>>> + Copyright (C) 2023 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 <sysdep.h> >>>> +#define _ERRNO_H 1 >>>> +#include <bits/errno.h> >>>> + >>>> +/* The userland implementation is: >>>> + int clone3 (struct clone_args *cl_args, size_t size, >>>> + int (*func)(void *arg), void *arg); >>>> + >>>> + the kernel entry is: >>>> + int clone3 (struct clone_args *cl_args, size_t size); >>>> + >>>> + The parameters are passed in registers from userland: >>>> + r2: cl_args >>>> + r3: size >>>> + r4: func >>>> + r5: arg */ >>>> + >>>> + .text >>>> +ENTRY(__clone3) >>>> + stg %r6, 48(%r15) >>> Add cfi_offset (%r6,-112) >>> >>> >>>> + >>>> + /* Sanity check args. */ >>>> + ltgr %r2, %r2 >>>> + je error >>>> + ltgr %r6, %r4 >>>> + je error >>>> + >>>> + /* Do the system call, the kernel expects: >>>> + r1: system call number >>>> + r2: cl_args >>>> + r3: size */ >>>> + lghi %r1, SYS_ify(clone3) >>>> + svc 0 >>>> + ltgr %r2,%r2 /* check return code */ >>>> + jz thread_start >>>> + lg %r6, 48(%r15) >>>> + jgm SYSCALL_ERROR_LABEL >>>> + br %r14 >>>> +error: >>>> + lghi %r2,-EINVAL >>>> + jg SYSCALL_ERROR_LABEL >>>> +PSEUDO_END (__clone3) >>>> + >>>> + .align 4 >>> The ENTRY-macro from sysdep.h is using an alignment of 16 bytes. Can you >>> please also use it here? >>> >>>> + .type thread_start, %function >>>> +thread_start: >>>> + cfi_startproc >>>> + /* Mark r14 as undefined in order to stop unwinding here. */ >>>> + cfi_undefined (r14) >>>> + >>>> + /* func is in gpr 6, arg in gpr 5. */ >>>> + lgr %r2, %r5 >>>> + aghi %r15, -160 >>>> + xc 0(8,%r15),0(%r15) >>>> + basr %r14, %r6 >>>> + >>>> + DO_CALL (exit, 1) >>>> + cfi_endproc >>>> + .size thread_start, .-thread_start >>> If you want, you can use ASM_SIZE_DIRECTIVE (thread_start) from sysdep.h >>> here, which is also used in END-macros. >>>> + >>>> +libc_hidden_def (__clone3) >>>> +weak_alias (__clone3, clone3) >>>> diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h >>>> index 3bde8ba19c..b099fea9c6 100644 >>>> --- a/sysdeps/unix/sysv/linux/s390/sysdep.h >>>> +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h >>>> @@ -72,6 +72,7 @@ >>>> #ifdef __s390x__ >>>> #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" >>>> #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" >>>> +#define HAVE_CLONE3_WRAPPER 1 >>>> #else >>>> #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" >>>> #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" >> >> Updated patch below. >> >> From 74f79943014c4df13f2ce6d6ccd60b8b271319b3 Mon Sep 17 00:00:00 2001 >> From: Adhemerval Zanella <adhemerval.zanella@linaro.org> >> Date: Tue, 27 Sep 2022 17:00:27 -0300 >> Subject: [PATCH 1/9] s390x: Add the clone3 wrapper >> >> It follows the internal signature: >> >> extern int clone3 (struct clone_args *__cl_args, size_t __size, >> int (*__func) (void *__arg), void *__arg); >> >> Checked on s390x-linux-gnu. >> --- >> sysdeps/unix/sysv/linux/s390/s390-64/clone3.S | 82 +++++++++++++++++++ >> sysdeps/unix/sysv/linux/s390/sysdep.h | 1 + >> 2 files changed, 83 insertions(+) >> create mode 100644 sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >> >> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >> new file mode 100644 >> index 0000000000..22e07fa450 >> --- /dev/null >> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone3.S >> @@ -0,0 +1,82 @@ >> +/* The clone3 syscall wrapper. Linux/s390x version. >> + Copyright (C) 2023 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 <sysdep.h> >> +#define _ERRNO_H 1 >> +#include <bits/errno.h> >> + >> +/* The userland implementation is: >> + int clone3 (struct clone_args *cl_args, size_t size, >> + int (*func)(void *arg), void *arg); >> + >> + the kernel entry is: >> + int clone3 (struct clone_args *cl_args, size_t size); >> + >> + The parameters are passed in registers from userland: >> + r2: cl_args >> + r3: size >> + r4: func >> + r5: arg */ >> + >> + .text >> +ENTRY(__clone3) >> + stg %r6, 48(%r15) >> + cfi_offset (%r6, -112) >> + >> + /* Sanity check args. */ >> + ltgr %r2, %r2 >> + je error >> + ltgr %r6, %r4 >> + je error >> + >> + /* Do the system call, the kernel expects: >> + r1: system call number >> + r2: cl_args >> + r3: size */ >> + lghi %r1, SYS_ify(clone3) >> + svc 0 >> + ltgr %r2,%r2 /* check return code */ >> + jz thread_start >> + lg %r6, 48(%r15) >> + jgm SYSCALL_ERROR_LABEL >> + br %r14 >> +error: >> + lghi %r2,-EINVAL >> + jg SYSCALL_ERROR_LABEL >> +PSEUDO_END (__clone3) >> + >> + .align 16 >> + .type thread_start, %function >> +thread_start: >> + cfi_startproc >> + /* Mark r14 as undefined in order to stop unwinding here. */ >> + cfi_undefined (r14) >> + >> + /* func is in gpr 6, arg in gpr 5. */ >> + lgr %r2, %r5 >> + aghi %r15, -160 >> + xc 0(8,%r15),0(%r15) >> + basr %r14, %r6 >> + >> + DO_CALL (exit, 1) >> + cfi_endproc >> + ASM_SIZE_DIRECTIVE (thread_start) >> + >> +libc_hidden_def (__clone3) >> +weak_alias (__clone3, clone3) >> diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h >> index 3bde8ba19c..b099fea9c6 100644 >> --- a/sysdeps/unix/sysv/linux/s390/sysdep.h >> +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h >> @@ -72,6 +72,7 @@ >> #ifdef __s390x__ >> #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres" >> #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" >> +#define HAVE_CLONE3_WRAPPER 1 >> #else >> #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres" >> #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime" ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/4] arm: Add the clone3 wrapper 2023-07-10 18:40 [PATCH v2 0/4] Add clone3 support for multiple architectures Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 1/4] s390x: Add the clone3 wrapper Adhemerval Zanella @ 2023-07-10 18:40 ` Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 3/4] mips: " Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 4/4] linux: Undef __ASSUME_CLONE3 for alpha, ia64, nios2, sh, and sparc Adhemerval Zanella 3 siblings, 0 replies; 9+ messages in thread From: Adhemerval Zanella @ 2023-07-10 18:40 UTC (permalink / raw) To: libc-alpha It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on arm-linux-gnueabihf. --- sysdeps/unix/sysv/linux/arm/clone3.S | 80 ++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/arm/sysdep.h | 1 + 2 files changed, 81 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/arm/clone3.S diff --git a/sysdeps/unix/sysv/linux/arm/clone3.S b/sysdeps/unix/sysv/linux/arm/clone3.S new file mode 100644 index 0000000000..f236d18390 --- /dev/null +++ b/sysdeps/unix/sysv/linux/arm/clone3.S @@ -0,0 +1,80 @@ +/* The clone3 syscall wrapper. Linux/arm version. + Copyright (C) 2023 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 <sysdep.h> +#define _ERRNO_H 1 +#include <bits/errno.h> + +/* The userland implementation is: + int clone3 (struct clone_args *cl_args, size_t size, + int (*func)(void *arg), void *arg); + + the kernel entry is: + int clone3 (struct clone_args *cl_args, size_t size); + + The parameters are passed in registers from userland: + r0: cl_args + r1: size + r2: func + r3: arg */ + + .text +ENTRY(__clone3) + /* Sanity check args. */ + cmp r0, #0 + ite ne + cmpne r1, #0 + moveq r0, #-EINVAL + beq PLTJMP(syscall_error) + + /* Do the syscall, the kernel expects: + r7: system call number: + r0: cl_args + r1: size */ + push { r7 } + cfi_adjust_cfa_offset (4) + cfi_rel_offset (r7, 0) + ldr r7, =SYS_ify(clone3) + swi 0x0 + cfi_endproc + + cmp r0, #0 + beq 1f + pop {r7} + blt PLTJMP(C_SYMBOL_NAME(__syscall_error)) + RETINSTR(, lr) + + cfi_startproc +PSEUDO_END (__clone3) + +1: + .fnstart + .cantunwind + mov r0, r3 + mov ip, r2 + BLX (ip) + + /* And we are done, passing the return value through r0. */ + ldr r7, =SYS_ify(exit) + swi 0x0 + + .fnend + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.h b/sysdeps/unix/sysv/linux/arm/sysdep.h index 2f321881c8..57fc5f16bd 100644 --- a/sysdeps/unix/sysv/linux/arm/sysdep.h +++ b/sysdeps/unix/sysv/linux/arm/sysdep.h @@ -362,6 +362,7 @@ __local_syscall_error: \ #define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime" #define HAVE_CLOCK_GETTIME64_VSYSCALL "__vdso_clock_gettime64" #define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" +#define HAVE_CLONE3_WRAPPER 1 #define LOAD_ARGS_0() #define ASM_ARGS_0 -- 2.34.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] mips: Add the clone3 wrapper 2023-07-10 18:40 [PATCH v2 0/4] Add clone3 support for multiple architectures Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 1/4] s390x: Add the clone3 wrapper Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 2/4] arm: " Adhemerval Zanella @ 2023-07-10 18:40 ` Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 4/4] linux: Undef __ASSUME_CLONE3 for alpha, ia64, nios2, sh, and sparc Adhemerval Zanella 3 siblings, 0 replies; 9+ messages in thread From: Adhemerval Zanella @ 2023-07-10 18:40 UTC (permalink / raw) To: libc-alpha It follows the internal signature: extern int clone3 (struct clone_args *__cl_args, size_t __size, int (*__func) (void *__arg), void *__arg); Checked on mips64el-linux-gnueabihf, mips64el-n32-linux-gnu, and mipsel-linux-gnu. --- sysdeps/unix/sysv/linux/mips/clone3.S | 139 ++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/mips/sysdep.h | 2 + 2 files changed, 141 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/mips/clone3.S diff --git a/sysdeps/unix/sysv/linux/mips/clone3.S b/sysdeps/unix/sysv/linux/mips/clone3.S new file mode 100644 index 0000000000..1d16bfcef6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/clone3.S @@ -0,0 +1,139 @@ +/* The clone3 syscall wrapper. Linux/mips version. + Copyright (C) 2023 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 <sys/asm.h> +#include <sysdep.h> +#define _ERRNO_H 1 +#include <bits/errno.h> + +/* The userland implementation is: + int clone3 (struct clone_args *cl_args, size_t size, + int (*func)(void *arg), void *arg); + + the kernel entry is: + int clone3 (struct clone_args *cl_args, size_t size); + + The parameters are passed in registers from userland: + a0/$4: cl_args + a1/$5: size + a2/$6: func + a3/$7: arg */ + + .text + .set nomips16 +#if _MIPS_SIM == _ABIO32 +# define EXTRA_LOCALS 1 +#else +# define EXTRA_LOCALS 0 +#endif +#define FRAMESZ ((NARGSAVE*SZREG)+ALSZ)&ALMASK +GPOFF= FRAMESZ-(1*SZREG) +NESTED(__clone3, SZREG, sp) +#ifdef __PIC__ + SETUP_GP +#endif +#if FRAMESZ + PTR_SUBU sp, FRAMESZ + cfi_adjust_cfa_offset (FRAMESZ) +#endif + SETUP_GP64_STACK (GPOFF, __clone3) +#ifdef __PIC__ + SAVE_GP (GPOFF) +#endif +#ifdef PROF + .set noat + move $1,ra + jal _mcount + .set at +#endif + + /* Sanity check args. */ + li v0, EINVAL + beqz a0, L(error) /* No NULL cl_args pointer. */ + beqz a2, L(error) /* No NULL function pointer. */ + + move $8, a3 /* a3 is set to 0/1 for syscall success/error + while a4/$8 is returned unmodified. */ + + /* Do the system call, the kernel expects: + v0: system call number + a0: cl_args + a1: size */ + li v0, __NR_clone3 + cfi_endproc + syscall + + bnez a3, L(error) + beqz v0, L(thread_start_clone3) + + /* Successful return from the parent */ + cfi_startproc +#if FRAMESZ + cfi_adjust_cfa_offset (FRAMESZ) +#endif + SETUP_GP64_STACK_CFI (GPOFF) + cfi_remember_state + RESTORE_GP64_STACK +#if FRAMESZ + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) +#endif + ret + +L(error): + cfi_restore_state +#ifdef __PIC__ + PTR_LA t9, __syscall_error + RESTORE_GP64_STACK + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) + jr t9 +#else + RESTORE_GP64_STACK + PTR_ADDU sp, FRAMESZ + cfi_adjust_cfa_offset (-FRAMESZ) + j __syscall_error +#endif +END (__clone3) + +/* Load up the arguments to the function. Put this block of code in + its own function so that we can terminate the stack trace with our + debug info. */ + +ENTRY(__thread_start_clone3) +L(thread_start_clone3): + cfi_undefined ($31) + /* cp is already loaded. */ + SAVE_GP (GPOFF) + /* The stackframe has been created on entry of clone3. */ + + /* Restore the arg for user's function. */ + move t9, a2 /* Function pointer. */ + move a0, $8 /* Argument pointer. */ + + /* Call the user's function. */ + jal t9 + + move a0, v0 + li v0, __NR_exit + syscall +END(__thread_start_clone3) + +libc_hidden_def (__clone3) +weak_alias (__clone3, clone3) diff --git a/sysdeps/unix/sysv/linux/mips/sysdep.h b/sysdeps/unix/sysv/linux/mips/sysdep.h index ff84a91b31..673aa08b57 100644 --- a/sysdeps/unix/sysv/linux/mips/sysdep.h +++ b/sysdeps/unix/sysv/linux/mips/sysdep.h @@ -28,3 +28,5 @@ #endif #define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday" #define HAVE_CLOCK_GETRES_VSYSCALL "__vdso_clock_getres" + +#define HAVE_CLONE3_WRAPPER 1 -- 2.34.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 4/4] linux: Undef __ASSUME_CLONE3 for alpha, ia64, nios2, sh, and sparc 2023-07-10 18:40 [PATCH v2 0/4] Add clone3 support for multiple architectures Adhemerval Zanella ` (2 preceding siblings ...) 2023-07-10 18:40 ` [PATCH v2 3/4] mips: " Adhemerval Zanella @ 2023-07-10 18:40 ` Adhemerval Zanella 3 siblings, 0 replies; 9+ messages in thread From: Adhemerval Zanella @ 2023-07-10 18:40 UTC (permalink / raw) To: libc-alpha Not all architectures added clone3 syscall. --- .../unix/sysv/linux/alpha/kernel-features.h | 3 +++ .../unix/sysv/linux/ia64/kernel-features.h | 3 +++ .../unix/sysv/linux/nios2/kernel-features.h | 23 +++++++++++++++++++ sysdeps/unix/sysv/linux/sh/kernel-features.h | 3 +++ .../unix/sysv/linux/sparc/kernel-features.h | 3 +++ 5 files changed, 35 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/nios2/kernel-features.h diff --git a/sysdeps/unix/sysv/linux/alpha/kernel-features.h b/sysdeps/unix/sysv/linux/alpha/kernel-features.h index 3151e75449..e298bf2bcc 100644 --- a/sysdeps/unix/sysv/linux/alpha/kernel-features.h +++ b/sysdeps/unix/sysv/linux/alpha/kernel-features.h @@ -50,4 +50,7 @@ /* Alpha requires old sysvipc even being a 64-bit architecture. */ #undef __ASSUME_SYSVIPC_DEFAULT_IPC_64 +/* Alpha does not provide clone3. */ +#undef __ASSUME_CLONE3 + #endif /* _KERNEL_FEATURES_H */ diff --git a/sysdeps/unix/sysv/linux/ia64/kernel-features.h b/sysdeps/unix/sysv/linux/ia64/kernel-features.h index 98ebfb74bf..6580ec20fe 100644 --- a/sysdeps/unix/sysv/linux/ia64/kernel-features.h +++ b/sysdeps/unix/sysv/linux/ia64/kernel-features.h @@ -34,4 +34,7 @@ #undef __ASSUME_CLONE_DEFAULT #define __ASSUME_CLONE2 +/* ia64 does not provide clone3. */ +#undef __ASSUME_CLONE3 + #endif /* _KERNEL_FEATURES_H */ diff --git a/sysdeps/unix/sysv/linux/nios2/kernel-features.h b/sysdeps/unix/sysv/linux/nios2/kernel-features.h new file mode 100644 index 0000000000..bb2d887dd5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/kernel-features.h @@ -0,0 +1,23 @@ +/* Set flags signalling availability of kernel features based on given + kernel version number. NIOS2 version. + Copyright (C) 2023 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> + +/* nios2 does not provide clone3. */ +#undef __ASSUME_CLONE3 diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h index 953fa8dff0..80a90d05bb 100644 --- a/sysdeps/unix/sysv/linux/sh/kernel-features.h +++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h @@ -55,4 +55,7 @@ # undef __ASSUME_STATX #endif +/* sh does not provide clone3. */ +#undef __ASSUME_CLONE3 + #endif diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h index 98c938c16d..fa9383081f 100644 --- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h +++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h @@ -87,3 +87,6 @@ (INLINE_CLONE_SYSCALL). */ #undef __ASSUME_CLONE_DEFAULT #define __ASSUME_CLONE_BACKWARDS 1 + +/* sparc does not provide clone3. */ +#undef __ASSUME_CLONE3 -- 2.34.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-07-13 11:52 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-07-10 18:40 [PATCH v2 0/4] Add clone3 support for multiple architectures Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 1/4] s390x: Add the clone3 wrapper Adhemerval Zanella 2023-07-12 14:51 ` Stefan Liebler 2023-07-12 18:08 ` Adhemerval Zanella Netto 2023-07-13 9:30 ` Stefan Liebler 2023-07-13 11:52 ` Adhemerval Zanella Netto 2023-07-10 18:40 ` [PATCH v2 2/4] arm: " Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 3/4] mips: " Adhemerval Zanella 2023-07-10 18:40 ` [PATCH v2 4/4] linux: Undef __ASSUME_CLONE3 for alpha, ia64, nios2, sh, and sparc Adhemerval Zanella
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).