Re: [PATCH v5 16/18] iommufd: Add APIs to preserve/unpreserve a vfio cdev

From: Nicolin Chen

Date: Wed Oct 07 2026 - 18:01:46 EST


On Mon, Sep 21, 2026 at 12:48:32AM +0000, Samiullah Khawaja wrote:
> diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
> @@ -686,6 +687,10 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
> int rc;
>
> mutex_lock(&igroup->lock);
> + if (iommufd_device_is_preserved(idev)) {
> + rc = -EBUSY;
> + goto err_unlock;
> + }

You might need the same check in iommufd_device_do_replace?

> +#ifdef CONFIG_IOMMU_LIVEUPDATE
> +static bool _iommufd_device_has_pasid_attachments(struct iommufd_device *idev)
> +{
> + struct iommufd_group *igroup = idev->igroup;
> + unsigned long start = IOMMU_NO_PASID;
> +
> + if (xa_find_after(&igroup->pasid_attach,
> + &start, UINT_MAX, XA_PRESENT))

Nit: it could fit into a single line.

Nicolin