[PATCH] MIPS: Add get_thread_area syscall

From: Guoyun Sun
Date: Fri Dec 13 2019 - 01:16:14 EST


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@xxxxxxxxxxx>
---
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