From: Guoyun Sun <sunguoyun@loongson.cn>
To: Ralf Baechle <ralf@linux-mips.org>,
Paul Burton <paulburton@kernel.org>,
James Hogan <jhogan@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Christian Brauner <christian.brauner@ubuntu.com>,
Arnd Bergmann <arnd@arndb.de>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
David Howells <dhowells@redhat.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Catalin Marinas <catalin.marinas@arm.com>,
linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>,
Xuefeng Li <lixuefeng@loongson.cn>,
Guoyun Sun <sunguoyun@loongson.cn>
Subject: [PATCH V3] MIPS: Add get_thread_area syscall
Date: Mon, 16 Dec 2019 10:17:51 +0800 [thread overview]
Message-ID: <1576462671-7226-1-git-send-email-sunguoyun@loongson.cn> (raw)
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@loongson.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
next reply other threads:[~2019-12-16 2:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-16 2:17 Guoyun Sun [this message]
2019-12-16 19:33 ` [PATCH V3] MIPS: Add get_thread_area syscall Paul Burton
2019-12-17 1:47 ` 孙国云
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1576462671-7226-1-git-send-email-sunguoyun@loongson.cn \
--to=sunguoyun@loongson.cn \
--cc=arnd@arndb.de \
--cc=catalin.marinas@arm.com \
--cc=christian.brauner@ubuntu.com \
--cc=dhowells@redhat.com \
--cc=geert@linux-m68k.org \
--cc=heiko.carstens@de.ibm.com \
--cc=jhogan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=lixuefeng@loongson.cn \
--cc=paulburton@kernel.org \
--cc=peterz@infradead.org \
--cc=ralf@linux-mips.org \
--cc=yangtiezhu@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).