Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2987384pxa; Tue, 18 Aug 2020 03:37:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHWUPNJwSPMP4GpP3D1CihkqSpLQzFMApJllJ1Fq0hk4JuVy43I2PQtIstbi0mU4SZaX70 X-Received: by 2002:a05:6402:38c:: with SMTP id o12mr19790185edv.271.1597747060000; Tue, 18 Aug 2020 03:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597747059; cv=none; d=google.com; s=arc-20160816; b=D46Wt4WXF6zIKTlckphsEGIW7AAsgN/bHS24beyAHRw8Xl+Plc7QLV+EBbdWYYPRS3 YP/tUTAYZyq8kEUH8IG++p6yAMyJM+Tz7DNuR5RASXPiQA8wuXlHXzj+GEbDGENCwq/P skf0NSzmBayYMJ4uMJWpLk6C5v/MqdVxyloRAh7b1Yv3o0iBrQT0T+JbPA5rYHBLJaD+ 7fA6cwbXEUqTodgiF7IYfkpmGrVq2Nnsx3OBMp0/0Vs9k3pJWcIOFLg/Tm4h3aLjiAaN q4C/dluItRbTi2mSgFT7276CtlAXL3ykHW0vS2jIhC8vQ31c10HG8nwnpERm2eXItDlT t7Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=cfTq8OdVMyh0VUIk4wD4nOhLxaAcptw0W172C9WKuOk=; b=FRUcnMvMkUi5ECbyno9vUr0gXAaI4EqEkSHUpNCySRnAKPr7KTH48WUMJQbgHrupAx ktce8/kNt0Vb3vt/iX96AcADcUDoazLP9fmVkopYGl6sSnDm4eFcq3Cv2hVKdXXFWei6 HtNGTQcpv+t5xu4VPJCgJzymO+iFKpSZ3I8JMnpW2clfXG4xjwJt5CLrwAeuauyopK2h XH3iVdhtMrAtIacnwwgsb+O3cobF3KNYsUJK2UtcC2h8gKaQ5GUKwxfZBPFbCE874bkD 8aiRyeBhnh+dP5z+/FJGoz1VUwKcj0I8HvtUI04H9JJkPleGPgyi0WFPo5EwPnh04iID 0a3A== 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 v16si16292891ejk.147.2020.08.18.03.37.16; Tue, 18 Aug 2020 03:37:39 -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 S1726709AbgHRKgb (ORCPT + 99 others); Tue, 18 Aug 2020 06:36:31 -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 >