[PATCH 5/9] mm: kmemleak: do not scan sparsemap_buf

From: George Prekas
Date: Mon Jan 23 2023 - 12:05:36 EST


sparsemap_buf is used for vmemmap and vmemmap contains an array of
struct page. kmemleak scans the pages separately. If it scans them
twice, then it will duplicate the number of found references and will
cause missed leaks.

Signed-off-by: George Prekas <george@xxxxxxxxxxxxx>
---
mm/sparse.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/mm/sparse.c b/mm/sparse.c
index 2779b419ef2a..49df7a052037 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -14,6 +14,7 @@
#include <linux/swap.h>
#include <linux/swapops.h>
#include <linux/bootmem_info.h>
+#include <linux/kmemleak.h>

#include "internal.h"
#include <asm/dma.h>
@@ -466,6 +467,8 @@ static void __init sparse_buffer_init(unsigned long size, int nid)
*/
sparsemap_buf = memmap_alloc(size, section_map_size(), addr, nid, true);
sparsemap_buf_end = sparsemap_buf + size;
+ /* sparsemap_buf has been registered with its physical address in kmemleak */
+ kmemleak_no_scan_phys(virt_to_phys(sparsemap_buf));
}

static void __init sparse_buffer_fini(void)
--
2.37.1