ARC: mm: fix leakage of memory allocated for PTE
Subsystems (2)
PATCH 1/1 ARC: mm: fix leakage of memory allocated for PTE
From: Pavel Kozlov <[email protected]>
Since commit d9820ff ("ARC: mm: switch pgtable_t back to struct page *") a memory leakage problem occurs. Memory allocated for page table entries not released during process termination. This issue can be reproduced by a small program that allocates a large amount of memory. After several runs, you'll see that the amount of free memory has reduced and will continue to reduce after each run. All ARC CPUs are effected by this issue. The issue was introduced since the kernel stable release v5.15-rc1.
As described in commit d9820ff after switch pgtable_t back to struct page *, a pointer to "struct page" and appropriate functions are used to allocate and free a memory page for PTEs, but the pmd_pgtable macro hasn't changed and returns the direct virtual address from the PMD (PGD) entry. Than this address used as a parameter in the __pte_free() and as a result this function couldn't release memory page allocated for PTEs.
Fix this issue by changing the pmd_pgtable macro and returning pointer to struct page.
--- arch/arc/include/asm/pgtable-levels.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arc/include/asm/pgtable-levels.h +1 -1
@@ -161,7 +161,7 @@#define pmd_pfn (pmd) ((pmd_val(pmd) & PAGE_MASK) >> PAGE_SHIFT)#define pmd_page (pmd) virt_to_page(pmd_page_vaddr(pmd))#define set_pmd (pmdp, pmd) (*(pmdp) = pmd) -#define pmd_pgtable (pmd) ((pgtable_t) pmd_page_vaddr(pmd)) +#define pmd_pgtable (pmd) ((pgtable_t) pmd_page(pmd))/* * 4th level paging: pte
Signature · 1 line
2.25.1
Vineet Gupta
maintainerQuoted 17 lines · On 10/17/22 09:11, [email protected] wrote:
From: Pavel Kozlov <[email protected]>
Since commit d9820ff ("ARC: mm: switch
pgtable_tback to struct page *") a memory leakage problem occurs. Memory allocated for page table entries not released during process termination. This issue can be reproduced by a small program that allocates a large amount of memory. After several runs, you'll see that the amount of free memory has reduced and will continue to reduce after each run. All ARC CPUs are effected by this issue. The issue was introduced since the kernel stable release v5.15-rc1.As described in commit d9820ff after switch
pgtable_tback to struct page *, a pointer to "struct page" and appropriate functions are used to allocate and free a memory page for PTEs, but thepmd_pgtablemacro hasn't changed and returns the direct virtual address from the PMD (PGD) entry. Than this address used as a parameter in the__pte_free()and as a result this function couldn't release memory page allocated for PTEs.
Quoted 2 lines
Fix this issue by changing the
pmd_pgtablemacro and returning pointer to struct page.
Good catch. Curious how did you find it. KMEMCHECK or some such or just oom.
Quoted 5 lines
Fixes d9820ff76f95 ("ARC: mm: switch pgtable_t back to struct page *")Signed-off-by Pavel Kozlov <[email protected]>Cc Vineet Gupta <[email protected]>Cc Mike Rapoport <[email protected]>Cc <[email protected]> # 4.15.x
You meant 5.15.x
Added to for-curr.
Thx,
-Vineet
Quoted 9 lines
--- arch/arc/include/asm/pgtable-levels.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arc/include/asm/pgtable-levels.h +0
-0
arch/arc/include/asm/pgtable-levels.h line 167
Quoted 8 lines
arch/arc/include/asm/pgtable-levels.h +1
-1@@ -161,7 +161,7 @@#define pmd_pfn (pmd) ((pmd_val(pmd) & PAGE_MASK) >> PAGE_SHIFT)#define pmd_page (pmd) virt_to_page(pmd_page_vaddr(pmd))#define set_pmd (pmdp, pmd) (*(pmdp) = pmd) -#define pmd_pgtable (pmd) ((pgtable_t) pmd_page_vaddr(pmd)) +#define pmd_pgtable (pmd) ((pgtable_t) pmd_page(pmd))/* * 4th level paging: pte
_______________________________________________
linux-snps-arc mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Quoted 1 line
Good catch. Curious how did you find it. KMEMCHECK or some such or just oom.
I've run glibc tests with 5.16 kernel and got many oom-killer messages and even kernel panic because lack of memory. These symptoms pointed to an issue. kmemleak didn't show anything. Didn't try kmemcheck. I prepared a small test and used git bisect to find to the "blame" commit.
Quoted 3 lines
Quoted 1 line
Cc <[email protected]> # 4.15.xYou meant 5.15.x
Yes, you right, that's my typo.
Quoted 1 line
Added to for-curr.
Thanks!
Regards,
Pavel
_______________________________________________
linux-snps-arc mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-snps-arc