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=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 2A342C433E1 for ; Tue, 18 Aug 2020 10:36:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1244A204EA for ; Tue, 18 Aug 2020 10:36:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726815AbgHRKgd (ORCPT ); Tue, 18 Aug 2020 06:36:33 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:39029 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726482AbgHRKgZ (ORCPT ); Tue, 18 Aug 2020 06:36:25 -0400 Received: from ip5f5af70b.dynamic.kabel-deutschland.de ([95.90.247.11] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k7yyc-0002zb-TF; Tue, 18 Aug 2020 10:36:23 +0000 Date: Tue, 18 Aug 2020 12:36:16 +0200 From: Christian Brauner To: "Eric W. Biederman" Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, criu@openvz.org, bpf@vger.kernel.org, Linus Torvalds , Alexander Viro , Oleg Nesterov , Cyrill Gorcunov , Jann Horn , Kees Cook , Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= , Jeff Layton , Miklos Szeredi , Matthew Wilcox , "J. Bruce Fields" , Matthew Wilcox , Trond Myklebust , Chris Wright , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh Subject: Re: [PATCH 08/17] proc/fd: In proc_fd_link use fcheck_task Message-ID: <20200818103616.u2fht5c6zeeivqg6@wittgenstein> References: <87ft8l6ic3.fsf@x220.int.ebiederm.org> <20200817220425.9389-8-ebiederm@xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200817220425.9389-8-ebiederm@xmission.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 17, 2020 at 05:04:16PM -0500, Eric W. Biederman wrote: > When discussing[1] exec and posix file locks it was realized that none > of the callers of get_files_struct fundamentally needed to call > get_files_struct, and that by switching them to helper functions > instead it will both simplify their code and remove unnecessary > increments of files_struct.count. Those unnecessary increments can > result in exec unnecessarily unsharing files_struct which breaking > posix locks, and it can result in fget_light having to fallback to > fget reducing system performance. > > Using fcheck_task instead of get_files_struct simplifies proc_fd_link by > removing unnecessary locking, and reference counting. > > [1] https://lkml.kernel.org/r/20180915160423.GA31461@redhat.com > Suggested-by: Oleg Nesterov > Signed-off-by: "Eric W. Biederman" > --- Acked-by: Christian Brauner > fs/proc/fd.c | 14 ++++---------- > 1 file changed, 4 insertions(+), 10 deletions(-) > > diff --git a/fs/proc/fd.c b/fs/proc/fd.c > index 4048a87c51ee..abfdcb21cc79 100644 > --- a/fs/proc/fd.c > +++ b/fs/proc/fd.c > @@ -141,29 +141,23 @@ static const struct dentry_operations tid_fd_dentry_operations = { > > static int proc_fd_link(struct dentry *dentry, struct path *path) > { > - struct files_struct *files = NULL; > struct task_struct *task; > int ret = -ENOENT; > > task = get_proc_task(d_inode(dentry)); > if (task) { > - files = get_files_struct(task); > - put_task_struct(task); > - } > - > - if (files) { > unsigned int fd = proc_fd(d_inode(dentry)); > struct file *fd_file; > > - spin_lock(&files->file_lock); > - fd_file = fcheck_files(files, fd); > + rcu_read_lock(); > + fd_file = fcheck_task(task, fd); > if (fd_file) { > *path = fd_file->f_path; > path_get(&fd_file->f_path); > ret = 0; > } > - spin_unlock(&files->file_lock); > - put_files_struct(files); > + rcu_read_unlock(); > + put_task_struct(task); > } > > return ret; > -- > 2.25.0 >