linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures.
@ 2020-07-31 11:34 Aneesh Kumar K.V
  2020-07-31 11:35 ` [PATCH 2/2] powerpc/vmemmap: Don't warn if we don't find a mapping vmemmap list entry Aneesh Kumar K.V
  2020-09-09 13:37 ` [PATCH 1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Aneesh Kumar K.V @ 2020-07-31 11:34 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V

If we fail to allocate vmemmap list, we don't keep track of allocated
vmemmap block buf. Hence on section deactivate we skip vmemmap block
buf free. This results in memory leak.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/mm/init_64.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
index 152aa0200cef..8a198504c0e1 100644
--- a/arch/powerpc/mm/init_64.c
+++ b/arch/powerpc/mm/init_64.c
@@ -162,16 +162,16 @@ static __meminit struct vmemmap_backing * vmemmap_list_alloc(int node)
 	return next++;
 }
 
-static __meminit void vmemmap_list_populate(unsigned long phys,
-					    unsigned long start,
-					    int node)
+static __meminit int vmemmap_list_populate(unsigned long phys,
+					   unsigned long start,
+					   int node)
 {
 	struct vmemmap_backing *vmem_back;
 
 	vmem_back = vmemmap_list_alloc(node);
 	if (unlikely(!vmem_back)) {
-		WARN_ON(1);
-		return;
+		pr_debug("vmemap list allocation failed\n");
+		return -ENOMEM;
 	}
 
 	vmem_back->phys = phys;
@@ -179,6 +179,7 @@ static __meminit void vmemmap_list_populate(unsigned long phys,
 	vmem_back->list = vmemmap_list;
 
 	vmemmap_list = vmem_back;
+	return 0;
 }
 
 static bool altmap_cross_boundary(struct vmem_altmap *altmap, unsigned long start,
@@ -199,6 +200,7 @@ static bool altmap_cross_boundary(struct vmem_altmap *altmap, unsigned long star
 int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
 		struct vmem_altmap *altmap)
 {
+	bool altmap_alloc;
 	unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift;
 
 	/* Align to the page size of the linear mapping. */
@@ -228,13 +230,32 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
 			p = altmap_alloc_block_buf(page_size, altmap);
 			if (!p)
 				pr_debug("altmap block allocation failed, falling back to system memory");
+			else
+				altmap_alloc = true;
 		}
-		if (!p)
+		if (!p) {
 			p = vmemmap_alloc_block_buf(page_size, node);
+			altmap_alloc = false;
+		}
 		if (!p)
 			return -ENOMEM;
 
-		vmemmap_list_populate(__pa(p), start, node);
+		if (vmemmap_list_populate(__pa(p), start, node)) {
+			/*
+			 * If we don't populate vmemap list, we don't have
+			 * the ability to free the allocated vmemmap
+			 * pages in section_deactivate. Hence free them
+			 * here.
+			 */
+			int nr_pfns = page_size >> PAGE_SHIFT;
+			unsigned long page_order = get_order(page_size);
+
+			if (altmap_alloc)
+				vmem_altmap_free(altmap, nr_pfns);
+			else
+				free_pages((unsigned long)p, page_order);
+			return -ENOMEM;
+		}
 
 		pr_debug("      * %016lx..%016lx allocated at %p\n",
 			 start, start + page_size, p);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] powerpc/vmemmap: Don't warn if we don't find a mapping vmemmap list entry
  2020-07-31 11:34 [PATCH 1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures Aneesh Kumar K.V
@ 2020-07-31 11:35 ` Aneesh Kumar K.V
  2020-09-09 13:37 ` [PATCH 1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Aneesh Kumar K.V @ 2020-07-31 11:35 UTC (permalink / raw)
  To: linuxppc-dev, mpe; +Cc: Aneesh Kumar K.V

Now that we are handling vmemmap list allocation failure correctly, don't
WARN in section deactivate when we don't find a mapping vmemmap list entry.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 arch/powerpc/mm/init_64.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
index 8a198504c0e1..3ffe8b84aab2 100644
--- a/arch/powerpc/mm/init_64.c
+++ b/arch/powerpc/mm/init_64.c
@@ -285,10 +285,8 @@ static unsigned long vmemmap_list_free(unsigned long start)
 		vmem_back_prev = vmem_back;
 	}
 
-	if (unlikely(!vmem_back)) {
-		WARN_ON(1);
+	if (unlikely(!vmem_back))
 		return 0;
-	}
 
 	/* remove it from vmemmap_list */
 	if (vmem_back == vmemmap_list) /* remove head */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures.
  2020-07-31 11:34 [PATCH 1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures Aneesh Kumar K.V
  2020-07-31 11:35 ` [PATCH 2/2] powerpc/vmemmap: Don't warn if we don't find a mapping vmemmap list entry Aneesh Kumar K.V
@ 2020-09-09 13:37 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2020-09-09 13:37 UTC (permalink / raw)
  To: mpe, Aneesh Kumar K.V, linuxppc-dev

On Fri, 31 Jul 2020 17:04:59 +0530, Aneesh Kumar K.V wrote:
> If we fail to allocate vmemmap list, we don't keep track of allocated
> vmemmap block buf. Hence on section deactivate we skip vmemmap block
> buf free. This results in memory leak.

Applied to powerpc/next.

[1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures.
      https://git.kernel.org/powerpc/c/ccaea15296f9773abd43aaa17ee4b88848e4a505
[2/2] powerpc/vmemmap: Don't warn if we don't find a mapping vmemmap list entry
      https://git.kernel.org/powerpc/c/1c0a7ac0ec63ee626f669c9a4e278f6ae1dbfcf2

cheers

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-09 15:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 11:34 [PATCH 1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures Aneesh Kumar K.V
2020-07-31 11:35 ` [PATCH 2/2] powerpc/vmemmap: Don't warn if we don't find a mapping vmemmap list entry Aneesh Kumar K.V
2020-09-09 13:37 ` [PATCH 1/2] powerpc/vmemmap: Fix memory leak with vmemmap list allocation failures Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).