]> Git Repo - linux.git/commitdiff
mm/pagewalk: walk_pte_range() allow for pte_offset_map()
authorHugh Dickins <[email protected]>
Fri, 9 Jun 2023 01:18:49 +0000 (18:18 -0700)
committerAndrew Morton <[email protected]>
Mon, 19 Jun 2023 23:19:14 +0000 (16:19 -0700)
walk_pte_range() has a no_vma option to serve walk_page_range_novma().  I
don't know of any problem, but it looks safer to check for init_mm, and
use pte_offset_kernel() rather than pte_offset_map() in that case:
pte_offset_map()'s pmdval validation is intended for userspace.

Allow for its pte_offset_map() or pte_offset_map_lock() to fail, and retry
with ACTION_AGAIN if so.  Add a second check for ACTION_AGAIN in
walk_pmd_range(), to catch it after return from walk_pte_range().

Remove the pmd_trans_unstable() check after split_huge_pmd() in
walk_pmd_range(): walk_pte_range() now handles those cases safely (and
they must fail powerpc's is_hugepd() check).

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Hugh Dickins <[email protected]>
Cc: Alistair Popple <[email protected]>
Cc: Anshuman Khandual <[email protected]>
Cc: Axel Rasmussen <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: "Huang, Ying" <[email protected]>
Cc: Ira Weiny <[email protected]>
Cc: Jason Gunthorpe <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Miaohe Lin <[email protected]>
Cc: Mike Kravetz <[email protected]>
Cc: Mike Rapoport (IBM) <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Naoya Horiguchi <[email protected]>
Cc: Pavel Tatashin <[email protected]>
Cc: Peter Xu <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Qi Zheng <[email protected]>
Cc: Ralph Campbell <[email protected]>
Cc: Ryan Roberts <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Steven Price <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Thomas Hellström <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Yang Shi <[email protected]>
Cc: Yu Zhao <[email protected]>
Cc: Zack Rusin <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
mm/pagewalk.c

index cb23f8a15c134af536b9464e425660aba3f5ea6d..64437105fe0d928d7447f121d24c57fe8363f574 100644 (file)
@@ -46,15 +46,27 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
        spinlock_t *ptl;
 
        if (walk->no_vma) {
-               pte = pte_offset_map(pmd, addr);
-               err = walk_pte_range_inner(pte, addr, end, walk);
-               pte_unmap(pte);
+               /*
+                * pte_offset_map() might apply user-specific validation.
+                */
+               if (walk->mm == &init_mm)
+                       pte = pte_offset_kernel(pmd, addr);
+               else
+                       pte = pte_offset_map(pmd, addr);
+               if (pte) {
+                       err = walk_pte_range_inner(pte, addr, end, walk);
+                       if (walk->mm != &init_mm)
+                               pte_unmap(pte);
+               }
        } else {
                pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
-               err = walk_pte_range_inner(pte, addr, end, walk);
-               pte_unmap_unlock(pte, ptl);
+               if (pte) {
+                       err = walk_pte_range_inner(pte, addr, end, walk);
+                       pte_unmap_unlock(pte, ptl);
+               }
        }
-
+       if (!pte)
+               walk->action = ACTION_AGAIN;
        return err;
 }
 
@@ -141,11 +153,8 @@ again:
                    !(ops->pte_entry))
                        continue;
 
-               if (walk->vma) {
+               if (walk->vma)
                        split_huge_pmd(walk->vma, pmd, addr);
-                       if (pmd_trans_unstable(pmd))
-                               goto again;
-               }
 
                if (is_hugepd(__hugepd(pmd_val(*pmd))))
                        err = walk_hugepd_range((hugepd_t *)pmd, addr, next, walk, PMD_SHIFT);
@@ -153,6 +162,10 @@ again:
                        err = walk_pte_range(pmd, addr, next, walk);
                if (err)
                        break;
+
+               if (walk->action == ACTION_AGAIN)
+                       goto again;
+
        } while (pmd++, addr = next, addr != end);
 
        return err;
This page took 0.054509 seconds and 4 git commands to generate.