iommu/vt-d: Add qi_batch for dmar_domain
authorLu Baolu <baolu.lu@linux.intel.com>
Mon, 2 Sep 2024 02:27:23 +0000 (10:27 +0800)
committerJoerg Roedel <jroedel@suse.de>
Mon, 2 Sep 2024 16:15:02 +0000 (18:15 +0200)
Introduces a qi_batch structure to hold batched cache invalidation
descriptors on a per-dmar_domain basis. A fixed-size descriptor
array is used for simplicity. The qi_batch is allocated when the
first cache tag is added to the domain and freed during
iommu_free_domain().

Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
Link: https://lore.kernel.org/r/20240815065221.50328-4-tina.zhang@intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/intel/cache.c
drivers/iommu/intel/iommu.c
drivers/iommu/intel/iommu.h
drivers/iommu/intel/nested.c
drivers/iommu/intel/svm.c

index 08f7ce2c16c3b06697b8ba639f3253925e2094b7..2e997d782bebe36461fc9cc033ccc3d3043d7288 100644 (file)
@@ -190,6 +190,13 @@ int cache_tag_assign_domain(struct dmar_domain *domain,
        u16 did = domain_get_id_for_dev(domain, dev);
        int ret;
 
+       /* domain->qi_bach will be freed in iommu_free_domain() path. */
+       if (!domain->qi_batch) {
+               domain->qi_batch = kzalloc(sizeof(*domain->qi_batch), GFP_KERNEL);
+               if (!domain->qi_batch)
+                       return -ENOMEM;
+       }
+
        ret = __cache_tag_assign_domain(domain, did, dev, pasid);
        if (ret || domain->domain.type != IOMMU_DOMAIN_NESTED)
                return ret;
index dfd33adffb140ea478017b3df327f9bd4df36010..038a81efaaf71d137922f6457296ffc5fc1a2538 100644 (file)
@@ -1572,6 +1572,7 @@ static void domain_exit(struct dmar_domain *domain)
        if (WARN_ON(!list_empty(&domain->devices)))
                return;
 
+       kfree(domain->qi_batch);
        kfree(domain);
 }
 
index 74634805abd1940d943ccba678dbe332ece38b31..d21eca94cb8f9474b2549d4a368f958c1f5116df 100644 (file)
@@ -584,6 +584,19 @@ struct iommu_domain_info {
                                         * to VT-d spec, section 9.3 */
 };
 
+/*
+ * We start simply by using a fixed size for the batched descriptors. This
+ * size is currently sufficient for our needs. Future improvements could
+ * involve dynamically allocating the batch buffer based on actual demand,
+ * allowing us to adjust the batch size for optimal performance in different
+ * scenarios.
+ */
+#define QI_MAX_BATCHED_DESC_COUNT 16
+struct qi_batch {
+       struct qi_desc descs[QI_MAX_BATCHED_DESC_COUNT];
+       unsigned int index;
+};
+
 struct dmar_domain {
        int     nid;                    /* node id */
        struct xarray iommu_array;      /* Attached IOMMU array */
@@ -608,6 +621,7 @@ struct dmar_domain {
 
        spinlock_t cache_lock;          /* Protect the cache tag list */
        struct list_head cache_tags;    /* Cache tag list */
+       struct qi_batch *qi_batch;      /* Batched QI descriptors */
 
        int             iommu_superpage;/* Level of superpages supported:
                                           0 == 4KiB (no superpages), 1 == 2MiB,
index 36a91b1b52be3a412531787f14525bab2d1c0e04..433c58944401f9f4c15ba816d5e2b177a120bb18 100644 (file)
@@ -83,6 +83,7 @@ static void intel_nested_domain_free(struct iommu_domain *domain)
        spin_lock(&s2_domain->s1_lock);
        list_del(&dmar_domain->s2_link);
        spin_unlock(&s2_domain->s1_lock);
+       kfree(dmar_domain->qi_batch);
        kfree(dmar_domain);
 }
 
index ef12e95e400a3b2b1d6851e9acb8f029954d8f94..078d1e32a24eeb1f60f28859a1678ddddc82f297 100644 (file)
@@ -184,7 +184,10 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm)
 
 static void intel_mm_free_notifier(struct mmu_notifier *mn)
 {
-       kfree(container_of(mn, struct dmar_domain, notifier));
+       struct dmar_domain *domain = container_of(mn, struct dmar_domain, notifier);
+
+       kfree(domain->qi_batch);
+       kfree(domain);
 }
 
 static const struct mmu_notifier_ops intel_mmuops = {