]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm: rename vm_ops->find_special_page() to vm_ops->find_normal_page()
authorDavid Hildenbrand <david@redhat.com>
Mon, 11 Aug 2025 11:26:31 +0000 (13:26 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 13 Sep 2025 23:54:53 +0000 (16:54 -0700)
...  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>
drivers/xen/Kconfig
drivers/xen/gntdev.c
include/linux/mm.h
mm/Kconfig
mm/memory.c
tools/testing/vma/vma_internal.h

index 24f485827e03990bdf8561e05a0644c288e836d9..f9a35ed266ecfc9c44088a38608736219101fa41 100644 (file)
@@ -138,6 +138,7 @@ config XEN_GNTDEV
        depends on XEN
        default m
        select MMU_NOTIFIER
+       select FIND_NORMAL_PAGE
        help
          Allows userspace processes to use grants.
 
index 1f21607656182a321dce0b1114c8fa4b8905fb25..26f13b37c78e64b5adca945aad91a440f2b3bd26 100644 (file)
@@ -321,6 +321,7 @@ static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data)
        BUG_ON(pgnr >= map->count);
        pte_maddr = arbitrary_virt_to_machine(pte).maddr;
 
+       /* Note: this will perform a pte_mkspecial() through the hypercall. */
        gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags,
                          map->grants[pgnr].ref,
                          map->grants[pgnr].domid);
@@ -528,7 +529,7 @@ static void gntdev_vma_close(struct vm_area_struct *vma)
        gntdev_put_map(priv, map);
 }
 
-static struct page *gntdev_vma_find_special_page(struct vm_area_struct *vma,
+static struct page *gntdev_vma_find_normal_page(struct vm_area_struct *vma,
                                                 unsigned long addr)
 {
        struct gntdev_grant_map *map = vma->vm_private_data;
@@ -539,7 +540,7 @@ static struct page *gntdev_vma_find_special_page(struct vm_area_struct *vma,
 static const struct vm_operations_struct gntdev_vmops = {
        .open = gntdev_vma_open,
        .close = gntdev_vma_close,
-       .find_special_page = gntdev_vma_find_special_page,
+       .find_normal_page = gntdev_vma_find_normal_page,
 };
 
 /* ------------------------------------------------------------------ */
index 8ca7d2fa71343bd264675c3734787510213f5abb..3868ca1a25f9c4bb163f65d23740b0afda5cd783 100644 (file)
@@ -657,13 +657,21 @@ struct vm_operations_struct {
        struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
                                        unsigned long addr, pgoff_t *ilx);
 #endif
+#ifdef CONFIG_FIND_NORMAL_PAGE
        /*
-        * Called by vm_normal_page() for special PTEs to find the
-        * page for @addr.  This is useful if the default behavior
-        * (using pte_page()) would not find the correct page.
+        * Called by vm_normal_page() for special PTEs in @vma at @addr. This
+        * allows for returning a "normal" page from vm_normal_page() even
+        * though the PTE indicates that the "struct page" either does not exist
+        * or should not be touched: "special".
+        *
+        * Do not add new users: this really only works when a "normal" page
+        * was mapped, but then the PTE got changed to something weird (+
+        * marked special) that would not make pte_pfn() identify the originally
+        * inserted page.
         */
-       struct page *(*find_special_page)(struct vm_area_struct *vma,
-                                         unsigned long addr);
+       struct page *(*find_normal_page)(struct vm_area_struct *vma,
+                                        unsigned long addr);
+#endif /* CONFIG_FIND_NORMAL_PAGE */
 };
 
 #ifdef CONFIG_NUMA_BALANCING
index e443fe8cd6cf256ca20b8a58b95d18b6f5448f47..59a04d0b2e272e33551643ce66db7d9ddc4128f3 100644 (file)
@@ -1381,6 +1381,8 @@ config PT_RECLAIM
 
          Note: now only empty user PTE page table pages will be reclaimed.
 
+config FIND_NORMAL_PAGE
+       def_bool n
 
 source "mm/damon/Kconfig"
 
index 6f806bf3cc994b0d6fae1fdc840470a2c666b9e7..002c28795d8b732fd6cefe79b66da3c00d124930 100644 (file)
@@ -639,6 +639,12 @@ static void print_bad_page_map(struct vm_area_struct *vma,
  * trivial. Secondly, an architecture may not have a spare page table
  * entry bit, which requires a more complicated scheme, described below.
  *
+ * With CONFIG_FIND_NORMAL_PAGE, we might have the "special" bit set on
+ * page table entries that actually map "normal" pages: however, that page
+ * cannot be looked up through the PFN stored in the page table entry, but
+ * instead will be looked up through vm_ops->find_normal_page(). So far, this
+ * only applies to PTEs.
+ *
  * A raw VM_PFNMAP mapping (ie. one that is not COWed) is always considered a
  * special mapping (even if there are underlying and valid "struct pages").
  * COWed pages of a VM_PFNMAP are always normal.
@@ -679,8 +685,10 @@ static inline struct page *__vm_normal_page(struct vm_area_struct *vma,
 {
        if (IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL)) {
                if (unlikely(special)) {
-                       if (vma->vm_ops && vma->vm_ops->find_special_page)
-                               return vma->vm_ops->find_special_page(vma, addr);
+#ifdef CONFIG_FIND_NORMAL_PAGE
+                       if (vma->vm_ops && vma->vm_ops->find_normal_page)
+                               return vma->vm_ops->find_normal_page(vma, addr);
+#endif /* CONFIG_FIND_NORMAL_PAGE */
                        if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
                                return NULL;
                        if (is_zero_pfn(pfn) || is_huge_zero_pfn(pfn))
index 3639aa8dd2b06ebe5b9cfcfe6669994fd38c482d..cb1c2a8afe26583e49edadf38050d1bae58354f5 100644 (file)
@@ -467,13 +467,21 @@ struct vm_operations_struct {
        struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
                                        unsigned long addr, pgoff_t *ilx);
 #endif
+#ifdef CONFIG_FIND_NORMAL_PAGE
        /*
-        * Called by vm_normal_page() for special PTEs to find the
-        * page for @addr.  This is useful if the default behavior
-        * (using pte_page()) would not find the correct page.
+        * Called by vm_normal_page() for special PTEs in @vma at @addr. This
+        * allows for returning a "normal" page from vm_normal_page() even
+        * though the PTE indicates that the "struct page" either does not exist
+        * or should not be touched: "special".
+        *
+        * Do not add new users: this really only works when a "normal" page
+        * was mapped, but then the PTE got changed to something weird (+
+        * marked special) that would not make pte_pfn() identify the originally
+        * inserted page.
         */
-       struct page *(*find_special_page)(struct vm_area_struct *vma,
-                                         unsigned long addr);
+       struct page *(*find_normal_page)(struct vm_area_struct *vma,
+                                        unsigned long addr);
+#endif /* CONFIG_FIND_NORMAL_PAGE */
 };
 
 struct vm_unmapped_area_info {