[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1576462671-7226-1-git-send-email-sunguoyun@loongson.cn>
Date: Mon, 16 Dec 2019 10:17:51 +0800
From: Guoyun Sun <sunguoyun@...ngson.cn>
To: Ralf Baechle <ralf@...ux-mips.org>,
Paul Burton <paulburton@...nel.org>,
James Hogan <jhogan@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Christian Brauner <christian.brauner@...ntu.com>,
Arnd Bergmann <arnd@...db.de>,
Heiko Carstens <heiko.carstens@...ibm.com>,
David Howells <dhowells@...hat.com>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Catalin Marinas <catalin.marinas@....com>,
linux-mips@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: Tiezhu Yang <yangtiezhu@...ngson.cn>,
Xuefeng Li <lixuefeng@...ngson.cn>,
Guoyun Sun <sunguoyun@...ngson.cn>
Subject: [PATCH V3] MIPS: Add get_thread_area syscall
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 this syscall, criu restore will fail on MIPS platform
because a variable with GCC __thread will be 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");
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@...ngson.cn>
---
arch/mips/kernel/syscall.c | 11 +++++++++++
arch/mips/kernel/syscalls/syscall_n32.tbl | 2 ++
arch/mips/kernel/syscalls/syscall_n64.tbl | 2 ++
arch/mips/kernel/syscalls/syscall_o32.tbl | 2 ++
4 files changed, 17 insertions(+)
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index c333e57..7ac78bf 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -27,6 +27,7 @@
#include <linux/slab.h>
#include <linux/elf.h>
#include <linux/sched/task_stack.h>
+#include <linux/compat.h>
#include <asm/asm.h>
#include <asm/asm-eva.h>
@@ -94,6 +95,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 (in_compat_syscall())
+ return put_user(ti->tp_value, (__u32 *)u_info);
+
+ return put_user(ti->tp_value, u_info);
+}
+
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..3aa4858 100644
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
@@ -341,6 +341,8 @@
330 n32 statx sys_statx
331 n32 rseq sys_rseq
332 n32 io_pgetevents compat_sys_io_pgetevents
+333 n32 get_thread_area sys_get_thread_area
+
# 333 through 402 are unassigned to sync up with generic numbers
403 n32 clock_gettime64 sys_clock_gettime
404 n32 clock_settime64 sys_clock_settime
diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl
index 13cd665..14b6796 100644
--- a/arch/mips/kernel/syscalls/syscall_n64.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
@@ -337,6 +337,8 @@
326 n64 statx sys_statx
327 n64 rseq sys_rseq
328 n64 io_pgetevents sys_io_pgetevents
+329 n64 get_thread_area sys_get_thread_area
+
# 329 through 423 are reserved to sync up with other architectures
424 n64 pidfd_send_signal sys_pidfd_send_signal
425 n64 io_uring_setup sys_io_uring_setup
diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl
index 353539e..bb4e050 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -380,6 +380,8 @@
366 o32 statx sys_statx
367 o32 rseq sys_rseq
368 o32 io_pgetevents sys_io_pgetevents_time32 compat_sys_io_pgetevents
+369 o32 get_thread_area sys_get_thread_area
+
# room for arch specific calls
393 o32 semget sys_semget
394 o32 semctl sys_semctl compat_sys_semctl
--
2.1.0
Powered by blists - more mailing lists