Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <baolu.lu@linux.intel.com>
Tested-by: Alex Williamson <alex.williamson@redhat.com>
Link: https://lore.kernel.org/r/20220927053109.4053662-2-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>

authored by

Lu Baolu and committed by
Joerg Roedel
0251d010 9abf2313

+27 -18
+2 -1
drivers/acpi/arm64/iort.c
··· 1142 1142 struct iommu_resv_region *region; 1143 1143 1144 1144 region = iommu_alloc_resv_region(base + SZ_64K, SZ_64K, 1145 - prot, IOMMU_RESV_MSI); 1145 + prot, IOMMU_RESV_MSI, 1146 + GFP_KERNEL); 1146 1147 if (region) 1147 1148 list_add_tail(&region->list, head); 1148 1149 }
+4 -3
drivers/iommu/amd/iommu.c
··· 2330 2330 type = IOMMU_RESV_RESERVED; 2331 2331 2332 2332 region = iommu_alloc_resv_region(entry->address_start, 2333 - length, prot, type); 2333 + length, prot, type, 2334 + GFP_KERNEL); 2334 2335 if (!region) { 2335 2336 dev_err(dev, "Out of memory allocating dm-regions\n"); 2336 2337 return; ··· 2341 2340 2342 2341 region = iommu_alloc_resv_region(MSI_RANGE_START, 2343 2342 MSI_RANGE_END - MSI_RANGE_START + 1, 2344 - 0, IOMMU_RESV_MSI); 2343 + 0, IOMMU_RESV_MSI, GFP_KERNEL); 2345 2344 if (!region) 2346 2345 return; 2347 2346 list_add_tail(&region->list, head); 2348 2347 2349 2348 region = iommu_alloc_resv_region(HT_RANGE_START, 2350 2349 HT_RANGE_END - HT_RANGE_START + 1, 2351 - 0, IOMMU_RESV_RESERVED); 2350 + 0, IOMMU_RESV_RESERVED, GFP_KERNEL); 2352 2351 if (!region) 2353 2352 return; 2354 2353 list_add_tail(&region->list, head);
+1 -1
drivers/iommu/apple-dart.c
··· 758 758 759 759 region = iommu_alloc_resv_region(DOORBELL_ADDR, 760 760 PAGE_SIZE, prot, 761 - IOMMU_RESV_MSI); 761 + IOMMU_RESV_MSI, GFP_KERNEL); 762 762 if (!region) 763 763 return; 764 764
+1 -1
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
··· 2757 2757 int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; 2758 2758 2759 2759 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); 2761 2761 if (!region) 2762 2762 return; 2763 2763
+1 -1
drivers/iommu/arm/arm-smmu/arm-smmu.c
··· 1534 1534 int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO; 1535 1535 1536 1536 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); 1538 1538 if (!region) 1539 1539 return; 1540 1540
+5 -3
drivers/iommu/intel/iommu.c
··· 4552 4552 IOMMU_RESV_DIRECT_RELAXABLE : IOMMU_RESV_DIRECT; 4553 4553 4554 4554 resv = iommu_alloc_resv_region(rmrr->base_address, 4555 - length, prot, type); 4555 + length, prot, type, 4556 + GFP_KERNEL); 4556 4557 if (!resv) 4557 4558 break; 4558 4559 ··· 4568 4567 4569 4568 if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA) { 4570 4569 reg = iommu_alloc_resv_region(0, 1UL << 24, prot, 4571 - IOMMU_RESV_DIRECT_RELAXABLE); 4570 + IOMMU_RESV_DIRECT_RELAXABLE, 4571 + GFP_KERNEL); 4572 4572 if (reg) 4573 4573 list_add_tail(&reg->list, head); 4574 4574 } ··· 4578 4576 4579 4577 reg = iommu_alloc_resv_region(IOAPIC_RANGE_START, 4580 4578 IOAPIC_RANGE_END - IOAPIC_RANGE_START + 1, 4581 - 0, IOMMU_RESV_MSI); 4579 + 0, IOMMU_RESV_MSI, GFP_KERNEL); 4582 4580 if (!reg) 4583 4581 return; 4584 4582 list_add_tail(&reg->list, head);
+4 -3
drivers/iommu/iommu.c
··· 504 504 LIST_HEAD(stack); 505 505 506 506 nr = iommu_alloc_resv_region(new->start, new->length, 507 - new->prot, new->type); 507 + new->prot, new->type, GFP_KERNEL); 508 508 if (!nr) 509 509 return -ENOMEM; 510 510 ··· 2579 2579 2580 2580 struct iommu_resv_region *iommu_alloc_resv_region(phys_addr_t start, 2581 2581 size_t length, int prot, 2582 - enum iommu_resv_type type) 2582 + enum iommu_resv_type type, 2583 + gfp_t gfp) 2583 2584 { 2584 2585 struct iommu_resv_region *region; 2585 2586 2586 - region = kzalloc(sizeof(*region), GFP_KERNEL); 2587 + region = kzalloc(sizeof(*region), gfp); 2587 2588 if (!region) 2588 2589 return NULL; 2589 2590
+2 -1
drivers/iommu/mtk_iommu.c
··· 917 917 continue; 918 918 919 919 region = iommu_alloc_resv_region(resv->iova_base, resv->size, 920 - prot, IOMMU_RESV_RESERVED); 920 + prot, IOMMU_RESV_RESERVED, 921 + GFP_KERNEL); 921 922 if (!region) 922 923 return; 923 924
+6 -3
drivers/iommu/virtio-iommu.c
··· 490 490 fallthrough; 491 491 case VIRTIO_IOMMU_RESV_MEM_T_RESERVED: 492 492 region = iommu_alloc_resv_region(start, size, 0, 493 - IOMMU_RESV_RESERVED); 493 + IOMMU_RESV_RESERVED, 494 + GFP_KERNEL); 494 495 break; 495 496 case VIRTIO_IOMMU_RESV_MEM_T_MSI: 496 497 region = iommu_alloc_resv_region(start, size, prot, 497 - IOMMU_RESV_MSI); 498 + IOMMU_RESV_MSI, 499 + GFP_KERNEL); 498 500 break; 499 501 } 500 502 if (!region) ··· 911 909 */ 912 910 if (!msi) { 913 911 msi = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH, 914 - prot, IOMMU_RESV_SW_MSI); 912 + prot, IOMMU_RESV_SW_MSI, 913 + GFP_KERNEL); 915 914 if (!msi) 916 915 return; 917 916
+1 -1
include/linux/iommu.h
··· 455 455 extern bool iommu_default_passthrough(void); 456 456 extern struct iommu_resv_region * 457 457 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); 459 459 extern int iommu_get_group_resv_regions(struct iommu_group *group, 460 460 struct list_head *head); 461 461