2020-03-01 21:39:20

by Stafford Horne

[permalink] [raw]
Subject: [PATCH v2 0/3] OpenRISC clone3 support

This series fixes the clone3 not implemented warnings I have been seeing
during recent builds. It was a simple case of implementing copy_thread_tls
and turning on clone3 generic support. Testing shows no issues.

Changes since v1:

- Fix some comments pointed out in reviews
- Add Acks to 2/3 and 3/3 from Christian Brauner

Stafford Horne (3):
openrisc: Convert copy_thread to copy_thread_tls
openrisc: Enable the clone3 syscall
openrisc: Cleanup copy_thread_tls docs and comments

arch/openrisc/Kconfig | 1 +
arch/openrisc/include/uapi/asm/unistd.h | 1 +
arch/openrisc/kernel/process.c | 18 ++++++------------
3 files changed, 8 insertions(+), 12 deletions(-)

--
2.21.0


2020-03-01 21:39:30

by Stafford Horne

[permalink] [raw]
Subject: [PATCH v2 1/3] openrisc: Convert copy_thread to copy_thread_tls

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

Signed-off-by: Stafford Horne <[email protected]>
---
arch/openrisc/Kconfig | 1 +
arch/openrisc/kernel/process.c | 17 ++++++-----------
2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig
index 1928e061ff96..5debdbe6fc35 100644
--- a/arch/openrisc/Kconfig
+++ b/arch/openrisc/Kconfig
@@ -14,6 +14,7 @@ config OPENRISC
select HANDLE_DOMAIN_IRQ
select GPIOLIB
select HAVE_ARCH_TRACEHOOK
+ select HAVE_COPY_THREAD_TLS
select SPARSE_IRQ
select GENERIC_IRQ_CHIP
select GENERIC_IRQ_PROBE
diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c
index b06f84f6676f..5caa47f7de4f 100644
--- a/arch/openrisc/kernel/process.c
+++ b/arch/openrisc/kernel/process.c
@@ -117,12 +117,13 @@ void release_thread(struct task_struct *dead_task)
extern asmlinkage void ret_from_fork(void);

/*
- * copy_thread
+ * copy_thread_tls
* @clone_flags: flags
* @usp: user stack pointer or fn for kernel thread
* @arg: arg to fn for kernel thread; always NULL for userspace thread
* @p: the newly created task
* @regs: CPU context to copy for userspace thread; always NULL for kthread
+ * @tls: the Thread Local Storage pointer for the new process
*
* At the top of a newly initialized kernel stack are two stacked pt_reg
* structures. The first (topmost) is the userspace context of the thread.
@@ -148,8 +149,8 @@ extern asmlinkage void ret_from_fork(void);
*/

