2022-08-18 13:01:34

by Liu Shixin

[permalink] [raw]
Subject: [PATCH -next] bootmem: remove the vmemmap pages from kmemleak in free_bootmem_page

The vmemmap pages is marked by kmemleak when allocated from memblock.
Remove it from kmemleak when free the page. Otherwise, when we reuse the
page, kmemleak may report such an error and then stop working.

kmemleak: Cannot insert 0xffff98fb6eab3d40 into the object search tree (overlaps existing)
kmemleak: Kernel memory leak detector disabled
kmemleak: Object 0xffff98fb6be00000 (size 335544320):
kmemleak: comm "swapper", pid 0, jiffies 4294892296
kmemleak: min_count = 0
kmemleak: count = 0
kmemleak: flags = 0x1
kmemleak: checksum = 0
kmemleak: backtrace:

Fixes: f41f2ed43ca5 ("mm: hugetlb: free the vmemmap pages associated with each HugeTLB page")
Signed-off-by: Liu Shixin <[email protected]>
---
include/linux/bootmem_info.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/bootmem_info.h b/include/linux/bootmem_info.h
index cc35d010fa94..899bc56948f7 100644
--- a/include/linux/bootmem_info.h
+++ b/include/linux/bootmem_info.h
@@ -3,6 +3,7 @@
#define __LINUX_BOOTMEM_INFO_H

#include <linux/mm.h>
+#include <linux/kmemleak.h>

/*
* Types for free bootmem stored in page->lru.next. These have to be in
@@ -38,9 +39,10 @@ static inline void free_bootmem_page(struct page *page)
*/
VM_BUG_ON_PAGE(page_ref_count(page) != 2, page);

- if (magic == SECTION_INFO || magic == MIX_SECTION_INFO)
+ if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) {
+ kmemleak_free_part(page_to_virt(page), PAGE_SIZE);
put_page_bootmem(page);
- else
+ } else
VM_BUG_ON_PAGE(1, page);
}
#else
--
2.25.1


2022-08-19 04:04:11

by Muchun Song

[permalink] [raw]
Subject: Re: [PATCH -next] bootmem: remove the vmemmap pages from kmemleak in free_bootmem_page



> On Aug 18, 2022, at 21:21, Liu Shixin <[email protected]> wrote:
>
> The vmemmap pages is marked by kmemleak when allocated from memblock.
> Remove it from kmemleak when free the page. Otherwise, when we reuse the
> page, kmemleak may report such an error and then stop working.
>
> kmemleak: Cannot insert 0xffff98fb6eab3d40 into the object search tree (overlaps existing)
> kmemleak: Kernel memory leak detector disabled
> kmemleak: Object 0xffff98fb6be00000 (size 335544320):
> kmemleak: comm "swapper", pid 0, jiffies 4294892296
> kmemleak: min_count = 0
> kmemleak: count = 0
> kmemleak: flags = 0x1
> kmemleak: checksum = 0
> kmemleak: backtrace:
>
> Fixes: f41f2ed43ca5 ("mm: hugetlb: free the vmemmap pages associated with each HugeTLB page")
> Signed-off-by: Liu Shixin <[email protected]>
> ---
> include/linux/bootmem_info.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/bootmem_info.h b/include/linux/bootmem_info.h
> index cc35d010fa94..899bc56948f7 100644
> --- a/include/linux/bootmem_info.h
> +++ b/include/linux/bootmem_info.h
> @@ -3,6 +3,7 @@
> #define __LINUX_BOOTMEM_INFO_H
>
> #include <linux/mm.h>
> +#include <linux/kmemleak.h>
>
> /*
> * Types for free bootmem stored in page->lru.next. These have to be in
> @@ -38,9 +39,10 @@ static inline void free_bootmem_page(struct page *page)
> */
> VM_BUG_ON_PAGE(page_ref_count(page) != 2, page);

I am wondering if we should fix put_page_bootmem() instead of
free_bootmem_page() since there are some users of put_page_bootmem()
to free a page allocated from memblock which also can be reused
afterwards.

Thanks.

>
> - if (magic == SECTION_INFO || magic == MIX_SECTION_INFO)
> + if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) {
> + kmemleak_free_part(page_to_virt(page), PAGE_SIZE);
> put_page_bootmem(page);
> - else
> + } else
> VM_BUG_ON_PAGE(1, page);
> }
> #else
> --
> 2.25.1
>
>

2022-08-19 07:16:36

by Liu Shixin

[permalink] [raw]
Subject: Re: [PATCH -next] bootmem: remove the vmemmap pages from kmemleak in free_bootmem_page

