Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3986392iog; Tue, 28 Jun 2022 06:54:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sInA5deyg0bEf1eF7copWrTpsELE8ohm2yUtWtOaqZQ9HhCc0Y8TIybwn3kpA5dtW6dSLv X-Received: by 2002:a05:6a02:18f:b0:411:4cc0:688 with SMTP id bj15-20020a056a02018f00b004114cc00688mr5899264pgb.257.1656424454796; Tue, 28 Jun 2022 06:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656424454; cv=none; d=google.com; s=arc-20160816; b=fbdfItUi+M3onC3xdXgkAPkEYZrSHUVO4AlDqtz9Dz7xPBE8FC6++oBAhsk85MjtOa LhnRbHctndBBJa052RnngCHdDOwHvf8L/cpRWTgQj5gToBHd88VH9/vt7lCR9Uqn28KP q6wpz8MbLl27W4FBOxhkUM3sQESt0yeLNQbdtEerv4KmREf4xZ5pZ/1gm8mMNy62T9Ww u29OGMTOcRIPdCnh+AnWgOe4mIwL7fVCWoxuHHOyM5ZkKrUNJe5wFAXazuUTULd0enB9 iPRX1HgT9MjLtRVQsHgMWNcCJ3bPYqL5r2tM9EErOhp0c3J9be1jZh8W3jOG3Bo9oMBr R8XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pwb0864F0dBHy9aZYDLPM51zdDcV51oxvamtBp8MxyE=; b=uOxNfLJ7ksD61yJvbEJGpfV1vZlNN6uPqstVZuqBtLZahPbhu+iv6a0LyEA1TYC/kE UCdDfSiFE9DUItIsQDzH3wmMXwBjcZC5SNCmuAUNjFprv3QfbIhyIXJ3P8VSE+pyERCP eQua9tsLv2A5tFQKJHe3J2mVDMaRTwrjOVlt+gcCAe6Uj3S9xJvkWp8J1E6kGlP9x6NV ldTWmiAypXNLW5GpP+ZXM6C5/2bWqlOqxMkTJesBxDPBoXMp0ClPQiRWIwwY2nZucnYU RwYsEcuq77IWZeiLu6Z7Xc2mVzMvJDNNIAwk1OGUxKciKIhbJEY5wK4cO5LhFBNnXBdw NlHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J26wAUkM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n2-20020a17090a4e0200b001ef0bf76041si1093586pjh.60.2022.06.28.06.54.01; Tue, 28 Jun 2022 06:54:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J26wAUkM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346859AbiF1Nnf (ORCPT + 99 others); Tue, 28 Jun 2022 09:43:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346848AbiF1Nnd (ORCPT ); Tue, 28 Jun 2022 09:43:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC1151CB09; Tue, 28 Jun 2022 06:43:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7B55DB81E16; Tue, 28 Jun 2022 13:43:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93634C3411D; Tue, 28 Jun 2022 13:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656423806; bh=Mu07+NkAeIWQxqDrSfWHBkagAH3qiS5hRkhUS/KEB+8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=J26wAUkMEANntFYIvZPSyjRIRDBcF+0CYhgasflX/sFmF3R2jSZgCYNFz3Ynufqqz nzeG/jqshDGe3knqrMZ6LXcKAICeN8pbhTN0uX0rgz8dRC1YlEMk7ISAYbSEGNsozr vMxbVtI/cVWlsFmtm6PBsVByLIwnivkOj1AJrkxj/wXQRhS/ln9VsFhQnbbn/n2PIn QzAw/V4dQkJ41Sn1oOGwbBEr5dwHr6L6ETynGtdZIr8NvIdrA2IOpy2Ggx+LW85NkG M7m209vEq9dxSuBiAncmEIgn4Mvu51957qmvXRBAQRo+OwPw3t5gNRgFO+Buf2FD6s 0aBj8RlvROlWA== Date: Tue, 28 Jun 2022 15:43:17 +0200 From: Christian Brauner To: David Laight Cc: Ralph Corderoy , Matthew Wilcox , Nate Karstens , Alexander Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , Richard Henderson , Ivan Kokshaysky , Matt Turner , "James E.J. Bottomley" , Helge Deller , "David S. Miller" , Jakub Kicinski , Eric Dumazet , "linux-fsdevel@vger.kernel.org" , "linux-arch@vger.kernel.org" , "linux-alpha@vger.kernel.org" , "linux-parisc@vger.kernel.org" , "sparclinux@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Changli Gao Subject: Re: [PATCH v2] Implement close-on-fork Message-ID: <20220628134317.heagqm6dplf5vk7u@wittgenstein> References: <20200515152321.9280-1-nate.karstens@garmin.com> <20220618114111.61EC71F981@orac.inputplus.co.uk> <20220619104228.A9789201F7@orac.inputplus.co.uk> <20220628131304.gbiqqxamg6pmvsxf@wittgenstein> <35d0facc934748f995c2e7ab695301f7@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <35d0facc934748f995c2e7ab695301f7@AcuMS.aculab.com> X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 28, 2022 at 01:38:07PM +0000, David Laight wrote: > From: Christian Brauner > > Sent: 28 June 2022 14:13 > > > > On Sun, Jun 19, 2022 at 11:42:28AM +0100, Ralph Corderoy wrote: > > > Hi Matthew, thanks for replying. > > > > > > > > The need for O_CLOFORK might be made more clear by looking at a > > > > > long-standing Go issue, i.e. unrelated to system(3), which was started > > > > > in 2017 by Russ Cox when he summed up the current race-condition > > > > > behaviour of trying to execve(2) a newly created file: > > > > > https://github.com/golang/go/issues/22315. > > > > > > > > The problem is that people advocating for O_CLOFORK understand its > > > > value, but not its cost. Other google employees have a system which > > > > has literally millions of file descriptors in a single process. > > > > Having to maintain this extra state per-fd is a cost they don't want > > > > to pay (and have been quite vocal about earlier in this thread). > > > > > > So do you agree the userspace issue is best solved by *_CLOFORK and the > > > problem is how to implement *_CLOFORK at an acceptable cost? > > > > > > OTOH David Laight was making suggestions on moving the load to the > > > fork/exec path earlier in the thread, but OTOH Al Viro mentioned a > > > ‘portable solution’, though that could have been to a specific issue > > > rather than the more general case. > > > > > > How would you recommend approaching an acceptable cost is progressed? > > > Iterate on patch versions? Open a bugzilla.kernel.org for central > > > tracking and linking from the other projects? ..? > > > > Quoting from that go thread > > > > "If the OS had a "close all fds above x", we could use that. (I don't know of any that do, but it sure > > would help.)" > > > > So why can't this be solved with: > > close_range(fd_first, fd_last, CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_UNSHARE)? > > e.g. > > close_range(100, ~0U, CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_UNSHARE)? > > That is a relatively recent linux system call. > Although it can be (mostly) emulated by reading /proc/fd > - but that may not be mounted. > > In any case another thread can open an fd between the close_range() > and fork() calls. The CLOSE_RANGE_UNSHARE gives the calling thread a private file descriptor table before marking fs close-on-exec. close_range(100, ~0U, CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_UNSHARE)?