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=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 E2150C47257 for ; Fri, 8 May 2020 15:55:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFE6721473 for ; Fri, 8 May 2020 15:55:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RH/5e3x/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728135AbgEHPzR (ORCPT ); Fri, 8 May 2020 11:55:17 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:45025 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727940AbgEHPzQ (ORCPT ); Fri, 8 May 2020 11:55:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588953315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o2NuVDMsNek1XqDZ23KXOT0aYU3U9mtuti+eij0cQ3Y=; b=RH/5e3x/Aznsbd5AM1J6BO+2cqjJRQKQ+ghv58yZ4onqXKu52Yll3jfDrYllFqRXnZ0nKO 3f2rtaNllTzDrvWbaSRolJ2itxGSdcZE0opMh4qcFX2KXuNbcI3CtqooBvkUkAiwE+/gsb us/8o0UifSojcAi6TAgXtPfpSD3kH2Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-172-tB1ktjf7Nd6ZDjXX8AJRsw-1; Fri, 08 May 2020 11:55:11 -0400 X-MC-Unique: tB1ktjf7Nd6ZDjXX8AJRsw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 59A41107ACCA; Fri, 8 May 2020 15:55:09 +0000 (UTC) Received: from w520.home (ovpn-113-111.phx2.redhat.com [10.3.113.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 615F6341E3; Fri, 8 May 2020 15:55:08 +0000 (UTC) Date: Fri, 8 May 2020 09:55:07 -0600 From: Alex Williamson To: Christoph Hellwig Cc: Alexander Viro , 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: Re: [PATCH 08/12] vfio: use __anon_inode_getfd Message-ID: <20200508095507.54051943@w520.home> In-Reply-To: <20200508153634.249933-9-hch@lst.de> References: <20200508153634.249933-1-hch@lst.de> <20200508153634.249933-9-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On Fri, 8 May 2020 17:36:30 +0200 Christoph Hellwig wrote: > 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(-) Thanks! Acked-by: Alex Williamson > 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; > } >