From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935903AbdKPUGO (ORCPT ); Thu, 16 Nov 2017 15:06:14 -0500 Received: from mail.efficios.com ([167.114.142.141]:57574 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935910AbdKPUGG (ORCPT ); Thu, 16 Nov 2017 15:06:06 -0500 Date: Thu, 16 Nov 2017 20:06:47 +0000 (UTC) From: Mathieu Desnoyers To: Thomas Gleixner Cc: Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson , linux-kernel , linux-api , Paul Turner , Andrew Morton , Russell King , Ingo Molnar , "H. Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Alexander Viro Message-ID: <231776211.16804.1510862807870.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20171114200414.2188-1-mathieu.desnoyers@efficios.com> <20171114200414.2188-2-mathieu.desnoyers@efficios.com> <20171116184305.snpudnjdhua2obby@hirez.programming.kicks-ass.net> <1523632942.16739.1510858189882.JavaMail.zimbra@efficios.com> Subject: Re: [RFC PATCH v11 for 4.15 01/24] Restartable sequences system call MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.141] X-Mailer: Zimbra 8.7.11_GA_1854 (ZimbraWebClient - FF52 (Linux)/8.7.11_GA_1854) Thread-Topic: Restartable sequences system call Thread-Index: Y9dSrPfrv2UdVn61y2AAKNzG0h99kg== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Nov 16, 2017, at 2:06 PM, Thomas Gleixner tglx@linutronix.de wrote: > On Thu, 16 Nov 2017, Mathieu Desnoyers wrote: >> ----- On Nov 16, 2017, at 1:43 PM, Peter Zijlstra peterz@infradead.org wrote: >> >> > On Tue, Nov 14, 2017 at 03:03:51PM -0500, Mathieu Desnoyers wrote: >> >> +/* >> >> + * If parent process has a registered restartable sequences area, the >> >> + * child inherits. Only applies when forking a process, not a thread. In >> >> + * case a parent fork() in the middle of a restartable sequence, set the >> >> + * resume notifier to force the child to retry. >> >> + */ >> >> +static inline void rseq_fork(struct task_struct *t, unsigned long clone_flags) >> >> +{ >> >> + if (clone_flags & CLONE_THREAD) { >> >> + t->rseq = NULL; >> >> + t->rseq_len = 0; >> >> + t->rseq_sig = 0; >> >> + } else { >> >> + t->rseq = current->rseq; >> >> + t->rseq_len = current->rseq_len; >> >> + t->rseq_sig = current->rseq_sig; >> >> + rseq_set_notify_resume(t); >> >> + } >> >> +} >> > >> > This hurts my brain... what happens if you fork a multi-threaded >> > process? >> > >> > Do we fully inherit the TLS state of the calling thread? >> >> Yes, exactly. The user-space TLS should be inherited from that of >> the calling thread. >> >> At kernel-level, the only thing that's not inherited here is the >> task struct rseq_event_mask, which tracks whether a restart is >> needed. But this would only be relevant if fork() can be invoked >> from a signal handler, or if fork() could be invoked from a >> rseq critical section (which really makes little sense). > > Whether it makes sense or not does not matter much, especially in context > of user space. You cannot make assumptions like that. When something can be > done, then it's bound to happen sooner than later because somebody thinks > he is extra clever. > > The first priority is robustness in any aspect which has to do with user > space. > >> Should I copy the current->rseq_event_mask on process fork just to >> be on the safe side though ? > > I think so, unless you let fork() fail when invoked from a rseq critical > section. Allright, I'll set the rseq_event_mask to 0 explicitly on exec() and thread-fork, and copy it from the parent on process-fork. Thanks, Mathieu > > Thanks, > > tglx -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com