Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp254763pxu; Tue, 13 Oct 2020 23:46:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYNxiD5fEIttsgUxjiaechZrOg/576tvWvoP9/NkEzuRQONOzC3HsZ+3k4iI6E2YV5QBue X-Received: by 2002:a17:906:c209:: with SMTP id d9mr3514792ejz.465.1602658017190; Tue, 13 Oct 2020 23:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602658017; cv=none; d=google.com; s=arc-20160816; b=bQEjmCNLbDupMGqffb2ge+8f8QdH8ou4iZqLzly0PetiBZobj/qt3T06Out8ziSklc 5PyuiMfYwDO+emqZthmqoKLfnSzTV0QdJGUMCW4usx+n7Z9S7pNjXRgiPYHbB8X4Ct6G kXLFHsqLzed2syG05oeTgIl7VYT3I+XOJNIJgJNFJd0l+DB79NiHqurYlE9UTtZrZAIw bhfrVonGgGwm/N4JWuPlet6B+8/YyJv+KTYA1MGPg6bsMYutZPqddGgRrSlUKwOkJsE7 qd0MgGY3eyzueuajiUOfWDKhw0TGKPVFW9zhGTmfCPtergqFAX4dyuZBgdR7Ab/I1CJP 9A3Q== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=XAPQOkLRPRPnoeN7iazVKwb8iEPQI7pzPYRAkpN1V68=; b=Q9wissBEz6YCASxbebl5WQwuPYBlbYXoahIV6fZss3Xn4/FKViiLkzWebN1Cu0pAyu csJvMUkrxseIHDxS1j4YPDcszBwIARlQBnNgYDgD31P1Qn0kgKghQfUTtcBUMkVgYh9H 8B2D1DSmcYcVal187PKxnWoCSi2+hxHckToh6SHUVOuu217jjGRuwKjYSdVcpwNoxCoI wbYsfSrjDWb4q8QD6eXMIabn4ikzqWaqPM4l1z+CtUEnRdKdbsOPeO2E2CbwNf6xNas0 PPt1bpPXmK1dFVFj+0mrbWYvieBa/jrjGar6KnnH3PTIjAWS/hWSULmYeWl795bfK6Xj JVMQ== ARC-Authentication-Results: i=1; mx.google.com; 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 re8si1616679ejb.480.2020.10.13.23.46.33; Tue, 13 Oct 2020 23:46:57 -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; 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 S1728076AbgJMVWc (ORCPT + 99 others); Tue, 13 Oct 2020 17:22:32 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:37603 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726652AbgJMVWc (ORCPT ); Tue, 13 Oct 2020 17:22:32 -0400 Received: from ip5f5af0a0.dynamic.kabel-deutschland.de ([95.90.240.160] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kSRka-0007PO-QI; Tue, 13 Oct 2020 21:22:28 +0000 Date: Tue, 13 Oct 2020 23:22:28 +0200 From: Christian Brauner To: Rasmus Villemoes Cc: Giuseppe Scrivano , linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, containers@lists.linux-foundation.org Subject: Re: [PATCH 1/2] fs, close_range: add flag CLOSE_RANGE_CLOEXEC Message-ID: <20201013212228.gan6rcayveanujwd@wittgenstein> References: <20201013140609.2269319-1-gscrivan@redhat.com> <20201013140609.2269319-2-gscrivan@redhat.com> <20201013205427.clvqno24ctwxbuyv@wittgenstein> <22ff41f8-c009-84f4-849b-a807b7382253@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <22ff41f8-c009-84f4-849b-a807b7382253@rasmusvillemoes.dk> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 13, 2020 at 11:04:21PM +0200, Rasmus Villemoes wrote: > On 13/10/2020 22.54, Christian Brauner wrote: > > On Tue, Oct 13, 2020 at 04:06:08PM +0200, Giuseppe Scrivano wrote: > > > > Hey Guiseppe, > > > > Thanks for the patch! > > > >> When the flag CLOSE_RANGE_CLOEXEC is set, close_range doesn't > >> immediately close the files but it sets the close-on-exec bit. > > > > Hm, please expand on the use-cases a little here so people know where > > and how this is useful. Keeping the rationale for a change in the commit > > log is really important. > > > > > I think I don't have quarrels with this patch in principle but I wonder > > if something like the following wouldn't be easier to follow: > > > > diff --git a/fs/file.c b/fs/file.c > > index 21c0893f2f1d..872a4098c3be 100644 > > --- a/fs/file.c > > +++ b/fs/file.c > > @@ -672,6 +672,32 @@ int __close_fd(struct files_struct *files, unsigned fd) > > } > > EXPORT_SYMBOL(__close_fd); /* for ksys_close() */ > > > > +static inline void __range_cloexec(struct files_struct *cur_fds, > > + unsigned int fd, unsigned max_fd) > > +{ > > + struct fdtable *fdt; > > + spin_lock(&cur_fds->file_lock); > > + fdt = files_fdtable(cur_fds); > > + while (fd <= max_fd) > > + __set_close_on_exec(fd++, fdt); > (I should've warned that I just proposed this as a completely untested brainstorm.) > Doesn't that want to be > > bitmap_set(fdt->close_on_exec, fd, max_fd - fd + 1) > > to do word-at-a-time? I assume this would mostly be called with (3, ~0U) > as arguments or something like that. Yes, that is the common case. Thanks Rasmus, I was unaware we had that function. In that case I think we'd actually need sm like: spin_lock(&cur_fds->file_lock); fdt = files_fdtable(cur_fds); cur_max = files_fdtable(cur_fds)->max_fds - 1; max_fd = min(max_fd, cur_max); bitmap_set(fdt->close_on_exec, fd, max_fd - fd + 1) so we retrieve max_fd with the spinlock held, I think. Christian