Skip to content

Commit d5c383f

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu/iova: Squash entry_dtor abstraction
All flush queues are driven by iommu-dma now, so there is no need to abstract entry_dtor or its data any more. Squash the now-canonical implementation directly into the IOVA code to get it out of the way. 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/2260f8de00ab5e0f9d2a1cf8978e6ae7cd4f182c.1639753638.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent d706162 commit d5c383f

File tree

3 files changed

+20
-51
lines changed

3 files changed

+20
-51
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@ static int __init iommu_dma_forcedac_setup(char *str)
6464
}
6565
early_param("iommu.forcedac", iommu_dma_forcedac_setup);
6666

67-
static void iommu_dma_entry_dtor(unsigned long data)
68-
{
69-
struct page *freelist = (struct page *)data;
70-
71-
while (freelist) {
72-
unsigned long p = (unsigned long)page_address(freelist);
73-
74-
freelist = freelist->freelist;
75-
free_page(p);
76-
}
77-
}
78-
7967
static inline size_t cookie_msi_granule(struct iommu_dma_cookie *cookie)
8068
{
8169
if (cookie->type == IOMMU_DMA_IOVA_COOKIE)
@@ -324,8 +312,7 @@ int iommu_dma_init_fq(struct iommu_domain *domain)
324312
if (cookie->fq_domain)
325313
return 0;
326314

327-
ret = init_iova_flush_queue(&cookie->iovad, iommu_dma_flush_iotlb_all,
328-
iommu_dma_entry_dtor);
315+
ret = init_iova_flush_queue(&cookie->iovad, iommu_dma_flush_iotlb_all);
329316
if (ret) {
330317
pr_warn("iova flush queue initialization failed\n");
331318
return ret;
@@ -471,7 +458,7 @@ static void iommu_dma_free_iova(struct iommu_dma_cookie *cookie,
471458
else if (gather && gather->queued)
472459
queue_iova(iovad, iova_pfn(iovad, iova),
473460
size >> iova_shift(iovad),
474-
(unsigned long)gather->freelist);
461+
gather->freelist);
475462
else
476463
free_iova_fast(iovad, iova_pfn(iovad, iova),
477464
size >> iova_shift(iovad));

drivers/iommu/iova.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ static void free_iova_flush_queue(struct iova_domain *iovad)
9191

9292
iovad->fq = NULL;
9393
iovad->flush_cb = NULL;
94-
iovad->entry_dtor = NULL;
9594
}
9695

97-
int init_iova_flush_queue(struct iova_domain *iovad,
98-
iova_flush_cb flush_cb, iova_entry_dtor entry_dtor)
96+
int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb)
9997
{
10098
struct iova_fq __percpu *queue;
10199
int cpu;
@@ -108,7 +106,6 @@ int init_iova_flush_queue(struct iova_domain *iovad,
108106
return -ENOMEM;
109107

110108
iovad->flush_cb = flush_cb;
111-
iovad->entry_dtor = entry_dtor;
112109

113110
for_each_possible_cpu(cpu) {
114111
struct iova_fq *fq;
@@ -547,6 +544,16 @@ free_iova_fast(struct iova_domain *iovad, unsigned long pfn, unsigned long size)
547544
}
548545
EXPORT_SYMBOL_GPL(free_iova_fast);
549546

547+
static void fq_entry_dtor(struct page *freelist)
548+
{
549+
while (freelist) {
550+
unsigned long p = (unsigned long)page_address(freelist);
551+
552+
freelist = freelist->freelist;
553+
free_page(p);
554+
}
555+
}
556+
550557
#define fq_ring_for_each(i, fq) \
551558
for ((i) = (fq)->head; (i) != (fq)->tail; (i) = ((i) + 1) % IOVA_FQ_SIZE)
552559

@@ -579,9 +586,7 @@ static void fq_ring_free(struct iova_domain *iovad, struct iova_fq *fq)
579586
if (fq->entries[idx].counter >= counter)
580587
break;
581588

582-
if (iovad->entry_dtor)
583-
iovad->entry_dtor(fq->entries[idx].data);
584-
589+
fq_entry_dtor(fq->entries[idx].freelist);
585590
free_iova_fast(iovad,
586591
fq->entries[idx].iova_pfn,
587592
fq->entries[idx].pages);
@@ -606,15 +611,12 @@ static void fq_destroy_all_entries(struct iova_domain *iovad)
606611
* bother to free iovas, just call the entry_dtor on all remaining
607612
* entries.
608613
*/
609-
if (!iovad->entry_dtor)
610-
return;
611-
612614
for_each_possible_cpu(cpu) {
613615
struct iova_fq *fq = per_cpu_ptr(iovad->fq, cpu);
614616
int idx;
615617

616618
fq_ring_for_each(idx, fq)
617-
iovad->entry_dtor(fq->entries[idx].data);
619+
fq_entry_dtor(fq->entries[idx].freelist);
618620
}
619621
}
620622

@@ -639,7 +641,7 @@ static void fq_flush_timeout(struct timer_list *t)
639641

640642
void queue_iova(struct iova_domain *iovad,
641643
unsigned long pfn, unsigned long pages,
642-
unsigned long data)
644+
struct page *freelist)
643645
{
644646
struct iova_fq *fq;
645647
unsigned long flags;
@@ -673,7 +675,7 @@ void queue_iova(struct iova_domain *iovad,
673675

674676
fq->entries[idx].iova_pfn = pfn;
675677
fq->entries[idx].pages = pages;
676-
fq->entries[idx].data = data;
678+
fq->entries[idx].freelist = freelist;
677679
fq->entries[idx].counter = atomic64_read(&iovad->fq_flush_start_cnt);
678680

679681
spin_unlock_irqrestore(&fq->lock, flags);

include/linux/iova.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ struct iova_domain;
4040
/* Call-Back from IOVA code into IOMMU drivers */
4141
typedef void (* iova_flush_cb)(struct iova_domain *domain);
4242

43-
/* Destructor for per-entry data */
44-
typedef void (* iova_entry_dtor)(unsigned long data);
45-
4643
/* Number of entries per Flush Queue */
4744
#define IOVA_FQ_SIZE 256
4845

@@ -53,7 +50,7 @@ typedef void (* iova_entry_dtor)(unsigned long data);
5350
struct iova_fq_entry {
5451
unsigned long iova_pfn;
5552
unsigned long pages;
56-
unsigned long data;
53+
struct page *freelist;
5754
u64 counter; /* Flush counter when this entrie was added */
5855
};
5956

@@ -88,9 +85,6 @@ struct iova_domain {
8885
iova_flush_cb flush_cb; /* Call-Back function to flush IOMMU
8986
TLBs */
9087

91-
iova_entry_dtor entry_dtor; /* IOMMU driver specific destructor for
92-
iova entry */
93-
9488
struct timer_list fq_timer; /* Timer to regularily empty the
9589
flush-queues */
9690
atomic_t fq_timer_on; /* 1 when timer is active, 0
@@ -146,15 +140,14 @@ void free_iova_fast(struct iova_domain *iovad, unsigned long pfn,
146140
unsigned long size);
147141
void queue_iova(struct iova_domain *iovad,
148142
unsigned long pfn, unsigned long pages,
149-
unsigned long data);
143+
struct page *freelist);
150144
unsigned long alloc_iova_fast(struct iova_domain *iovad, unsigned long size,
151145
unsigned long limit_pfn, bool flush_rcache);
152146
struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo,
153147
unsigned long pfn_hi);
154148
void init_iova_domain(struct iova_domain *iovad, unsigned long granule,
155149
unsigned long start_pfn);
156-
int init_iova_flush_queue(struct iova_domain *iovad,
157-
iova_flush_cb flush_cb, iova_entry_dtor entry_dtor);
150+
int init_iova_flush_queue(struct iova_domain *iovad, iova_flush_cb flush_cb);
158151
struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn);
159152
void put_iova_domain(struct iova_domain *iovad);
160153
#else
@@ -189,12 +182,6 @@ static inline void free_iova_fast(struct iova_domain *iovad,
189182
{
190183
}
191184

192-
static inline void queue_iova(struct iova_domain *iovad,
193-
unsigned long pfn, unsigned long pages,
194-
unsigned long data)
195-
{
196-
}
197-
198185
static inline unsigned long alloc_iova_fast(struct iova_domain *iovad,
199186
unsigned long size,
200187
unsigned long limit_pfn,
@@ -216,13 +203,6 @@ static inline void init_iova_domain(struct iova_domain *iovad,
216203
{
217204
}
218205

219-
static inline int init_iova_flush_queue(struct iova_domain *iovad,
220-
iova_flush_cb flush_cb,
221-
iova_entry_dtor entry_dtor)
222-
{
223-
return -ENODEV;
224-
}
225-
226206
static inline struct iova *find_iova(struct iova_domain *iovad,
227207
unsigned long pfn)
228208
{

0 commit comments

Comments
 (0)