linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: Add get_thread_area syscall
@ 2019-12-13  6:15 Guoyun Sun
  2019-12-13  6:42 ` Arnd Bergmann
  0 siblings, 1 reply; 2+ messages in thread
From: Guoyun Sun @ 2019-12-13  6:15 UTC (permalink / raw)
  To: Ralf Baechle, Paul Burton, James Hogan, Peter Zijlstra,
	Christian Brauner, Arnd Bergmann, Heiko Carstens, David Howells,
	Firoz Khan, Geert Uytterhoeven, Catalin Marinas, linux-mips,
	linux-kernel
  Cc: Guoyun Sun

CRIU(https://criu.org/) tools will dump TLS(Thread Local Storage) by
get_thread_area during checkpoint and restore TLS by set_thread_area during
restore. without syscall get_thread_area, criu restore will fail on MIPS
platform.because a variable with GCC __thread is invalid.

The following function will be called when criu restore

static inline void restore_tls(tls_t *ptls) {
        asm volatile(
                     "move $4, %0                                   \n"
                     "li $2,  "__stringify(__NR_set_thread_area)"  \n"
                     "syscall                                       \n"
                     :
                     : "r"(*ptls)
                     : "$4","$2","memory");

With this patch, the *ptls can be obtained by get_thread_area on MIPS
platform when criu checkpoint. just like this:

static inline void arch_get_tls(tls_t *ptls)
{
	asm volatile(
		     "move $4, %0				    \n"
		     "li $2,  "__stringify(__NR_get_thread_area)"  \n"
		     "syscall					    \n"
		     :
		     : "r"(ptls)
		     : "$4","$2","memory");

}

Signed-off-by: Guoyun Sun <sunguoyun@loongson.cn>
---
 arch/mips/kernel/syscall.c                | 10 ++++++++++
 arch/mips/kernel/syscalls/syscall_n32.tbl |  1 +
 arch/mips/kernel/syscalls/syscall_n64.tbl |  1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl |  1 +
 4 files changed, 13 insertions(+)

diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index c333e57..20bf4c5 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -94,6 +94,16 @@ SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
 	return 0;
 }
 
+SYSCALL_DEFINE1(get_thread_area, unsigned long __user *, u_info)
+{
+	struct thread_info *ti = task_thread_info(current);
+
+	if (copy_to_user(u_info, &(ti->tp_value), sizeof(ti->tp_value)))
+		return -EFAULT;
+
+	return 0;
+}
+
 static inline int mips_atomic_set(unsigned long addr, unsigned long new)
 {
 	unsigned long old, tmp;
diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl
index e7c5ab3..7da83d0 100644
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
@@ -374,3 +374,4 @@
 433	n32	fspick				sys_fspick
 434	n32	pidfd_open			sys_pidfd_open
 435	n32	clone3				__sys_clone3
+436	n32	get_thread_area			sys_get_thread_area
diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl
index 13cd665..4f04bf0 100644
--- a/arch/mips/kernel/syscalls/syscall_n64.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
@@ -350,3 +350,4 @@
 433	n64	fspick				sys_fspick
 434	n64	pidfd_open			sys_pidfd_open
 435	n64	clone3				__sys_clone3
+436	n64	get_thread_area			sys_get_thread_area
diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl
index 353539e..9d79abe 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -423,3 +423,4 @@
 433	o32	fspick				sys_fspick
 434	o32	pidfd_open			sys_pidfd_open
 435	o32	clone3				__sys_clone3
+436	o32	get_thread_area			sys_get_thread_area
-- 
2.1.0


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

* Re: [PATCH] MIPS: Add get_thread_area syscall
  2019-12-13  6:15 [PATCH] MIPS: Add get_thread_area syscall Guoyun Sun
@ 2019-12-13  6:42 ` Arnd Bergmann
  0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2019-12-13  6:42 UTC (permalink / raw)
  To: Guoyun Sun
  Cc: Ralf Baechle, Paul Burton, James Hogan, Peter Zijlstra,
	Christian Brauner, Heiko Carstens, David Howells, Firoz Khan,
	Geert Uytterhoeven, Catalin Marinas,
	open list:BROADCOM NVRAM DRIVER, linux-kernel

On Fri, Dec 13, 2019 at 7:15 AM Guoyun Sun <sunguoyun@loongson.cn> wrote:
>
> CRIU(https://criu.org/) tools will dump TLS(Thread Local Storage) by
> get_thread_area during checkpoint and restore TLS by set_thread_area during
> restore. without syscall get_thread_area, criu restore will fail on MIPS
> platform.because a variable with GCC __thread is invalid.
>
> The following function will be called when criu restore

> diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl
> index e7c5ab3..7da83d0 100644
> --- a/arch/mips/kernel/syscalls/syscall_n32.tbl
> +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
> @@ -374,3 +374,4 @@
>  433    n32     fspick                          sys_fspick
>  434    n32     pidfd_open                      sys_pidfd_open
>  435    n32     clone3                          __sys_clone3
> +436    n32     get_thread_area                 sys_get_thread_area

Please use a number in the arch-specific range below 393. The numbers
at the bottom are meant for syscalls that are common for all
architectures.

        Arnd

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

end of thread, other threads:[~2019-12-13  6:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-13  6:15 [PATCH] MIPS: Add get_thread_area syscall Guoyun Sun
2019-12-13  6:42 ` Arnd Bergmann

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 NNTP newsgroup(s).