On 2022/8/19 11:31, Muchun Song wrote:
>
>> On Aug 18, 2022, at 21:21, Liu Shixin <[email protected]> wrote:
>>
>> The vmemmap pages is marked by kmemleak when allocated from memblock.
>> Remove it from kmemleak when free the page. Otherwise, when we reuse the
>> page, kmemleak may report such an error and then stop working.
>>
>> kmemleak: Cannot insert 0xffff98fb6eab3d40 into the object search tree (overlaps existing)
>> kmemleak: Kernel memory leak detector disabled
>> kmemleak: Object 0xffff98fb6be00000 (size 335544320):
>> kmemleak: comm "swapper", pid 0, jiffies 4294892296
>> kmemleak: min_count = 0
>> kmemleak: count = 0
>> kmemleak: flags = 0x1
>> kmemleak: checksum = 0
>> kmemleak: backtrace:
>>
>> Fixes: f41f2ed43ca5 ("mm: hugetlb: free the vmemmap pages associated with each HugeTLB page")
>> Signed-off-by: Liu Shixin <[email protected]>
>> ---
>> include/linux/bootmem_info.h | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/bootmem_info.h b/include/linux/bootmem_info.h
>> index cc35d010fa94..899bc56948f7 100644
>> --- a/include/linux/bootmem_info.h
>> +++ b/include/linux/bootmem_info.h
>> @@ -3,6 +3,7 @@
>> #define __LINUX_BOOTMEM_INFO_H
>>
>> #include <linux/mm.h>
>> +#include <linux/kmemleak.h>
>>
>> /*
>> * Types for free bootmem stored in page->lru.next. These have to be in
>> @@ -38,9 +39,10 @@ static inline void free_bootmem_page(struct page *page)
>> */
>> VM_BUG_ON_PAGE(page_ref_count(page) != 2, page);
> I am wondering if we should fix put_page_bootmem() instead of
> free_bootmem_page() since there are some users of put_page_bootmem()
> to free a page allocated from memblock which also can be reused
> afterwards.
>
> Thanks.
Thanks for your advise, it looks like that this problem may be occurs in memory hotremove too.
So it's more appropriate to fix put_page_bootmem()

Thanks,

>
>> - if (magic == SECTION_INFO || magic == MIX_SECTION_INFO)
>> + if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) {
>> + kmemleak_free_part(page_to_virt(page), PAGE_SIZE);
>> put_page_bootmem(page);
>> - else
>> + } else
>> VM_BUG_ON_PAGE(1, page);
>> }
>> #else
>> --
>> 2.25.1
>>
>>
> .
>

2022-08-24 07:05:05

by Liu Shixin

[permalink] [raw]
Subject: Re: [PATCH -next] bootmem: remove the vmemmap pages from kmemleak in free_bootmem_page

Hi Andrew,

This patch is superseded by latter patch so don't merge it in next. Just the latter is fine.

Thanks,

https://lore.kernel.org/all/[email protected]/T/#u


On 2022/8/18 21:21, Liu Shixin wrote:
> The vmemmap pages is marked by kmemleak when allocated from memblock.
> Remove it from kmemleak when free the page. Otherwise, when we reuse the
> page, kmemleak may report such an error and then stop working.
>
> kmemleak: Cannot insert 0xffff98fb6eab3d40 into the object search tree (overlaps existing)
> kmemleak: Kernel memory leak detector disabled
> kmemleak: Object 0xffff98fb6be00000 (size 335544320):
> kmemleak: comm "swapper", pid 0, jiffies 4294892296
> kmemleak: min_count = 0
> kmemleak: count = 0
> kmemleak: flags = 0x1
> kmemleak: checksum = 0
> kmemleak: backtrace:
>
> Fixes: f41f2ed43ca5 ("mm: hugetlb: free the vmemmap pages associated with each HugeTLB page")
> Signed-off-by: Liu Shixin <[email protected]>
> ---
> include/linux/bootmem_info.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/bootmem_info.h b/include/linux/bootmem_info.h
> index cc35d010fa94..899bc56948f7 100644
> --- a/include/linux/bootmem_info.h
> +++ b/include/linux/bootmem_info.h
> @@ -3,6 +3,7 @@
> #define __LINUX_BOOTMEM_INFO_H
>
> #include <linux/mm.h>
> +#include <linux/kmemleak.h>
>
> /*
> * Types for free bootmem stored in page->lru.next. These have to be in
> @@ -38,9 +39,10 @@ static inline void free_bootmem_page(struct page *page)
> */
> VM_BUG_ON_PAGE(page_ref_count(page) != 2, page);
>
> - if (magic == SECTION_INFO || magic == MIX_SECTION_INFO)
> + if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) {
> + kmemleak_free_part(page_to_virt(page), PAGE_SIZE);
> put_page_bootmem(page);
> - else
> + } else
> VM_BUG_ON_PAGE(1, page);
> }
> #else