Received: by 10.223.164.202 with SMTP id h10csp169911wrb; Tue, 14 Nov 2017 13:04:06 -0800 (PST) X-Google-Smtp-Source: AGs4zMYp0bPYQOT+10x1n+EP5Lr90KqLzWI1bjTw6eJDKKbDy5jod68ZDBvTM/g5i8hVdf4S4lgi X-Received: by 10.101.93.141 with SMTP id f13mr12800875pgt.92.1510693446613; Tue, 14 Nov 2017 13:04:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510693446; cv=none; d=google.com; s=arc-20160816; b=ZuXQtwnk5dOmcBBLBlj8snwhocaiI/dEWxKrW6I1g+rdDtHaIB8aRlRSaW6PQ2sJMI 6tJ2TM8YQWlpWnfG/aXBlPAXIs/2+b0kWk/xhtfQRMA9EQYrRWjgWJ6Zjk61wTkmGdq1 D7YBfO+q0N0mpTYhwNnetUnSqpLGGwt2nPP9HuMOR70LJyUxT6AwkPAb5UlxAIUX4fNq qYUqHjW5aa//wJF8wPtfBCTgNGDT6Jx7zD3fgJNGZSeJzVGJLSAPmu4Ck/eK5+cL2GNO ocm8ik/yAeuttMSTxz2HVpcWV4LVgE8KAKa/ZQkBgdeOO18hfhDz058X1rBLK/8KFBpf Hprg== 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=v91HYfi1tr1WNWd3MQJodGgLHBN3+uMqdT4CbHmtbRA=; b=gKVBNHKBJhqAOAMt9vL1tzXYTsrCqJy9lORBGMYdehfixuwjgctSx4/iSvYw8OAAOf 9cjbi/jze1sSb1nv54F5dFqCPwmamowEg1iQ+yahATxTSVIL2qC+iZ2uq0ymOaFyFN4O RIsJXw24sexm55/b3bBndYxfaZ6zYizllp3CC5kgHR6aSQiQgZpHe9h3nXyoa3/D8+2J oS+K3oMEhQw/p2wVDRGpO8N6jUDEQpglNlokpJKkKC73gGBoGapqySaKY8iwF0q5DlFr zA+lcJCHAVk08gP/lVGLb0wM1yM6+w7/ip4bxBKL+vJMJwwpBSAztmNbnLZVKLrP0Quq 4NPA== 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 h89si10327030pld.701.2017.11.14.13.03.54; Tue, 14 Nov 2017 13:04:06 -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 S1756742AbdKNVCs (ORCPT + 87 others); Tue, 14 Nov 2017 16:02:48 -0500 Received: from mail.efficios.com ([167.114.142.141]:57951 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756615AbdKNVCl (ORCPT ); Tue, 14 Nov 2017 16:02:41 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 74A99340198; Tue, 14 Nov 2017 21:03:25 +0000 (UTC) Received: from mail.efficios.com ([127.0.0.1]) by localhost (evm-mail-1.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id TS_wLvOqvwh3; Tue, 14 Nov 2017 21:03:24 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id C64013401E3; Tue, 14 Nov 2017 21:03:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (evm-mail-1.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id pIgGMdT99pYb; Tue, 14 Nov 2017 21:03:24 +0000 (UTC) Received: from evm-mail-1.efficios.com (evm-mail-1.efficios.com [167.114.142.141]) by mail.efficios.com (Postfix) with ESMTP id A6BF7340198; Tue, 14 Nov 2017 21:03:24 +0000 (UTC) Date: Tue, 14 Nov 2017 21:03:24 +0000 (UTC) From: Mathieu Desnoyers To: Ben Maurer Cc: Peter Zijlstra , "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 , rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Alexander Viro Message-ID: <1641747353.15177.1510693404572.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20171114200414.2188-1-mathieu.desnoyers@efficios.com> <20171114200414.2188-2-mathieu.desnoyers@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: AQHTXYPhmIqd6HY5PUe1T5SV8sIkp6MUVpZlgAAB7cASFntJhQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Nov 14, 2017, at 3:49 PM, Ben Maurer bmaurer@fb.com wrote: > (apologies for the duplicate email, the previous one bounced as it was > accidentally using HTML formatting) > > If I understand correctly this is run on every context switch so we probably > want to make it really fast Yes, more precisely, it runs on return to user-space, after every context switch going back to a registered rseq thread. > >> +static int rseq_need_restart(struct task_struct *t, uint32_t cs_flags) >> +{ >> + bool need_restart = false; >> + uint32_t flags; >> + >> + /* Get thread flags. */ >> + if (__get_user(flags, &t->rseq->flags)) >> + return -EFAULT; >> + >> + /* Take into account critical section flags. */ >> + flags |= cs_flags; >> + >> + /* >> + * Restart on signal can only be inhibited when restart on >> + * preempt and restart on migrate are inhibited too. Otherwise, >> + * a preempted signal handler could fail to restart the prior >> + * execution context on sigreturn. >> + */ >> + if (flags & RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL) { >> + if (!(flags & RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE)) >> + return -EINVAL; >> + if (!(flags & RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT)) >> + return -EINVAL; >> + } > > How does this error even get to userspace? Is it worth doing this switch on > every execution? If we detect this situation, the rseq_need_restart caller will end up sending a SIGSEGV signal to user-space. Note that the two nested if() checks are only executing in the unlikely case where the NO_RESTART_ON_SIGNAL flag is set. > > >> + if (t->rseq_migrate >> + && !(flags & RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE)) >> + need_restart = true; >> + else if (t->rseq_preempt >> + && !(flags & RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT)) >> + need_restart = true; >> + else if (t->rseq_signal >> + && !(flags & RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL)) >> + need_restart = true; > > This could potentially be sped up by having the rseq_* fields in t use a single > bitmask with the same bit offsets as RSEQ_CS_FLAG_NO_* then using bit > operations to check the appropriate overlap. Given that those are not requests impacting the ABI presented to user-space, I'm tempted to keep these optimizations for the following 4.16 merge window. Is that ok with you ? Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com From 1584075547283150793@xxx Tue Nov 14 20:42:44 +0000 2017 X-GM-THRID: 1584073814600987930 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread