On 2022/6/10 17:01, Tian, Kevin wrote:
From: Baolu Lu <baolu...@linux.intel.com>
Sent: Friday, June 10, 2022 2:47 PM

On 2022/6/10 03:01, Raj, Ashok wrote:
On Tue, Jun 07, 2022 at 09:49:33AM +0800, Lu Baolu wrote:
@@ -218,6 +219,30 @@ static void dev_iommu_free(struct device *dev)
        kfree(param);
   }

+static u32 dev_iommu_get_max_pasids(struct device *dev)
+{
+       u32 max_pasids = dev->iommu->iommu_dev->max_pasids;
+       u32 num_bits;
+       int ret;
+
+       if (!max_pasids)
+               return 0;
+
+       if (dev_is_pci(dev)) {
+               ret = pci_max_pasids(to_pci_dev(dev));
+               if (ret < 0)
+                       return 0;
+
+               return min_t(u32, max_pasids, ret);

Ah.. that answers my other question to consider device pasid-max. I guess
if we need any enforcement of restricting devices that aren't supporting
the full PASID, that will be done by some higher layer?

The mm->pasid style of SVA is explicitly enabled through
iommu_dev_enable_feature(IOMMU_DEV_FEAT_SVA). The IOMMU driver
specific
restriction might be put there?


too many returns in this function, maybe setup all returns to the end of
the function might be elegant?

I didn't find cleanup room after a quick scan of the code. But sure, let
me go through code again offline.


If we do care:

+static u32 dev_iommu_get_max_pasids(struct device *dev)
+{
+       u32 max_pasids = 0,
+       u32 num_bits = 0;
+       int ret;
+
+       if (dev_is_pci(dev)) {
+               ret = pci_max_pasids(to_pci_dev(dev));
+               if (ret > 0)
+                       max_pasids = ret;
+       } else {
+               ret = device_property_read_u32(dev, "pasid-num-bits", 
&num_bits);
+               if (!ret)
+                       max_pasids = 1UL << num_bits;
+       }
+
+       return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids);
+}

Great! Cleaner and more compact than mine. Thank you!

Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to