Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp922966imm; Fri, 5 Oct 2018 14:20:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV61sP1mAJoRGp/KHJVp6TwY8enISVUL22TaMQSz8094wrJ7JiQZ0NkjY2jxAjEBBJv9cJCNx X-Received: by 2002:a17:902:7c85:: with SMTP id y5-v6mr12965333pll.200.1538774408947; Fri, 05 Oct 2018 14:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538774408; cv=none; d=google.com; s=arc-20160816; b=sOi7np5SAn9HtBr+eOKYU+SXbIbo9iJNxnDqILgcMuo58gj8/Wffm7/mFPcSaMr7GW xS9MAp9xRLEG+s+fEXek14QohJUllwHn7PUTe91OKmr6bTGYFiXzc8q+Axk35MKHWCJx ZJUC4ysRdZ3+ZgmVzTMdP26Yrr0hZ6DayfTngM5I3wZHAac5+kcphjnAMNcpNkvLoQtz fv7o59JUps1MaxhYPY5IY+dj3eVGKLeOKDpJr1jo8xa5qP6ienbkW0WH1qDFV4LhoAr7 tg1LD8DZGkZTylE4ll6Axb5yNTbqfWfm57vgDyaMEx+KP233NOh38izqhKaScfbxXbpX 189Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=l/AGQjcyPVVCCgaGRJ/cxcVcirta+N27HdxFuSmQuwo=; b=L8nu7fR6XodUA82EuopYc0vl1iHJhg1pCZNf3WteP5DqyIm7YXwE64JCisUFo6yd+d GQgCVW5/auwgf03JieS/O1OyCYP7pXz1Ljel4sDSAm/Bavrdod7f3UIapJUC8TN9WEiP c3o5eJvAEg5EvGfIwuOCIGjhGL2WrTVBB5L8wVxVk6PUxYsjuc0mCusvhIMcC16vJb5x N0MdRnTa6WyQZ+Uq88ExrkIPxjkvcSLTkT76Ax1ojf82/1KjdJSTuS4VTXZwXsV2qEPS 2XykUfL2tgGQEr02xrXnimRfO1DDWWgQdTYL6sASMufv5d6sZoTCsCF20z85zQYDQ4eb MrlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=RS1gRwgW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z19-v6si9042275pga.468.2018.10.05.14.19.53; Fri, 05 Oct 2018 14:20:08 -0700 (PDT) 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; dkim=pass header.i=@synopsys.com header.s=mail header.b=RS1gRwgW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727348AbeJFEUJ (ORCPT + 99 others); Sat, 6 Oct 2018 00:20:09 -0400 Received: from smtprelay.synopsys.com ([198.182.60.111]:36068 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbeJFEUJ (ORCPT ); Sat, 6 Oct 2018 00:20:09 -0400 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id 7806710C0A70; Fri, 5 Oct 2018 14:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1538774377; bh=tDzuuME0GaDD8mj1n0Jn2SE0+gTmpd+ZjEhD4sQaywU=; h=From:To:CC:Subject:Date:From; b=RS1gRwgW0CWddBXRjaGD5kh5t6WNMeInxmVTyOq68KwqJL6qiaCYHNllJbYCHG1gO +sgc5xVxi2EZNOYUBrLRARS3cgSy1BDPDQct0D69jRLoA8gN4GVdkYAzpqpnkigTqL EMjEYCuuVnyb7C9KITtfouvnPopM8qgbqBxvgDFMr70DaiB44b0b4Q6HKpGMgb9o+G ZUVfSV0okU3R0kPJKfxzwUHWIHs4ABV2GbU9JgJc+Gr4Ly/K7DiGisM0kb6sTvSaLo Iaqvm4sSM0y6uq7WY1aiv3hcYoezwqt+RY1tjAplRAY6TuQdCipxVcmeX6c4cpnhjK Lm/2hMYDrnbyA== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) by mailhost.synopsys.com (Postfix) with ESMTP id 26C1735BE; Fri, 5 Oct 2018 14:19:36 -0700 (PDT) Received: from IN01WEHTCA.internal.synopsys.com (10.144.199.104) by US01WEHTC3.internal.synopsys.com (10.15.84.232) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 5 Oct 2018 14:19:36 -0700 Received: from IN01WEHTCB.internal.synopsys.com (10.144.199.105) by IN01WEHTCA.internal.synopsys.com (10.144.199.103) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sat, 6 Oct 2018 02:49:32 +0530 Received: from vineetg-Latitude-E7450.internal.synopsys.com (10.10.161.73) by IN01WEHTCB.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sat, 6 Oct 2018 02:49:32 +0530 From: Vineet Gupta To: CC: , , Al Viro , Vineet Gupta , Subject: [PATCH] ARC: clone syscall to setp r25 as thread pointer Date: Fri, 5 Oct 2018 14:19:21 -0700 Message-ID: <1538774361-9306-1-git-send-email-vgupta@synopsys.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.10.161.73] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Per ARC TLS ABI, r25 is designated TP (thread pointer register). However so far kernel didn't do any special treatment, like setting up usermode r25, even for CLONE_SETTLS. We instead relied on libc runtime to do this, in say clone libc wrapper [1]. This was deliberate to keep kernel ABI agnostic (userspace could potentially change TP, specially for different ARC ISA say ARCompact vs. ARCv2 with different spare registers etc) However userspace setting up r25, after clone syscall opens a race, if child is not scheduled and gets a signal instead. It starts off in userspace not in clone but in a signal handler and anything TP sepcific there such as pthread_self() fails which showed up with uClibc testsuite nptl/tst-kill6 [2] Fix this by having kernel populate r25 to TP value. So this locks in ABI, but it was not going to change anyways, and fwiw is same for both ARCompact (arc700 core) and ARCvs (HS3x cores) [1] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/arc/clone.S [2] https://github.com/wbx-github/uclibc-ng-test/blob/master/test/nptl/tst-kill6.c Fixes: ARC STAR 9001378481 Cc: stable@vger.kernel.org Reported-by: Nikita Sobolev Signed-off-by: Vineet Gupta --- arch/arc/kernel/process.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arc/kernel/process.c b/arch/arc/kernel/process.c index 4674541eba3f..c29fa8ceb2d6 100644 --- a/arch/arc/kernel/process.c +++ b/arch/arc/kernel/process.c @@ -241,6 +241,26 @@ int copy_thread(unsigned long clone_flags, task_thread_info(current)->thr_ptr; } + + /* + * setup usermode thread pointer #1: + * when child is picked by scheduler, __switch_to() uses @c_callee to + * populate usermode callee regs: this is fine even despite being in a + * kernel function since special return path for child @ret_from_fork() + * ensures those regs are not clobbered all the way to RTIE to usermode + */ + c_callee->r25 = task_thread_info(p)->thr_ptr; + +#ifdef CONFIG_ARC_CURR_IN_REG + /* + * setup usermode thread pointer #2: + * however for this special use of r25 in kernel, __switch_to() sets + * r25 for kernel needs and only in the final return path is usermode + * r25 setup, from pt_regs->user_r25. So set that up as well + */ + c_regs->user_r25 = c_callee->r25; +#endif + return 0; } -- 2.7.4