Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp469991ybl; Thu, 12 Dec 2019 22:32:58 -0800 (PST) X-Google-Smtp-Source: APXvYqwC3/OdokQrFae5SxrLnI+Q+B6sOW6RFe7DnT3dykpDNv1dTIFzoyPxgdQhrMCczrOgDE53 X-Received: by 2002:a9d:6f07:: with SMTP id n7mr12615640otq.112.1576218778020; Thu, 12 Dec 2019 22:32:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576218778; cv=none; d=google.com; s=arc-20160816; b=wOd3hHjRMcg52Qsrl8198UJsOq/8zMR15F0+p7nWiepn1Q989JLgSsLSXiSa4gLdpA UBP1MujXozPjpD6JE27BEwTl+LfYZFyM5yrABpeFXX5iNYD5VV3fQeyFIc+S0PkCOlS9 rVuW131QA3PxkVA19W9WQkth+yeI4u+TCBC/uNb4yVRbtPWN4Qb2rXBm9iPiiq4CCY34 rUP6UcvKQkXXGboJl9rU0vi68JNuPkTfVOkbIAyihBdvLmK8pvIfKbRjNTQceUUSuuXv dl9vaXfbDu88mLdgbkAuQ6vvjdM9kQEIFI+lPKYE1Zx9YSeYTJkt4ZnZahzvaphB5Ltv voQg== 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=nHhw4ZfcXOnbXitVtmYomG7mGD80JU6zseIBN2JG34k=; b=FQqr7LTF2SIzzGJn5I4ZutCocaAfYWmTD0NyqzYPy1UKbTxJhr9m28qgGTukKfacrw qQlaxRz4YwJOk9f6C0M0bJwGk+HDX+89j8RXwkI7QbabDrpTjoD8N5AXqnoWKzBVRzLQ voAWlrzjD6hBRevG+b0CujZDPeBZpYVVCcLobWXsofwpHFYZa6m6PL9me8qNNuuBqe3Q Kz6r6MfCt1CvJzbN5b2OigjfwUUTEZ9v83bCY+XSX3uYUszU+qJqu1lte0BAOZq0oW0X Fh99RjWSoDJX7XjCfdObtrWV35AD1+ORMRkNi/VLZVg2qfk6QoA2MoeAVuyQu/ftAliN 6P8Q== 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 g26si4796148otk.324.2019.12.12.22.32.45; Thu, 12 Dec 2019 22:32:58 -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 S1732131AbfLMGPq (ORCPT + 99 others); Fri, 13 Dec 2019 01:15:46 -0500 Received: from mail.loongson.cn ([114.242.206.163]:40382 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731920AbfLMGPq (ORCPT ); Fri, 13 Dec 2019 01:15:46 -0500 Received: from localhost.loongson.cn (unknown [10.40.23.36]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx_xRpLPNdqFcKAA--.3S2; Fri, 13 Dec 2019 14:15:05 +0800 (CST) From: Guoyun Sun To: Ralf Baechle , Paul Burton , James Hogan , Peter Zijlstra , Christian Brauner , Arnd Bergmann , Heiko Carstens , David Howells , Firoz Khan , Geert Uytterhoeven , Catalin Marinas , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Guoyun Sun Subject: [PATCH] MIPS: Add get_thread_area syscall Date: Fri, 13 Dec 2019 14:15:05 +0800 Message-Id: <1576217705-2634-1-git-send-email-sunguoyun@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dx_xRpLPNdqFcKAA--.3S2 X-Coremail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orr0wxvrqhubq/ 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 | 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