diff mbox series

[v3,2/2] powerpc/mm/radix: Free PUD table when freeing pagetable

Message ID 20190726050440.24798-3-bharata@linux.ibm.com (mailing list archive)
State Superseded
Headers show
Series Memory unplug fixes for radix guests | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch next (f3365d1a959d5c6527efe3d38276acc9b58e3f3f)
snowpatch_ozlabs/build-ppc64le success Build succeeded
snowpatch_ozlabs/build-ppc64be success Build succeeded
snowpatch_ozlabs/build-ppc64e warning Build succeeded but added 1 new sparse warnings
snowpatch_ozlabs/build-pmac32 warning Build succeeded but added 1 new sparse warnings
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 28 lines checked

Commit Message

Bharata B Rao July 26, 2019, 5:04 a.m. UTC
remove_pagetable() isn't freeing PUD table. This causes memory
leak during memory unplug. Fix this.

Signed-off-by: Bharata B Rao <bharata@linux.ibm.com>
---
 arch/powerpc/mm/book3s64/radix_pgtable.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Reza Arbab July 30, 2019, 7:37 p.m. UTC | #1
On Fri, Jul 26, 2019 at 10:34:40AM +0530, Bharata B Rao wrote:
>remove_pagetable() isn't freeing PUD table. This causes memory
>leak during memory unplug. Fix this.

On x86, this is intentional. See

af2cf278ef4f ("x86/mm/hotplug: Don't remove PGD entries in remove_pagetable()")
98fe3633c5a4 ("x86/mm/hotplug: Fix BUG_ON() after hot-remove by not freeing PUD")

Does their reasoning apply to powerpc as well?
Bharata B Rao July 31, 2019, 6:19 a.m. UTC | #2
On Tue, Jul 30, 2019 at 02:37:16PM -0500, Reza Arbab wrote:
> On Fri, Jul 26, 2019 at 10:34:40AM +0530, Bharata B Rao wrote:
> > remove_pagetable() isn't freeing PUD table. This causes memory
> > leak during memory unplug. Fix this.
> 
> On x86, this is intentional. See
> 
> af2cf278ef4f ("x86/mm/hotplug: Don't remove PGD entries in remove_pagetable()")
> 98fe3633c5a4 ("x86/mm/hotplug: Fix BUG_ON() after hot-remove by not freeing PUD")
> 
> Does their reasoning apply to powerpc as well?

x86 seems to maintain some global pgd list that needs to sync'ed up
when PGD entry is freed. Since powerpc doesn't have that equivalent
I don't see that reasoning applying here. However if there is more
to it than just this, then I am not sure.

Regards,
Bharata.
diff mbox series

Patch

diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index c440446ee00f..860eb37736c0 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -783,6 +783,21 @@  static void free_pmd_table(pmd_t *pmd_start, pud_t *pud)
 	pud_clear(pud);
 }
 
+static void free_pud_table(pud_t *pud_start, pgd_t *pgd)
+{
+	pud_t *pud;
+	int i;
+
+	for (i = 0; i < PTRS_PER_PUD; i++) {
+		pud = pud_start + i;
+		if (!pud_none(*pud))
+			return;
+	}
+
+	pud_free(&init_mm, pud_start);
+	pgd_clear(pgd);
+}
+
 struct change_mapping_params {
 	pte_t *pte;
 	unsigned long start;
@@ -953,6 +968,7 @@  static void __meminit remove_pagetable(unsigned long start, unsigned long end)
 
 		pud_base = (pud_t *)pgd_page_vaddr(*pgd);
 		remove_pud_table(pud_base, addr, next);
+		free_pud_table(pud_base, pgd);
 	}
 
 	spin_unlock(&init_mm.page_table_lock);