Linux-m68k Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] m68k: Implement copy_thread_tls()
@ 2020-01-13 10:30 Geert Uytterhoeven
  2020-01-13 10:37 ` Christian Brauner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2020-01-13 10:30 UTC (permalink / raw)
  To: Greg Ungerer
  Cc: Amanieu d'Antras, Christian Brauner, Kars de Jong, Al Viro,
	linux-m68k, linux-kernel, linux-next, Geert Uytterhoeven

This is required for clone3(), which passes the TLS value through a
struct rather than a register.

As do_fork() is only available if CONFIG_HAVE_COPY_THREAD_TLS is set,
m68k_clone() must be changed to call _do_fork() directly.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
This is a dependency for the combination of commits
e8bb2a2a1d51511e ("m68k: Wire up clone3() syscall") in m68k/for-next,
dd499f7a7e342702 ("clone3: ensure copy_thread_tls is implemented") in
v5.5-rc6.
---
 arch/m68k/Kconfig          |  1 +
 arch/m68k/kernel/process.c | 31 ++++++++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 6663f1741798e83f..6ad6cdac74b3dc42 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -14,6 +14,7 @@ config M68K
 	select HAVE_AOUT if MMU
 	select HAVE_ASM_MODVERSIONS
 	select HAVE_DEBUG_BUGVERBOSE
+	select HAVE_COPY_THREAD_TLS
 	select GENERIC_IRQ_SHOW
 	select GENERIC_ATOMIC64
 	select HAVE_UID16
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index 22e6b8f4f9582aa4..8f0d9140700f09ad 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -108,16 +108,28 @@ void flush_thread(void)
  * on top of pt_regs, which means that sys_clone() arguments would be
  * buried.  We could, of course, copy them, but it's too costly for no
  * good reason - generic clone() would have to copy them *again* for
- * do_fork() anyway.  So in this case it's actually better to pass pt_regs *
- * and extract arguments for do_fork() from there.  Eventually we might
- * go for calling do_fork() directly from the wrapper, but only after we
- * are finished with do_fork() prototype conversion.
+ * _do_fork() anyway.  So in this case it's actually better to pass pt_regs *
+ * and extract arguments for _do_fork() from there.  Eventually we might
+ * go for calling _do_fork() directly from the wrapper, but only after we
+ * are finished with _do_fork() prototype conversion.
  */
 asmlinkage int m68k_clone(struct pt_regs *regs)
 {
 	/* regs will be equal to current_pt_regs() */
-	return do_fork(regs->d1, regs->d2, 0,
-		       (int __user *)regs->d3, (int __user *)regs->d4);
+	struct kernel_clone_args args = {
+		.flags		= regs->d1 & ~CSIGNAL,
+		.pidfd		= (int __user *)regs->d3,
+		.child_tid	= (int __user *)regs->d4,
+		.parent_tid	= (int __user *)regs->d3,
+		.exit_signal	= regs->d1 & CSIGNAL,
+		.stack		= regs->d2,
+		.tls		= regs->d5,
+	};
+
+	if (!legacy_clone_args_valid(&args))
+		return -EINVAL;
+
+	return _do_fork(&args);
 }
 
 /*
@@ -130,8 +142,9 @@ asmlinkage int m68k_clone3(struct pt_regs *regs)
 	return sys_clone3((struct clone_args __user *)regs->d1, regs->d2);
 }
 
-int copy_thread(unsigned long clone_flags, unsigned long usp,
-		 unsigned long arg, struct task_struct *p)
+int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
+		    unsigned long arg, struct task_struct *p,
+		    unsigned long tls)
 {
 	struct fork_frame {
 		struct switch_stack sw;
@@ -166,7 +179,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 	p->thread.usp = usp ?: rdusp();
 
 	if (clone_flags & CLONE_SETTLS)
-		task_thread_info(p)->tp_value = frame->regs.d5;
+		task_thread_info(p)->tp_value = tls;
 
 #ifdef CONFIG_FPU
 	if (!FPU_IS_EMU) {
-- 
2.17.1


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

* Re: [PATCH] m68k: Implement copy_thread_tls()
  2020-01-13 10:30 [PATCH] m68k: Implement copy_thread_tls() Geert Uytterhoeven
@ 2020-01-13 10:37 ` Christian Brauner
  2020-01-14  1:55 ` Greg Ungerer
  2020-01-14  9:50 ` Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2020-01-13 10:37 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Ungerer, Amanieu d'Antras, Christian Brauner,
	Kars de Jong, Al Viro, linux-m68k, linux-kernel, linux-next

