powerpc: use helper functions to get and set hash slots
authorRam Pai <linuxram@us.ibm.com>
Mon, 6 Nov 2017 08:50:51 +0000 (00:50 -0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 20 Dec 2017 07:57:25 +0000 (18:57 +1100)
replace redundant code in __hash_page_4K() and flush_hash_page()
with helper functions pte_get_hash_gslot() and pte_set_hidx()

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Ram Pai <linuxram@us.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/mm/hash64_4k.c
arch/powerpc/mm/hash_utils_64.c

index 6fa450c..5a69b51 100644 (file)
@@ -20,6 +20,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
                   pte_t *ptep, unsigned long trap, unsigned long flags,
                   int ssize, int subpg_prot)
 {
+       real_pte_t rpte;
        unsigned long hpte_group;
        unsigned long rflags, pa;
        unsigned long old_pte, new_pte;
@@ -54,6 +55,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
         * need to add in 0x1 if it's a read-only user page
         */
        rflags = htab_convert_pte_flags(new_pte);
+       rpte = __real_pte(__pte(old_pte), ptep);
 
        if (cpu_has_feature(CPU_FTR_NOEXECUTE) &&
            !cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
@@ -64,13 +66,10 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
                /*
                 * There MIGHT be an HPTE for this pte
                 */
-               hash = hpt_hash(vpn, shift, ssize);
-               if (old_pte & H_PAGE_F_SECOND)
-                       hash = ~hash;
-               slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
-               slot += (old_pte & H_PAGE_F_GIX) >> H_PAGE_F_GIX_SHIFT;
+               unsigned long gslot = pte_get_hash_gslot(vpn, shift, ssize,
+                                                        rpte, 0);
 
-               if (mmu_hash_ops.hpte_updatepp(slot, rflags, vpn, MMU_PAGE_4K,
+               if (mmu_hash_ops.hpte_updatepp(gslot, rflags, vpn, MMU_PAGE_4K,
                                               MMU_PAGE_4K, ssize, flags) == -1)
                        old_pte &= ~_PAGE_HPTEFLAGS;
        }
@@ -118,8 +117,7 @@ repeat:
                        return -1;
                }
                new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | H_PAGE_HASHPTE;
-               new_pte |= (slot << H_PAGE_F_GIX_SHIFT) &
-                       (H_PAGE_F_SECOND | H_PAGE_F_GIX);
+               new_pte |= pte_set_hidx(ptep, rpte, 0, slot);
        }
        *ptep = __pte(new_pte & ~H_PAGE_BUSY);
        return 0;
index 88102b6..0c802de 100644 (file)
@@ -1618,23 +1618,18 @@ unsigned long pte_get_hash_gslot(unsigned long vpn, unsigned long shift,
 void flush_hash_page(unsigned long vpn, real_pte_t pte, int psize, int ssize,
                     unsigned long flags)
 {
-       unsigned long hash, index, shift, hidx, slot;
+       unsigned long index, shift, gslot;
        int local = flags & HPTE_LOCAL_UPDATE;
 
        DBG_LOW("flush_hash_page(vpn=%016lx)\n", vpn);
        pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) {
-               hash = hpt_hash(vpn, shift, ssize);
-               hidx = __rpte_to_hidx(pte, index);
-               if (hidx & _PTEIDX_SECONDARY)
-                       hash = ~hash;
-               slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
-               slot += hidx & _PTEIDX_GROUP_IX;
-               DBG_LOW(" sub %ld: hash=%lx, hidx=%lx\n", index, slot, hidx);
+               gslot = pte_get_hash_gslot(vpn, shift, ssize, pte, index);
+               DBG_LOW(" sub %ld: gslot=%lx\n", index, gslot);
                /*
                 * We use same base page size and actual psize, because we don't
                 * use these functions for hugepage
                 */
-               mmu_hash_ops.hpte_invalidate(slot, vpn, psize, psize,
+               mmu_hash_ops.hpte_invalidate(gslot, vpn, psize, psize,
                                             ssize, local);
        } pte_iterate_hashed_end();