All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ARC: Add the clone3 wrapper
@ 2023-03-02 16:10 Pavel.Kozlov
  2023-03-02 16:10 ` [PATCH 2/2] ARC: run child from the separate start block in __clone Pavel.Kozlov
  2023-03-07 12:02 ` [PATCH 1/2] ARC: Add the clone3 wrapper Adhemerval Zanella Netto
  0 siblings, 2 replies; 4+ messages in thread
From: Pavel.Kozlov @ 2023-03-02 16:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: linux-snps-arc, Pavel Kozlov

From: Pavel Kozlov <pavel.kozlov@synopsys.com>

Use the clone3 wrapper on ARC. It doesn't care about stack alignment.
All callers should provide an aligned stack.
It follows the internal signature:

extern int clone3 (struct clone_args *__cl_args, size_t __size,
 int (*__func) (void *__arg), void *__arg);
---
Checked on arc-linux-gnu. Previously observed tst-misaling-clone-internal
test fail was because I used outdated master branch.
Full testsuite runs without regressions.
But I also see fail of the new tst-spawn7, as already repoted at [1].

[1]
https://sourceware.org/pipermail/libc-alpha/2023-February/145937.html

 sysdeps/unix/sysv/linux/arc/clone3.S | 90 ++++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/arc/sysdep.h |  2 +
 2 files changed, 92 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/arc/clone3.S

diff --git a/sysdeps/unix/sysv/linux/arc/clone3.S b/sysdeps/unix/sysv/linux/arc/clone3.S
new file mode 100644
index 000000000000..87a8272a3977
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/arc/clone3.S
@@ -0,0 +1,90 @@
+/* The clone3 syscall wrapper.  Linux/arc 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  */
+
+ENTRY(__clone3)
+
+	/* Save args for the child.  */
+	mov	r10, r0		/* cl_args  */
+	mov	r11, r2		/* func	 */
+	mov	r12, r3		/* args  */
+
+	/* Sanity check args.  */
+	breq	r10, 0, L (__sys_err)	/* No NULL cl_args pointer.  */
+	breq	r11, 0, L (__sys_err)	/* No NULL function pointer.  */
+
+	/* Do the system call, the kernel expects:
+	   r8: system call number
+	   r0: cl_args
+	   r1: size  */
+	mov	r0, r10
+	mov	r8, __NR_clone3
+	ARC_TRAP_INSN
+
+	cmp	r0, 0
+	beq	thread_start_clone3	/* Child returns.  */
+	blt	L (__sys_err2)
+	j	[blink]			/* Parent returns.  */
+
+L (__sys_err):
+	mov	r0, -EINVAL
+L (__sys_err2):
+	b	__syscall_error
+PSEUDO_END (__clone3)
+
+
+	.align 4
+	.type thread_start_clone3, %function
+thread_start_clone3:
+	cfi_startproc
+	/* Terminate call stack by noting ra is undefined.  */
+	cfi_undefined (blink)
+
+	/* Child jumps off to @fn with @arg as argument.  */
+	jl.d	[r11]
+	mov	r0, r12
+
+	/* exit() with result from @fn (already in r0).  */
+	mov	r8, __NR_exit
+	ARC_TRAP_INSN
+
+	/* In case it ever came back.  */
+	flag	1
+
+	cfi_endproc
+	.size thread_start_clone3, .-thread_start_clone3
+
+libc_hidden_def (__clone3)
+weak_alias (__clone3, clone3)
diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.h b/sysdeps/unix/sysv/linux/arc/sysdep.h
index dd6fe73445f9..88dc1dff017f 100644
--- a/sysdeps/unix/sysv/linux/arc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/arc/sysdep.h
@@ -141,6 +141,8 @@ hidden_proto (__syscall_error)
 
 # define ARC_TRAP_INSN	"trap_s 0	\n\t"
 
