iommu: Add gfp parameter to iommu_alloc_resv_region
authorLu Baolu <baolu.lu@linux.intel.com>
Wed, 19 Oct 2022 00:44:44 +0000 (08:44 +0800)
committerJoerg Roedel <jroedel@suse.de>
Fri, 21 Oct 2022 08:49:32 +0000 (10:49 +0200)
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>
drivers/acpi/arm64/iort.c
drivers/iommu/amd/iommu.c
drivers/iommu/apple-dart.c
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
drivers/iommu/arm/arm-smmu/arm-smmu.c
drivers/iommu/intel/iommu.c
drivers/iommu/iommu.c
drivers/iommu/mtk_iommu.c
drivers/iommu/virtio-iommu.c
include/linux/iommu.h

index ca2aed8..8059baf 100644 (file)
@@ -1142,7 +1142,8 @@ static void iort_iommu_msi_get_resv_regions(struct device *dev,
                        struct iommu_resv_region *region;
 
                        region = iommu_alloc_resv_region(base + SZ_64K, SZ_64K,
-                                                        prot, IOMMU_RESV_MSI);
+                                                        prot, IOMMU_RESV_MSI,
+                                                        GFP_KERNEL);
                        if (region)
                                list_add_tail(&region->list, head);
                }
index 65856e4..d3b39d0 100644 (file)
@@ -2330,7 +2330,8 @@ static void amd_iommu_get_resv_regions(struct device *dev,
                        type = IOMMU_RESV_RESERVED;
 
                region = iommu_alloc_resv_region(entry->address_start,
-                                                length, prot, type);
+                                                length, prot, type,
+                                                GFP_KERNEL);
                if (!region) {
                        dev_err(dev, "Out of memory allocating dm-regions\n");
                        return;
@@ -2340,14 +2341,14 @@ static void amd_iommu_get_resv_regions(struct device *dev,
 
        region = iommu_alloc_resv_region(MSI_RANGE_START,
                                         MSI_RANGE_END - MSI_RANGE_START + 1,
-                                        0, IOMMU_RESV_MSI);
+                                        0, IOMMU_RESV_MSI, GFP_KERNEL);
        if (!region)
                return;
        list_add_tail(&region->list, head);
 
        region = iommu_alloc_resv_region(HT_RANGE_START,
                                         HT_RANGE_END - HT_RANGE_START + 1,
-                                        0, IOMMU_RESV_RESERVED);
+                                        0, IOMMU_RESV_RESERVED, GFP_KERNEL);
        if (!region)
                return;
        list_add_tail(&region->list, head);
index 4526575..4f4a323 100644 (file)
@@ -758,7 +758,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
 
                region = iommu_alloc_resv_region(DOORBELL_ADDR,
                                                 PAGE_SIZE, prot,
-                                                IOMMU_RESV_MSI);
+                                                IOMMU_RESV_MSI, GFP_KERNEL);
                if (!region)
                        return;
 
index ba47c73..6d5df91 100644 (file)
@@ -2757,7 +2757,7 @@ static void arm_smmu_get_resv_regions(struct device *dev,
        int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
 
        region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
-                                        prot, IOMMU_RESV_SW_MSI);
+                                        prot, IOMMU_RESV_SW_MSI, GFP_KERNEL);
        if (!region)
                return;
 
index 6c1114a..30dab14 100644 (file)
@@ -1534,7 +1534,7 @@ static void arm_smmu_get_resv_regions(struct device *dev,
        int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
 
        region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
-                                        prot, IOMMU_RESV_SW_MSI);
+                                        prot, IOMMU_RESV_SW_MSI, GFP_KERNEL);
        if (!region)
                return;
 
index a8b36c3..d5965b4 100644 (file)
@@ -4552,7 +4552,8 @@ static void intel_iommu_get_resv_regions(struct device *device,
                                IOMMU_RESV_DIRECT_RELAXABLE : IOMMU_RESV_DIRECT;
 
                        resv = iommu_alloc_resv_region(rmrr->base_address,
-                                                      length, prot, type);
+                                                      length, prot, type,
+                                                      GFP_KERNEL);
                        if (!resv)
                                break;
 
