Skip to contentSkip to conversation

dma-contiguous: reserve NUMA CMA areas after default reservation failure

PATCH In review Avi Weiss 3 participants 4 messages Nov 15 – Nov 16 DMA mapping helpers

lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 dma-contiguous: reserve NUMA CMA areas after default reservation failure

dma_contiguous_reserve() returns when reserving the default CMA area fails, skipping independently configured NUMA CMA areas that might still be reservable.

Register the default area only when its reservation succeeds, then continue with NUMA CMA reservation even if the default area fails.

Fixes 7e6ace2535d0 ("dma-contiguous: add kconfig option to setup numa cma area if not configured explicitly")
---
 kernel/dma/contiguous.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/dma/contiguous.c +5 -5
index 90937dc7c627..0b6500bb6cd9 100644
@@ -287,8 +287,6 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 						  selected_limit,
 						  &dma_contiguous_default_area,
 						  fixed);
-		if (ret)
-			return;
 
 		/*
 		 * We need to insert the new area in our list to avoid
@@ -305,9 +303,11 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 		 * but we also need to insert it in our list to avoid
 		 * having a default area but an empty list.
 		 */
-		ret = dma_contiguous_insert_area(dma_contiguous_default_area);
-		if (ret)
-			pr_warn("Couldn't queue default CMA region for heap creation.");
+		if (!ret) {
+			ret = dma_contiguous_insert_area(dma_contiguous_default_area);
+			if (ret)
+				pr_warn("Couldn't queue default CMA region for heap creation.");
+		}
 	}
 
 	dma_numa_cma_reserve();

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa

Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Avi Weiss

dma_contiguous_reserve() returns when reserving the default CMA area fails, skipping independently configured NUMA CMA areas that might still be reservable.

Register the default area only when its reservation succeeds, then continue with NUMA CMA reservation even if the default area fails.

Fixes 7e6ace2535d0 ("dma-contiguous: add kconfig option to setup numa cma area if not configured explicitly")
---
 kernel/dma/contiguous.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/dma/contiguous.c +0 -2
index 90937dc7c627..0b6500bb6cd9 100644
@@ -287,8 +287,6 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 						  selected_limit,
 						  &dma_contiguous_default_area,
 						  fixed);
-		if (ret)
-			return;
 
 		/*
 		 * We need to insert the new area in our list to avoid
@@ -305,9 +303,11 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 		 * but we also need to insert it in our list to avoid

kernel/dma/contiguous.c void __init dma_contiguous_reserve(phys_addr_t limit) · line 310

Quoted 10 lines
kernel/dma/contiguous.c +5 -3
 		 * having a default area but an empty list.
 		 */
-		ret = dma_contiguous_insert_area(dma_contiguous_default_area);
-		if (ret)
-			pr_warn("Couldn't queue default CMA region for heap creation.");
+		if (!ret) {
+			ret = dma_contiguous_insert_area(dma_contiguous_default_area);
+			if (ret)
+				pr_warn("Couldn't queue default CMA region for heap creation.");
+		}

Thanks for the fix!

one nitpick is, is the below code more readable? (I'm OK with your patch as is):

kernel/dma/contiguous.c +2 -1
index 90937dc7c627..3daa9ae3ab7d 100644
@@ -288,7 +288,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 						  &dma_contiguous_default_area,
 						  fixed);
 		if (ret)
-			return;
+			goto numa_resv;
 
 		/*
 		 * We need to insert the new area in our list to avoid
@@ -310,6 +310,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 			pr_warn("Couldn't queue default CMA region for heap creation.");
 	}
 
+numa_resv:
 	dma_numa_cma_reserve();
 }
 
author
#2 lore raw

I think both quite clear, but I don't mind either way ;-)

Quoted 69 lines · Feng Tang
Quoted 28 lines · Avi Weiss

dma_contiguous_reserve() returns when reserving the default CMA area fails, skipping independently configured NUMA CMA areas that might still be reservable.

Register the default area only when its reservation succeeds, then continue with NUMA CMA reservation even if the default area fails.

Fixes 7e6ace2535d0 ("dma-contiguous: add kconfig option to setup numa cma area if not configured explicitly")
---
 kernel/dma/contiguous.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/dma/contiguous.c +0 -2
index 90937dc7c627..0b6500bb6cd9 100644
@@ -287,8 +287,6 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
                                                selected_limit,
                                                &dma_contiguous_default_area,
                                                fixed);
-             if (ret)
-                     return;
 
              /*
               * We need to insert the new area in our list to avoid
@@ -305,9 +303,11 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
               * but we also need to insert it in our list to avoid

kernel/dma/contiguous.c void __init dma_contiguous_reserve(phys_addr_t limit) · line 310

Quoted 10 lines
kernel/dma/contiguous.c +5 -3
               * having a default area but an empty list.
               */
-             ret = dma_contiguous_insert_area(dma_contiguous_default_area);
-             if (ret)
-                     pr_warn("Couldn't queue default CMA region for heap creation.");
+             if (!ret) {
+                     ret = dma_contiguous_insert_area(dma_contiguous_default_area);
+                     if (ret)
+                             pr_warn("Couldn't queue default CMA region for heap creation.");
+             }

Thanks for the fix!

one nitpick is, is the below code more readable? (I'm OK with your patch as is):

kernel/dma/contiguous.c +2 -1
index 90937dc7c627..3daa9ae3ab7d 100644
@@ -288,7 +288,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
                                                  &dma_contiguous_default_area,
                                                  fixed);
                if (ret)
-                       return;
+                       goto numa_resv;
 
                /*
                 * We need to insert the new area in our list to avoid
@@ -310,6 +310,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
                        pr_warn("Couldn't queue default CMA region for heap creation.");
        }
 
+numa_resv:
        dma_numa_cma_reserve();
 }
 
maintainer
#3 lore raw
In reply to Avi Weiss
Quoted 9 lines · Avi Weiss

dma_contiguous_reserve() returns when reserving the default CMA area fails, skipping independently configured NUMA CMA areas that might still be reservable.

Register the default area only when its reservation succeeds, then continue with NUMA CMA reservation even if the default area fails.

Fixes 7e6ace2535d0 ("dma-contiguous: add kconfig option to setup numa cma area if not configured explicitly")

When reservation of the default CMA area fails, there is something really wrong with system configuration. I don't think that it is worth trying to setup NUMA related regions in such case.

Quoted 33 lines
---
 kernel/dma/contiguous.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/dma/contiguous.c +5 -5
index 90937dc7c627..0b6500bb6cd9 100644
@@ -287,8 +287,6 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 						  selected_limit,
 						  &dma_contiguous_default_area,
 						  fixed);
-		if (ret)
-			return;
 
 		/*
 		 * We need to insert the new area in our list to avoid
@@ -305,9 +303,11 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
 		 * but we also need to insert it in our list to avoid
 		 * having a default area but an empty list.
 		 */
-		ret = dma_contiguous_insert_area(dma_contiguous_default_area);
-		if (ret)
-			pr_warn("Couldn't queue default CMA region for heap creation.");
+		if (!ret) {
+			ret = dma_contiguous_insert_area(dma_contiguous_default_area);
+			if (ret)
+				pr_warn("Couldn't queue default CMA region for heap creation.");
+		}
 	}
 
 	dma_numa_cma_reserve();
Quoted 1 line

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland