Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2975484imu; Sun, 9 Dec 2018 14:05:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/WTrhJm0oWV5Gol4wkS+vTnGZUR0/K58qdehPfpbxg8UsFP8clofj5QEZM796RF4jdSAr4Y X-Received: by 2002:a63:a51b:: with SMTP id n27mr8993303pgf.17.1544393129138; Sun, 09 Dec 2018 14:05:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544393129; cv=none; d=google.com; s=arc-20160816; b=K286rHy2rba+PF0XAUu5eybrQ7staLzkQixlTsT27/tjGRIVKbPy1/ZqRDCsCuhaRV 1ua6tv/KxKl6oh9oXuGPod6E17A/z+MRVDVd5NdOD0CKI11flhUI0fWn5bhT2TH/YTFj K/MRTz8G/sURFqsHZeMSh5YuIgDMa/O4FjOx6yCN7n1MKpi0oDTtyvPnXeY2/HrWkh7/ zoiLsd394mV0xH3+WhqXCkFod+VBcP3Fln1qOFPq9Tlt2f/JqvGEbFbjAeybQ92Gz78c icGWMLjdB9FycMeBa347kiM35OWh+tTCKl/E2ntQz6cI0lKs1fgqLzUtZR0PF2oX8oTs S1vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=yJ7qL97q56q4U8mn2wjlXZF6geV9LKkhDYRx/6PLI6s=; b=ikDGASXSGQX5HPZ3Oln3F8DMsgT3uvcF6ULAVzceCChzGKv/QLXAeW5PFcH0e0X+k5 wC/yPuc64Zv3Ou45GxYeQqptSyVYqax+qtfhZddECtm/KpDL+I/CooxuqdNNMtO0rkwK TFdrF30fw6s14XJakxOxvIWwfJBtMRPIVyWSte+Beg8RTYYmaCJcSH3cI9r2Rbl3LVZl eHv9g5cDxZhtDmy1IBngBCAoTsC7/tfoAifwgYZp6lhf9xOf1HK4xyA7dfV2+/BHjB4b VgH3y9YRz7d3A7NEAzjlekVf8FDvtcRqLyXHlH61sK7ZznfZsHPfJ99XKGKefcKpX7eh Db6Q== 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 g5si8355747plt.273.2018.12.09.14.05.14; Sun, 09 Dec 2018 14:05:29 -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 S1727400AbeLIWDo (ORCPT + 99 others); Sun, 9 Dec 2018 17:03:44 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35624 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbeLIVz2 (ORCPT ); Sun, 9 Dec 2018 16:55:28 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72r-0002iZ-7v; Sun, 09 Dec 2018 21:55:25 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72k-0003ed-LF; Sun, 09 Dec 2018 21:55:18 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Nikita Sobolev" , "Vineet Gupta" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 296/328] ARC: clone syscall to setp r25 as thread pointer In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Vineet Gupta commit c58a584f05e35d1d4342923cd7aac07d9c3d3d16 upstream. 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 Reported-by: Nikita Sobolev Signed-off-by: Vineet Gupta Signed-off-by: Ben Hutchings --- arch/arc/kernel/process.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) --- a/arch/arc/kernel/process.c +++ b/arch/arc/kernel/process.c @@ -147,6 +147,26 @@ int copy_thread(unsigned long clone_flag 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 works (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; }