From patchwork Fri May 8 15:36:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219611 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.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 C6CA8C38A2A for ; Fri, 8 May 2020 15:36:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FA2321974 for ; Fri, 8 May 2020 15:36:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="srCBSzZw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727983AbgEHPgn (ORCPT ); Fri, 8 May 2020 11:36:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbgEHPgk (ORCPT ); Fri, 8 May 2020 11:36:40 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE5C2C061A0C; Fri, 8 May 2020 08:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=6EYCyTrFxa9+uQHjnJOrj9adSL4387IIusv8CGn+u5c=; b=srCBSzZwpa/R8vT9FGb8MSiNzT Qqn1uYSRLBeu5tyD/4XSsT0mYDn4lLbRdOf4moLFs/SGTwShV9DVJofzbIoBQmBoBJiCsWqkwHDqS 6ifMQM06Uy05ogqQUznA5cW2YOrFFIeJ5LsIJcSd7jpMi1tvx7P3FtVwCveS1aikMR4WbSiyK0LT7 /969LGJr0wCQLH7KzkFKs+MMOy8JW/daxQoggK4NgoMsrtAgwQEv7YMXtPvYU5W4jXBe7XEl/OQ1p uHAT3dFwh9mYW4W9MObM6CGHUmn/fWgH3Ylz2U2jryjURgP+RE+6QKq4EsiRP1gW7DDlgIA4OYoga wlnUSMRw==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53I-00047B-4u; Fri, 08 May 2020 15:36:40 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 01/12] fd: add a new __anon_inode_getfd helper Date: Fri, 8 May 2020 17:36:23 +0200 Message-Id: <20200508153634.249933-2-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add a helper that is equivalent to anon_inode_getfd minus the final fd_install. Signed-off-by: Christoph Hellwig --- fs/anon_inodes.c | 41 ++++++++++++++++++++++--------------- include/linux/anon_inodes.h | 2 ++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 89714308c25b8..1b2acd2bbaa32 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c @@ -106,6 +106,26 @@ struct file *anon_inode_getfile(const char *name, } EXPORT_SYMBOL_GPL(anon_inode_getfile); +int __anon_inode_getfd(const char *name, const struct file_operations *fops, + void *priv, int flags, struct file **file) +{ + int fd; + + fd = get_unused_fd_flags(flags); + if (fd < 0) + return fd; + + *file = anon_inode_getfile(name, fops, priv, flags); + if (IS_ERR(*file)) + goto err_put_unused_fd; + return fd; + +err_put_unused_fd: + put_unused_fd(fd); + return PTR_ERR(*file); +} +EXPORT_SYMBOL_GPL(__anon_inode_getfd); + /** * anon_inode_getfd - creates a new file instance by hooking it up to an * anonymous inode, and a dentry that describe the "class" @@ -125,26 +145,13 @@ EXPORT_SYMBOL_GPL(anon_inode_getfile); int anon_inode_getfd(const char *name, const struct file_operations *fops, void *priv, int flags) { - int error, fd; struct file *file; + int fd; - error = get_unused_fd_flags(flags); - if (error < 0) - return error; - fd = error; - - file = anon_inode_getfile(name, fops, priv, flags); - if (IS_ERR(file)) { - error = PTR_ERR(file); - goto err_put_unused_fd; - } - fd_install(fd, file); - + fd = __anon_inode_getfd(name, fops, priv, flags, &file); + if (fd >= 0) + fd_install(fd, file); return fd; - -err_put_unused_fd: - put_unused_fd(fd); - return error; } EXPORT_SYMBOL_GPL(anon_inode_getfd); diff --git a/include/linux/anon_inodes.h b/include/linux/anon_inodes.h index d0d7d96261adf..338449d06b617 100644 --- a/include/linux/anon_inodes.h +++ b/include/linux/anon_inodes.h @@ -16,6 +16,8 @@ struct file *anon_inode_getfile(const char *name, void *priv, int flags); int anon_inode_getfd(const char *name, const struct file_operations *fops, void *priv, int flags); +int __anon_inode_getfd(const char *name, const struct file_operations *fops, + void *priv, int flags, struct file **file); #endif /* _LINUX_ANON_INODES_H */ From patchwork Fri May 8 15:36:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219606 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.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 95DC7C4724C for ; Fri, 8 May 2020 15:38:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75CDB21841 for ; Fri, 8 May 2020 15:38:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UNM07rxT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728607AbgEHPiO (ORCPT ); Fri, 8 May 2020 11:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728174AbgEHPgt (ORCPT ); Fri, 8 May 2020 11:36:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 035BDC061A0C; Fri, 8 May 2020 08:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=MVpXPi4fO9ek2hxfJ7eaB5mhfWvQarx43ZgTOZ4t1BM=; b=UNM07rxTMrjSKj57obB1kc0GKN 4c/P3xwFW5d9k3Hfi744eTkLYszdumNcpfrOjsxrJ9UyA5pDgJlACed00AREq1SZCfAHi0YTUfXeL 1a3vaAcVbG4IQqGt9D66OEKVcFQkxqBxp4rUGWmpPQER44ale5ue+RbbzOgzgKvdrdhoJt3D2NNxV 1eAPLhsMIzXbIHLL3++l6NlGgamQ555CXKlTkvYsF5jaAuaiGhVap01g1xYLqxcArTXcJZqmFMBoz IZqNqIah5HvQMt9E9lRkiTzhTJQ5P5+JS/j09j+PuFEw8yw+wQnDHAw0xudwrm7AWdgH4vpWmQFKP ZOHP/mFw==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53Q-00049Y-EX; Fri, 08 May 2020 15:36:48 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 04/12] bpf: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:26 +0200 Message-Id: <20200508153634.249933-5-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Also switch the bpf_link_new_file calling conventions to match __anon_inode_getfd. Signed-off-by: Christoph Hellwig --- include/linux/bpf.h | 2 +- kernel/bpf/cgroup.c | 6 +++--- kernel/bpf/syscall.c | 31 +++++++++---------------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index fd2b2322412d7..539649fe8b885 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1103,7 +1103,7 @@ void bpf_link_cleanup(struct bpf_link *link, struct file *link_file, void bpf_link_inc(struct bpf_link *link); void bpf_link_put(struct bpf_link *link); int bpf_link_new_fd(struct bpf_link *link); -struct file *bpf_link_new_file(struct bpf_link *link, int *reserved_fd); +int bpf_link_new_file(struct bpf_link *link, struct file **link_file); struct bpf_link *bpf_link_get_from_fd(u32 ufd); int bpf_obj_pin_user(u32 ufd, const char __user *pathname); diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index cb305e71e7deb..8605287adcd9e 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -836,10 +836,10 @@ int cgroup_bpf_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) link->cgroup = cgrp; link->type = attr->link_create.attach_type; - link_file = bpf_link_new_file(&link->link, &link_fd); - if (IS_ERR(link_file)) { + link_fd = bpf_link_new_file(&link->link, &link_file); + if (link_fd < 0) { kfree(link); - err = PTR_ERR(link_file); + err = link_fd; goto out_put_cgroup; } diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 64783da342020..cb2364e17423c 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2307,23 +2307,10 @@ int bpf_link_new_fd(struct bpf_link *link) * complicated and expensive operations and should be delayed until all the fd * reservation and anon_inode creation succeeds. */ -struct file *bpf_link_new_file(struct bpf_link *link, int *reserved_fd) +int bpf_link_new_file(struct bpf_link *link, struct file **file) { - struct file *file; - int fd; - - fd = get_unused_fd_flags(O_CLOEXEC); - if (fd < 0) - return ERR_PTR(fd); - - file = anon_inode_getfile("bpf_link", &bpf_link_fops, link, O_CLOEXEC); - if (IS_ERR(file)) { - put_unused_fd(fd); - return file; - } - - *reserved_fd = fd; - return file; + return __anon_inode_getfd("bpf_link", &bpf_link_fops, link, O_CLOEXEC, + file); } struct bpf_link *bpf_link_get_from_fd(u32 ufd) @@ -2406,10 +2393,10 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog) } bpf_link_init(&link->link, &bpf_tracing_link_lops, prog); - link_file = bpf_link_new_file(&link->link, &link_fd); - if (IS_ERR(link_file)) { + link_fd = bpf_link_new_file(&link->link, &link_file); + if (link_fd < 0) { kfree(link); - err = PTR_ERR(link_file); + err = link_fd; goto out_put_prog; } @@ -2520,10 +2507,10 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr) bpf_link_init(&link->link, &bpf_raw_tp_lops, prog); link->btp = btp; - link_file = bpf_link_new_file(&link->link, &link_fd); - if (IS_ERR(link_file)) { + link_fd = bpf_link_new_file(&link->link, &link_file); + if (link_fd < 0) { kfree(link); - err = PTR_ERR(link_file); + err = link_fd; goto out_put_btp; } From patchwork Fri May 8 15:36:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219610 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.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 8A416C47257 for ; Fri, 8 May 2020 15:36:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61BF224953 for ; Fri, 8 May 2020 15:36:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AWoCrBmc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728277AbgEHPgz (ORCPT ); Fri, 8 May 2020 11:36:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726736AbgEHPgw (ORCPT ); Fri, 8 May 2020 11:36:52 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9235C061A0C; Fri, 8 May 2020 08:36:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=84Q6+XvESATHkPDs3NezzlHWwc4KFGjN8N6drGU+t58=; b=AWoCrBmcbiNeSqG41R8zejRyGu q9id5MMqFDnvfrZaKfLud0DzqWzP81fdQM2386RtOX+d1YUMf/xfAOiVUr699SfUMz7BTaVNStXYL URpd5PGUP47QmFtYhFKrjV9Chp+yOi6JLX3053q5fnCJsoCaJC0JS55pAMk20L88eIz9rHxZgVuGV yjg4TCdQyTS/tDFunEk4vcDsvmGZCUFGy9Yo0DcC3s6+nRk9Or5FqCiCQQmg/86acEJlB6AwC/r2W ha+mGlYY+7L0ukMxEOgVwW3F6ckPe0jf7choEDgXl4CQfuHU79gbeHfvDNAxNZBTXBT7Mjx37VB6E BcK7J1bg==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53T-0004BL-6n; Fri, 08 May 2020 15:36:51 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 05/12] io_uring: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:27 +0200 Message-Id: <20200508153634.249933-6-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Signed-off-by: Christoph Hellwig --- fs/io_uring.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 5190bfb6a6657..4104f8a45d11e 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7709,18 +7709,11 @@ static int io_uring_get_fd(struct io_ring_ctx *ctx) return ret; #endif - ret = get_unused_fd_flags(O_RDWR | O_CLOEXEC); + ret = __anon_inode_getfd("[io_uring]", &io_uring_fops, ctx, + O_RDWR | O_CLOEXEC, &file); if (ret < 0) goto err; - file = anon_inode_getfile("[io_uring]", &io_uring_fops, ctx, - O_RDWR | O_CLOEXEC); - if (IS_ERR(file)) { - put_unused_fd(ret); - ret = PTR_ERR(file); - goto err; - } - #if defined(CONFIG_UNIX) ctx->ring_sock->file = file; #endif From patchwork Fri May 8 15:36:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219607 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.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 D5D7DC38A2A for ; Fri, 8 May 2020 15:37:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACBB324955 for ; Fri, 8 May 2020 15:37:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="r/T2Qu4D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728328AbgEHPhB (ORCPT ); Fri, 8 May 2020 11:37:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728264AbgEHPgy (ORCPT ); Fri, 8 May 2020 11:36:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E19C061A0C; Fri, 8 May 2020 08:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Y6GByYBpY6pH5k9QcdAJgxxwyoCDdXaPGt39GnAtfcU=; b=r/T2Qu4Dq2EPB6e8g5rt10rdUS xxIMdT2OcwOzQanXgb4lV4q1HK2YMY6jUhqZw4kqLXgZCPDWdZw6jUGIRcchb87UWGNEuuzBouvX4 4YS6XQKp60nPAtzrXWUhDMdzUDn2lFo59J/30GXVF9vyt86zvxErfvhDIjdhWfDQu5QTV2MczwT2x fGalI5f7Wmy57824Eoy61rqGOadOiirp9dqXejOb+NK5CiWjdMnCeU4VkmDWFCec3wc6SAXB9cpOu qVjmdlypsglLL/MZUS2SpJ5wA9C0Z291fcC9yHzmdGJanj/2UhJ/FJKsXGQ6ggPMKfRpM8NzQ3VrW aO9USAMw==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53V-0004Cz-VR; Fri, 08 May 2020 15:36:54 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 06/12] eventpoll: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:28 +0200 Message-Id: <20200508153634.249933-7-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Signed-off-by: Christoph Hellwig --- fs/eventpoll.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 8c596641a72b0..8abdb9fff611a 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -2055,23 +2055,14 @@ static int do_epoll_create(int flags) * Creates all the items needed to setup an eventpoll file. That is, * a file structure and a free file descriptor. */ - fd = get_unused_fd_flags(O_RDWR | (flags & O_CLOEXEC)); - if (fd < 0) { - error = fd; + fd = __anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep, + O_RDWR | (flags & O_CLOEXEC), &file); + if (fd < 0) goto out_free_ep; - } - file = anon_inode_getfile("[eventpoll]", &eventpoll_fops, ep, - O_RDWR | (flags & O_CLOEXEC)); - if (IS_ERR(file)) { - error = PTR_ERR(file); - goto out_free_fd; - } ep->file = file; fd_install(fd, file); return fd; -out_free_fd: - put_unused_fd(fd); out_free_ep: ep_free(ep); return error; From patchwork Fri May 8 15:36:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219609 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.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 8053DC38A2A for ; Fri, 8 May 2020 15:37:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5909D24955 for ; Fri, 8 May 2020 15:37:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Qa2htAHP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728362AbgEHPhH (ORCPT ); Fri, 8 May 2020 11:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728355AbgEHPhD (ORCPT ); Fri, 8 May 2020 11:37:03 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37EFC061A0C; Fri, 8 May 2020 08:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Fa8g/lJWKeJOUWpYZKXVATFBsUbfwqV0WZlzPMoN0uA=; b=Qa2htAHPQfxVvAUTYEeMqFgrdh GOwnTg4ulWQqLx6PIvQwXwOQ38d99ysssfAJK0A0785ViFbs5O4fMdbZzuq2dDKpS8pELW7HGvkBM p1nwmkCOWeGuhoWNIarZEKQnoIq2R5Ex6v5mA07Q/8cRXM1obeyxcP5oPlOnMLj/LE/DGq17tKzG5 C72uis6BvgLT+nnvwsubs4tEk9aZUMn1y7yUC4eLB2h/N8MLIsTdMkKA9um8pxHIhYStpxq4EUKhW JF8NNAytHWoxkh5ov5BS8g1yn0WriNp19+/h+gp0YDDSf/AdqPHNP83wqLC7LkpEXhpV8LqMLPmdF xf6VlBZg==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53e-0004QB-FT; Fri, 08 May 2020 15:37:02 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 09/12] rdma: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:31 +0200 Message-Id: <20200508153634.249933-10-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Signed-off-by: Christoph Hellwig --- drivers/infiniband/core/rdma_core.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c index 5128cb16bb485..541e5e06347f6 100644 --- a/drivers/infiniband/core/rdma_core.c +++ b/drivers/infiniband/core/rdma_core.c @@ -462,30 +462,21 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj, if (WARN_ON(fd_type->fops->release != &uverbs_uobject_fd_release)) return ERR_PTR(-EINVAL); - new_fd = get_unused_fd_flags(O_CLOEXEC); - if (new_fd < 0) - return ERR_PTR(new_fd); - uobj = alloc_uobj(attrs, obj); if (IS_ERR(uobj)) - goto err_fd; + return uobj; /* Note that uverbs_uobject_fd_release() is called during abort */ - filp = anon_inode_getfile(fd_type->name, fd_type->fops, NULL, - fd_type->flags); - if (IS_ERR(filp)) { - uobj = ERR_CAST(filp); + new_fd = __anon_inode_getfd(fd_type->name, fd_type->fops, NULL, + fd_type->flags | O_CLOEXEC, &filp); + if (new_fd < 0) goto err_uobj; - } uobj->object = filp; - uobj->id = new_fd; return uobj; err_uobj: uverbs_uobject_put(uobj); -err_fd: - put_unused_fd(new_fd); return uobj; } From patchwork Fri May 8 15:36:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 219608 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.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 79F34C54E4A for ; Fri, 8 May 2020 15:37:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58BE724956 for ; Fri, 8 May 2020 15:37:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QaziO0NS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728444AbgEHPhM (ORCPT ); Fri, 8 May 2020 11:37:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728355AbgEHPhI (ORCPT ); Fri, 8 May 2020 11:37:08 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 570CBC061A0C; Fri, 8 May 2020 08:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=NUGZNNRYFM0r6kvrHWtMu9/AVBHfp8IFXSz0BKnUiVc=; b=QaziO0NSeQwoBUsoW2UkQtna/5 NGR+c8JIXGOc/mERbPJ/qE6LMl1yRyZBdONWcRQxh2qN+Rk/qihtN73flB3sHOwJF72lSyQj02odD tRz1FUuNgGFRL/cQ8TnpfPM5h5Cp1GcTIBamE9zY4bwV4OvEgkOaL+zUguxEmbvpSuUMR1MxJzv8+ vEWhImZDiwF5ZZ6jdFCkj2PmwdYN4Nsf7H6j0MBRkCAKtQhrPY8M7ps9NjGjWNJmItph2EXtAXF+u 6pUJHGpwiV3rE/TKreks53fL62TXAD3rNPY8PafEfyIqPvSP+y90xG3LSslfGPcOAJa2l3FCXL0ip KwSFPwBQ==; Received: from [2001:4bb8:180:9d3f:90d7:9df8:7cd:3504] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jX53j-0004SG-Pl; Fri, 08 May 2020 15:37:08 +0000 From: Christoph Hellwig To: Alexander Viro Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 11/12] gpiolib: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:33 +0200 Message-Id: <20200508153634.249933-12-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508153634.249933-1-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use __anon_inode_getfd instead of opencoding the logic using get_unused_fd_flags + anon_inode_getfile. Signed-off-by: Christoph Hellwig --- drivers/gpio/gpiolib.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 40f2d7f69be26..cbcf47b1e6a40 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -736,21 +736,13 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) i--; lh->numdescs = handlereq.lines; - fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); + fd = __anon_inode_getfd("gpio-linehandle", &linehandle_fileops, lh, + O_RDONLY | O_CLOEXEC, &file); if (fd < 0) { ret = fd; goto out_free_descs; } - file = anon_inode_getfile("gpio-linehandle", - &linehandle_fileops, - lh, - O_RDONLY | O_CLOEXEC); - if (IS_ERR(file)) { - ret = PTR_ERR(file); - goto out_put_unused_fd; - } - handlereq.fd = fd; if (copy_to_user(ip, &handlereq, sizeof(handlereq))) { /* @@ -769,8 +761,6 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) return 0; -out_put_unused_fd: - put_unused_fd(fd); out_free_descs: for (i = 0; i < count; i++) gpiod_free(lh->descs[i]); @@ -1110,21 +1100,13 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) if (ret) goto out_free_desc; - fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); + fd = __anon_inode_getfd("gpio-event", &lineevent_fileops, le, + O_RDONLY | O_CLOEXEC, &file); if (fd < 0) { ret = fd; goto out_free_irq; } - file = anon_inode_getfile("gpio-event", - &lineevent_fileops, - le, - O_RDONLY | O_CLOEXEC); - if (IS_ERR(file)) { - ret = PTR_ERR(file); - goto out_put_unused_fd; - } - eventreq.fd = fd; if (copy_to_user(ip, &eventreq, sizeof(eventreq))) { /* @@ -1140,8 +1122,6 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) return 0; -out_put_unused_fd: - put_unused_fd(fd); out_free_irq: free_irq(le->irq, le); out_free_desc: