Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp157610ybj; Fri, 8 May 2020 08:40:11 -0700 (PDT) X-Google-Smtp-Source: APiQypKznqFkR+daGOg7h4eMaX4sBBmnJb6Nh7s1rC2RMT3qouLSt1c5LOR/ATqWS8b0dFHnB4Xh X-Received: by 2002:a17:906:4993:: with SMTP id p19mr2234289eju.67.1588952411533; Fri, 08 May 2020 08:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588952411; cv=none; d=google.com; s=arc-20160816; b=xo4wxBrVh76/KSLjiV71mY1iA2Xxl45SLzPz3iits7TBLdnqenb1QH0VRwuvaiqbQy q67W3UzNJuTfdM9FgBt5nZ7HacHSsDE3w8AbEEPWaY+UfxLpawUumu1CqA32jxpBhdFD gQiJzI0MHIsXiUSfELrb4yQPEkCyWcWtAsAvI3AqyCdUnQOJV6BywHj9g9qYG+1Lgbq7 2c/XLnXH1ESuPKVV7ur3Ta23qjGaqIgYk1fCVRJTXBMXTKyjzNTSVXEtIhNL8HNgZUo+ FScU14/gx2WGxCTk9srg+nxeb1BVqZ3xSHkztAbEDnVd4Y1XAySkmttY7wM9PGYLJDNw p9jA== 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=nmjnltB29xld+C3Z+3PwCdDAVaharMq9Nb/YJIWz0Mw=; b=1BpUwOHwD3mDBH+TQzjNK3giMRIgbubuMgGDLpuAp+b3r3l+1RLpapLflcKs/+jf8G wd1OIjiZVZv0qaifFIjHkUNkVdV7h+9RLjJbreI9B6EdCOjBVuW6nu0xQ5mglMmPQVCT twBiRUHANDGhslXhVXLLCSXom+scTkjTQ9iDPFzsZYjP1UzwvYWjUGY5tfZU60XNJ8py R0Nq5a+07SwojuLHXy++NaYLyJarO9QDH3vm2MEHn2moaI1K9Tq2ZpbN5XimbStBq2So 3E0+mXybPNeKnYyI5iFziC8IHU7rcwknnXxFblvElRCXF1kBy0aTf5hkPxUzmTYVgcJu fixA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=XC7dRbkc; 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 g16si1034313edr.382.2020.05.08.08.39.48; Fri, 08 May 2020 08:40:11 -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=XC7dRbkc; 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 S1728564AbgEHPhv (ORCPT + 99 others); Fri, 8 May 2020 11:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728304AbgEHPhA (ORCPT ); Fri, 8 May 2020 11:37:00 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24ABEC061A0C; Fri, 8 May 2020 08:37:00 -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=nmjnltB29xld+C3Z+3PwCdDAVaharMq9Nb/YJIWz0Mw=; b=XC7dRbkcv1Z+9Aj3oRe1TSTHyA 92hwRGkNvqNC1eKJPiFAchuwONZiLGsaR09OC9v+N2an8W+SAyjulwp7XCmGWsm1fNWqkmFfGnGQe d+lsRHk/Bu2X6EcnRHqZEP/tmf+cfJDroBH3O+RBLMcto3g5Hpz5EsuYPzyIRDUd6Tx0MGnxaD+o4 8NZidjToalkxI1guS+RsMSwlFeAWxK4ZTLFqmVkASNbu0eweGVJrRiijmA8PNH65Z8vpwwddiqMrD /VgNAyZqKh5bCLc5iRU9un0MeHL8up6W0xpMpgOOCMrlYGGig+ysKu6//vM1JaYlCnY64yS1RWO6e E1IikOWA==; 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 1jX53b-0004Kk-JZ; Fri, 08 May 2020 15:37:00 +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 08/12] vfio: use __anon_inode_getfd Date: Fri, 8 May 2020 17:36:30 +0200 Message-Id: <20200508153634.249933-9-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. Signed-off-by: Christoph Hellwig --- drivers/vfio/vfio.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 765e0e5d83ed9..33a88103f857f 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1451,42 +1451,21 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) return ret; } - /* - * We can't use anon_inode_getfd() because we need to modify - * the f_mode flags directly to allow more than just ioctls - */ - ret = get_unused_fd_flags(O_CLOEXEC); - if (ret < 0) { - device->ops->release(device->device_data); - vfio_device_put(device); - return ret; - } - - filep = anon_inode_getfile("[vfio-device]", &vfio_device_fops, - device, O_RDWR); - if (IS_ERR(filep)) { - put_unused_fd(ret); - ret = PTR_ERR(filep); - device->ops->release(device->device_data); - vfio_device_put(device); - return ret; - } - - /* - * TODO: add an anon_inode interface to do this. - * Appears to be missing by lack of need rather than - * explicitly prevented. Now there's need. - */ + ret = __anon_inode_getfd("[vfio-device]", &vfio_device_fops, + device, O_CLOEXEC | O_RDWR, &filep); + if (ret < 0) + goto release; filep->f_mode |= (FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE); - atomic_inc(&group->container_users); - fd_install(ret, filep); if (group->noiommu) dev_warn(device->dev, "vfio-noiommu device opened by user " "(%s:%d)\n", current->comm, task_pid_nr(current)); - + return ret; +release: + device->ops->release(device->device_data); + vfio_device_put(device); return ret; } -- 2.26.2