int
-copy_thread(unsigned long clone_flags, unsigned long usp,
- unsigned long arg, struct task_struct *p)
+copy_thread_tls(unsigned long clone_flags, unsigned long usp,
+ unsigned long arg, struct task_struct *p, unsigned long tls)
{
struct pt_regs *userregs;
struct pt_regs *kregs;
@@ -179,16 +180,10 @@ copy_thread(unsigned long clone_flags, unsigned long usp,
userregs->sp = usp;

/*
- * For CLONE_SETTLS set "tp" (r10) to the TLS pointer passed to sys_clone.
- *
- * The kernel entry is:
- * int clone (long flags, void *child_stack, int *parent_tid,
- * int *child_tid, struct void *tls)
- *
- * This makes the source r7 in the kernel registers.
+ * For CLONE_SETTLS set "tp" (r10) to the TLS pointer.
*/
if (clone_flags & CLONE_SETTLS)
- userregs->gpr[10] = userregs->gpr[7];
+ userregs->gpr[10] = tls;

userregs->gpr[11] = 0; /* Result from fork() */

--
2.21.0

2020-03-01 21:40:20

by Stafford Horne

[permalink] [raw]
Subject: [PATCH v2 3/3] openrisc: Cleanup copy_thread_tls docs and comments

Previously copy_thread_tls was copy_thread and before that something
else. Remove the documentation about the regs parameter that didn't
exist in either version.

Next, fix comment wrapping and details about how TLS pointer gets to the
copy_thread_tls function.

Signed-off-by: Stafford Horne <[email protected]>
Acked-by: Christian Brauner <[email protected]>
---
arch/openrisc/kernel/process.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c
index 5caa47f7de4f..6bcdca424e11 100644
--- a/arch/openrisc/kernel/process.c
+++ b/arch/openrisc/kernel/process.c
@@ -122,7 +122,6 @@ extern asmlinkage void ret_from_fork(void);
* @usp: user stack pointer or fn for kernel thread
* @arg: arg to fn for kernel thread; always NULL for userspace thread
* @p: the newly created task
- * @regs: CPU context to copy for userspace thread; always NULL for kthread
* @tls: the Thread Local Storage pointer for the new process
*
* At the top of a newly initialized kernel stack are two stacked pt_reg
--
2.21.0

2020-03-01 21:40:49

by Stafford Horne

[permalink] [raw]
Subject: [PATCH v2 2/3] openrisc: Enable the clone3 syscall

Enable the clone3 syscall for OpenRISC. We use the generic version.

This was tested with the clone3 test from selftests. Note, for all
tests to pass it required enabling CONFIG_NAMESPACES which is not
enabled in the default OpenRISC kernel config.

Signed-off-by: Stafford Horne <[email protected]>
Acked-by: Christian Brauner <[email protected]>
---
arch/openrisc/include/uapi/asm/unistd.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/openrisc/include/uapi/asm/unistd.h b/arch/openrisc/include/uapi/asm/unistd.h
index 566f8c4f8047..fae34c60fa88 100644
--- a/arch/openrisc/include/uapi/asm/unistd.h
+++ b/arch/openrisc/include/uapi/asm/unistd.h
@@ -24,6 +24,7 @@
#define __ARCH_WANT_SET_GET_RLIMIT
#define __ARCH_WANT_SYS_FORK
#define __ARCH_WANT_SYS_CLONE
+#define __ARCH_WANT_SYS_CLONE3
#define __ARCH_WANT_TIME32_SYSCALLS

#include <asm-generic/unistd.h>
--
2.21.0

2020-03-02 07:44:43

by Christian Brauner

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] OpenRISC clone3 support

On Mon, Mar 02, 2020 at 06:38:48AM +0900, Stafford Horne wrote:
> This series fixes the clone3 not implemented warnings I have been seeing
> during recent builds. It was a simple case of implementing copy_thread_tls
> and turning on clone3 generic support. Testing shows no issues.
>
> Changes since v1:
>
> - Fix some comments pointed out in reviews
> - Add Acks to 2/3 and 3/3 from Christian Brauner

Excellent. I acked all individual patches now. But the whole series:

Acked-by: Christian Brauner <[email protected]>

2020-03-02 07:45:14

by Christian Brauner

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] openrisc: Convert copy_thread to copy_thread_tls

On Mon, Mar 02, 2020 at 06:38:49AM +0900, Stafford Horne wrote:
> This is required for clone3 which passes the TLS value through a
> struct rather than a register.
>
> Signed-off-by: Stafford Horne <[email protected]>

Thanks!
Acked-by: Christian Brauner <[email protected]>

2020-03-02 09:15:02

by Stafford Horne

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] OpenRISC clone3 support

On Mon, Mar 02, 2020 at 08:44:11AM +0100, Christian Brauner wrote:
> On Mon, Mar 02, 2020 at 06:38:48AM +0900, Stafford Horne wrote:
> > This series fixes the clone3 not implemented warnings I have been seeing
> > during recent builds. It was a simple case of implementing copy_thread_tls
> > and turning on clone3 generic support. Testing shows no issues.
> >
> > Changes since v1:
> >
> > - Fix some comments pointed out in reviews
> > - Add Acks to 2/3 and 3/3 from Christian Brauner
>
> Excellent. I acked all individual patches now. But the whole series:
>
> Acked-by: Christian Brauner <[email protected]>

Thanks a lot for the review.

-Stafford