Skip to content

Commit 5087f66

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/pages: Remove iommu_alloc_page_node()
Use iommu_alloc_pages_node_sz() instead. AMD and Intel are both using 4K pages for these structures since those drivers only work on 4K PAGE_SIZE. riscv is also spec'd to use SZ_4K. Reviewed-by: Lu Baolu <[email protected]> Tested-by: Alejandro Jimenez <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 2802456 commit 5087f66

File tree

7 files changed

+22
-28
lines changed

7 files changed

+22
-28
lines changed

drivers/iommu/amd/io_pgtable.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static bool increase_address_space(struct amd_io_pgtable *pgtable,
114114
bool ret = true;
115115
u64 *pte;
116116

117-
pte = iommu_alloc_page_node(cfg->amd.nid, gfp);
117+
pte = iommu_alloc_pages_node_sz(cfg->amd.nid, gfp, SZ_4K);
118118
if (!pte)
119119
return false;
120120

@@ -206,7 +206,8 @@ static u64 *alloc_pte(struct amd_io_pgtable *pgtable,
206206

207207
if (!IOMMU_PTE_PRESENT(__pte) ||
208208
pte_level == PAGE_MODE_NONE) {
209-
page = iommu_alloc_page_node(cfg->amd.nid, gfp);
209+
page = iommu_alloc_pages_node_sz(cfg->amd.nid, gfp,
210+
SZ_4K);
210211

211212
if (!page)
212213
return NULL;
@@ -535,7 +536,8 @@ static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo
535536
{
536537
struct amd_io_pgtable *pgtable = io_pgtable_cfg_to_data(cfg);
537538

538-
pgtable->root = iommu_alloc_page_node(cfg->amd.nid, GFP_KERNEL);
539+
pgtable->root =
540+
iommu_alloc_pages_node_sz(cfg->amd.nid, GFP_KERNEL, SZ_4K);
539541
if (!pgtable->root)
540542
return NULL;
541543
pgtable->mode = PAGE_MODE_3_LEVEL;

drivers/iommu/amd/io_pgtable_v2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned long iova,
152152
}
153153

154154
if (!IOMMU_PTE_PRESENT(__pte)) {
155-
page = iommu_alloc_page_node(nid, gfp);
155+
page = iommu_alloc_pages_node_sz(nid, gfp, SZ_4K);
156156
if (!page)
157157
return NULL;
158158

@@ -346,7 +346,7 @@ static struct io_pgtable *v2_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo
346346
struct amd_io_pgtable *pgtable = io_pgtable_cfg_to_data(cfg);
347347
int ias = IOMMU_IN_ADDR_BIT_SIZE;
348348

349-
pgtable->pgd = iommu_alloc_page_node(cfg->amd.nid, GFP_KERNEL);
349+
pgtable->pgd = iommu_alloc_pages_node_sz(cfg->amd.nid, GFP_KERNEL, SZ_4K);
350350
if (!pgtable->pgd)
351351
return NULL;
352352

drivers/iommu/amd/iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ static int setup_gcr3_table(struct gcr3_tbl_info *gcr3_info,
18841884
return -ENOSPC;
18851885
gcr3_info->domid = domid;
18861886

1887-
gcr3_info->gcr3_tbl = iommu_alloc_page_node(nid, GFP_ATOMIC);
1887+
gcr3_info->gcr3_tbl = iommu_alloc_pages_node_sz(nid, GFP_ATOMIC, SZ_4K);
18881888
if (gcr3_info->gcr3_tbl == NULL) {
18891889
pdom_id_free(domid);
18901890
return -ENOMEM;

drivers/iommu/intel/iommu.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus,
397397
if (!alloc)
398398
return NULL;
399399

400-
context = iommu_alloc_page_node(iommu->node, GFP_ATOMIC);
400+
context = iommu_alloc_pages_node_sz(iommu->node, GFP_ATOMIC,
401+
SZ_4K);
401402
if (!context)
402403
return NULL;
403404

@@ -731,7 +732,8 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,
731732
if (!dma_pte_present(pte)) {
732733
uint64_t pteval, tmp;
733734

734-
tmp_page = iommu_alloc_page_node(domain->nid, gfp);
735+
tmp_page = iommu_alloc_pages_node_sz(domain->nid, gfp,
736+
SZ_4K);
735737

736738
if (!tmp_page)
737739
return NULL;
@@ -982,7 +984,7 @@ static int iommu_alloc_root_entry(struct intel_iommu *iommu)
982984
{
983985
struct root_entry *root;
984986

985-
root = iommu_alloc_page_node(iommu->node, GFP_ATOMIC);
987+
root = iommu_alloc_pages_node_sz(iommu->node, GFP_ATOMIC, SZ_4K);
986988
if (!root) {
987989
pr_err("Allocating root entry for %s failed\n",
988990
iommu->name);
@@ -2026,7 +2028,8 @@ static int copy_context_table(struct intel_iommu *iommu,
20262028
if (!old_ce)
20272029
goto out;
20282030

2029-
new_ce = iommu_alloc_page_node(iommu->node, GFP_KERNEL);
2031+
new_ce = iommu_alloc_pages_node_sz(iommu->node,
2032+
GFP_KERNEL, SZ_4K);
20302033
if (!new_ce)
20312034
goto out_unmap;
20322035

@@ -3359,7 +3362,7 @@ static struct dmar_domain *paging_domain_alloc(struct device *dev, bool first_st
33593362
domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw);
33603363

33613364
/* always allocate the top pgd */
3362-
domain->pgd = iommu_alloc_page_node(domain->nid, GFP_KERNEL);
3365+
domain->pgd = iommu_alloc_pages_node_sz(domain->nid, GFP_KERNEL, SZ_4K);
33633366
if (!domain->pgd) {
33643367
kfree(domain);
33653368
return ERR_PTR(-ENOMEM);

drivers/iommu/intel/pasid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
147147
if (!entries) {
148148
u64 tmp;
149149

150-
entries = iommu_alloc_page_node(info->iommu->node, GFP_ATOMIC);
150+
entries = iommu_alloc_pages_node_sz(info->iommu->node,
151+
GFP_ATOMIC, SZ_4K);
151152
if (!entries)
152153
return NULL;
153154

drivers/iommu/iommu-pages.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,4 @@ static inline void *iommu_alloc_pages_sz(gfp_t gfp, size_t size)
114114
return iommu_alloc_pages_node_sz(NUMA_NO_NODE, gfp, size);
115115
}
116116

117-
/**
118-
* iommu_alloc_page_node - allocate a zeroed page at specific NUMA node.
119-
* @nid: memory NUMA node id
120-
* @gfp: buddy allocator flags
121-
*
122-
* returns the virtual address of the allocated page
123-
* Prefer to use iommu_alloc_pages_node_lg2()
124-
*/
125-
static inline void *iommu_alloc_page_node(int nid, gfp_t gfp)
126-
{
127-
return iommu_alloc_pages_node_sz(nid, gfp, PAGE_SIZE);
128-
}
129-
130117
#endif /* __IOMMU_PAGES_H */

drivers/iommu/riscv/iommu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,8 @@ static unsigned long *riscv_iommu_pte_alloc(struct riscv_iommu_domain *domain,
11441144
* page table. This might race with other mappings, retry.
11451145
*/
11461146
if (_io_pte_none(pte)) {
1147-
addr = iommu_alloc_page_node(domain->numa_node, gfp);
1147+
addr = iommu_alloc_pages_node_sz(domain->numa_node, gfp,
1148+
SZ_4K);
11481149
if (!addr)
11491150
return NULL;
11501151
old = pte;
@@ -1385,8 +1386,8 @@ static struct iommu_domain *riscv_iommu_alloc_paging_domain(struct device *dev)
13851386
domain->numa_node = dev_to_node(iommu->dev);
13861387
domain->amo_enabled = !!(iommu->caps & RISCV_IOMMU_CAPABILITIES_AMO_HWAD);
13871388
domain->pgd_mode = pgd_mode;
1388-
domain->pgd_root = iommu_alloc_page_node(domain->numa_node,
1389-
GFP_KERNEL_ACCOUNT);
1389+
domain->pgd_root = iommu_alloc_pages_node_sz(domain->numa_node,
1390+
GFP_KERNEL_ACCOUNT, SZ_4K);
13901391
if (!domain->pgd_root) {
13911392
kfree(domain);
13921393
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)