Skip to content

Commit 0251d01

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Add gfp parameter to iommu_alloc_resv_region
Add gfp parameter to iommu_alloc_resv_region() for the callers to specify the memory allocation behavior. Thus iommu_alloc_resv_region() could also be available in critical contexts. Signed-off-by: Lu Baolu <[email protected]> Tested-by: Alex Williamson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 9abf231 commit 0251d01

File tree

10 files changed

+27
-18
lines changed

10 files changed

+27
-18
lines changed

drivers/acpi/arm64/iort.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,8 @@ static void iort_iommu_msi_get_resv_regions(struct device *dev,
11421142
struct iommu_resv_region *region;
11431143

11441144
region = iommu_alloc_resv_region(base + SZ_64K, SZ_64K,
1145-
prot, IOMMU_RESV_MSI);
1145+
prot, IOMMU_RESV_MSI,
1146+
GFP_KERNEL);
11461147
if (region)
11471148
list_add_tail(&region->list, head);
11481149
}

drivers/iommu/amd/iommu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,8 @@ static void amd_iommu_get_resv_regions(struct device *dev,
23302330
type = IOMMU_RESV_RESERVED;
23312331

23322332
region = iommu_alloc_resv_region(entry->address_start,
2333-
length, prot, type);
2333+
length, prot, type,
2334+
GFP_KERNEL);
23342335
if (!region) {
23352336
dev_err(dev, "Out of memory allocating dm-regions\n");
23362337
return;
@@ -2340,14 +2341,14 @@ static void amd_iommu_get_resv_regions(struct device *dev,
23402341

23412342
region = iommu_alloc_resv_region(MSI_RANGE_START,
23422343
MSI_RANGE_END - MSI_RANGE_START + 1,
2343-
0, IOMMU_RESV_MSI);
2344+
0, IOMMU_RESV_MSI, GFP_KERNEL);
23442345
if (!region)
23452346
return;
23462347
list_add_tail(&region->list, head);
23472348

23482349
region = iommu_alloc_resv_region(HT_RANGE_START,
23492350
HT_RANGE_END - HT_RANGE_START + 1,
2350-
0, IOMMU_RESV_RESERVED);
2351+
0, IOMMU_RESV_RESERVED, GFP_KERNEL);
23512352
if (!region)
23522353
return;
23532354
list_add_tail(&region->list, head);

drivers/iommu/apple-dart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
758758

759759
region = iommu_alloc_resv_region(DOORBELL_ADDR,
760760
PAGE_SIZE, prot,
761-
IOMMU_RESV_MSI);
761+
IOMMU_RESV_MSI, GFP_KERNEL);
762762
if (!region)
763763
return;
764764

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,7 @@ static void arm_smmu_get_resv_regions(struct device *dev,
27572757
int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
27582758

27592759
region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
2760-
prot, IOMMU_RESV_SW_MSI);
2760+
prot, IOMMU_RESV_SW_MSI, GFP_KERNEL);
27612761
if (!region)
27622762
return;
27632763

drivers/iommu/arm/arm-smmu/arm-smmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ static void arm_smmu_get_resv_regions(struct device *dev,
15341534
int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
15351535

15361536
region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
1537-
prot, IOMMU_RESV_SW_MSI);
1537+
prot, IOMMU_RESV_SW_MSI, GFP_KERNEL);
15381538
if (!region)
15391539
return;
15401540

drivers/iommu/intel/iommu.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,7 +4552,8 @@ static void intel_iommu_get_resv_regions(struct device *device,
45524552
IOMMU_RESV_DIRECT_RELAXABLE : IOMMU_RESV_DIRECT;
45534553

45544554
resv = iommu_alloc_resv_region(rmrr->base_address,
4555-
length, prot, type);
4555+
length, prot, type,
4556+
GFP_KERNEL);
45564557
if (!resv)
45574558
break;
45584559

@@ -4567,7 +4568,8 @@ static void intel_iommu_get_resv_regions(struct device *device,
45674568

45684569
if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA) {
45694570
reg = iommu_alloc_resv_region(0, 1UL << 24, prot,
4570-
IOMMU_RESV_DIRECT_RELAXABLE);
4571+
IOMMU_RESV_DIRECT_RELAXABLE,
4572+
GFP_KERNEL);
45714573
if (reg)
45724574
list_add_tail(&reg->list, head);
45734575
}
@@ -4576,7 +4578,7 @@ static void intel_iommu_get_resv_regions(struct device *device,
45764578

45774579
reg = iommu_alloc_resv_region(IOAPIC_RANGE_START,
45784580
IOAPIC_RANGE_END - IOAPIC_RANGE_START + 1,
4579-
0, IOMMU_RESV_MSI);
4581+
0, IOMMU_RESV_MSI, GFP_KERNEL);
45804582
if (!reg)
45814583
return;
45824584
list_add_tail(&reg->list, head);

drivers/iommu/iommu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new,
504504
LIST_HEAD(stack);
505505

506506
nr = iommu_alloc_resv_region(new->start, new->length,
507-
new->prot, new->type);
507+
new->prot, new->type, GFP_KERNEL);
508508
if (!nr)
509509
return -ENOMEM;
510510

@@ -2579,11 +2579,12 @@ EXPORT_SYMBOL(iommu_put_resv_regions);
25792579

25802580
struct iommu_resv_region *iommu_alloc_resv_region(phys_addr_t start,
25812581
size_t length, int prot,
2582-
enum iommu_resv_type type)
2582+
enum iommu_resv_type type,
2583+
gfp_t gfp)
25832584
{
25842585
struct iommu_resv_region *region;
25852586

2586-
region = kzalloc(sizeof(*region), GFP_KERNEL);
2587+
region = kzalloc(sizeof(*region), gfp);
25872588
if (!region)
25882589
return NULL;
25892590

drivers/iommu/mtk_iommu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,8 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
917917
continue;
918918

919919
region = iommu_alloc_resv_region(resv->iova_base, resv->size,
920-
prot, IOMMU_RESV_RESERVED);
920+
prot, IOMMU_RESV_RESERVED,
921+
GFP_KERNEL);
921922
if (!region)
922923
return;
923924

drivers/iommu/virtio-iommu.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,13 @@ static int viommu_add_resv_mem(struct viommu_endpoint *vdev,
490490
fallthrough;
491491
case VIRTIO_IOMMU_RESV_MEM_T_RESERVED:
492492
region = iommu_alloc_resv_region(start, size, 0,
493-
IOMMU_RESV_RESERVED);
493+
IOMMU_RESV_RESERVED,
494+
GFP_KERNEL);
494495
break;
495496
case VIRTIO_IOMMU_RESV_MEM_T_MSI:
496497
region = iommu_alloc_resv_region(start, size, prot,
497-
IOMMU_RESV_MSI);
498+
IOMMU_RESV_MSI,
499+
GFP_KERNEL);
498500
break;
499501
}
500502
if (!region)
@@ -909,7 +911,8 @@ static void viommu_get_resv_regions(struct device *dev, struct list_head *head)
909911
*/
910912
if (!msi) {
911913
msi = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
912-
prot, IOMMU_RESV_SW_MSI);
914+
prot, IOMMU_RESV_SW_MSI,
915+
GFP_KERNEL);
913916
if (!msi)
914917
return;
915918

include/linux/iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ extern void iommu_set_default_translated(bool cmd_line);
455455
extern bool iommu_default_passthrough(void);
456456
extern struct iommu_resv_region *
457457
iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot,
458-
enum iommu_resv_type type);
458+
enum iommu_resv_type type, gfp_t gfp);
459459
extern int iommu_get_group_resv_regions(struct iommu_group *group,
460460
struct list_head *head);
461461

0 commit comments

Comments
 (0)