Skip to content

Commit 83ce8bf

Browse files
hansendcgregkh
authored andcommitted
mm: actually mark kernel page table pages
commit 9778705 upstream. Now that the API is in place, mark kernel page table pages just after they are allocated. Unmark them just before they are freed. Note: Unconditionally clearing the 'kernel' marking (via ptdesc_clear_kernel()) would be functionally identical to what is here. But having the if() makes it logically clear that this function can be used for kernel and non-kernel page tables. Link: https://lkml.kernel.org/r/20251022082635.2462433-4-baolu.lu@linux.intel.com Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Acked-by: David Hildenbrand <david@redhat.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Alistair Popple <apopple@nvidia.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Betkov <bp@alien8.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Jean-Philippe Brucker <jean-philippe@linaro.org> Cc: Joerg Roedel <joro@8bytes.org> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Robin Murohy <robin.murphy@arm.com> Cc: Thomas Gleinxer <tglx@linutronix.de> Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com> Cc: Vasant Hegde <vasant.hegde@amd.com> Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Will Deacon <will@kernel.org> Cc: Yi Lai <yi1.lai@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1ca0f9e commit 83ce8bf

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

include/asm-generic/pgalloc.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static inline pte_t *__pte_alloc_one_kernel_noprof(struct mm_struct *mm)
2828
return NULL;
2929
}
3030

31+
ptdesc_set_kernel(ptdesc);
32+
3133
return ptdesc_address(ptdesc);
3234
}
3335
#define __pte_alloc_one_kernel(...) alloc_hooks(__pte_alloc_one_kernel_noprof(__VA_ARGS__))
@@ -146,6 +148,10 @@ static inline pmd_t *pmd_alloc_one_noprof(struct mm_struct *mm, unsigned long ad
146148
pagetable_free(ptdesc);
147149
return NULL;
148150
}
151+
152+
if (mm == &init_mm)
153+
ptdesc_set_kernel(ptdesc);
154+
149155
return ptdesc_address(ptdesc);
150156
}
151157
#define pmd_alloc_one(...) alloc_hooks(pmd_alloc_one_noprof(__VA_ARGS__))
@@ -179,6 +185,10 @@ static inline pud_t *__pud_alloc_one_noprof(struct mm_struct *mm, unsigned long
179185
return NULL;
180186

181187
pagetable_pud_ctor(ptdesc);
188+
189+
if (mm == &init_mm)
190+
ptdesc_set_kernel(ptdesc);
191+
182192
return ptdesc_address(ptdesc);
183193
}
184194
#define __pud_alloc_one(...) alloc_hooks(__pud_alloc_one_noprof(__VA_ARGS__))
@@ -233,6 +243,10 @@ static inline p4d_t *__p4d_alloc_one_noprof(struct mm_struct *mm, unsigned long
233243
return NULL;
234244

235245
pagetable_p4d_ctor(ptdesc);
246+
247+
if (mm == &init_mm)
248+
ptdesc_set_kernel(ptdesc);
249+
236250
return ptdesc_address(ptdesc);
237251
}
238252
#define __p4d_alloc_one(...) alloc_hooks(__p4d_alloc_one_noprof(__VA_ARGS__))
@@ -277,6 +291,10 @@ static inline pgd_t *__pgd_alloc_noprof(struct mm_struct *mm, unsigned int order
277291
return NULL;
278292

279293
pagetable_pgd_ctor(ptdesc);
294+
295+
if (mm == &init_mm)
296+
ptdesc_set_kernel(ptdesc);
297+
280298
return ptdesc_address(ptdesc);
281299
}
282300
#define __pgd_alloc(...) alloc_hooks(__pgd_alloc_noprof(__VA_ARGS__))

include/linux/mm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,6 +3042,9 @@ static inline void pagetable_free(struct ptdesc *pt)
30423042
{
30433043
struct page *page = ptdesc_page(pt);
30443044

3045+
if (ptdesc_test_kernel(pt))
3046+
ptdesc_clear_kernel(pt);
3047+
30453048
__free_pages(page, compound_order(page));
30463049
}
30473050

0 commit comments

Comments
 (0)