@@ -4567,7 +4568,8 @@ static void intel_iommu_get_resv_regions(struct device *device,
 
                if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA) {
                        reg = iommu_alloc_resv_region(0, 1UL << 24, prot,
-                                                  IOMMU_RESV_DIRECT_RELAXABLE);
+                                       IOMMU_RESV_DIRECT_RELAXABLE,
+                                       GFP_KERNEL);
                        if (reg)
                                list_add_tail(&reg->list, head);
                }
@@ -4576,7 +4578,7 @@ static void intel_iommu_get_resv_regions(struct device *device,
 
        reg = iommu_alloc_resv_region(IOAPIC_RANGE_START,
                                      IOAPIC_RANGE_END - IOAPIC_RANGE_START + 1,
-                                     0, IOMMU_RESV_MSI);
+                                     0, IOMMU_RESV_MSI, GFP_KERNEL);
        if (!reg)
                return;
        list_add_tail(&reg->list, head);
index 4893c24..65a3b3d 100644 (file)
@@ -504,7 +504,7 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new,
        LIST_HEAD(stack);
 
        nr = iommu_alloc_resv_region(new->start, new->length,
-                                    new->prot, new->type);
+                                    new->prot, new->type, GFP_KERNEL);
        if (!nr)
                return -ENOMEM;
 
@@ -2579,11 +2579,12 @@ EXPORT_SYMBOL(iommu_put_resv_regions);
 
 struct iommu_resv_region *iommu_alloc_resv_region(phys_addr_t start,
                                                  size_t length, int prot,
-                                                 enum iommu_resv_type type)
+                                                 enum iommu_resv_type type,
+                                                 gfp_t gfp)
 {
        struct iommu_resv_region *region;
 
-       region = kzalloc(sizeof(*region), GFP_KERNEL);
+       region = kzalloc(sizeof(*region), gfp);
        if (!region)
                return NULL;
 
index 5a4e00e..2ab2ecf 100644 (file)
@@ -917,7 +917,8 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
                        continue;
 
                region = iommu_alloc_resv_region(resv->iova_base, resv->size,
-                                                prot, IOMMU_RESV_RESERVED);
+                                                prot, IOMMU_RESV_RESERVED,
+                                                GFP_KERNEL);
                if (!region)
                        return;
 
index b7c2280..8b1b5c2 100644 (file)
@@ -490,11 +490,13 @@ static int viommu_add_resv_mem(struct viommu_endpoint *vdev,
                fallthrough;
        case VIRTIO_IOMMU_RESV_MEM_T_RESERVED:
                region = iommu_alloc_resv_region(start, size, 0,
-                                                IOMMU_RESV_RESERVED);
+                                                IOMMU_RESV_RESERVED,
+                                                GFP_KERNEL);
                break;
        case VIRTIO_IOMMU_RESV_MEM_T_MSI:
                region = iommu_alloc_resv_region(start, size, prot,
-                                                IOMMU_RESV_MSI);
+                                                IOMMU_RESV_MSI,
+                                                GFP_KERNEL);
                break;
        }
        if (!region)
@@ -909,7 +911,8 @@ static void viommu_get_resv_regions(struct device *dev, struct list_head *head)
         */
        if (!msi) {
                msi = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
-                                             prot, IOMMU_RESV_SW_MSI);
+                                             prot, IOMMU_RESV_SW_MSI,
+                                             GFP_KERNEL);
                if (!msi)
                        return;
 
index a325532..3c9da1f 100644 (file)
@@ -455,7 +455,7 @@ extern void iommu_set_default_translated(bool cmd_line);
 extern bool iommu_default_passthrough(void);
 extern struct iommu_resv_region *
 iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot,
-                       enum iommu_resv_type type);
+                       enum iommu_resv_type type, gfp_t gfp);
 extern int iommu_get_group_resv_regions(struct iommu_group *group,
                                        struct list_head *head);