Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp904810pxb; Wed, 6 Oct 2021 18:36:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEwZ+9IlohA+tppJLN/LoVb6t2yh4EFbgI/UmvNErSd/YfrKLsyNqZQEKv2389u41UgYDd X-Received: by 2002:a63:258:: with SMTP id 85mr1131671pgc.11.1633570601481; Wed, 06 Oct 2021 18:36:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633570601; cv=none; d=google.com; s=arc-20160816; b=rWjRtb/ZlYnuau8dWS7D9+aspHGPA/gzPS3A6QL5c6Ih1tUIXdSlXMvvLQhvuptpj5 WV83KrK1DcPuPxIgw2AOBMgQLKlxxjUVGuP2nZLQ7ZHQ3gY/JSkoLJW6LyTWbmn9D1bH l+skr4ZXBCLO9DvpyappSp8JLaiQWdgpxUiXJvZvaiZIbPrS4NeYjymMw91mMXL9yLvV 3rnCQ5O0LIH49X+cp6lGPCNJBu4BaUHQe/YUpe+7Vic0PgUqU7OzM9DDW/plJu1F/vpV 89iBmlMvor4Jrv2oKG1AWhqicUCYaf5kazmJUteAbTV0NMrIKIQcOpWA+I7bpegubAyr pZdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qstVtDT91XWliCaW5kitB3WljFF05mjQismqLt2KJ+A=; b=dn6x00nIZlYhp8XMjZCbMJQAXVMYk3m1SWXASOO19U7vhq2DD6pa0yyNSLnFml/x5w GTnFcHocOmPgseHHAFQ+oDVC6G9noxvpoVaKOQfmdku/Kyn1tyfGJDclIseF62NL4yzO oKDOT+WYSdKLo63NOsVZjfo+pgrncTYrQ4ZFef2U6S5QGSTt3mt6YvyZx5z4/Il9nSMb gsXBn82ucwJwPLb3b2oZmzA4m4KMLBvTlEd0Gq40hL6p/lHMi5Fdc+BJ1YqEn+6jfYhU V/3mS/qA9plIm8X4Mn6nF4yfHt8TvpgN5Jxg7gvBd7+7t5zGmv0e3c9jeXrWDBfn+h6r S8xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=n70FR0j9; 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 ob4si5292713pjb.148.2021.10.06.18.36.28; Wed, 06 Oct 2021 18:36:41 -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=@gibson.dropbear.id.au header.s=201602 header.b=n70FR0j9; 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 S232191AbhJGBZQ (ORCPT + 99 others); Wed, 6 Oct 2021 21:25:16 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]:51283 "EHLO gandalf.ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbhJGBZM (ORCPT ); Wed, 6 Oct 2021 21:25:12 -0400 Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4HPtqp36Vbz4xbG; Thu, 7 Oct 2021 12:23:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1633569798; bh=qstVtDT91XWliCaW5kitB3WljFF05mjQismqLt2KJ+A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=n70FR0j9KTEGEzxwCxf2JDFXaUu8zShyp+4N0lscr1waf+K/ZgaxwyX9ZowdEeqyT 93j/gp22nAcMRYODT0LPRwZZf8hod6y0LuY2l71D1O/R3Do5F53fEXCE37Ph8arTyB 8uacyxaJkPxNRjhkPqJtBB70Xzz+taoWwt0m2ERk= Date: Thu, 7 Oct 2021 12:23:13 +1100 From: David Gibson To: Jason Gunthorpe Cc: Liu Yi L , alex.williamson@redhat.com, hch@lst.de, jasowang@redhat.com, joro@8bytes.org, jean-philippe@linaro.org, kevin.tian@intel.com, parav@mellanox.com, lkml@metux.net, pbonzini@redhat.com, lushenming@huawei.com, eric.auger@redhat.com, corbet@lwn.net, ashok.raj@intel.com, yi.l.liu@linux.intel.com, jun.j.tian@intel.com, hao.wu@intel.com, dave.jiang@intel.com, jacob.jun.pan@linux.intel.com, kwankhede@nvidia.com, robin.murphy@arm.com, kvm@vger.kernel.org, iommu@lists.linux-foundation.org, dwmw2@infradead.org, linux-kernel@vger.kernel.org, baolu.lu@linux.intel.com, nicolinc@nvidia.com Subject: Re: [RFC 07/20] iommu/iommufd: Add iommufd_[un]bind_device() Message-ID: References: <20210919063848.1476776-1-yi.l.liu@intel.com> <20210919063848.1476776-8-yi.l.liu@intel.com> <20210929122457.GP964074@nvidia.com> <20211001124322.GN964074@nvidia.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KDKmP08LDN9ERU6o" Content-Disposition: inline In-Reply-To: <20211001124322.GN964074@nvidia.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --KDKmP08LDN9ERU6o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 01, 2021 at 09:43:22AM -0300, Jason Gunthorpe wrote: > On Thu, Sep 30, 2021 at 01:10:29PM +1000, David Gibson wrote: > > On Wed, Sep 29, 2021 at 09:24:57AM -0300, Jason Gunthorpe wrote: > > > On Wed, Sep 29, 2021 at 03:25:54PM +1000, David Gibson wrote: > > >=20 > > > > > +struct iommufd_device { > > > > > + unsigned int id; > > > > > + struct iommufd_ctx *ictx; > > > > > + struct device *dev; /* always be the physical device */ > > > > > + u64 dev_cookie; > > > >=20 > > > > Why do you need both an 'id' and a 'dev_cookie'? Since they're both > > > > unique, couldn't you just use the cookie directly as the index into > > > > the xarray? > > >=20 > > > ID is the kernel value in the xarray - xarray is much more efficient & > > > safe with small kernel controlled values. > > >=20 > > > dev_cookie is a user assigned value that may not be unique. It's > > > purpose is to allow userspace to receive and event and go back to its > > > structure. Most likely userspace will store a pointer here, but it is > > > also possible userspace could not use it. > > >=20 > > > It is a pretty normal pattern > >=20 > > Hm, ok. Could you point me at an example? >=20 > For instance user_data vs fd in io_uring Ok, but one of those is an fd, which is an existing type of handle. Here we're introducing two different unique handles that aren't an existing kernel concept. > RDMA has many similar examples. >=20 > More or less anytime you want to allow the kernel to async retun some > information providing a 64 bit user_data lets userspace have an easier > time to deal with it. I absolutely see the need for user_data. What I'm questioning is having two different, user-visible unique handles, neither of which is an fd. That said... is there any strong reason why user_data needs to be unique? I can imagine userspace applications where you don't care which device the notification is coming from - or at least don't care down to the same granularity that /dev/iommu is using. In which case having the kernel provided unique handle and the not-necessarily-unique user_data would make perfect sense. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --KDKmP08LDN9ERU6o Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAmFeTAAACgkQbDjKyiDZ s5IHfA//dHZrmxuC2Eg7GpSZRzPqLOFtDPTlZ/fOS0A3Ww2bU6S+CuugltvCz+U2 KZ65d6W7oAiRDmaxTdPARsY/JsYFSu+jGnVfYI4ZUf/N6v0NIInS5L5z31og1nhu VYPLtYEPenL5Ikj/e3Ul9E6l5AqLcRqRw/j5G83ygQB3Wk93LdeF/p8wdEvEt599 U5V8JbGKUYzBySYD4+m6EhhYpAEagGRRltJE10AZm4WB9w6KbjkrQryg7zSfbbEo ulwVrlY/IBzHmbBi82IQOiXFIZkdbvuigelt34UPdMSVj50Wmo4t/bxyTbRGk9O8 YMGa0Y5l0bH6gtl1M/e9Gq3rEwGrjSP/GyvLCZSv1D3nAti/WK7INv9NVEz1E74O frugTJBSsodRVz31hMt+WDT5NTTv+F+xQjEnFZTcCeogHvDissXh2wnhUXSi5kQq g8GcJfG621SrtvulFlFIhjgtXqxPzRJm+uXWTI5ESCA7+3g79Pr5kKo9UTiRK1c1 HtB8mM70Hp+vOmWSZ5D3wYZX4ImXpcWdHk0y0c1O0QQVmFF07iyqjVXu+A6r/A5y ly8PwxvM0gnM7Ewuz37YXpGTgeiCTVaUVPITz09GN1mMqYa2V0l1X3q/G5iwb/g8 0SqR8HFGjS87nbngGm/vjD/AscCOHePTMrFQvN/GFytfMWdJO3c= =VYju -----END PGP SIGNATURE----- --KDKmP08LDN9ERU6o--