Skip to content

Commit d525a5b

Browse files
committed
iommufd: Move isolated msi enforcement to iommufd_device_bind()
With the recent rework this no longer needs to be done at domain attachment time, we know if the device is usable by iommufd when we bind it. The value of msi_device_has_isolated_msi() is not allowed to change while a driver is bound. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 41ac3c2 commit d525a5b

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx,
6060
if (!group)
6161
return ERR_PTR(-ENODEV);
6262

63+
/*
64+
* For historical compat with VFIO the insecure interrupt path is
65+
* allowed if the module parameter is set. Secure/Isolated means that a
66+
* MemWr operation from the device (eg a simple DMA) cannot trigger an
67+
* interrupt outside this iommufd context.
68+
*/
69+
if (!iommufd_selftest_is_mock_dev(dev) &&
70+
!iommu_group_has_isolated_msi(group)) {
71+
if (!allow_unsafe_interrupts) {
72+
rc = -EPERM;
73+
goto out_group_put;
74+
}
75+
76+
dev_warn(
77+
dev,
78+
"MSI interrupts are not secure, they cannot be isolated by the platform. "
79+
"Check that platform features like interrupt remapping are enabled. "
80+
"Use the \"allow_unsafe_interrupts\" module parameter to override\n");
81+
}
82+
6383
rc = iommu_device_claim_dma_owner(dev, ictx);
6484
if (rc)
6585
goto out_group_put;
@@ -188,24 +208,6 @@ static int iommufd_device_setup_msi(struct iommufd_device *idev,
188208
*/
189209
hwpt->msi_cookie = true;
190210
}
191-
192-
/*
193-
* For historical compat with VFIO the insecure interrupt path is
194-
* allowed if the module parameter is set. Insecure means that a MemWr
195-
* operation from the device (eg a simple DMA) cannot trigger an
196-
* interrupt outside this iommufd context.
197-
*/
198-
if (!iommufd_selftest_is_mock_dev(idev->dev) &&
199-
!iommu_group_has_isolated_msi(idev->group)) {
200-
if (!allow_unsafe_interrupts)
201-
return -EPERM;
202-
203-
dev_warn(
204-
idev->dev,
205-
"MSI interrupts are not secure, they cannot be isolated by the platform. "
206-
"Check that platform features like interrupt remapping are enabled. "
207-
"Use the \"allow_unsafe_interrupts\" module parameter to override\n");
208-
}
209211
return 0;
210212
}
211213

0 commit comments

Comments
 (0)