Received: by 10.192.165.148 with SMTP id m20csp2065779imm; Thu, 3 May 2018 09:49:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpu6HRUcg4rpJLKNvS5D0FTUE6H0l0/L6HlAwzJWdUfocH9plz7yIORWTWeZ2uURRvPuTuT X-Received: by 2002:a17:902:8c95:: with SMTP id t21-v6mr20530731plo.306.1525366143228; Thu, 03 May 2018 09:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525366143; cv=none; d=google.com; s=arc-20160816; b=iB4/1qJZB/00jzXENO27ob5T5pyuBFYey/prX5Riby+iXUDhiZunCCoPvEqpxn5KnX CYbP6BcHswET8y+scUnfcmtte+Aq98Rin3YPb5pturzFEbtMgbaO0wI3bFA9iLo2sea8 CSeqJUslQkB3w4wBeVQ8H36wlvYJpPP/6hA0VMNpBqQHwFqxHDMc+GAttppOqL/h+ALi 6eDSaqvllKQfRMZ9y5asIkMG3YDXVyybCUyU/3rLDJZ7OUXwnMZJJJOz9ELQnspdPpgr tT8S8GX5rb5HrHfcaGczKgkw8b36Pq/fG9+v2re1u6QkmPk0TTw8xoEHRluPT5YbG1F5 3MsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=LHPZFZJsxJTY5nZMv5EXoDM5CRbucb6miyXlJedkgAw=; b=u4ZaDXQ5xIkfjcGCjiZ2zX0+E217MtrBopHJXa3ZLlwt9+tpbc9vbHg7F+BMT27ln6 0dROuZPGjsXeSfWUTFi4eGI17B/ZJX9h0+jpE64wWm3wAtdR+IeMUUFFLl2gG3p+FbVT K+1EVcOvDy/MZFWErC1iXsT9n5jEG0KKq1V44XdXvK5G5zinHwU9rsdbEHPAnnAOJ7Sw 3gP+zGpzlheFaACXv0FHN2zxgjVe1pF0K8nFmnpRAbtM1xrzecEbGZ9SRIQM963DT380 3fYlwc3nNeoX6FbMMo8sGLk+5Km7xHaa7HslOf8b7fzHXkt/jip4V7yp41Rc6GrRe/4H N4UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HOcQV0tx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u78-v6si11755762pgb.136.2018.05.03.09.48.48; Thu, 03 May 2018 09:49:03 -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=@google.com header.s=20161025 header.b=HOcQV0tx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751272AbeECQse (ORCPT + 99 others); Thu, 3 May 2018 12:48:34 -0400 Received: from mail-io0-f169.google.com ([209.85.223.169]:43724 "EHLO mail-io0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750954AbeECQsb (ORCPT ); Thu, 3 May 2018 12:48:31 -0400 Received: by mail-io0-f169.google.com with SMTP id t23-v6so22391959ioc.10 for ; Thu, 03 May 2018 09:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LHPZFZJsxJTY5nZMv5EXoDM5CRbucb6miyXlJedkgAw=; b=HOcQV0txFrQrWZW2fZyYMePTlr4dkoZpQi8KfJt7LXNMvWw9RL3DpC5eO/Uh5MVz5D C5tTLRCu2yGZXkvPj85iR21KLhbgKobx4FUbWxMwiCSwzSS0FcKqHqxUKkvix6AK1jA7 /GJwhlb0fXeHNw0HaZi/iIbxzcKT705wK0vYrzx3KV4x2g+2a6I+tp2o+ccoC3E4OGde +OCm34lG+oT5fT9fGvMCj9KC7W0VQbCYEKa1+kt94q3zyxK5NzH+EOZNLYXpQo0deaGf 4N067Cv6zl4SnLjrmICYOlV/CsKGoeIZPnIUDgGJiVqauj3PNmsllnGj2igIoN8u7meO TCYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LHPZFZJsxJTY5nZMv5EXoDM5CRbucb6miyXlJedkgAw=; b=QFDbuK+jWBg3pWU94w70oLbmHUckfmHPAXtwxPq8eimLeFGqr4wS8PH9t/sFlaEDa9 qi6Heezb853emwNSVsaF88n4JGU7dFJLgEs9udBMllZXsKwKklyS8KIrFKz0LH2UkVlO YKpcW1QOoxUGcl78qHFv5tQPaY/UX7SzIptmxjZS7gUgCCapjib8fGAwr+ANDkVXFfFY kH1JOJjgeUdeQ9i/UWM/CpdZusObQjUvg9o7vND4SoHMttTe2UKHtOcUw5dTmdTvmhvc qpGgOsFvhMpPvbzUax7yETpEQJNo6mfgE3MQSyQ5UYED8RKPzrGvRYwJ02LTeMKqQHcz 0f8A== X-Gm-Message-State: ALQs6tDZaY73gdM1yT5+3gw6WqkyLHJxe54ppjsT12e/bnTmuiPZinwm GsORIX3g59TlHo7qm8UFzlDiIDkHSTEq4bfDO/fADA== X-Received: by 2002:a6b:2251:: with SMTP id i78-v6mr24360197ioi.276.1525366109955; Thu, 03 May 2018 09:48:29 -0700 (PDT) MIME-Version: 1.0 References: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> <660904075.9201.1525276988842.JavaMail.zimbra@efficios.com> <1718748931.10084.1525363941807.JavaMail.zimbra@efficios.com> In-Reply-To: <1718748931.10084.1525363941807.JavaMail.zimbra@efficios.com> From: Joel Fernandes Date: Thu, 03 May 2018 16:48:19 +0000 Message-ID: Subject: Re: [RFC PATCH for 4.18 00/14] Restartable Sequences To: Mathieu Desnoyers Cc: Daniel Colascione , Peter Zijlstra , Paul McKenney , Boqun Feng , Andy Lutomirski , davejwatson@fb.com, LKML , linux-api@vger.kernel.org, Paul Turner , Andrew Morton , linux@arm.linux.org.uk, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Andrew Hunter , andi@firstfloor.org, cl@linux.com, bmaurer@fb.com, Steven Rostedt , Josh Triplett , torvalds@linux-foundation.org, Catalin Marinas , Will Deacon , mtk.manpages@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 3, 2018 at 9:12 AM Mathieu Desnoyers < mathieu.desnoyers@efficios.com> wrote: > ----- On May 2, 2018, at 12:07 PM, Daniel Colascione dancol@google.com wrote: > > On Wed, May 2, 2018 at 9:03 AM Mathieu Desnoyers < > > mathieu.desnoyers@efficios.com> wrote: > > > >> ----- On May 1, 2018, at 11:53 PM, Daniel Colascione dancol@google.com > > wrote: > >> [...] > >> > > >> > I think a small enhancement to rseq would let us build a perfect > > userspace > >> > mutex, one that spins on lock-acquire only when the lock owner is > > running > >> > and that sleeps otherwise, freeing userspace from both specifying ad-hoc > >> > spin counts and from trying to detect situations in which spinning is > >> > generally pointless. > >> > > >> > It'd work like this: in the per-thread rseq data structure, we'd > > include a > >> > description of a futex operation for the kernel would perform (in the > >> > context of the preempted thread) upon preemption, immediately before > >> > schedule(). If the futex operation itself sleeps, that's no problem: we > >> > will have still accomplished our goal of running some other thread > > instead > >> > of the preempted thread. > > > >> Hi Daniel, > > > >> I agree that the problem you are aiming to solve is important. Let's see > >> what prevents the proposed rseq implementation from doing what you > > envision. > > > >> The main issue here is touching userspace immediately before schedule(). > >> At that specific point, it's not possible to take a page fault. In the > > proposed > >> rseq implementation, we get away with it by raising a task struct flag, > > and using > >> it in a return to userspace notifier (where we can actually take a > > fault), where > >> we touch the userspace TLS area. > > > >> If we can find a way to solve this limitation, then the rest of your > > design > >> makes sense to me. > > > > Thanks for taking a look! > > > > Why couldn't we take a page fault just before schedule? The reason we can't > > take a page fault in atomic context is that doing so might call schedule. > > Here, we're about to call schedule _anyway_, so what harm does it do to > > call something that might call schedule? If we schedule via that call, we > > can skip the manual schedule we were going to perform. > By the way, if we eventually find a way to enhance user-space mutexes in the > fashion you describe here, it would belong to another TLS area, and would > be registered by another system call than rseq. I proposed a more generic Right. Also I still don't see any good reason why optimistic spinning in the kernel with FUTEX_LOCK, as Peter described, can't be used instead of using the rseq implementation and spinning in userspace, for such a case. I don't really fully buy that we need to design this interface assuming any privilege transition level time. If privilege level transitions are slow, we're going to have bad performance anyway. Unless there's some data to show that we have to optimistically spin in userspace than the kernel because its better to do so, we should really stick to using FUTEX_LOCK and reuse all the work that went into that area for Android and otherwise (and work with Waiman and others on improving that if there are any problems with it). I am excited though about the other synchronization design other than lock implementation that rseq can help in. thanks! - Joel