Skip to content

Commit 08d5b29

Browse files
soleentorvalds
authored andcommitted
mm: ptep_clear() page table helper
We have ptep_get_and_clear() and ptep_get_and_clear_full() helpers to clear PTE from user page tables, but there is no variant for simple clear of a present PTE from user page tables without using a low level pte_clear() which can be either native or para-virtualised. Add a new ptep_clear() that can be used in common code to clear PTEs from page table. We will need this call later in order to add a hook for page table check. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pasha Tatashin <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Rientjes <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Greg Thelen <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Slaby <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Kees Cook <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Muchun Song <[email protected]> Cc: Paul Turner <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Sami Tolvanen <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Wei Xu <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1eba86c commit 08d5b29

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

Documentation/vm/arch_pgtable_helpers.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ PTE Page Table Helpers
6666
+---------------------------+--------------------------------------------------+
6767
| pte_mknotpresent | Invalidates a mapped PTE |
6868
+---------------------------+--------------------------------------------------+
69-
| ptep_get_and_clear | Clears a PTE |
69+
| ptep_clear | Clears a PTE |
7070
+---------------------------+--------------------------------------------------+
71-
| ptep_get_and_clear_full | Clears a PTE |
71+
| ptep_get_and_clear | Clears and returns PTE |
72+
+---------------------------+--------------------------------------------------+
73+
| ptep_get_and_clear_full | Clears and returns PTE (batched PTE unmap) |
7274
+---------------------------+--------------------------------------------------+
7375
| ptep_test_and_clear_young | Clears young from a PTE |
7476
+---------------------------+--------------------------------------------------+

include/linux/pgtable.h

+8
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
258258
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
259259
#endif
260260

261+
#ifndef __HAVE_ARCH_PTEP_CLEAR
262+
static inline void ptep_clear(struct mm_struct *mm, unsigned long addr,
263+
pte_t *ptep)
264+
{
265+
pte_clear(mm, addr, ptep);
266+
}
267+
#endif
268+
261269
#ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR
262270
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
263271
unsigned long address,

mm/debug_vm_pgtable.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ static void __init pte_clear_tests(struct pgtable_debug_args *args)
652652
set_pte_at(args->mm, args->vaddr, args->ptep, pte);
653653
flush_dcache_page(page);
654654
barrier();
655-
pte_clear(args->mm, args->vaddr, args->ptep);
655+
ptep_clear(args->mm, args->vaddr, args->ptep);
656656
pte = ptep_get(args->ptep);
657657
WARN_ON(!pte_none(pte));
658658
}

mm/khugepaged.c

+2-10
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,7 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page,
756756
* ptl mostly unnecessary.
757757
*/
758758
spin_lock(ptl);
759-
/*
760-
* paravirt calls inside pte_clear here are
761-
* superfluous.
762-
*/
763-
pte_clear(vma->vm_mm, address, _pte);
759+
ptep_clear(vma->vm_mm, address, _pte);
764760
spin_unlock(ptl);
765761
}
766762
} else {
@@ -774,11 +770,7 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page,
774770
* inside page_remove_rmap().
775771
*/
776772
spin_lock(ptl);
777-
/*
778-
* paravirt calls inside pte_clear here are
779-
* superfluous.
780-
*/
781-
pte_clear(vma->vm_mm, address, _pte);
773+
ptep_clear(vma->vm_mm, address, _pte);
782774
page_remove_rmap(src_page, false);
783775
spin_unlock(ptl);
784776
free_page_and_swap_cache(src_page);

0 commit comments

Comments
 (0)