From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8741EC43603 for ; Mon, 16 Dec 2019 02:18:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 59C632467B for ; Mon, 16 Dec 2019 02:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726478AbfLPCSb (ORCPT ); Sun, 15 Dec 2019 21:18:31 -0500 Received: from mail.loongson.cn ([114.242.206.163]:47684 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726299AbfLPCSa (ORCPT ); Sun, 15 Dec 2019 21:18:30 -0500 Received: from localhost.loongson.cn (unknown [10.40.23.36]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxX9ZP6fZddEkLAA--.98S2; Mon, 16 Dec 2019 10:17:51 +0800 (CST) From: Guoyun Sun To: Ralf Baechle , Paul Burton , James Hogan , Peter Zijlstra , Christian Brauner , Arnd Bergmann , Heiko Carstens , David Howells , Geert Uytterhoeven , Catalin Marinas , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tiezhu Yang , Xuefeng Li , Guoyun Sun Subject: [PATCH V3] MIPS: Add get_thread_area syscall Date: Mon, 16 Dec 2019 10:17:51 +0800 Message-Id: <1576462671-7226-1-git-send-email-sunguoyun@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf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UUU== X-CM-SenderInfo: 5vxqw3hr1x0qxorr0wxvrqhubq/ Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org 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 --- 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 #include #include +#include #include #include @@ -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