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.

highmem: introduce clear_user_highpages()

Define clear_user_highpages() which uses the range clearing primitive,
clear_user_pages(). We can safely use this when CONFIG_HIGHMEM is
disabled and if the architecture does not have clear_user_highpage.

The first is needed to ensure that contiguous page ranges stay contiguous
which precludes intermediate maps via HIGMEM. The second, because if the
architecture has clear_user_highpage(), it likely needs flushing magic
when clearing the page, magic that we aren't privy to.

For both of those cases, just fallback to a loop around
clear_user_highpage().

Link: https://lkml.kernel.org/r/20260107072009.1615991-4-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
8d846b72 62a9f5a8

+44 -1
+44 -1
include/linux/highmem.h
··· 251 251 #endif 252 252 } 253 253 254 - /* when CONFIG_HIGHMEM is not set these will be plain clear/copy_page */ 254 + /** 255 + * clear_user_highpage() - clear a page to be mapped to user space 256 + * @page: start page 257 + * @vaddr: start address of the user mapping 258 + * 259 + * With !CONFIG_HIGHMEM this (and the copy_user_highpage() below) will 260 + * be plain clear_user_page() (and copy_user_page()). 261 + */ 255 262 static inline void clear_user_highpage(struct page *page, unsigned long vaddr) 256 263 { 257 264 void *addr = kmap_local_page(page); ··· 266 259 kunmap_local(addr); 267 260 } 268 261 #endif /* clear_user_highpage */ 262 + 263 + /** 264 + * clear_user_highpages() - clear a page range to be mapped to user space 265 + * @page: start page 266 + * @vaddr: start address of the user mapping 267 + * @npages: number of pages 268 + * 269 + * Assumes that all the pages in the region (@page, +@npages) are valid 270 + * so this does no exception handling. 271 + */ 272 + static inline void clear_user_highpages(struct page *page, unsigned long vaddr, 273 + unsigned int npages) 274 + { 275 + 276 + #if defined(clear_user_highpage) || defined(CONFIG_HIGHMEM) 277 + /* 278 + * An architecture defined clear_user_highpage() implies special 279 + * handling is needed. 280 + * 281 + * So we use that or, the generic variant if CONFIG_HIGHMEM is 282 + * enabled. 283 + */ 284 + do { 285 + clear_user_highpage(page, vaddr); 286 + vaddr += PAGE_SIZE; 287 + page++; 288 + } while (--npages); 289 + #else 290 + 291 + /* 292 + * Prefer clear_user_pages() to allow for architectural optimizations 293 + * when operating on contiguous page ranges. 294 + */ 295 + clear_user_pages(page_address(page), vaddr, page, npages); 296 + #endif 297 + } 269 298 270 299 #ifndef vma_alloc_zeroed_movable_folio 271 300 /**