Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: introduce clear_pages() and clear_user_pages()

Introduce clear_pages(), to be overridden by architectures that support
more efficient clearing of consecutive pages.

Also introduce clear_user_pages(), however, we will not expect this
function to be overridden anytime soon.

As we do for clear_user_page(), define clear_user_pages() only if the
architecture does not define clear_user_highpage().

That is because if the architecture does define clear_user_highpage(),
then it likely needs some flushing magic when clearing user pages or
highpages. This means we can get away without defining
clear_user_pages(), since, much like its single page sibling, its only
potential user is the generic clear_user_highpages() which should instead
be using clear_user_highpage().

Link: https://lkml.kernel.org/r/20260107072009.1615991-3-ankur.a.arora@oracle.com
Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Konrad Rzessutek Wilk <konrad.wilk@oracle.com>
Cc: Lance Yang <ioworker0@gmail.com>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Li Zhe <lizhe.67@bytedance.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Raghavendra K T <raghavendra.kt@amd.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ankur Arora and committed by
Andrew Morton
62a9f5a8 8e38607a

+53
+33
include/linux/highmem.h
··· 218 218 } 219 219 #endif 220 220 221 + /** 222 + * clear_user_pages() - clear a page range to be mapped to user space 223 + * @addr: start address 224 + * @vaddr: start address of the user mapping 225 + * @page: start page 226 + * @npages: number of pages 227 + * 228 + * Assumes that the region (@addr, +@npages) has been validated 229 + * already so this does no exception handling. 230 + * 231 + * If the architecture provides a clear_user_page(), use that; 232 + * otherwise, we can safely use clear_pages(). 233 + */ 234 + static inline void clear_user_pages(void *addr, unsigned long vaddr, 235 + struct page *page, unsigned int npages) 236 + { 237 + 238 + #ifdef clear_user_page 239 + do { 240 + clear_user_page(addr, vaddr, page); 241 + addr += PAGE_SIZE; 242 + vaddr += PAGE_SIZE; 243 + page++; 244 + } while (--npages); 245 + #else 246 + /* 247 + * Prefer clear_pages() to allow for architectural optimizations 248 + * when operating on contiguous page ranges. 249 + */ 250 + clear_pages(addr, npages); 251 + #endif 252 + } 253 + 221 254 /* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */ 222 255 static inline void clear_user_highpage(struct page *page, unsigned long vaddr) 223 256 {
+20
include/linux/mm.h
··· 4198 4198 unsigned int order) {} 4199 4199 #endif /* CONFIG_DEBUG_PAGEALLOC */ 4200 4200 4201 + #ifndef clear_pages 4202 + /** 4203 + * clear_pages() - clear a page range for kernel-internal use. 4204 + * @addr: start address 4205 + * @npages: number of pages 4206 + * 4207 + * Use clear_user_pages() instead when clearing a page range to be 4208 + * mapped to user space. 4209 + * 4210 + * Does absolutely no exception handling. 4211 + */ 4212 + static inline void clear_pages(void *addr, unsigned int npages) 4213 + { 4214 + do { 4215 + clear_page(addr); 4216 + addr += PAGE_SIZE; 4217 + } while (--npages); 4218 + } 4219 + #endif 4220 + 4201 4221 #ifdef __HAVE_ARCH_GATE_AREA 4202 4222 extern struct vm_area_struct *get_gate_vma(struct mm_struct *mm); 4203 4223 extern int in_gate_area_no_mm(unsigned long addr);