Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp159087ybj; Fri, 8 May 2020 08:42:14 -0700 (PDT) X-Google-Smtp-Source: APiQypIM3pcZAJzthfT9hogz7wekNJmrd+XflKefHJ59q/PVbU7K5C5CYYsG3SX8T9EQzM2g8lbs X-Received: by 2002:a50:950a:: with SMTP id u10mr2788996eda.45.1588952533981; Fri, 08 May 2020 08:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588952533; cv=none; d=google.com; s=arc-20160816; b=ljcXdSOxxddqNFWeDQxlT5jARNkvA5+YKt6dYZAwnPB6I6YYCiIbxwGxvLtuCm8Z3E NYAmBMyr9X4UbJNG+RceJ7WKJsQzMVvOktbGNcD85ONwMGZKwp5tMuw63B2YrB9nHlhR sWmq2PdrlexNVBpRhMiO7FAdwrFuGUm7jyiIkqvVtIi/xUL0HOXlUkjtRxBQWQSBlfrV 1tNgTru41Xl2f8wnu0AUpw9KpI7bwgh+ktZ1FMhIe+RDG4MsRVHaPYun+c0wb9gKgwQ8 /gaBU6E2W1wEvKdNnSqymWPefBWhk4PqidyhsdtR6jgoEChGYjuCaNWEwKdrscjSGQWb 7yeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MVpXPi4fO9ek2hxfJ7eaB5mhfWvQarx43ZgTOZ4t1BM=; b=TRql0Wq/GtrZaXm2a1h4YlYzQJcNMi1PlNBCJtFYEWAqH4xUMfifeIgPlNdrtkZpFt T3wBbnKE4SuB4miAIgUstmNSel3k2ahnV1HFiUoZycRN5YkbLfFDT57Wgl6ppApINguB lBHCMjHecH1WUO/ZAaL+9eo5its1tCWEPmR42gEvACLbJa+8/G6wLpfN3/T4Rq0S4MBb hVct8ee27WL7QKIFxZtQqCAhvWKvhfhaf2tr0MCFtVu2ENCgxHpi7MUFWWB+0FPBMUTv 7PZGZJ4IZyPy2NSlRmMflL5LfzsL8gO/EuewmdkDyjgNgKg/xtakkDNiLxmSQ9Gekuap 4OiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=UNM07rxT; 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 q26si1157065ejx.520.2020.05.08.08.41.51; Fri, 08 May 2020 08:42:13 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=UNM07rxT; 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 S1728592AbgEHPiO (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; } -- 2.26.2