powerpc/mm/radix/hugetlb: Add helper for finding page size from hstate
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Wed, 13 Jul 2016 09:36:42 +0000 (15:06 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 1 Aug 2016 01:15:12 +0000 (11:15 +1000)
Use the helper instead of open coding the same at multiple place

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/book3s/64/hugetlb-radix.h
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h
arch/powerpc/mm/hugetlbpage-radix.c
arch/powerpc/mm/tlb-radix.c

index 60f47649306fe8297af8d40860dabd1260ef0e25..c45189aa7476f844fc2400901e630c93d53c68c9 100644 (file)
@@ -11,4 +11,19 @@ extern unsigned long
 radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
                                unsigned long len, unsigned long pgoff,
                                unsigned long flags);
+
+static inline int hstate_get_psize(struct hstate *hstate)
+{
+       unsigned long shift;
+
+       shift = huge_page_shift(hstate);
+       if (shift == mmu_psize_defs[MMU_PAGE_2M].shift)
+               return MMU_PAGE_2M;
+       else if (shift == mmu_psize_defs[MMU_PAGE_1G].shift)
+               return MMU_PAGE_1G;
+       else {
+               WARN(1, "Wrong huge page shift\n");
+               return mmu_virtual_psize;
+       }
+}
 #endif
index a0c7f76c13b3bd4020cd59123b0e3ef254d2d7fd..10eb0d1e31404c2435484d6b1bef491eed5a2646 100644 (file)
@@ -22,14 +22,14 @@ extern void radix__local_flush_tlb_mm(struct mm_struct *mm);
 extern void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
 extern void radix__local_flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr);
 extern void radix__local_flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
-                                             unsigned long ap);
+                                             int psize);
 extern void radix__tlb_flush(struct mmu_gather *tlb);
 #ifdef CONFIG_SMP
 extern void radix__flush_tlb_mm(struct mm_struct *mm);
 extern void radix__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
 extern void radix__flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr);
 extern void radix__flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
-                                       unsigned long ap);
+                                       int psize);
 #else
 #define radix__flush_tlb_mm(mm)                radix__local_flush_tlb_mm(mm)
 #define radix__flush_tlb_page(vma,addr)        radix__local_flush_tlb_page(vma,addr)
index 0dfa1816f0c64c1d0598438b2e6acb2a3eaa1bdf..1eca0deaf89b0c9683c53aca4eed1117d3d88506 100644 (file)
@@ -5,39 +5,24 @@
 #include <asm/cacheflush.h>
 #include <asm/machdep.h>
 #include <asm/mman.h>
+#include <asm/tlb.h>
 
 void radix__flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
 {
-       unsigned long ap, shift;
+       int psize;
        struct hstate *hstate = hstate_file(vma->vm_file);
 
-       shift = huge_page_shift(hstate);
-       if (shift == mmu_psize_defs[MMU_PAGE_2M].shift)
-               ap = mmu_get_ap(MMU_PAGE_2M);
-       else if (shift == mmu_psize_defs[MMU_PAGE_1G].shift)
-               ap = mmu_get_ap(MMU_PAGE_1G);
-       else {
-               WARN(1, "Wrong huge page shift\n");
-               return ;
-       }
-       radix__flush_tlb_page_psize(vma->vm_mm, vmaddr, ap);
+       psize = hstate_get_psize(hstate);
+       radix__flush_tlb_page_psize(vma->vm_mm, vmaddr, psize);
 }
 
 void radix__local_flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
 {
-       unsigned long ap, shift;
+       int psize;
        struct hstate *hstate = hstate_file(vma->vm_file);
 
-       shift = huge_page_shift(hstate);
-       if (shift == mmu_psize_defs[MMU_PAGE_2M].shift)
-               ap = mmu_get_ap(MMU_PAGE_2M);
-       else if (shift == mmu_psize_defs[MMU_PAGE_1G].shift)
-               ap = mmu_get_ap(MMU_PAGE_1G);
-       else {
-               WARN(1, "Wrong huge page shift\n");
-               return ;
-       }
-       radix__local_flush_tlb_page_psize(vma->vm_mm, vmaddr, ap);
+       psize = hstate_get_psize(hstate);
+       radix__local_flush_tlb_page_psize(vma->vm_mm, vmaddr, psize);
 }
 
 /*
index fb9974abdde7379b7cdacb602ff9e08da7c92640..48df05ef523100e9aa67eb29fadf8b22cd116daf 100644 (file)
@@ -141,9 +141,10 @@ void radix__local_flush_tlb_pwc(struct mmu_gather *tlb, unsigned long addr)
 EXPORT_SYMBOL(radix__local_flush_tlb_pwc);
 
 void radix__local_flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
-                                      unsigned long ap)
+                                      int psize)
 {
        unsigned long pid;
+       unsigned long ap = mmu_get_ap(psize);
 
        preempt_disable();
        pid = mm ? mm->context.id : 0;
@@ -160,7 +161,7 @@ void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmadd
                return __local_flush_hugetlb_page(vma, vmaddr);
 #endif
        radix__local_flush_tlb_page_psize(vma ? vma->vm_mm : NULL, vmaddr,
-                                         mmu_get_ap(mmu_virtual_psize));
+                                         mmu_virtual_psize);
 }
 EXPORT_SYMBOL(radix__local_flush_tlb_page);
 
@@ -216,9 +217,10 @@ no_context:
 EXPORT_SYMBOL(radix__flush_tlb_pwc);
 
 void radix__flush_tlb_page_psize(struct mm_struct *mm, unsigned long vmaddr,
-                                unsigned long ap)
+                                int psize)
 {
        unsigned long pid;
+       unsigned long ap = mmu_get_ap(psize);
 
        preempt_disable();
        pid = mm ? mm->context.id : 0;
@@ -245,7 +247,7 @@ void radix__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
                return flush_hugetlb_page(vma, vmaddr);
 #endif
        radix__flush_tlb_page_psize(vma ? vma->vm_mm : NULL, vmaddr,
-                                   mmu_get_ap(mmu_virtual_psize));
+                                   mmu_virtual_psize);
 }
 EXPORT_SYMBOL(radix__flush_tlb_page);