Skip to content

Commit 777cdd8

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Add qi_batch for dmar_domain
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 <[email protected]> Signed-off-by: Tina Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 3297d04 commit 777cdd8

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

drivers/iommu/intel/cache.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ int cache_tag_assign_domain(struct dmar_domain *domain,
190190
u16 did = domain_get_id_for_dev(domain, dev);
191191
int ret;
192192

193+
/* domain->qi_bach will be freed in iommu_free_domain() path. */
194+
if (!domain->qi_batch) {
195+
domain->qi_batch = kzalloc(sizeof(*domain->qi_batch), GFP_KERNEL);
196+
if (!domain->qi_batch)
197+
return -ENOMEM;
198+
}
199+
193200
ret = __cache_tag_assign_domain(domain, did, dev, pasid);
194201
if (ret || domain->domain.type != IOMMU_DOMAIN_NESTED)
195202
return ret;

drivers/iommu/intel/iommu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ static void domain_exit(struct dmar_domain *domain)
15721572
if (WARN_ON(!list_empty(&domain->devices)))
15731573
return;
15741574

1575+
kfree(domain->qi_batch);
15751576
kfree(domain);
15761577
}
15771578

drivers/iommu/intel/iommu.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,19 @@ struct iommu_domain_info {
584584
* to VT-d spec, section 9.3 */
585585
};
586586

587+
/*
588+
* We start simply by using a fixed size for the batched descriptors. This
589+
* size is currently sufficient for our needs. Future improvements could
590+
* involve dynamically allocating the batch buffer based on actual demand,
591+
* allowing us to adjust the batch size for optimal performance in different
592+
* scenarios.
593+
*/
594+
#define QI_MAX_BATCHED_DESC_COUNT 16
595+
struct qi_batch {
596+
struct qi_desc descs[QI_MAX_BATCHED_DESC_COUNT];
597+
unsigned int index;
598+
};
599+
587600
struct dmar_domain {
588601
int nid; /* node id */
589602
struct xarray iommu_array; /* Attached IOMMU array */
@@ -608,6 +621,7 @@ struct dmar_domain {
608621

609622
spinlock_t cache_lock; /* Protect the cache tag list */
610623
struct list_head cache_tags; /* Cache tag list */
624+
struct qi_batch *qi_batch; /* Batched QI descriptors */
611625

612626
int iommu_superpage;/* Level of superpages supported:
613627
0 == 4KiB (no superpages), 1 == 2MiB,

drivers/iommu/intel/nested.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static void intel_nested_domain_free(struct iommu_domain *domain)
8383
spin_lock(&s2_domain->s1_lock);
8484
list_del(&dmar_domain->s2_link);
8585
spin_unlock(&s2_domain->s1_lock);
86+
kfree(dmar_domain->qi_batch);
8687
kfree(dmar_domain);
8788
}
8889

drivers/iommu/intel/svm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ static void intel_mm_release(struct mmu_notifier *mn, struct mm_struct *mm)
184184

185185
static void intel_mm_free_notifier(struct mmu_notifier *mn)
186186
{
187-
kfree(container_of(mn, struct dmar_domain, notifier));
187+
struct dmar_domain *domain = container_of(mn, struct dmar_domain, notifier);
188+
189+
kfree(domain->qi_batch);
190+
kfree(domain);
188191
}
189192

190193
static const struct mmu_notifier_ops intel_mmuops = {

0 commit comments

Comments
 (0)