diff mbox series

[RFC,1/3] mm: ptep_clear() page table helper

Message ID 20211116220038.116484-2-pasha.tatashin@soleen.com (mailing list archive)
State New
Headers show
Series page table check | expand

Commit Message

Pasha Tatashin Nov. 16, 2021, 10 p.m. UTC
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.

Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 Documentation/vm/arch_pgtable_helpers.rst |  6 ++++--
 include/linux/pgtable.h                   |  8 ++++++++
 mm/khugepaged.c                           | 12 ++----------
 3 files changed, 14 insertions(+), 12 deletions(-)

Comments

Anshuman Khandual Nov. 17, 2021, 8:51 a.m. UTC | #1
On 11/17/21 3:30 AM, Pasha Tatashin wrote:
> diff --git a/Documentation/vm/arch_pgtable_helpers.rst b/Documentation/vm/arch_pgtable_helpers.rst
> index 552567d863b8..fbe06ec75370 100644
> --- a/Documentation/vm/arch_pgtable_helpers.rst
> +++ b/Documentation/vm/arch_pgtable_helpers.rst
> @@ -66,9 +66,11 @@ PTE Page Table Helpers
>  +---------------------------+--------------------------------------------------+
>  | pte_mknotpresent          | Invalidates a mapped PTE                         |
>  +---------------------------+--------------------------------------------------+
> -| ptep_get_and_clear        | Clears a PTE                                     |
> +| ptep_clear                | Clears a PTE                                     |
>  +---------------------------+--------------------------------------------------+
> -| ptep_get_and_clear_full   | Clears a PTE                                     |
> +| ptep_get_and_clear        | Clears and returns PTE                           |
> ++---------------------------+--------------------------------------------------+
> +| ptep_get_and_clear_full   | Clears and returns PTE (batched PTE unmap)       |
>  +---------------------------+--------------------------------------------------+
>  | ptep_test_and_clear_young | Clears young from a PTE                          |
>  +---------------------------+--------------------------------------------------+

Just curious. This does not have a corresponding change in mm/debug_vm_pgtable.c ?
Pasha Tatashin Nov. 17, 2021, 4:43 p.m. UTC | #2
On Wed, Nov 17, 2021 at 3:52 AM Anshuman Khandual
<anshuman.khandual@arm.com> wrote:
>
>
>
> On 11/17/21 3:30 AM, Pasha Tatashin wrote:
> > diff --git a/Documentation/vm/arch_pgtable_helpers.rst b/Documentation/vm/arch_pgtable_helpers.rst
> > index 552567d863b8..fbe06ec75370 100644
> > --- a/Documentation/vm/arch_pgtable_helpers.rst
> > +++ b/Documentation/vm/arch_pgtable_helpers.rst
> > @@ -66,9 +66,11 @@ PTE Page Table Helpers
> >  +---------------------------+--------------------------------------------------+
> >  | pte_mknotpresent          | Invalidates a mapped PTE                         |
> >  +---------------------------+--------------------------------------------------+
> > -| ptep_get_and_clear        | Clears a PTE                                     |
> > +| ptep_clear                | Clears a PTE                                     |
> >  +---------------------------+--------------------------------------------------+
> > -| ptep_get_and_clear_full   | Clears a PTE                                     |
> > +| ptep_get_and_clear        | Clears and returns PTE                           |
> > ++---------------------------+--------------------------------------------------+
> > +| ptep_get_and_clear_full   | Clears and returns PTE (batched PTE unmap)       |
> >  +---------------------------+--------------------------------------------------+
> >  | ptep_test_and_clear_young | Clears young from a PTE                          |
> >  +---------------------------+--------------------------------------------------+
>
> Just curious. This does not have a corresponding change in mm/debug_vm_pgtable.c ?

You are right, I need to replace it in mm/debug_vm_pgtable.c as well.
I will do it in the next version.

Thanks,
Pasha
diff mbox series

Patch

diff --git a/Documentation/vm/arch_pgtable_helpers.rst b/Documentation/vm/arch_pgtable_helpers.rst
index 552567d863b8..fbe06ec75370 100644
--- a/Documentation/vm/arch_pgtable_helpers.rst
+++ b/Documentation/vm/arch_pgtable_helpers.rst
@@ -66,9 +66,11 @@  PTE Page Table Helpers
 +---------------------------+--------------------------------------------------+
 | pte_mknotpresent          | Invalidates a mapped PTE                         |
 +---------------------------+--------------------------------------------------+
-| ptep_get_and_clear        | Clears a PTE                                     |
+| ptep_clear                | Clears a PTE                                     |
 +---------------------------+--------------------------------------------------+
-| ptep_get_and_clear_full   | Clears a PTE                                     |
+| ptep_get_and_clear        | Clears and returns PTE                           |
++---------------------------+--------------------------------------------------+
+| ptep_get_and_clear_full   | Clears and returns PTE (batched PTE unmap)       |
 +---------------------------+--------------------------------------------------+
 | ptep_test_and_clear_young | Clears young from a PTE                          |
 +---------------------------+--------------------------------------------------+
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index e24d2c992b11..bc8713a76e03 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -258,6 +258,14 @@  static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 #endif
 
+#ifndef __HAVE_ARCH_PTEP_CLEAR
+static inline void ptep_clear(struct mm_struct *mm, unsigned long addr,
+			      pte_t *ptep)
+{
+	pte_clear(mm, addr, ptep);
+}
+#endif
+
 #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR
 static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 				       unsigned long address,
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 5f02fda6f265..6ae659ef7e08 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -756,11 +756,7 @@  static void __collapse_huge_page_copy(pte_t *pte, struct page *page,
 				 * ptl mostly unnecessary.
 				 */
 				spin_lock(ptl);
-				/*
-				 * paravirt calls inside pte_clear here are
-				 * superfluous.
-				 */
-				pte_clear(vma->vm_mm, address, _pte);
+				ptep_clear(vma->vm_mm, address, _pte);
 				spin_unlock(ptl);
 			}
 		} else {
@@ -774,11 +770,7 @@  static void __collapse_huge_page_copy(pte_t *pte, struct page *page,
 			 * inside page_remove_rmap().
 			 */
 			spin_lock(ptl);
-			/*
-			 * paravirt calls inside pte_clear here are
-			 * superfluous.
-			 */
-			pte_clear(vma->vm_mm, address, _pte);
+			ptep_clear(vma->vm_mm, address, _pte);
 			page_remove_rmap(src_page, false);
 			spin_unlock(ptl);
 			free_page_and_swap_cache(src_page);