+# define HAVE_CLONE3_WRAPPER	1
+
 # undef INTERNAL_SYSCALL_NCS
 # define INTERNAL_SYSCALL_NCS(number, nr_args, args...)	\
   ({								\
-- 
2.25.1


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] ARC: run child from the separate start block in __clone
  2023-03-02 16:10 [PATCH 1/2] ARC: Add the clone3 wrapper Pavel.Kozlov
@ 2023-03-02 16:10 ` Pavel.Kozlov
  2023-03-07 12:03   ` Adhemerval Zanella Netto
  2023-03-07 12:02 ` [PATCH 1/2] ARC: Add the clone3 wrapper Adhemerval Zanella Netto
  1 sibling, 1 reply; 4+ messages in thread
From: Pavel.Kozlov @ 2023-03-02 16:10 UTC (permalink / raw)
  To: libc-alpha; +Cc: linux-snps-arc, Pavel Kozlov

From: Pavel Kozlov <pavel.kozlov@synopsys.com>

For better debug experience use separate code block with extra
cfi_* directives to run child (same as in __clone3).
---
 sysdeps/unix/sysv/linux/arc/clone.S | 40 ++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/arc/clone.S b/sysdeps/unix/sysv/linux/arc/clone.S
index 766649625658..0029aaeb8170 100644
--- a/sysdeps/unix/sysv/linux/arc/clone.S
+++ b/sysdeps/unix/sysv/linux/arc/clone.S
@@ -20,9 +20,6 @@
 #include <sysdep.h>
 #define _ERRNO_H	1
 #include <bits/errno.h>
-#include <tcb-offsets.h>
-
-#define CLONE_SETTLS		0x00080000
 
 /* int clone(int (*fn)(void *), void *child_stack,
            int flags, void *arg, ...
@@ -63,19 +60,9 @@ ENTRY (__clone)
 	ARC_TRAP_INSN
 
 	cmp	r0, 0		/* return code : 0 new process, !0 parent.  */
+	beq	thread_start_clone
 	blt	L (__sys_err2)	/* < 0 (signed) error.  */
-	jnz	[blink]		/* Parent returns.  */
-
-	/* child jumps off to @fn with @arg as argument
-           TP register already set by kernel.  */
-	jl.d	[r10]
-	mov	r0, r11
-
-	/* exit() with result from @fn (already in r0).  */
-	mov	r8, __NR_exit
-	ARC_TRAP_INSN
-	/* In case it ever came back.  */
-	flag	1
+	j	[blink]		/* Parent returns.  */
 
 L (__sys_err):
 	mov	r0, -EINVAL
@@ -89,5 +76,28 @@ L (__sys_err2):
 	       position independent.  */
 	b   __syscall_error
 PSEUDO_END (__clone)
+
+
+	.align 4
+	.type thread_start_clone, %function
+thread_start_clone:
+	cfi_startproc
+	/* Terminate call stack by noting ra is undefined.  */
+	cfi_undefined (blink)
+
+	/* Child jumps off to @fn with @arg as argument.  */
+	jl.d	[r10]
+	mov	r0, r11
+
+	/* exit() with result from @fn (already in r0).  */
+	mov	r8, __NR_exit
+	ARC_TRAP_INSN
+
+	/* In case it ever came back.  */
+	flag	1
+
+	cfi_endproc
+	.size thread_start_clone, .-thread_start_clone
+
 libc_hidden_def (__clone)
 weak_alias (__clone, clone)
-- 
2.25.1


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] ARC: Add the clone3 wrapper
  2023-03-02 16:10 [PATCH 1/2] ARC: Add the clone3 wrapper Pavel.Kozlov
  2023-03-02 16:10 ` [PATCH 2/2] ARC: run child from the separate start block in __clone Pavel.Kozlov
@ 2023-03-07 12:02 ` Adhemerval Zanella Netto
  1 sibling, 0 replies; 4+ messages in thread
From: Adhemerval Zanella Netto @ 2023-03-07 12:02 UTC (permalink / raw)
  To: Pavel.Kozlov, libc-alpha; +Cc: linux-snps-arc



On 02/03/23 13:10, Pavel Kozlov via Libc-alpha wrote:
> From: Pavel Kozlov <pavel.kozlov@synopsys.com>
> 
> Use the clone3 wrapper on ARC. It doesn't care about stack alignment.
> All callers should provide an aligned stack.
> It follows the internal signature:
> 
> extern int clone3 (struct clone_args *__cl_args, size_t __size,
>  int (*__func) (void *__arg), void *__arg);

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
> Checked on arc-linux-gnu. Previously observed tst-misaling-clone-internal
> test fail was because I used outdated master branch.
> Full testsuite runs without regressions.
> But I also see fail of the new tst-spawn7, as already repoted at [1].
> 
> [1]
> https://sourceware.org/pipermail/libc-alpha/2023-February/145937.html
> 
>  sysdeps/unix/sysv/linux/arc/clone3.S | 90 ++++++++++++++++++++++++++++
>  sysdeps/unix/sysv/linux/arc/sysdep.h |  2 +
>  2 files changed, 92 insertions(+)
>  create mode 100644 sysdeps/unix/sysv/linux/arc/clone3.S
> 
> diff --git a/sysdeps/unix/sysv/linux/arc/clone3.S b/sysdeps/unix/sysv/linux/arc/clone3.S
> new file mode 100644
> index 000000000000..87a8272a3977
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/arc/clone3.S
> @@ -0,0 +1,90 @@
> +/* The clone3 syscall wrapper.  Linux/arc 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  */
> +
> +ENTRY(__clone3)
> +
> +	/* Save args for the child.  */
> +	mov	r10, r0		/* cl_args  */
> +	mov	r11, r2		/* func	 */
> +	mov	r12, r3		/* args  */
> +
> +	/* Sanity check args.  */
> +	breq	r10, 0, L (__sys_err)	/* No NULL cl_args pointer.  */
> +	breq	r11, 0, L (__sys_err)	/* No NULL function pointer.  */
> +
> +	/* Do the system call, the kernel expects:
> +	   r8: system call number
> +	   r0: cl_args
> +	   r1: size  */
> +	mov	r0, r10
> +	mov	r8, __NR_clone3
> +	ARC_TRAP_INSN
> +
> +	cmp	r0, 0
> +	beq	thread_start_clone3	/* Child returns.  */
> +	blt	L (__sys_err2)
> +	j	[blink]			/* Parent returns.  */
> +
> +L (__sys_err):
> +	mov	r0, -EINVAL
> +L (__sys_err2):
> +	b	__syscall_error
> +PSEUDO_END (__clone3)
> +
> +
> +	.align 4
> +	.type thread_start_clone3, %function
> +thread_start_clone3:
> +	cfi_startproc
> +	/* Terminate call stack by noting ra is undefined.  */
> +	cfi_undefined (blink)
> +
> +	/* Child jumps off to @fn with @arg as argument.  */
> +	jl.d	[r11]
> +	mov	r0, r12
> +
> +	/* exit() with result from @fn (already in r0).  */
> +	mov	r8, __NR_exit
> +	ARC_TRAP_INSN
> +
> +	/* In case it ever came back.  */
> +	flag	1
> +
> +	cfi_endproc
> +	.size thread_start_clone3, .-thread_start_clone3
> +
> +libc_hidden_def (__clone3)
> +weak_alias (__clone3, clone3)
> diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.h b/sysdeps/unix/sysv/linux/arc/sysdep.h
> index dd6fe73445f9..88dc1dff017f 100644
> --- a/sysdeps/unix/sysv/linux/arc/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/arc/sysdep.h
> @@ -141,6 +141,8 @@ hidden_proto (__syscall_error)
>  
>  # define ARC_TRAP_INSN	"trap_s 0	\n\t"
>  
> +# define HAVE_CLONE3_WRAPPER	1
> +
>  # undef INTERNAL_SYSCALL_NCS
>  # define INTERNAL_SYSCALL_NCS(number, nr_args, args...)	\
>    ({								\

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] ARC: run child from the separate start block in __clone
  2023-03-02 16:10 ` [PATCH 2/2] ARC: run child from the separate start block in __clone Pavel.Kozlov
@ 2023-03-07 12:03   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 4+ messages in thread
From: Adhemerval Zanella Netto @ 2023-03-07 12:03 UTC (permalink / raw)
  To: Pavel.Kozlov, libc-alpha; +Cc: linux-snps-arc



On 02/03/23 13:10, Pavel Kozlov via Libc-alpha wrote:
> From: Pavel Kozlov <pavel.kozlov@synopsys.com>
> 
> For better debug experience use separate code block with extra
> cfi_* directives to run child (same as in __clone3).

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/unix/sysv/linux/arc/clone.S | 40 ++++++++++++++++++-----------
>  1 file changed, 25 insertions(+), 15 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/arc/clone.S b/sysdeps/unix/sysv/linux/arc/clone.S
> index 766649625658..0029aaeb8170 100644
> --- a/sysdeps/unix/sysv/linux/arc/clone.S
> +++ b/sysdeps/unix/sysv/linux/arc/clone.S
> @@ -20,9 +20,6 @@
>  #include <sysdep.h>
>  #define _ERRNO_H	1
>  #include <bits/errno.h>
> -#include <tcb-offsets.h>
> -
> -#define CLONE_SETTLS		0x00080000
>  
>  /* int clone(int (*fn)(void *), void *child_stack,
>             int flags, void *arg, ...
> @@ -63,19 +60,9 @@ ENTRY (__clone)
>  	ARC_TRAP_INSN
>  
>  	cmp	r0, 0		/* return code : 0 new process, !0 parent.  */
> +	beq	thread_start_clone
>  	blt	L (__sys_err2)	/* < 0 (signed) error.  */
> -	jnz	[blink]		/* Parent returns.  */
> -
> -	/* child jumps off to @fn with @arg as argument
> -           TP register already set by kernel.  */
> -	jl.d	[r10]
> -	mov	r0, r11
> -
> -	/* exit() with result from @fn (already in r0).  */
> -	mov	r8, __NR_exit
> -	ARC_TRAP_INSN
> -	/* In case it ever came back.  */
> -	flag	1
> +	j	[blink]		/* Parent returns.  */
>  
>  L (__sys_err):
>  	mov	r0, -EINVAL
> @@ -89,5 +76,28 @@ L (__sys_err2):
>  	       position independent.  */
>  	b   __syscall_error
>  PSEUDO_END (__clone)
> +
> +
> +	.align 4
> +	.type thread_start_clone, %function
> +thread_start_clone:
> +	cfi_startproc
> +	/* Terminate call stack by noting ra is undefined.  */
> +	cfi_undefined (blink)
> +
> +	/* Child jumps off to @fn with @arg as argument.  */
> +	jl.d	[r10]
> +	mov	r0, r11
> +
> +	/* exit() with result from @fn (already in r0).  */
> +	mov	r8, __NR_exit
> +	ARC_TRAP_INSN
> +
> +	/* In case it ever came back.  */
> +	flag	1
> +
> +	cfi_endproc
> +	.size thread_start_clone, .-thread_start_clone
> +
>  libc_hidden_def (__clone)
>  weak_alias (__clone, clone)

_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-07 12:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 16:10 [PATCH 1/2] ARC: Add the clone3 wrapper Pavel.Kozlov
2023-03-02 16:10 ` [PATCH 2/2] ARC: run child from the separate start block in __clone Pavel.Kozlov
2023-03-07 12:03   ` Adhemerval Zanella Netto
2023-03-07 12:02 ` [PATCH 1/2] ARC: Add the clone3 wrapper Adhemerval Zanella Netto

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.