Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp594083ybk; Fri, 15 May 2020 08:35:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwshshmDD5Fywn1JsyYn+lxVi1Fb8e/L+GpZ4kwGjBJgzRHXHb7pek996iwsAuQqziFL6Tr X-Received: by 2002:a17:906:970e:: with SMTP id k14mr3394911ejx.202.1589556930789; Fri, 15 May 2020 08:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589556930; cv=none; d=google.com; s=arc-20160816; b=kU/tcfEaytSeI1h/13raIWeBQ9E1anVTvg86F4+0l5CqB8cN2OtN4rKlkbsrbB7Cke HFlijNHjdRfTuh+8CqLA7F2Ie3nv/fPIFbmWLbTYqAcvZQrfL7sfdcecN06LB/Nx7hs4 dyarOisv65wrJrU0t9E4Du4J+B5MQWHBp3NI7P0259Or7V5qvaKiqxYDtRoZFddC99Z/ crj5jbsh60hudUsGvYPONeO80vsGWDfyuLZ0JlRvtkETks+hp8Awasx3ahE9VifshOHj pzD/xOkhvTZgAHFQ2bD2ilCnycRkKF0xrshC29RyNnM4C1xDNLqSmmmt5HnnS9cVf1Hm /Puw== 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=8M59T4cDEOJLPfWM3NacG+hlwu0HRvMBD7PQYBjxWz0=; b=u1wQJyuo/lLyF11CR0Xra1/LGqzkrOoS2Aeu8oYIlYzQM5kP8qmaVBhVNcfRh4jo/R xCo+t0WJotn4qgS1vEj48+iM5rcOeZ6XMrWImrgxrgTxiQybZA38ice9dv+nfB2sPzxv O+G2OvqZomJDPZCp1nIkrDJWLuo1LbaIr1BqvMDxqA8hnvbg9cDxt15g68QLYNLEyhnO MOgXyIhHEX31vb9D5DB81Iwmm5XCgtYjaIMq9N0roqwiVGoxzbTtIMJHTbHcXZ0m4saE 30T3J4qsh0j/I0MaakW88hcB3uoOefY57HxTceDOuHWSoMrqNlBM8v7+VxIGqAU+XDfT ZXeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cVfP1EZH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id s22si1306835edy.242.2020.05.15.08.35.07; Fri, 15 May 2020 08:35:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cVfP1EZH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727770AbgEOPbB (ORCPT + 99 others); Fri, 15 May 2020 11:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726872AbgEOPbA (ORCPT ); Fri, 15 May 2020 11:31:00 -0400 Received: from mail-yb1-xb43.google.com (mail-yb1-xb43.google.com [IPv6:2607:f8b0:4864:20::b43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9957C05BD0D for ; Fri, 15 May 2020 08:30:59 -0700 (PDT) Received: by mail-yb1-xb43.google.com with SMTP id y10so1034670ybm.12 for ; Fri, 15 May 2020 08:30:59 -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=8M59T4cDEOJLPfWM3NacG+hlwu0HRvMBD7PQYBjxWz0=; b=cVfP1EZHgz8zdenOeWvamnc44GBqLYOdr2WmAyykkyFcAcIDQ0SV5/TAmshikDIQvo yulpVfC68Xv6ngiE6t/ar4WCoTC7n8dOzgdF0s4AwSjprKEmd6/x8y0xNTO1ts6dbKRu HygxDJEWJDMfefS2YpJfD9lUwOJQzZwpxGZrCeOX2xIR2XmDWnRHejKeeLEPSsIfEycx NcMYydsGE/GFGoRpzpQnm92PyE7h0lsWZp/wQ6nxOlUzgqAo5JPE9937EGZ3EQvzvUO2 5sebEPqx/YzaSzx7L8Z3nGUFkvkov/gwZzpiOLfHeDqul8vNOpDG74jjK2mZQjtJoQhR iVoA== 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=8M59T4cDEOJLPfWM3NacG+hlwu0HRvMBD7PQYBjxWz0=; b=YpSuj8KyZeJYQG3FPWqxfpJ10GBNHY7JgPdUeybGHql3i5hLquHzDwepHyU/2+5wAn mb09w+C87pUsfrervl6XUOW6lciHFvGps+ervm63Vjr3x4cKwKutM2oPvVTQGSwZDw0g EF2FU73ZRnyqv9OyP0r47IYEduJbtmlFmargS0dWl1Pau+XXu4pHcpubjer7POU/X2Ub UuLK4xjWlDQ4vnlybj9QAjm8NGDnftHvfQVpfi63wdAdoSj11F+DpBnj1rDUiAhI6rms IqQu1HlN2lBfOB4K3dyKKV2wkYOzfMa+rUFhEk4BzPTPKadUwTqIViq69Pz7WQVqchVm 6DlA== X-Gm-Message-State: AOAM532GBUx2vQwXznl1V+IfxFEWtSytjO29D9NOmOZcB02X4R4/aEr4 PoNFDRnzKpzWFZ4lRimw+RD89oUrNzpMWFO75C6Eyg== X-Received: by 2002:a25:8182:: with SMTP id p2mr6384609ybk.408.1589556658495; Fri, 15 May 2020 08:30:58 -0700 (PDT) MIME-Version: 1.0 References: <20200515152321.9280-1-nate.karstens@garmin.com> In-Reply-To: <20200515152321.9280-1-nate.karstens@garmin.com> From: Eric Dumazet Date: Fri, 15 May 2020 08:30:47 -0700 Message-ID: Subject: Re: [PATCH v2] Implement close-on-fork To: Nate Karstens Cc: 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 , David Laight , linux-fsdevel , linux-arch , linux-alpha@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, netdev , LKML , Changli Gao 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 Fri, May 15, 2020 at 8:23 AM Nate Karstens wrote: > > > Series of 4 patches to implement close-on-fork. Tests have been > published to https://github.com/nkarstens/ltp/tree/close-on-fork > and cover close-on-fork functionality in the following syscalls: > > * accept(4) > * dup3(2) > * fcntl(2) > * open(2) > * socket(2) > * socketpair(2) > * unshare(2) > > Addresses underlying issue in that there is no way to prevent > a fork() from duplicating a file descriptor. The existing > close-on-exec flag partially-addresses this by allowing the > parent process to mark a file descriptor as exclusive to itself, > but there is still a period of time the failure can occur > because the auto-close only occurs during the exec(). > > One manifestation of this is a race conditions in system(), which > (depending on the implementation) is non-atomic in that it first > calls a fork() and then an exec(). > > This functionality was approved by the Austin Common Standards > Revision Group for inclusion in the next revision of the POSIX > standard (see issue 1318 in the Austin Group Defect Tracker). > > --- > > This is v2 of the change. See https://lkml.org/lkml/2020/4/20/113 > for the original work. > > Thanks to everyone who provided comments on the first series of > patches. Here are replies to specific comments: > > > I suggest we group the two bits of a file (close_on_exec, close_on_fork) > > together, so that we do not have to dirty two separate cache lines. > > I could be mistaken, but I don't think this would improve efficiency. > The close-on-fork and close-on-exec flags are read at different > times. If you assume separate syscalls for fork and exec then > there are several switches between when the two flags are read. > In addition, the close-on-fork flags in the new process must be > cleared, which will be much harder if the flags are interleaved. :/ Fast path in big and performance sensitive applications is not fork() and/or exec(). This is open()/close() and others (socket(), accept(), ...) We do not want them to access extra cache lines for this new feature. Sorry, I will say no to these patches in their current form.