Re: [PATCH RFC v3 02/12] iommu: Add a flag to indicate immutable singleton group

From: Lu Baolu
Date: Tue Apr 12 2022 - 09:21:35 EST


On 2022/4/12 15:39, Tian, Kevin wrote:
From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Sent: Sunday, April 10, 2022 6:25 PM
@@ -898,6 +941,20 @@ int iommu_group_add_device(struct iommu_group
*group, struct device *dev)
list_add_tail(&device->list, &group->devices);
if (group->domain && !iommu_is_attach_deferred(dev))
ret = __iommu_attach_device(group->domain, dev);
+
+ /*
+ * Use standard PCI bus topology, isolation features, and DMA
+ * alias quirks to set the immutable singleton attribute. If
+ * the device came from DT, assume it is static and then
+ * singleton can know from the device count in the group.
+ */
+ if (dev_is_pci(dev))
+ group->immutable_singleton =
+ pci_immutably_isolated(to_pci_dev(dev));
+ else if (is_of_node(dev_fwnode(dev)))
+ group->immutable_singleton =
+ (iommu_group_device_count(group) == 1);
+

btw probably we also want to check when a 2nd device is added
to a group marked as singleton, just in case some weird thing happens?

It depends on how we judge whether the group to which a DT device
belongs is a singleton. As I explained in another thread, current trick
doesn't support doing this.

Best regards,
baolu