From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: "Tian, Kevin" <kevin.tian@intel.com>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
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: Wed, 18 Jun 2025 20:22:44 +0530 [thread overview]
Message-ID: <yq5att4drtj7.fsf@kernel.org> (raw)
In-Reply-To: <20250618133527.GQ1376515@ziepe.ca>
Jason Gunthorpe <jgg@ziepe.ca> writes:
> On Wed, Jun 18, 2025 at 10:59:00AM +0530, Aneesh Kumar K.V wrote:
>> Jason Gunthorpe <jgg@ziepe.ca> writes:
>>
>> > On Tue, Jun 17, 2025 at 01:37:04PM +0530, Aneesh Kumar K.V wrote:
>> >
>> >> How do we reclaim that object id for further reuse?
>> >
>> > Maybe just don't? Userspace did something it shouldn't, it now leaked
>> > 8 bytes of kernel memory until the FD is closed.
>> >
>>
>> Between the two sequences below, Sequence 1 is the correct one, since we
>> want the object ID to be released after calling ioctl(DESTROY,
>> vdevice_id), right?
>>
>> Sequence 1 (Correct):
>>
>> close(vfio_cdev) → triggers vdevice destruction
>> ioctl(DESTROY, vdevice_id) → reclaims vdevice object ID
>> close(iommufd)
>
> This is wrong, the vdevice has outlived the idevice
>
>> Sequence 2:
>>
>> ioctl(DESTROY, vdevice_id) → returns EBUSY
>
> It should not return EBUSY, it should destry the vdevice.
>
> The full sequence I would expect a sane userspace to do is:
>
> open(vfio_cdev)
> ioctl(vfio_cdev, VFIO_DEVICE_BIND_IOMMUFD, iommufd)
> ioctl(iommufd, IOMMUFD_CMD_VIOMMU_ALLOC)
> ioctl(iommufd, IOMMUFD_CMD_VDEVICE_ALLOC)
> ioctl(iommufd, IOMMUFD_CMD_VDEVICE_DEALLOC)
> ioctl(iommufd, IOMMUFD_CMD_VIOMMU_DEALLOC)
> close(vfio_cdev);
>
And if the user does
open(vfio_cdev)
ioctl(vfio_cdev, VFIO_DEVICE_BIND_IOMMUFD, iommufd)
ioctl(iommufd, IOMMUFD_CMD_VIOMMU_ALLOC)
ioctl(iommufd, IOMMUFD_CMD_VDEVICE_ALLOC)
close(vfio_cdev); -> this should call vdevice_destroy because idevice is getting destroyed here (we will put XA_ZERO_ENTRY here).
ioctl(iommufd, IOMMUFD_CMD_VDEVICE_DEALLOC) -> No error, we convert the XA_ZERO_ENTRY to NULL here?
ioctl(iommufd, IOMMUFD_CMD_VIOMMU_DEALLOC)
-aneesh
next prev parent reply other threads:[~2025-06-18 14:52 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 [this message]
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
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=yq5att4drtj7.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).