Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp84567ybg; Tue, 2 Jun 2020 17:13:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeVDPNYxFzucAVFMHZ8fG3YiHflHHwyqY5tjeubW7SoUWOVFYIONX3Et/TsUcqcMNKpUzW X-Received: by 2002:a17:906:7684:: with SMTP id o4mr26858063ejm.449.1591143184639; Tue, 02 Jun 2020 17:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591143184; cv=none; d=google.com; s=arc-20160816; b=svPcIOMVkSId7DFNoBJFv5hIJAfkmSsSy7VUG1kLlUvkCUsipe56/68Eioz1PBdmxh oalrsYSp6yKbcz3xwzjmXWY/y8UOR9eN0uJRbOo+i/OmZAQkbE6lO7xI4YgYwdhj9ifY OkHVGoPzrIL/AT+Mo70Mzy5Mzka80pEc623vllRbp+hu8RjsLili1gZ4HgSl136VyolA eZ1riYMqzMjYVj82JI4P3WLaMiq2liWYnyI/dGzam4QpIPwhIeQg0o1aTPAh563eWk/t IUwqEubC6+WQFHlciAFvoL7WBm+cFLMI9kaQMEmaZHTNQvN7x52hfNqp2YhF4/tvz4YP lK4A== 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=PazKvjjbmAQeUYiZad4yyf2QZKpFBXiEaJOc1KsToFM=; b=sIqHE4mymJB7QIrVuZna2pnMkqnR5sKk9XEV0Pv19L/ojNc/gVTwuH56QlipZDQgNd Gl0u55i1GB3s1z3lovB7Vp5sme6+/gjMOdd/glVZL2eLvTqp6lIQYSwqPc5Q4FVHuVOd oFs3K3UYtKsGTb9gaIZ58cMoecjnSXtNP0QXD1svR7gfHahYVMAoLIhW/2XaqrysOSk8 7bljgjE7/6ZlZnD8oaMWLQEHtMuxxkGT5OWE7Zf63h40fEdONVsxloyO7Ci2lUZRx0Qt y2Bv0WmXEJn6H71hXvvmGhvD0/Pejm9TJwP1dbMyOcKKAZtn7rNRGrflhrZ+YIH+1KUm 2NNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=cxQ3fmuQ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gr2si228042ejb.221.2020.06.02.17.12.41; Tue, 02 Jun 2020 17:13:04 -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=@linux-foundation.org header.s=google header.b=cxQ3fmuQ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728390AbgFCAIp (ORCPT + 99 others); Tue, 2 Jun 2020 20:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbgFCAIo (ORCPT ); Tue, 2 Jun 2020 20:08:44 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07E46C08C5C0 for ; Tue, 2 Jun 2020 17:08:44 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id 202so162642lfe.5 for ; Tue, 02 Jun 2020 17:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PazKvjjbmAQeUYiZad4yyf2QZKpFBXiEaJOc1KsToFM=; b=cxQ3fmuQWsQSr6abyNc9/tsWVhRgX+CIskaA0+9tWleBkBxH+nD83NbhOrLA4+l62q IHd7DWRbt8QX/EQhJmNdBB/KVbcm3z19PVF4njNDsJ2EVCzILIGOTxNV+HKYvlu2vYC2 U0ZUjz234y+0uLMwggsMalqWy5B+hZTC5aMVY= 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=PazKvjjbmAQeUYiZad4yyf2QZKpFBXiEaJOc1KsToFM=; b=MbLujEcE6ustWQXNBHc55E6hxdripAc8d4iAJWUlFM7ROVYqnh6rDTVMpygOL5q1bp GaupN/aKtNL/pwoGXOkwkYZEkbDIhuR3BGoKe9xx97urKILhODvftRyTODhF4k8cz1pX jaCApZvEJE2zKv7qpE1ulr51drEtlo3OjEm5yx680Q9VIqgJxri2SRX0XXyfJhEKcNh3 1oSXUpD363efc3IgwWXqbn79FcmDzukNXZl4zpS3nI5971dxk4z6s1IISsm1rGDqz9Vu CoBEVXRNWwddTBqMUzT1bETYBOuCl8c1ZHGOUOwH2+xVHLSDB1joaHqKnUgE550Jm3Md PPQg== X-Gm-Message-State: AOAM531z6zBoDvKjp8rR+x7cHm5wIZA5KEwR0/VralbSKgV8rIGOXZCO +FGUX+PAAoeShwaEkIvZQDzqOOH9KcA= X-Received: by 2002:a19:8447:: with SMTP id g68mr958190lfd.132.1591142921356; Tue, 02 Jun 2020 17:08:41 -0700 (PDT) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com. [209.85.167.46]) by smtp.gmail.com with ESMTPSA id v28sm85908ljv.40.2020.06.02.17.08.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Jun 2020 17:08:40 -0700 (PDT) Received: by mail-lf1-f46.google.com with SMTP id z206so159631lfc.6 for ; Tue, 02 Jun 2020 17:08:39 -0700 (PDT) X-Received: by 2002:ac2:5a4c:: with SMTP id r12mr947879lfn.10.1591142919097; Tue, 02 Jun 2020 17:08:39 -0700 (PDT) MIME-Version: 1.0 References: <20200602204219.186620-1-christian.brauner@ubuntu.com> <20200602233355.zdwcfow3ff4o2dol@wittgenstein> In-Reply-To: <20200602233355.zdwcfow3ff4o2dol@wittgenstein> From: Linus Torvalds Date: Tue, 2 Jun 2020 17:08:22 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 0/3] close_range() To: Christian Brauner Cc: Linux Kernel Mailing List , Kyle Evans , Victor Stinner , Al Viro , linux-fsdevel , Linux API , Florian Weimer , Jann Horn , Oleg Nesterov , Arnd Bergmann , Shuah Khan , David Howells , "Dmitry V. Levin" 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 Tue, Jun 2, 2020 at 4:33 PM Christian Brauner wrote: > > > > And maybe this _did_ get mentioned last time, and I just don't find > > it. I also don't see anything like that in the patches, although the > > flags argument is there. > > I spent some good time digging and I couldn't find this mentioned > anywhere so maybe it just never got sent to the list? It's entirely possible that it was just a private musing, and you re-opening this issue just resurrected the thought. I'm not sure how simple it would be to implement, but looking at it it shouldn't be problematic to add a "max_fd" argument to unshare_fd() and dup_fd(). Although the range for unsharing is obviously reversed, so I'd suggest not trying to make "dup_fd()" take the exact range into account. More like just making __close_range() do basically something like rcu_read_lock(); cur_max = files_fdtable(files)->max_fds; rcu_read_unlock(); if (flags & CLOSE_RANGE_UNSHARE) { unsigned int max_unshare_fd = ~0u; if (cur_max >= max_fd) max_unshare_fd = fd; unshare_fd(max_unsgare_fd); } .. do the rest of __close_range() here .. and all that "max_unsgare_fd" would do would be to limit the top end of the file descriptor table unsharing: we'd still do the exact range handling in __close_range() itself. Because teaching unshare_fd() and dup_fd() about anything more complex than the above doesn't sound worth it, but adding a way to just avoid the unnecessary copy of any high file descriptors sounds simple enough. But I haven't thought deeply about this. I might have missed something. Linus