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

mm: rename vm_ops->find_special_page() to vm_ops->find_normal_page()

... and hide it behind a kconfig option. There is really no need for any
!xen code to perform this check.

The naming is a bit off: we want to find the "normal" page when a PTE was
marked "special". So it's really not "finding a special" page.

Improve the documentation, and add a comment in the code where XEN ends up
performing the pte_mkspecial() through a hypercall. More details can be
found in commit 923b2919e2c3 ("xen/gntdev: mark userspace PTEs as special
on x86 PV guests").

Link: https://lkml.kernel.org/r/20250811112631.759341-12-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Juegren Gross <jgross@suse.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
4c89792e 2db30816

+42 -14
+1
drivers/xen/Kconfig
··· 138 138 depends on XEN 139 139 default m 140 140 select MMU_NOTIFIER 141 + select FIND_NORMAL_PAGE 141 142 help 142 143 Allows userspace processes to use grants. 143 144
+3 -2
drivers/xen/gntdev.c
··· 321 321 BUG_ON(pgnr >= map->count); 322 322 pte_maddr = arbitrary_virt_to_machine(pte).maddr; 323 323 324 + /* Note: this will perform a pte_mkspecial() through the hypercall. */ 324 325 gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags, 325 326 map->grants[pgnr].ref, 326 327 map->grants[pgnr].domid); ··· 529 528 gntdev_put_map(priv, map); 530 529 } 531 530 532 - static struct page *gntdev_vma_find_special_page(struct vm_area_struct *vma, 531 + static struct page *gntdev_vma_find_normal_page(struct vm_area_struct *vma, 533 532 unsigned long addr) 534 533 { 535 534 struct gntdev_grant_map *map = vma->vm_private_data; ··· 540 539 static const struct vm_operations_struct gntdev_vmops = { 541 540 .open = gntdev_vma_open, 542 541 .close = gntdev_vma_close, 543 - .find_special_page = gntdev_vma_find_special_page, 542 + .find_normal_page = gntdev_vma_find_normal_page, 544 543 }; 545 544 546 545 /* ------------------------------------------------------------------ */
+13 -5
include/linux/mm.h
··· 657 657 struct mempolicy *(*get_policy)(struct vm_area_struct *vma, 658 658 unsigned long addr, pgoff_t *ilx); 659 659 #endif 660 + #ifdef CONFIG_FIND_NORMAL_PAGE 660 661 /* 661 - * Called by vm_normal_page() for special PTEs to find the 662 - * page for @addr. This is useful if the default behavior 663 - * (using pte_page()) would not find the correct page. 662 + * Called by vm_normal_page() for special PTEs in @vma at @addr. This 663 + * allows for returning a "normal" page from vm_normal_page() even 664 + * though the PTE indicates that the "struct page" either does not exist 665 + * or should not be touched: "special". 666 + * 667 + * Do not add new users: this really only works when a "normal" page 668 + * was mapped, but then the PTE got changed to something weird (+ 669 + * marked special) that would not make pte_pfn() identify the originally 670 + * inserted page. 664 671 */ 665 - struct page *(*find_special_page)(struct vm_area_struct *vma, 666 - unsigned long addr); 672 + struct page *(*find_normal_page)(struct vm_area_struct *vma, 673 + unsigned long addr); 674 + #endif /* CONFIG_FIND_NORMAL_PAGE */ 667 675 }; 668 676 669 677 #ifdef CONFIG_NUMA_BALANCING
+2
mm/Kconfig
··· 1381 1381 1382 1382 Note: now only empty user PTE page table pages will be reclaimed. 1383 1383 1384 + config FIND_NORMAL_PAGE 1385 + def_bool n 1384 1386 1385 1387 source "mm/damon/Kconfig" 1386 1388
+10 -2
mm/memory.c
··· 639 639 * trivial. Secondly, an architecture may not have a spare page table 640 640 * entry bit, which requires a more complicated scheme, described below. 641 641 * 642 + * With CONFIG_FIND_NORMAL_PAGE, we might have the "special" bit set on 643 + * page table entries that actually map "normal" pages: however, that page 644 + * cannot be looked up through the PFN stored in the page table entry, but 645 + * instead will be looked up through vm_ops->find_normal_page(). So far, this 646 + * only applies to PTEs. 647 + * 642 648 * A raw VM_PFNMAP mapping (ie. one that is not COWed) is always considered a 643 649 * special mapping (even if there are underlying and valid "struct pages"). 644 650 * COWed pages of a VM_PFNMAP are always normal. ··· 685 679 { 686 680 if (IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL)) { 687 681 if (unlikely(special)) { 688 - if (vma->vm_ops && vma->vm_ops->find_special_page) 689 - return vma->vm_ops->find_special_page(vma, addr); 682 + #ifdef CONFIG_FIND_NORMAL_PAGE 683 + if (vma->vm_ops && vma->vm_ops->find_normal_page) 684 + return vma->vm_ops->find_normal_page(vma, addr); 685 + #endif /* CONFIG_FIND_NORMAL_PAGE */ 690 686 if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)) 691 687 return NULL; 692 688 if (is_zero_pfn(pfn) || is_huge_zero_pfn(pfn))
+13 -5
tools/testing/vma/vma_internal.h
··· 467 467 struct mempolicy *(*get_policy)(struct vm_area_struct *vma, 468 468 unsigned long addr, pgoff_t *ilx); 469 469 #endif 470 + #ifdef CONFIG_FIND_NORMAL_PAGE 470 471 /* 471 - * Called by vm_normal_page() for special PTEs to find the 472 - * page for @addr. This is useful if the default behavior 473 - * (using pte_page()) would not find the correct page. 472 + * Called by vm_normal_page() for special PTEs in @vma at @addr. This 473 + * allows for returning a "normal" page from vm_normal_page() even 474 + * though the PTE indicates that the "struct page" either does not exist 475 + * or should not be touched: "special". 476 + * 477 + * Do not add new users: this really only works when a "normal" page 478 + * was mapped, but then the PTE got changed to something weird (+ 479 + * marked special) that would not make pte_pfn() identify the originally 480 + * inserted page. 474 481 */ 475 - struct page *(*find_special_page)(struct vm_area_struct *vma, 476 - unsigned long addr); 482 + struct page *(*find_normal_page)(struct vm_area_struct *vma, 483 + unsigned long addr); 484 + #endif /* CONFIG_FIND_NORMAL_PAGE */ 477 485 }; 478 486 479 487 struct vm_unmapped_area_info {