Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp168683ybj; Fri, 8 May 2020 08:57:16 -0700 (PDT) X-Google-Smtp-Source: APiQypIiU0ZAmla2w0imEB0NfoAQaMuBjjUS51tvZEEGR7M1G3yZ6gUymGcA57okmMZxfotoRqqq X-Received: by 2002:a50:9e23:: with SMTP id z32mr2590697ede.169.1588953436777; Fri, 08 May 2020 08:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588953436; cv=none; d=google.com; s=arc-20160816; b=XdkFdLiLF12SAtdJC94Wav2DgsDcnOSEH1RIdgsS7Q16xgvDTV3QIpuyC6G2q3jkvZ QdQzvJbsoJ7crenMndV7cBmeuFs9EddAmbu7FktoOrUDaUbtITaBpzl5TNrpubv2L9b8 3RaHXJ+VJ22FngEjazFqa0goz3YVojVbrenAvIkinqMBfdckaqa/7e9iHr0otP9otQDz uWwUgjD8Ta1/nHNiYSpsrjz0jT8ckXewJQ3stM2kN2R8MPUSCBVajFsa47BN+RCmkE8U cfdxjNkqA/sAF5yicJwux11NCGsek/ct1hg2cfzBXbFJiqelq9uvJsuJaMvIMyHSmjWP XNfQ== 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:subject:cc:to:from:date :dkim-signature; bh=o2NuVDMsNek1XqDZ23KXOT0aYU3U9mtuti+eij0cQ3Y=; b=M88zzffdQvBOzSwuRjETGeWjtqKhVdjKpiKfYEumfMP0bsnr2Tiw4AH/Vtpd9CjOGu WrBe73w3db7QWvMXswdcBxMzlHDFEgw09lw+PMJJAoETFvtAw19ASQ7ERcuo+3Dod1yd HPMkR3f+fzQgvsWC33AIrwaxG3zxGZtLd2z5WYdmMZkAWGYDWBy7FbgT0jJ0lv2T2eBb AxOUKeenVLxaH62NHlzklsgeNCV9tnbZh5+K6DOb4G5TTMCwtf+j5gIG88P6ukpEet4T HwEXyW+c0rtr3Gi4Mn6Y/mGwNlqHiDzi7FPkodo/CqVrSOZBpKl5z0Lz8jfXft2Vx98M rSiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="RH/5e3x/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g12si1111384ejw.314.2020.05.08.08.56.53; Fri, 08 May 2020 08:57:16 -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=pass header.i=@redhat.com header.s=mimecast20190719 header.b="RH/5e3x/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728152AbgEHPzR (ORCPT + 99 others); Fri, 8 May 2020 11:55:17 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:52784 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727882AbgEHPzQ (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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; > } >