Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp462194yba; Mon, 1 Apr 2019 09:47:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqx19YxuGqa0VpAKWHhrJUdYTc/8lG1bDUDYpWaZzc1Dnrd78iTo8ablP4NT9lrhUIpvLrq+ X-Received: by 2002:a62:70c6:: with SMTP id l189mr11267713pfc.139.1554137225957; Mon, 01 Apr 2019 09:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554137225; cv=none; d=google.com; s=arc-20160816; b=mLiOiALgHRuuApggeQyY1RuKzhBu77kUxwpevneOw9D45pp6TmuLm45GCL18IUXv9n pFO06e04WesiU5uV8EQCfH/hwIZ9CTj+3oW6dc/mcFQCmuhrOBXKSjs9eMqTeTyxkE8q 4pZQludY1c0BOBX6MJd9F5Nv5NAtdFaOSwoAQ0SxlFfQVY2jH2bMeyWnYpq3GlD/ajyP QBvu8iVvNmElx8DPc76wEXVMj4IscazJTqV3I1SyWhWd05gnoTiomJXqFjXgv/YzK/SC KeptvP0YVlVpHRqDLuU5ZgonmhjzTqNQKwKYnAXiXWUGAJ1rbwySn/7MRNxOkpWhUwN5 lnbw== 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; bh=hAbcN6cBCqeqTNzKtohbGa72KbiSDzlsAims65Bpf/c=; b=tgcqOLST2mQowop67+UqdIy6uvD632YI+830DZRs5JtiCAhX7LHSA4HIinIaYDPUbY V5VV5zRPelXf8eMWr/t5U8T5cROIwoKK0UcxP5zp6U3dWsEkRjDmwVtQqu13Tb+/0uMD 8B2rRZ38Tn2SztbuuncSsosI4oVMpvBS5zJjvV4Vzl8G7d1mlCGo4YsIBXGz+BQXSNj0 AHzTZbN38qxEeZhAHk/dDj3/xUofiVdbl07beb2MRxQds/ZHjMzOFrIEeEsV5TaaF/tq UGHn9G5BshPpHd/q8jOaacUKJSuFayDheH/04QKz1/hdA8I4sTQXd+l+BlHnaydPgFEc xH7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="O9/XLfO1"; 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 k7si9227121pfb.69.2019.04.01.09.46.50; Mon, 01 Apr 2019 09:47:05 -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="O9/XLfO1"; 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 S1728752AbfDAQpg (ORCPT + 99 others); Mon, 1 Apr 2019 12:45:36 -0400 Received: from mail-vs1-f68.google.com ([209.85.217.68]:44006 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727074AbfDAQpf (ORCPT ); Mon, 1 Apr 2019 12:45:35 -0400 Received: by mail-vs1-f68.google.com with SMTP id i207so5905650vsd.10 for ; Mon, 01 Apr 2019 09:45:34 -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=hAbcN6cBCqeqTNzKtohbGa72KbiSDzlsAims65Bpf/c=; b=O9/XLfO1D/h9EbV7CtDD8L2fyiUlcSfeQwb0cCdcHK+j4NGRTQic5X0OfSbvHbxalk uO3f8XMUBflbKQ0gzW98MhpkPFdzicMaOy41z6DzkxiGn+oeVRjEsbfMV6260Ki+f05W uwTU6wEzqwpI0xYj1eT+0SAlRP8ZAkjz6cBTq1RBcpP0Qi0uWCmdRfccErUNgIhQL+gz plbMX6nkmsYi7gLPvex+cej3ZH9aTTpGK2yo+wn++GMTZ8F9pBQyz5y+oDzysCQojcGy P+pkqmv5dNIkNDRlLi6r4l4c7A3ro7jj9zcOhSJ2yvQ4j6pfmoZsml14/R2AF6l+bWgN sktQ== 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=hAbcN6cBCqeqTNzKtohbGa72KbiSDzlsAims65Bpf/c=; b=M2LpgQ1iGx2vcNDYO+rDtIRq3mGRCeqcrwf1yIXHd8NDqf8RQSIk4dTMB5ILPrr/xL MGZK4Co6W4AjHbdH4IO9o6+mvWWo6/LO40NjOle5mFYXEclrbhB7AeXoZvLADCe43AXf NsgBVMJSep2XqJLOMxGhmzdxtMoHMZUZ/zpJLT4iVnmQPyWBKPJ1oGzzWu8/XLmgqOmk jDgf408U+e6ASnRF4nEcsn9siFQrOcR3PDI1YBiGaJ+gp7BWn+4T6yTVLFeWA0g4QsyC vghjYBhqP+fqKMasXSz2y1X+gO4/KlJhRuvb6VnrQcm6So0sY+mK0jOlUNoA7WlEH6bj ZFUw== X-Gm-Message-State: APjAAAWTXi2tepABybc4jqBqJ0gBEd4Nhip5BRQk4BdW7iIrujXsS/pH UCxUmmeM1py6K/KTCZPOHIJHp0FHWvKXG6YWCscvcLjNH2M= X-Received: by 2002:a05:6102:212:: with SMTP id z18mr17511804vsp.218.1554137134009; Mon, 01 Apr 2019 09:45:34 -0700 (PDT) MIME-Version: 1.0 References: <20190330171215.3yrfxwodstmgzmxy@brauner.io> <132107F4-F56B-4D6E-9E00-A6F7C092E6BD@amacapital.net> <20190331211041.vht7dnqg4e4bilr2@brauner.io> <18C7FCB9-2CBA-4237-94BB-9C4395A2106B@amacapital.net> <20190401114059.7gdsvcqyoz2o5bbz@yavin> In-Reply-To: From: Daniel Colascione Date: Mon, 1 Apr 2019 09:45:22 -0700 Message-ID: Subject: Re: [PATCH v2 0/5] pid: add pidfd_open() To: Linus Torvalds Cc: Jonathan Kowalski , Aleksa Sarai , Andy Lutomirski , Christian Brauner , Jann Horn , Andrew Lutomirski , David Howells , "Serge E. Hallyn" , Linux API , Linux List Kernel Mailing , Arnd Bergmann , "Eric W. Biederman" , Konstantin Khlebnikov , Kees Cook , Alexey Dobriyan , Thomas Gleixner , Michael Kerrisk-manpages , "Dmitry V. Levin" , Andrew Morton , Oleg Nesterov , Nagarathnam Muthusamy , Al Viro , Joel Fernandes 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 Mon, Apr 1, 2019 at 9:30 AM Linus Torvalds wrote: > > On Mon, Apr 1, 2019 at 9:22 AM Daniel Colascione wrote: > > > > There's a subtlety: suppose I'm a library and I want to create a > > private subprocess. I use the new clone facility, whatever it is, and > > get a pidfd back. I need to be able to read the child's exit status > > even if the child exits before clone returns in the parent. Doesn't > > this requirement imply that the pidfd, kernel-side, contain something > > a bit more than a struct pid? > > Note that clone() has always supported this, but it has basically > never been used. > > One of the early thinkings behind clone() was that it could be used > for basically "AIO in user space", by having exactly these kinds of > library-private internal subthreads that are hidden as real threads. > > It's why we have that special CSIGNAL mask for setting the exit > signal. It doesn't *just* set the signal to be sent when the thread > exits - setting the signal to something else than SIGCHLD actually > changes behavior in other ways too. > > In particular a non-SIGCHLD thread won't be found by a regular > "waitpid()". You have to explicitly wait for it with __WCLONE (which > in turn is supposed to be used with the explicit pid to be waited > for). But doesn't the CSIGNAL approach still require that libraries somehow coordinate which non-SIGCHLD signal they use? (Signal coordination a separate problem, unfortunately.) If you don't set a signal, you don't get any notification at all, and in that case, you have to burn a thread on a blocking wait, right? And you don't *have* to wait for a specific PID with __WCLONE. If two libraries each did a separate __WCLONE or __WALL wait on all subprocesses, they'd still interfere, AIUI, even if the interface isn't supposed to be used that way. I like the pidfd way of doing private subprocesses a bit more than the CSIGNAL approach because it's more "natural" (in that a pidfd is just a handle like we have handles to tons of other things), integrates with existing event and wait facilities, doesn't require any global coordination at all, and works for more than this one use case. (CSIGNAL is limited to immediate parents. You could, in principle, SCM_RIGHTS a pidfd to someone else.) > Now, none of this was ever really used. The people who wanted AIO > wanted the brain-damaged POSIX kind of AIO, not something cool and > clever. So I suspect the whole exit-signal thing was just used for > random small per-project things. AIO is a whole other ball of wax. :-)