Skip to content

Commit d50aaa4

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Update various drivers to pass in lg2sz instead of order to iommu pages
Convert most of the places calling get_order() as an argument to the iommu-pages allocator into order_base_2() or the _sz flavour instead. These places already have an exact size, there is no particular reason to use order here. Reviewed-by: Lu Baolu <[email protected]> Tested-by: Nicolin Chen <[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 9dda3f0 commit d50aaa4

File tree

5 files changed

+32
-31
lines changed

5 files changed

+32
-31
lines changed

drivers/iommu/amd/init.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table, u16 pci_
626626
/* Allocate per PCI segment device table */
627627
static inline int __init alloc_dev_table(struct amd_iommu_pci_seg *pci_seg)
628628
{
629-
pci_seg->dev_table = iommu_alloc_pages(GFP_KERNEL | GFP_DMA32,
630-
get_order(pci_seg->dev_table_size));
629+
pci_seg->dev_table = iommu_alloc_pages_sz(GFP_KERNEL | GFP_DMA32,
630+
pci_seg->dev_table_size);
631631
if (!pci_seg->dev_table)
632632
return -ENOMEM;
633633

@@ -707,8 +707,7 @@ static void __init free_alias_table(struct amd_iommu_pci_seg *pci_seg)
707707
*/
708708
static int __init alloc_command_buffer(struct amd_iommu *iommu)
709709
{
710-
iommu->cmd_buf = iommu_alloc_pages(GFP_KERNEL,
711-
get_order(CMD_BUFFER_SIZE));
710+
iommu->cmd_buf = iommu_alloc_pages_sz(GFP_KERNEL, CMD_BUFFER_SIZE);
712711

713712
return iommu->cmd_buf ? 0 : -ENOMEM;
714713
}
@@ -811,14 +810,16 @@ static void __init free_command_buffer(struct amd_iommu *iommu)
811810
void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu, gfp_t gfp,
812811
size_t size)
813812
{
814-
int order = get_order(size);
815-
void *buf = iommu_alloc_pages(gfp, order);
813+
void *buf;
816814

817-
if (buf &&
818-
check_feature(FEATURE_SNP) &&
819-
set_memory_4k((unsigned long)buf, (1 << order))) {
815+
size = PAGE_ALIGN(size);
816+
buf = iommu_alloc_pages_sz(gfp, size);
817+
if (!buf)
818+
return NULL;
819+
if (check_feature(FEATURE_SNP) &&
820+
set_memory_4k((unsigned long)buf, size / PAGE_SIZE)) {
820821
iommu_free_pages(buf);
821-
buf = NULL;
822+
return NULL;
822823
}
823824

824825
return buf;
@@ -913,11 +914,11 @@ static int iommu_init_ga_log(struct amd_iommu *iommu)
913914
if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
914915
return 0;
915916

916-
iommu->ga_log = iommu_alloc_pages(GFP_KERNEL, get_order(GA_LOG_SIZE));
917+
iommu->ga_log = iommu_alloc_pages_sz(GFP_KERNEL, GA_LOG_SIZE);
917918
if (!iommu->ga_log)
918919
goto err_out;
919920

920-
iommu->ga_log_tail = iommu_alloc_pages(GFP_KERNEL, get_order(8));
921+
iommu->ga_log_tail = iommu_alloc_pages_sz(GFP_KERNEL, 8);
921922
if (!iommu->ga_log_tail)
922923
goto err_out;
923924

@@ -1012,8 +1013,8 @@ static bool __copy_device_table(struct amd_iommu *iommu)
10121013
if (!old_devtb)
10131014
return false;
10141015

1015-
pci_seg->old_dev_tbl_cpy = iommu_alloc_pages(GFP_KERNEL | GFP_DMA32,
1016-
get_order(pci_seg->dev_table_size));
1016+
pci_seg->old_dev_tbl_cpy = iommu_alloc_pages_sz(
1017+
GFP_KERNEL | GFP_DMA32, pci_seg->dev_table_size);
10171018
if (pci_seg->old_dev_tbl_cpy == NULL) {
10181019
pr_err("Failed to allocate memory for copying old device table!\n");
10191020
memunmap(old_devtb);

drivers/iommu/intel/dmar.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,6 @@ int dmar_enable_qi(struct intel_iommu *iommu)
16811681
{
16821682
struct q_inval *qi;
16831683
void *desc;
1684-
int order;
16851684

16861685
if (!ecap_qis(iommu->ecap))
16871686
return -ENOENT;
@@ -1702,8 +1701,9 @@ int dmar_enable_qi(struct intel_iommu *iommu)
17021701
* Need two pages to accommodate 256 descriptors of 256 bits each
17031702
* if the remapping hardware supports scalable mode translation.
17041703
*/
1705-
order = ecap_smts(iommu->ecap) ? 1 : 0;
1706-
desc = iommu_alloc_pages_node(iommu->node, GFP_ATOMIC, order);
1704+
desc = iommu_alloc_pages_node_sz(iommu->node, GFP_ATOMIC,
1705+
ecap_smts(iommu->ecap) ? SZ_8K :
1706+
SZ_4K);
17071707
if (!desc) {
17081708
kfree(qi);
17091709
iommu->qi = NULL;

drivers/iommu/io-pgtable-arm.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,20 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp,
263263
void *cookie)
264264
{
265265
struct device *dev = cfg->iommu_dev;
266-
int order = get_order(size);
266+
size_t alloc_size;
267267
dma_addr_t dma;
268268
void *pages;
269269

270+
/*
271+
* For very small starting-level translation tables the HW requires a
272+
* minimum alignment of at least 64 to cover all cases.
273+
*/
274+
alloc_size = max(size, 64);
270275
if (cfg->alloc)
271-
pages = cfg->alloc(cookie, size, gfp);
276+
pages = cfg->alloc(cookie, alloc_size, gfp);
272277
else
273-
pages = iommu_alloc_pages_node(dev_to_node(dev), gfp, order);
278+
pages = iommu_alloc_pages_node_sz(dev_to_node(dev), gfp,
279+
alloc_size);
274280

275281
if (!pages)
276282
return NULL;

drivers/iommu/io-pgtable-dart.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,6 @@ static phys_addr_t iopte_to_paddr(dart_iopte pte,
107107
return paddr;
108108
}
109109

110-
static void *__dart_alloc_pages(size_t size, gfp_t gfp)
111-
{
112-
int order = get_order(size);
113-
114-
return iommu_alloc_pages(gfp, order);
115-
}
116-
117110
static int dart_init_pte(struct dart_io_pgtable *data,
118111
unsigned long iova, phys_addr_t paddr,
119112
dart_iopte prot, int num_entries,
@@ -255,7 +248,7 @@ static int dart_map_pages(struct io_pgtable_ops *ops, unsigned long iova,
255248

256249
/* no L2 table present */
257250
if (!pte) {
258-
cptep = __dart_alloc_pages(tblsz, gfp);
251+
cptep = iommu_alloc_pages_sz(gfp, tblsz);
259252
if (!cptep)
260253
return -ENOMEM;
261254

@@ -412,7 +405,8 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
412405
cfg->apple_dart_cfg.n_ttbrs = 1 << data->tbl_bits;
413406

414407
for (i = 0; i < cfg->apple_dart_cfg.n_ttbrs; ++i) {
415-
data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL);
408+
data->pgd[i] =
409+
iommu_alloc_pages_sz(GFP_KERNEL, DART_GRANULE(data));
416410
if (!data->pgd[i])
417411
goto out_free_data;
418412
cfg->apple_dart_cfg.ttbr[i] = virt_to_phys(data->pgd[i]);

drivers/iommu/sun50i-iommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ sun50i_iommu_domain_alloc_paging(struct device *dev)
690690
if (!sun50i_domain)
691691
return NULL;
692692

693-
sun50i_domain->dt = iommu_alloc_pages(GFP_KERNEL | GFP_DMA32,
694-
get_order(DT_SIZE));
693+
sun50i_domain->dt =
694+
iommu_alloc_pages_sz(GFP_KERNEL | GFP_DMA32, DT_SIZE);
695695
if (!sun50i_domain->dt)
696696
goto err_free_domain;
697697

0 commit comments

Comments
 (0)