On Mon, Jan 13, 2020 at 11:30:40AM +0100, Geert Uytterhoeven wrote:
> This is required for clone3(), which passes the TLS value through a
> struct rather than a register.
> 
> As do_fork() is only available if CONFIG_HAVE_COPY_THREAD_TLS is set,
> m68k_clone() must be changed to call _do_fork() directly.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Thanks!
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>

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

* Re: [PATCH] m68k: Implement copy_thread_tls()
  2020-01-13 10:30 [PATCH] m68k: Implement copy_thread_tls() Geert Uytterhoeven
  2020-01-13 10:37 ` Christian Brauner
@ 2020-01-14  1:55 ` Greg Ungerer
  2020-01-14  9:50 ` Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Greg Ungerer @ 2020-01-14  1:55 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Amanieu d'Antras, Christian Brauner, Kars de Jong, Al Viro,
	linux-m68k, linux-kernel, linux-next

Hi Geert,

On 13/1/20 8:30 pm, Geert Uytterhoeven wrote:
> This is required for clone3(), which passes the TLS value through a
> struct rather than a register.
> 
> As do_fork() is only available if CONFIG_HAVE_COPY_THREAD_TLS is set,
> m68k_clone() must be changed to call _do_fork() directly.
> 
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Looks good for ColdFire too. I compiled for both MMU and non-MMU
targets and no regressions (I did not test clone3() itself though).

Acked-by: Greg Ungerer <gerg@linux-m68k.org>

Regards
Greg


> ---
> This is a dependency for the combination of commits
> e8bb2a2a1d51511e ("m68k: Wire up clone3() syscall") in m68k/for-next,
> dd499f7a7e342702 ("clone3: ensure copy_thread_tls is implemented") in
> v5.5-rc6.
> ---
>   arch/m68k/Kconfig          |  1 +
>   arch/m68k/kernel/process.c | 31 ++++++++++++++++++++++---------
>   2 files changed, 23 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
> index 6663f1741798e83f..6ad6cdac74b3dc42 100644
> --- a/arch/m68k/Kconfig
> +++ b/arch/m68k/Kconfig
> @@ -14,6 +14,7 @@ config M68K
>   	select HAVE_AOUT if MMU
>   	select HAVE_ASM_MODVERSIONS
>   	select HAVE_DEBUG_BUGVERBOSE
> +	select HAVE_COPY_THREAD_TLS
>   	select GENERIC_IRQ_SHOW
>   	select GENERIC_ATOMIC64
>   	select HAVE_UID16
> diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
> index 22e6b8f4f9582aa4..8f0d9140700f09ad 100644
> --- a/arch/m68k/kernel/process.c
> +++ b/arch/m68k/kernel/process.c
> @@ -108,16 +108,28 @@ void flush_thread(void)
>    * on top of pt_regs, which means that sys_clone() arguments would be
>    * buried.  We could, of course, copy them, but it's too costly for no
>    * good reason - generic clone() would have to copy them *again* for
> - * do_fork() anyway.  So in this case it's actually better to pass pt_regs *
> - * and extract arguments for do_fork() from there.  Eventually we might
> - * go for calling do_fork() directly from the wrapper, but only after we
> - * are finished with do_fork() prototype conversion.
> + * _do_fork() anyway.  So in this case it's actually better to pass pt_regs *
> + * and extract arguments for _do_fork() from there.  Eventually we might
> + * go for calling _do_fork() directly from the wrapper, but only after we
> + * are finished with _do_fork() prototype conversion.
>    */
>   asmlinkage int m68k_clone(struct pt_regs *regs)
>   {
>   	/* regs will be equal to current_pt_regs() */
> -	return do_fork(regs->d1, regs->d2, 0,
> -		       (int __user *)regs->d3, (int __user *)regs->d4);
> +	struct kernel_clone_args args = {
> +		.flags		= regs->d1 & ~CSIGNAL,
> +		.pidfd		= (int __user *)regs->d3,
> +		.child_tid	= (int __user *)regs->d4,
> +		.parent_tid	= (int __user *)regs->d3,
> +		.exit_signal	= regs->d1 & CSIGNAL,
> +		.stack		= regs->d2,
> +		.tls		= regs->d5,
> +	};
> +
> +	if (!legacy_clone_args_valid(&args))
> +		return -EINVAL;
> +
> +	return _do_fork(&args);
>   }
>   
>   /*
> @@ -130,8 +142,9 @@ asmlinkage int m68k_clone3(struct pt_regs *regs)
>   	return sys_clone3((struct clone_args __user *)regs->d1, regs->d2);
>   }
>   
> -int copy_thread(unsigned long clone_flags, unsigned long usp,
> -		 unsigned long arg, struct task_struct *p)
> +int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
> +		    unsigned long arg, struct task_struct *p,
> +		    unsigned long tls)
>   {
>   	struct fork_frame {
>   		struct switch_stack sw;
> @@ -166,7 +179,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
>   	p->thread.usp = usp ?: rdusp();
>   
>   	if (clone_flags & CLONE_SETTLS)
> -		task_thread_info(p)->tp_value = frame->regs.d5;
> +		task_thread_info(p)->tp_value = tls;
>   
>   #ifdef CONFIG_FPU
>   	if (!FPU_IS_EMU) {
> 

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

* Re: [PATCH] m68k: Implement copy_thread_tls()
  2020-01-13 10:30 [PATCH] m68k: Implement copy_thread_tls() Geert Uytterhoeven
  2020-01-13 10:37 ` Christian Brauner
  2020-01-14  1:55 ` Greg Ungerer
@ 2020-01-14  9:50 ` Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2020-01-14  9:50 UTC (permalink / raw)
  To: Greg Ungerer
  Cc: Amanieu d'Antras, Christian Brauner, Kars de Jong, Al Viro,
	linux-m68k, Linux Kernel Mailing List, Linux-Next

On Mon, Jan 13, 2020 at 11:30 AM Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> This is required for clone3(), which passes the TLS value through a
> struct rather than a register.
>
> As do_fork() is only available if CONFIG_HAVE_COPY_THREAD_TLS is set,
> m68k_clone() must be changed to call _do_fork() directly.
>
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> This is a dependency for the combination of commits
> e8bb2a2a1d51511e ("m68k: Wire up clone3() syscall") in m68k/for-next,
> dd499f7a7e342702 ("clone3: ensure copy_thread_tls is implemented") in
> v5.5-rc6.

Applied and queued for v5.6.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-13 10:30 [PATCH] m68k: Implement copy_thread_tls() Geert Uytterhoeven
2020-01-13 10:37 ` Christian Brauner
2020-01-14  1:55 ` Greg Ungerer
2020-01-14  9:50 ` Geert Uytterhoeven

Linux-m68k Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-m68k/0 linux-m68k/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-m68k linux-m68k/ https://lore.kernel.org/linux-m68k \
		linux-m68k@vger.kernel.org linux-m68k@lists.linux-m68k.org
	public-inbox-index linux-m68k

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-m68k


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git