Skip to content

Commit 868240c

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Change iommu_iotlb_gather to use iommu_page_list
This converts the remaining places using list of pages to the new API. The Intel free path was shared with its gather path, so it is converted at the same time. Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/11-v4-c8663abbb606+3f7-iommu_pages_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent c70637c commit 868240c

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

drivers/iommu/dma-iommu.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ early_param("iommu.forcedac", iommu_dma_forcedac_setup);
105105
struct iova_fq_entry {
106106
unsigned long iova_pfn;
107107
unsigned long pages;
108-
struct list_head freelist;
108+
struct iommu_pages_list freelist;
109109
u64 counter; /* Flush counter when this entry was added */
110110
};
111111

@@ -192,7 +192,7 @@ static void fq_flush_timeout(struct timer_list *t)
192192

193193
static void queue_iova(struct iommu_dma_cookie *cookie,
194194
unsigned long pfn, unsigned long pages,
195-
struct list_head *freelist)
195+
struct iommu_pages_list *freelist)
196196
{
197197
struct iova_fq *fq;
198198
unsigned long flags;
@@ -231,7 +231,7 @@ static void queue_iova(struct iommu_dma_cookie *cookie,
231231
fq->entries[idx].iova_pfn = pfn;
232232
fq->entries[idx].pages = pages;
233233
fq->entries[idx].counter = atomic64_read(&cookie->fq_flush_start_cnt);
234-
list_splice(freelist, &fq->entries[idx].freelist);
234+
iommu_pages_list_splice(freelist, &fq->entries[idx].freelist);
235235

236236
spin_unlock_irqrestore(&fq->lock, flags);
237237

@@ -289,7 +289,8 @@ static void iommu_dma_init_one_fq(struct iova_fq *fq, size_t fq_size)
289289
spin_lock_init(&fq->lock);
290290

291291
for (i = 0; i < fq_size; i++)
292-
INIT_LIST_HEAD(&fq->entries[i].freelist);
292+
fq->entries[i].freelist =
293+
IOMMU_PAGES_LIST_INIT(fq->entries[i].freelist);
293294
}
294295

295296
static int iommu_dma_init_fq_single(struct iommu_dma_cookie *cookie)

drivers/iommu/intel/iommu.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -894,18 +894,16 @@ static void dma_pte_free_pagetable(struct dmar_domain *domain,
894894
The 'pte' argument is the *parent* PTE, pointing to the page that is to
895895
be freed. */
896896
static void dma_pte_list_pagetables(struct dmar_domain *domain,
897-
int level, struct dma_pte *pte,
898-
struct list_head *freelist)
897+
int level, struct dma_pte *parent_pte,
898+
struct iommu_pages_list *freelist)
899899
{
900-
struct page *pg;
900+
struct dma_pte *pte = phys_to_virt(dma_pte_addr(parent_pte));
901901

902-
pg = pfn_to_page(dma_pte_addr(pte) >> PAGE_SHIFT);
903-
list_add_tail(&pg->lru, freelist);
902+
iommu_pages_list_add(freelist, pte);
904903

905904
if (level == 1)
906905
return;
907906

908-
pte = page_address(pg);
909907
do {
910908
if (dma_pte_present(pte) && !dma_pte_superpage(pte))
911909
dma_pte_list_pagetables(domain, level - 1, pte, freelist);
@@ -916,7 +914,7 @@ static void dma_pte_list_pagetables(struct dmar_domain *domain,
916914
static void dma_pte_clear_level(struct dmar_domain *domain, int level,
917915
struct dma_pte *pte, unsigned long pfn,
918916
unsigned long start_pfn, unsigned long last_pfn,
919-
struct list_head *freelist)
917+
struct iommu_pages_list *freelist)
920918
{
921919
struct dma_pte *first_pte = NULL, *last_pte = NULL;
922920

@@ -961,7 +959,8 @@ static void dma_pte_clear_level(struct dmar_domain *domain, int level,
961959
the page tables, and may have cached the intermediate levels. The
962960
pages can only be freed after the IOTLB flush has been done. */
963961
static void domain_unmap(struct dmar_domain *domain, unsigned long start_pfn,
964-
unsigned long last_pfn, struct list_head *freelist)
962+
unsigned long last_pfn,
963+
struct iommu_pages_list *freelist)
965964
{
966965
if (WARN_ON(!domain_pfn_supported(domain, last_pfn)) ||
967966
WARN_ON(start_pfn > last_pfn))
@@ -973,8 +972,7 @@ static void domain_unmap(struct dmar_domain *domain, unsigned long start_pfn,
973972

974973
/* free pgd */
975974
if (start_pfn == 0 && last_pfn == DOMAIN_MAX_PFN(domain->gaw)) {
976-
struct page *pgd_page = virt_to_page(domain->pgd);
977-
list_add_tail(&pgd_page->lru, freelist);
975+
iommu_pages_list_add(freelist, domain->pgd);
978976
domain->pgd = NULL;
979977
}
980978
}
@@ -1449,7 +1447,8 @@ void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu)
14491447
static void domain_exit(struct dmar_domain *domain)
14501448
{
14511449
if (domain->pgd) {
1452-
LIST_HEAD(freelist);
1450+
struct iommu_pages_list freelist =
1451+
IOMMU_PAGES_LIST_INIT(freelist);
14531452

14541453
domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw), &freelist);
14551454
iommu_put_pages_list(&freelist);
@@ -3603,7 +3602,8 @@ static void intel_iommu_tlb_sync(struct iommu_domain *domain,
36033602
struct iommu_iotlb_gather *gather)
36043603
{
36053604
cache_tag_flush_range(to_dmar_domain(domain), gather->start,
3606-
gather->end, list_empty(&gather->freelist));
3605+
gather->end,
3606+
iommu_pages_list_empty(&gather->freelist));
36073607
iommu_put_pages_list(&gather->freelist);
36083608
}
36093609

include/linux/iommu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ struct iommu_iotlb_gather {
375375
unsigned long start;
376376
unsigned long end;
377377
size_t pgsize;
378-
struct list_head freelist;
378+
struct iommu_pages_list freelist;
379379
bool queued;
380380
};
381381

@@ -864,7 +864,7 @@ static inline void iommu_iotlb_gather_init(struct iommu_iotlb_gather *gather)
864864
{
865865
*gather = (struct iommu_iotlb_gather) {
866866
.start = ULONG_MAX,
867-
.freelist = LIST_HEAD_INIT(gather->freelist),
867+
.freelist = IOMMU_PAGES_LIST_INIT(gather->freelist),
868868
};
869869
}
870870

0 commit comments

Comments
 (0)