Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1152660pxb; Sun, 10 Oct 2021 22:38:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHRFByb6jF0wg9LjsD4WrPStNgV9jQbmDkZfKAXApmnWQqb0v/zmeLf19Dd0jIpO1wWjHP X-Received: by 2002:a17:90a:1548:: with SMTP id y8mr29551663pja.151.1633930687850; Sun, 10 Oct 2021 22:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633930687; cv=none; d=google.com; s=arc-20160816; b=G3EhgYtv9aH0OJ0dwIyF6zuqMveDMywnreDxoto3syk69mHdYbJ8GkA2wEHvgn/8+F iISVF0H/4CXfQEiLh4n/FKdv5lyWbEI884SNZTHMy5FXm8P6Hk7ZuGRq0UD3jW0UTwrq b/5YsCne1+xym1SrQXBM4xTjp1AIxMixiSJK/kQFH15Fv8ElT7/3OtRMlW3UE9OvS1LH ghqEp7alsracfEsjR3A5A7Jr0ikAoLV4D0ecVbtcHsJv9kNU/mIsBNY3FreDIOzeJkaY L47F2UhXqVYcGeTUgtV3gDqbcPxqvO9QRC9Civoz8tykEYpl3cvykmAT21S2JGB0yBQq 0e8Q== 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=RzarCJ/iuPvuUb6JjprFQQYugb74lPNA9To2B9JBEaA=; b=PTEcwGNQNY1K5ZJCyDjo9wfobcIfmcOpFPuvCjZteG2JYVXqh/pZtxnwzCfNuRHQGf 8VABVnQwket7vZtrGXiIjaDR3LDqx5qbWjow4wwZZZa+nEirh6GTAfK6du/8pfo4fZR7 ylPuud3uhiKb3aFcilE6GNCuxITgniScD2AP7KLEiWO04mmQkSSoviq+cMRldBDrwPdP f3HJIA0trRaO+LkBVQNNXSgf5eBIJ8Du+qtI1Rn+7D1cPhPHXiN+wOB7L5aKFC10nzCM RECd/sr9uO3PVS/lCGOMK8wyvlVzvkzMwcxhxrTfw3mVPuN6wNXWq4/uGQ5Mc7b7umY1 lyqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=LyZqqdQj; 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 o16si8550935pfk.63.2021.10.10.22.37.54; Sun, 10 Oct 2021 22:38:07 -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=LyZqqdQj; 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 S233839AbhJKD2y (ORCPT + 99 others); Sun, 10 Oct 2021 23:28:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233264AbhJKD2x (ORCPT ); Sun, 10 Oct 2021 23:28:53 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee2:21ea]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F30E1C061570; Sun, 10 Oct 2021 20:26:53 -0700 (PDT) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4HSPNW4sRpz4xbc; Mon, 11 Oct 2021 14:26:51 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1633922811; bh=RzarCJ/iuPvuUb6JjprFQQYugb74lPNA9To2B9JBEaA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LyZqqdQjik07FKZJ5xvz/gaQnsXaq5EqMzu7gBtg5Jw9Z4TpOl6I9mTY8emE9D1eU noM+JfptyGWe1TgtRLM5FS8DgHlLunji2lQ6SeL8O5qWxeswmKUAV5f5PzNluTsHAu 6BNFP38m2m86L5Qngupt69I+t0KCHDlyazEXXAfk= Date: Mon, 11 Oct 2021 14:24:21 +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> <20211007113503.GG2744544@nvidia.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0VYc2zw48AcQLMtf" Content-Disposition: inline In-Reply-To: <20211007113503.GG2744544@nvidia.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0VYc2zw48AcQLMtf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 07, 2021 at 08:35:03AM -0300, Jason Gunthorpe wrote: > On Thu, Oct 07, 2021 at 12:23:13PM +1100, David Gibson wrote: > > 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 effici= ent & > > > > > 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 i= t 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 > >=20 > > 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. >=20 > I'm not sure how that matters, the kernel has many handles - and we > get to make more of them.. Look at xarray/idr users in the kernel, many of > those are making userspace handles. Again, I'm commenting *just* on the fact that the current draft introduce *two* handles for the same object. I have no objection to either of the handles in isoation. > > 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 > I don't think the user_data 64 bit value should be unique, it is just > transported from user to kernal and back again. It is *not* a handle, > it is a cookie. >=20 > Handles for the kernel/user boundary should come from xarrays that > have nice lookup properties - not from user provided 64 bit values > that have to be stored in red black trees.. Yes, I think that would make more 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 --0VYc2zw48AcQLMtf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAmFjrmMACgkQbDjKyiDZ s5L66BAA2KSYaq6MCy69G1nEtfYbAGPDJ4QuXouV1K4wx7uIroH1P/RjgD3gcaw9 I2/Ity23aYrXP7e/JIthanEw7WnB9Zw8Y7SqhqPsXfkpoQt0F9Voykhh6PUobHPj FjAovwh2OID8MdecvxwsTVxfadH6Hs5E2ZJxgM7i7IexUFXp8ArKgTJoYfj1vvsz eUmRJdqUVQsmAhLsprRXEVxleF1McEorHfR+gz/cGmoJHt/z66PqLBjARlbXtebg 2Iux0IFpguxtrKT9zpTEflC9qGJveGz7dGsrf9RFO+P2Xvgn1NG5qHaB0iYjZZxQ hAdWXsW8SLOEmgDAfizHHRYJ/gbEx6rmmv8UmhdRD+CqvnFKj+g27bgN/AUuFUFf 2BZ0gAeQHyycgeKNruOUNq3p2grSzb4v1d3E8xFPnzJ9jXir2t78j4wcqwjdS3Ek PR4NriYCCjRMiDon+cFP/qvjq4Aj50PJfh6zPjMiKobKd165ubO+KYzFYZMzsQ5B wjyHMQwk5IzIxQTXXMhlV6ZgoATn6ivmaF5++e1YOitPOhFL5oKdcAR7ap5lt7Mq iLVEPbPb1pcUjJJe+OJqNyAL1g59UUFpvILvGXDbVq2cqlf+cPlQMwUaTV9Nyut4 TPz2KR1VWKXN+eT+k3p6MuORLsAV67F/FqnZF0jVKu3blPwonCs= =/qGA -----END PGP SIGNATURE----- --0VYc2zw48AcQLMtf--