The generic implementation of pte_{alloc_one,free}_kernel now calls
the [cd]tor, without initialising the ptlock needlessly as
pagetable_pte_ctor() skips it for init_mm.

On powerpc, all functions related to PTE allocation are implemented
by common helpers, which are passed a boolean to differentiate user
from kernel pgtables. This patch aligns the powerpc implementation
with the generic one by calling pagetable_pte_[cd]tor()
unconditionally in those helpers.

Signed-off-by: Kevin Brodsky <kevin.brod...@arm.com>
---
 arch/powerpc/mm/pgtable-frag.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/mm/pgtable-frag.c b/arch/powerpc/mm/pgtable-frag.c
index 387e9b1fe12c..77e55eac16e4 100644
--- a/arch/powerpc/mm/pgtable-frag.c
+++ b/arch/powerpc/mm/pgtable-frag.c
@@ -56,19 +56,17 @@ static pte_t *__alloc_for_ptecache(struct mm_struct *mm, 
int kernel)
 {
        void *ret = NULL;
        struct ptdesc *ptdesc;
+       gfp_t gfp = PGALLOC_GFP;
 
-       if (!kernel) {
-               ptdesc = pagetable_alloc(PGALLOC_GFP | __GFP_ACCOUNT, 0);
-               if (!ptdesc)
-                       return NULL;
-               if (!pagetable_pte_ctor(mm, ptdesc)) {
-                       pagetable_free(ptdesc);
-                       return NULL;
-               }
-       } else {
-               ptdesc = pagetable_alloc(PGALLOC_GFP, 0);
-               if (!ptdesc)
-                       return NULL;
+       if (!kernel)
+               gfp |= __GFP_ACCOUNT;
+
+       ptdesc = pagetable_alloc(gfp, 0);
+       if (!ptdesc)
+               return NULL;
+       if (!pagetable_pte_ctor(mm, ptdesc)) {
+               pagetable_free(ptdesc);
+               return NULL;
        }
 
        atomic_set(&ptdesc->pt_frag_refcount, 1);
@@ -124,12 +122,10 @@ void pte_fragment_free(unsigned long *table, int kernel)
 
        BUG_ON(atomic_read(&ptdesc->pt_frag_refcount) <= 0);
        if (atomic_dec_and_test(&ptdesc->pt_frag_refcount)) {
-               if (kernel)
-                       pagetable_free(ptdesc);
-               else if (folio_test_clear_active(ptdesc_folio(ptdesc)))
-                       call_rcu(&ptdesc->pt_rcu_head, pte_free_now);
-               else
+               if (kernel || !folio_test_clear_active(ptdesc_folio(ptdesc)))
                        pte_free_now(&ptdesc->pt_rcu_head);
+               else
+                       call_rcu(&ptdesc->pt_rcu_head, pte_free_now);
        }
 }
 
-- 
2.47.0


Reply via email to