Re: [PATCH 08/12] iommufd/selftest: Put iopf enablement in domain attach path

From: Baolu Lu
Date: Sat Feb 22 2025 - 02:29:04 EST


On 2/21/25 23:04, Jason Gunthorpe wrote:
- return mock_dev_enable_iopf(dev, domain);
+ if (mdev->domain)
+ mock_dev_disable_iopf(dev, mdev->domain);
+
+ ret = mock_dev_enable_iopf(dev, domain);
+ if (ret)
Though here the domain is disabled but not removed from mdev->domain,
is it OK?

That's not okay. I can make it like below:

static int mock_domain_nop_attach(struct iommu_domain *domain,
struct device *dev)
{
struct mock_dev *mdev = to_mock_dev(dev);
int ret;

if (domain->dirty_ops && (mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY))
return -EINVAL;

ret = mock_dev_enable_iopf(dev, domain);
if (ret)
return ret;

mock_dev_disable_iopf(dev, mdev->domain);
mdev->domain = domain;

return 0;
}

Both mock_dev_enable/disable_iopf() will be a no-op if domain or
domain's iopf handler is empty:

if (!domain || !domain->iopf_handler)
return;

Does it work for you?

Thanks,
baolu