|
9 | 9 |
|
10 | 10 | #include <linux/slab.h>
|
11 | 11 | #include <linux/cpumask.h>
|
| 12 | +#include <linux/kmemleak.h> |
12 | 13 | #include <linux/percpu.h>
|
13 | 14 |
|
14 | 15 | struct vmemmap_backing {
|
@@ -82,6 +83,13 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
|
82 | 83 |
|
83 | 84 | pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
|
84 | 85 | pgtable_gfp_flags(mm, GFP_KERNEL));
|
| 86 | + /* |
| 87 | + * Don't scan the PGD for pointers, it contains references to PUDs but |
| 88 | + * those references are not full pointers and so can't be recognised by |
| 89 | + * kmemleak. |
| 90 | + */ |
| 91 | + kmemleak_no_scan(pgd); |
| 92 | + |
85 | 93 | /*
|
86 | 94 | * With hugetlb, we don't clear the second half of the page table.
|
87 | 95 | * If we share the same slab cache with the pmd or pud level table,
|
@@ -110,8 +118,19 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
|
110 | 118 |
|
111 | 119 | static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
|
112 | 120 | {
|
113 |
| - return kmem_cache_alloc(PGT_CACHE(PUD_CACHE_INDEX), |
114 |
| - pgtable_gfp_flags(mm, GFP_KERNEL)); |
| 121 | + pud_t *pud; |
| 122 | + |
| 123 | + pud = kmem_cache_alloc(PGT_CACHE(PUD_CACHE_INDEX), |
| 124 | + pgtable_gfp_flags(mm, GFP_KERNEL)); |
| 125 | + /* |
| 126 | + * Tell kmemleak to ignore the PUD, that means don't scan it for |
| 127 | + * pointers and don't consider it a leak. PUDs are typically only |
| 128 | + * referred to by their PGD, but kmemleak is not able to recognise those |
| 129 | + * as pointers, leading to false leak reports. |
| 130 | + */ |
| 131 | + kmemleak_ignore(pud); |
| 132 | + |
| 133 | + return pud; |
115 | 134 | }
|
116 | 135 |
|
117 | 136 | static inline void pud_free(struct mm_struct *mm, pud_t *pud)
|
|
0 commit comments