On Fri, Dec 12, 2025 at 02:12:09AM +0000, Duan, Zhenzhong wrote:
>
>
> >-----Original Message-----
> >>> +static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD
> >*idev,
> >>> + VTDAddressSpace *vtd_as)
> >>> +{
> >>> + if (!vtd_as->fs_hwpt) {
> >>> + return;
> >>> + }
> >>> + iommufd_backend_free_id(idev->iommufd, vtd_as->fs_hwpt);
> >>> + vtd_as->fs_hwpt = 0;
> >>is it a valid assumption a valid ID cannot be null? Is it documented
> >>somewhere?
> >
> >I didn't find it in uAPI doc, but it's hard coded in kernel:
> >
> >xa_init_flags(&ictx->objects, XA_FLAGS_ALLOC1 | XA_FLAGS_ACCOUNT);
> >
> >Hi @[email protected], @[email protected] do you have a guideline
> >on this?
> >Could I take zero id reserved?
>
> Sorry, typo error, I meant to @Jason Gunthorpe
It is not documented in uAPI but there is some implication that
ID=0 is restricted from being an actual object ID:
297 /**
298 * enum iommufd_option - ioctl(IOMMU_OPTION_RLIMIT_MODE) and
299 * ioctl(IOMMU_OPTION_HUGE_PAGES)
300 * @IOMMU_OPTION_RLIMIT_MODE:
301 * Change how RLIMIT_MEMLOCK accounting works. The caller must have
privilege
302 * to invoke this. Value 0 (default) is user based accounting, 1 uses
process
303 * based accounting. Global option, object_id must be 0
So, I think that it'd be easier for user space to follow, if we
add a line of statement:
-----------------------------------------------------------------
diff --git a/Documentation/userspace-api/iommufd.rst
b/Documentation/userspace-api/iommufd.rst
index f1c4d21e5c5e..c250a9eafdd5 100644
--- a/Documentation/userspace-api/iommufd.rst
+++ b/Documentation/userspace-api/iommufd.rst
@@ -135,6 +135,8 @@ Following IOMMUFD objects are exposed to userspace:
HW QUEUE, the VMM must request a pair of mmap info (offset/length) and pass
in
exactly to an mmap syscall via its offset and length arguments.
+Each object must be allocated via uAPI and returned with a non-zero ID.
+
All user-visible objects are destroyed via the IOMMU_DESTROY uAPI.
The diagrams below show relationships between user-visible objects and kernel
diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index ce775fbbae94..4410f0561034 100644
--- a/drivers/iommu/iommufd/main.c
+++ b/drivers/iommu/iommufd/main.c
@@ -311,6 +311,7 @@ static int iommufd_fops_open(struct inode *inode, struct
file *filp)
}
init_rwsem(&ictx->ioas_creation_lock);
+ /* ID=0 is reserved for global use in uAPI */
xa_init_flags(&ictx->objects, XA_FLAGS_ALLOC1 | XA_FLAGS_ACCOUNT);
xa_init(&ictx->groups);
ictx->file = filp;
-----------------------------------------------------------------
Jason?
Thanks
Nicolin