From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: "Tian, Kevin" <kevin.tian@intel.com>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Joerg Roedel <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>
Subject: RE: [RFC PATCH] iommufd: Destroy vdevice on device unbind
Date: Mon, 16 Jun 2025 10:16:14 +0530 [thread overview]
Message-ID: <yq5a8qlstht5.fsf@kernel.org> (raw)
In-Reply-To: <BN9PR11MB527606182417BB7A35349F598C74A@BN9PR11MB5276.namprd11.prod.outlook.com>
"Tian, Kevin" <kevin.tian@intel.com> writes:
>> From: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
>> Sent: Tuesday, June 10, 2025 2:52 PM
>>
>> The iommufd subsystem uses the VFIO character device descriptor to bind
>
> it's the 'user' or 'vmm' initiating that operation, not the subsystem itself.
>
>> a device file to an iommufd context via the VFIO_DEVICE_BIND_IOMMUFD
>> ioctl. This binding returns a bind_id, which is then used in subsequent
>
> there is no 'bind_id' in any uAPI. let's stick to 'devid'.
>
>> iommufd ioctls such as IOMMU_HWPT_ALLOC, IOMMU_VIOMMU_ALLOC,
>> and
>> IOMMU_VDEVICE_ALLOC.
>>
>> Among these, IOMMU_VDEVICE_ALLOC is special—the lifetime of a virtual
>> device (vdevice) should be tied to the bound state of its physical
>> device.
>>
>> In the current kernel, there is no enforced dependency between
>> iommufd_device and iommufd_vdevice. This patch introduces such a
>> dependency: when the device is unbound, the associated vdevice is now
>> automatically destroyed.
>
> This went backward.
>
> The initial v5 patch [1] from Nicolin was similar to what this
> patch does. Jason explained [2] why it's unsafe to destroy "userspace
> created" objects behind the scene. And a general rule in iommufd is
> to not take long term references on kernel owned objects.
>
> [1] https://lore.kernel.org/all/53025c827c44d68edb6469bfd940a8e8bc6147a5.1729897278.git.nicolinc@nvidia.com/
> [2] https://lore.kernel.org/all/20241029184801.GW6956@nvidia.com/
>
>>
>> Although there is already an implicit dependency—vdevices can only be
>> destroyed after the iommufd_device is unbound due to the VFIO cdev file
>> descriptor holding a reference to the iommu file descriptor—this patch
>
> I didn't get this part. The user owns the life cycle of its created objects.
> We don't have such restriction that a vdevice object can be destroyed
> only after device is unbound...
>
What I described above explains how the kernel manages destruction of
these objects.
The vfio subsystem retains a reference to the iommufd file descriptor
through:
vfio_df_ioctl_bind_iommufd() → iommufd_ctx_from_fd()
This reference prevents the associated vdevice from being destroyed when
the iommufd file descriptor is closed, as long as the idevice remains
bound. While vdevice objects can still be explicitly destroyed using
iommufd_destroy(), with this patch, if the idevice is still bound,
attempting to destroy the vdevice will return EBUSY.
In effect, the change ensures that once a vdevice is created, its
lifecycle is tied to that of the idevice.
From other emails in this thread, I understand that beyond the the
changes in this patch, we want to prevent the reuse of the vdevice
object ID. We also need to ensure that any userspace-initiated operation
on this vdevice object ID results in an error after the idevice is
unbound?
-aneesh
next prev parent reply other threads:[~2025-06-16 4:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 6:51 [RFC PATCH] iommufd: Destroy vdevice on device unbind Aneesh Kumar K.V (Arm)
2025-06-12 8:05 ` Tian, Kevin
2025-06-12 17:26 ` Jason Gunthorpe
2025-06-13 7:31 ` Tian, Kevin
2025-06-13 12:42 ` Jason Gunthorpe
2025-06-16 3:56 ` Xu Yilun
2025-06-16 4:28 ` Aneesh Kumar K.V
2025-06-16 5:37 ` Tian, Kevin
2025-06-16 16:49 ` Jason Gunthorpe
2025-06-17 8:07 ` Aneesh Kumar K.V
2025-06-17 18:34 ` Jason Gunthorpe
2025-06-18 5:29 ` Aneesh Kumar K.V
2025-06-18 13:35 ` Jason Gunthorpe
2025-06-18 14:52 ` Aneesh Kumar K.V
2025-06-18 15:00 ` Jason Gunthorpe
2025-06-19 5:37 ` Tian, Kevin
2025-06-24 10:33 ` Aneesh Kumar K.V
2025-06-24 12:24 ` Tian, Kevin
2025-06-16 5:19 ` Tian, Kevin
2025-06-16 4:15 ` Aneesh Kumar K.V
2025-06-16 5:21 ` Tian, Kevin
2025-06-16 4:46 ` Aneesh Kumar K.V [this message]
2025-06-16 5:48 ` Tian, Kevin
2025-06-16 5:58 ` Xu Yilun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=yq5a8qlstht5.fsf@kernel.org \
--to=aneesh.kumar@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).