Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp558705ybl; Fri, 13 Dec 2019 00:33:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwueBUpf/wYtmfJhchuWnZjJCqlrDHeQ+l6eXD7R93O4Wu4LwYKt0+4/BDuyfK9fDBKK8KZ X-Received: by 2002:a9d:191f:: with SMTP id j31mr13007241ota.163.1576225984555; Fri, 13 Dec 2019 00:33:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576225984; cv=none; d=google.com; s=arc-20160816; b=t9fpzGMf0ljt+kDrqHtXISumeQTtynUC+Pu+51BuLIMdcSlf+hEbhRcR8nrPhcptHL XvYhr+4pjaFZsYKMiq/Vfz9IvBvzV6HbCNNetwkAIK9ZHAd/cUwKiQWFckRIDA787DlH o76Dy1OKYnO6MkTZBubcODpQVYwLKTdedksHGhbj7LufYpagS6xbejtxVIWfuY6ig0yd ar52C4/r7hIaAuhK/VWtO5WkqXTQ1CHS9rQI9XVTO0NHOyhr7MnY1PViQ/CBwmWdpUmJ XFiEdcg/7x+3SF2kPFESfLK9zbKWCtpJdlpSe2P9UWi5M2o3sWwoUtgJYfZ7f+REa49l 4k5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=tr7apkZK1dc9M6gEqn0pZDt3EhRxI3YmT9mVWx0ELAU=; b=xYdhNKsJ01qm3U9tUxnEVAnuEUwg6bEFUZqYsbfcvkEe7Rzd+flc2YRPfG1FIWwNVv 65m5CTVhlU2WKXSXub0Wuh/gYBvmEDJEoek6eJklMbrgx9SpYtAnk1uSGfuWau9XCj2c oqTiZxFB37pcTnV9q8X0lYiZhXi7aLtQPOPf97GC8z+AhWAqrS2YbP232amIYyrfFh1S XXmnmhHEI8ivba5svY1a/+pEz06UMTBlV1mMTH596iyWJDX3TZca76f30Xdt9ri3RHEs CyBb7qx6sdfY/WBAPNfVnhAma+v0KtFAf0WwBDIsdfYVdOQQT5Up0Hn5LSwt0Esbbc4y bZJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si4429195otq.31.2019.12.13.00.32.52; Fri, 13 Dec 2019 00:33:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbfLMIbK (ORCPT + 99 others); Fri, 13 Dec 2019 03:31:10 -0500 Received: from mail.loongson.cn ([114.242.206.163]:36384 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725980AbfLMIbK (ORCPT ); Fri, 13 Dec 2019 03:31:10 -0500 Received: from localhost.loongson.cn (unknown [10.40.23.36]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxOtEqTPNdV2IKAA--.179S2; Fri, 13 Dec 2019 16:30:35 +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 V2] MIPS: Add get_thread_area syscall Date: Fri, 13 Dec 2019 16:30:34 +0800 Message-Id: <1576225834-16389-1-git-send-email-sunguoyun@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9AxOtEqTPNdV2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CM-SenderInfo: 5vxqw3hr1x0qxorr0wxvrqhubq/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 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 --- arch/mips/kernel/syscall.c | 10 ++++++++++ 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, 16 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..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