Skip to content

Commit 649ad98

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu/iova: Squash flush_cb abstraction
Once again, with iommu-dma now being the only flush queue user, we no longer need the extra level of indirection through flush_cb. Squash that and let the flush queue code call the domain method directly. This does mean temporarily having to carry an additional copy of the IOMMU domain pointer around instead, but only until a later patch untangles it again. Reviewed-by: John Garry <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/e3f9b4acdd6640012ef4fbc819ac868d727b64a9.1639753638.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent d5c383f commit 649ad98

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,6 @@ static int iova_reserve_iommu_regions(struct device *dev,
282282
return ret;
283283
}
284284

285-
static void iommu_dma_flush_iotlb_all(struct iova_domain *iovad)
286-
{
287-
struct iommu_dma_cookie *cookie;
288-
struct iommu_domain *domain;
289-
290-
cookie = container_of(iovad, struct iommu_dma_cookie, iovad);
291-
domain = cookie->fq_domain;
292-
293-
domain->ops->flush_iotlb_all(domain);
294-
}
295-
296285
static bool dev_is_untrusted(struct device *dev)
297286
{
298287
return dev_is_pci(dev) && to_pci_dev(dev)->untrusted;
@@ -312,7 +301,7 @@ int iommu_dma_init_fq(struct iommu_domain *domain)
312301
if (cookie->fq_domain)
313302
return 0;
314303

315-
ret = init_iova_flush_queue(&cookie->iovad, iommu_dma_flush_iotlb_all);
304+
ret = init_iova_flush_queue(&cookie->iovad, domain);
316305
if (ret) {
317306
pr_warn("iova flush queue initialization failed\n");
318307
return ret;

drivers/iommu/iova.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ init_iova_domain(struct iova_domain *iovad, unsigned long granule,
6363
iovad->start_pfn = start_pfn;
6464
iovad->dma_32bit_pfn = 1UL << (32 - iova_shift(iovad));
6565
iovad->max32_alloc_size = iovad->dma_32bit_pfn;
66-
iovad->flush_cb = NULL;
66+
iovad->fq_domain = NULL;
6767
iovad->fq = NULL;
6868
iovad->anchor.pfn_lo = iovad->anchor.pfn_hi = IOVA_ANCHOR;
6969
rb_link_node(&iovad->anchor.node, NULL, &iovad->rbroot.rb_node);
@@ -90,10 +90,10 @@ static void free_iova_flush_queue(struct iova_domain *iovad)
9090
free_percpu(iovad->fq);
9191

9292
iovad->fq = NULL;
93-
iovad->flush_cb = NULL;
93+
iovad->fq_domain = NULL;
9494
}
9595

96-
int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb)
96+
int init_iova_flush_queue(struct iova_domain *iovad, struct iommu_domain *fq_domain)
9797
{
9898
struct iova_fq __percpu *queue;
9999
int cpu;
@@ -105,8 +105,6 @@ int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb)
105105
if (!queue)
106106
return -ENOMEM;
107107

108-
iovad->flush_cb = flush_cb;
109-
110108
for_each_possible_cpu(cpu) {
111109
struct iova_fq *fq;
112110

@@ -117,6 +115,7 @@ int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb)
117115
spin_lock_init(&fq->lock);
118116
}
119117

118+
iovad->fq_domain = fq_domain;
120119
iovad->fq = queue;
121120

122121
timer_setup(&iovad->fq_timer, fq_flush_timeout, 0);
@@ -598,7 +597,7 @@ static void fq_ring_free(struct iova_domain *iovad, struct iova_fq *fq)
598597
static void iova_domain_flush(struct iova_domain *iovad)
599598
{
600599
atomic64_inc(&iovad->fq_flush_start_cnt);
601-
iovad->flush_cb(iovad);
600+
iovad->fq_domain->ops->flush_iotlb_all(iovad->fq_domain);
602601
atomic64_inc(&iovad->fq_flush_finish_cnt);
603602
}
604603

include/linux/iova.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/rbtree.h>
1515
#include <linux/atomic.h>
1616
#include <linux/dma-mapping.h>
17+
#include <linux/iommu.h>
1718

1819
/* iova structure */
1920
struct iova {
@@ -35,11 +36,6 @@ struct iova_rcache {
3536
struct iova_cpu_rcache __percpu *cpu_rcaches;
3637
};
3738

38-
struct iova_domain;
39-
40-
/* Call-Back from IOVA code into IOMMU drivers */
41-
typedef void (* iova_flush_cb)(struct iova_domain *domain);
42-
4339
/* Number of entries per Flush Queue */
4440
#define IOVA_FQ_SIZE 256
4541

@@ -82,8 +78,7 @@ struct iova_domain {
8278
struct iova anchor; /* rbtree lookup anchor */
8379
struct iova_rcache rcaches[IOVA_RANGE_CACHE_MAX_SIZE]; /* IOVA range caches */
8480

85-
iova_flush_cb flush_cb; /* Call-Back function to flush IOMMU
86-
TLBs */
81+
struct iommu_domain *fq_domain;
8782

8883
struct timer_list fq_timer; /* Timer to regularily empty the
8984
flush-queues */
@@ -147,7 +142,7 @@ struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo,
147142
unsigned long pfn_hi);
148143
void init_iova_domain(struct iova_domain *iovad, unsigned long granule,
149144
unsigned long start_pfn);
150-
int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb);
145+
int init_iova_flush_queue(struct iova_domain *iovad, struct iommu_domain *fq_domain);
151146
struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn);
152147
void put_iova_domain(struct iova_domain *iovad);
153148
#else

0 commit comments

Comments
 (0)