From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 884A4C43381 for ; Mon, 1 Apr 2019 16:45:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54B3D208E4 for ; Mon, 1 Apr 2019 16:45:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="O9/XLfO1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728774AbfDAQpg (ORCPT ); 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-Google-Smtp-Source: APXvYqwq8qPRAP2tZruayuudL1iZkkkXWUBZEsDind3mgDddYs2SEZsIxJCQ9pZpyp42dBZVZ9MU4n2fIotxKkqJGXE= 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. :-)