Received: by 10.213.65.68 with SMTP id h4csp543095imn; Wed, 28 Mar 2018 08:18:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx48cWEbjStzFb1/m5o7+j31e7FTvyiOe5pCiYpmRXhnELR/glkW05w6Q4p5kaPnBgvIFnbnr X-Received: by 2002:a17:902:9a8f:: with SMTP id w15-v6mr4299988plp.103.1522250282368; Wed, 28 Mar 2018 08:18:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522250282; cv=none; d=google.com; s=arc-20160816; b=HIVTXzquFVynhZZDrFthbG0/7djy+R0rFf2eR8pPNmwpcNHPKvXdaV6z/dYFaDiXYF na5jvyejXEn6l/vQltxiGv2rjZjYaBsv61fut8S3IoFQgM1qQ5BuiJJpegUosmSCcgI2 2G4b5dYcqAFEIzK54HdzgYJwFWZ6+VFOw1n5oLCkaFWI7NPYjUa8uof1KHqW1glPUHcl w1wsEqYsLe/Uw/OvqtiDHj1HomcJm7KLW1tBzlxmmRodcOsLa+KGvwsGrpWqx/RilvE3 UM25s26Gac8eCBSVGMR6+zYLgqMCb1V1u/WqD1XTLu9xHD1xZgtTC7oO8qPgaxFHCJNp NnfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:arc-authentication-results; bh=yS2/yKDlvTbJxEkwFagaIgJWmWAeFXjGkvqXww10MyI=; b=Hb21b5UarfgZJUCfSEPHzNkKSZoGLuT0YKc7cVjhY46/KD/WUyIWdXI+HN9ejGxRW0 uNiB5trrrAbNrCvAjq1QJz79ppNA+tiFk7ncuPxCkk9fK8nDATKCao46u5dKM2+jBrDa Wx8aWXAWritZpZR49x90dPoKH+xegwJljM64MAH7AN57quHKvRtIMNfjChmjnbvUj1x6 7jjITNnvY9JyRTpT262SeGJnvGUFwoh8Fw091TQ375sL3f8cpexPXh2wt6fgwDfjyp04 E38FXHMUKusvxAUehpd7GTGoUVGHEG2abvilAyr/isJ1X3KMDVZvZdJomJwq3ZEQwnMS /YIA== 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 c1-v6si3816239plk.611.2018.03.28.08.17.48; Wed, 28 Mar 2018 08:18:02 -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; 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 S1753688AbeC1POJ (ORCPT + 99 others); Wed, 28 Mar 2018 11:14:09 -0400 Received: from mail.efficios.com ([167.114.142.138]:40438 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752941AbeC1POH (ORCPT ); Wed, 28 Mar 2018 11:14:07 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id D95E21A8342; Wed, 28 Mar 2018 11:14:06 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id LtqKgrx4Bl1C; Wed, 28 Mar 2018 11:14:06 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 1CE7E1A8336; Wed, 28 Mar 2018 11:14:06 -0400 (EDT) X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id WHYEHJj07k40; Wed, 28 Mar 2018 11:14:05 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id E652E1A832A; Wed, 28 Mar 2018 11:14:05 -0400 (EDT) Date: Wed, 28 Mar 2018 11:14:05 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: "Paul E. McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson , linux-kernel , linux-api , Paul Turner , Andrew Morton , Russell King , Thomas Gleixner , 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: <265889560.1.1522250045589.JavaMail.zimbra@efficios.com> In-Reply-To: <20180328145946.GH4082@hirez.programming.kicks-ass.net> References: <20180327160542.28457-1-mathieu.desnoyers@efficios.com> <20180327160542.28457-3-mathieu.desnoyers@efficios.com> <20180328125004.GV4043@hirez.programming.kicks-ass.net> <1523662633.2105.1522248474778.JavaMail.zimbra@efficios.com> <20180328145946.GH4082@hirez.programming.kicks-ass.net> Subject: Re: [RFC PATCH for 4.17 02/21] rseq: Introduce restartable sequences system call (v12) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.7_GA_1964 (ZimbraWebClient - FF52 (Linux)/8.8.7_GA_1964) Thread-Topic: rseq: Introduce restartable sequences system call (v12) Thread-Index: Ik1ojtJFElSzQ4s6o7/12obPRpQ/aQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Mar 28, 2018, at 10:59 AM, Peter Zijlstra peterz@infradead.org wrote: > On Wed, Mar 28, 2018 at 10:47:54AM -0400, Mathieu Desnoyers wrote: >> ----- On Mar 28, 2018, at 8:50 AM, Peter Zijlstra peterz@infradead.org wrote: >> >> > On Tue, Mar 27, 2018 at 12:05:23PM -0400, Mathieu Desnoyers wrote: >> >> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h >> >> index fb5fc458547f..66b070444a7e 100644 >> >> --- a/kernel/sched/sched.h >> >> +++ b/kernel/sched/sched.h >> >> @@ -1249,6 +1249,7 @@ static inline void __set_task_cpu(struct task_struct *p, >> >> unsigned int cpu) >> >> #endif >> >> p->wake_cpu = cpu; >> >> #endif >> >> + rseq_migrate(p); >> >> } >> > >> > I think you want that in set_task_cpu(), right next to nr_migrations++. >> >> This would miss the __set_task_cpu() call from sched_fork() and >> wake_up_new_task(). > > Correct; but since those are _new_ tasks they _SHOULD_ not have an > active RSEQ to begin with. As long as fork() can be issued from a rseq critical section, nothing actually prevents this. This is a fork(), not an exec(), so the new tasks may very well be going through a restartable sequence when fork() happens. > >> Those cases are not accounted as explicit "migrations", but it does change the >> CPU >> of the current task. So if for some weird reason userspace wants to fork() while >> in >> a rseq critical section, we want to trigger a rseq restart. > > If at all possible I would make it SIGSEGV when issueing SYSCALL()s from > within an RSEQ. What's the goal there ? rseq critical sections can technically do system calls if they wish. Why prevent this ? How would you handle signal handlers that issue system calls while nested on top of a rseq critical section in the userspace thread ? SIGSEGV on SYSCALLs will break this case. > >> An alternative to this would be to call rseq_migrate() in rseq_fork(). >> >> Thoughts ? > > Yes, don't try and support that at all. It's _insane_. Thomas told me those fork corner-cases should be correctly handled in a previous version of the patchset. I'm following his advice here. So either we disallow fork() within rseq critical sections completely with some kind of validation, or we need to provide a non-bogus behavior when this happens. Given that fork(2) is async-signal-safe, this means a signal handler can do a fork() while nested on top of a userspace thread's rseq critical section. So prohibiting fork() from being called over a rseq c.s. does not seem like something we can do here. Thoughts ? Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com