folio_zero_user() is defined in mm/memory.c under CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS. A subsequent patch will call it from post_alloc_hook() for all user page zeroing, so configs without THP or HUGETLBFS will need a stub.
Add a stub that uses clear_user_highpages() with aligned addr_hint. Without THP/HUGETLBFS, only order-0 user pages are allocated, so the locality optimization in the real folio_zero_user() (zero near the faulting address last) is not needed. This also matches what vma_alloc_zeroed_movable_folio currently does. Signed-off-by: Michael S. Tsirkin <[email protected]> Assisted-by: Claude:claude-opus-4-6 Assisted-by: cursor-agent:GPT-5.4-xhigh --- mm/folio_zero.h | 18 ++++++++++++++++++ mm/page_alloc.c | 1 + 2 files changed, 19 insertions(+) create mode 100644 mm/folio_zero.h diff --git a/mm/folio_zero.h b/mm/folio_zero.h new file mode 100644 index 000000000000..c135b3a34da8 --- /dev/null +++ b/mm/folio_zero.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef MM_FOLIO_ZERO_H +#define MM_FOLIO_ZERO_H + +#include <linux/highmem.h> + +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS) +void folio_zero_user(struct folio *folio, unsigned long addr_hint); +#else +static inline void folio_zero_user(struct folio *folio, unsigned long addr_hint) +{ + unsigned long base = ALIGN_DOWN(addr_hint, folio_size(folio)); + + clear_user_highpages(&folio->page, base, folio_nr_pages(folio)); +} +#endif + +#endif /* MM_FOLIO_ZERO_H */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6d3f284c607d..0943ab724032 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -17,6 +17,7 @@ #include <linux/stddef.h> #include <linux/mm.h> #include <linux/highmem.h> +#include "folio_zero.h" #include <linux/interrupt.h> #include <linux/jiffies.h> #include <linux/compiler.h> -- MST

