TLB flush improvments and Segment table support
Subsystems (12)
v2 cover TLB flush improvments and Segment table support
This series include patches which got posted earlier as independent series. Some of this patches will go upstream via -mm tree.
Changes from V1:
* Address review feedback
* rebase on top of radix fixes which got posted earlier
* Fixes for segment table support.
NOTE:
Even though the patch series include changes to generic mm and other architectures this series is not cross-posted. That is because, the generic mm changes got posted as a separate patch series which can be found at
http://thread.gmane.org/gmane.linux.kernel.mm/152620
Aneesh Kumar K.V (16):
mm/hugetlb: Simplify hugetlb unmap
mm: Change the interface for __tlb_remove_page mm/mmu_gather: Track page size with mmu gather and force flush if page
size change
powerpc/mm/radix: Implement tlb mmu gather flush efficiently powerpc/mm: Make MMU_FTR_RADIX a MMU family feature powerpc/mm/hash: Add helper for finding SLBE LLP encoding powerpc/mm: Use hugetlb flush functions
powerpc/mm: Drop multiple definition of mm_is_core_local powerpc/mm/radix: Add tlb flush of THP ptes powerpc/mm/radix: Rename function and drop unused arg powerpc/mm/radix/hugetlb: Add helper for finding page size from hstate powerpc/mm/hugetlb: Add flush_hugetlb_tlb_range powerpc/mm: remove flush_tlb_page_nohash
powerpc/mm: Cleanup LPCR defines
powerpc/mm: Switch user slb fault handling to translation enabled powerpc/mm: Support segment table for Power9
arch/arm/include/asm/tlb.h | 29 +- arch/ia64/include/asm/tlb.h | 31 +- arch/powerpc/include/asm/book3s/64/hash.h | 10 + arch/powerpc/include/asm/book3s/64/hugetlb-radix.h | 15 + arch/powerpc/include/asm/book3s/64/mmu-hash.h | 26 ++ arch/powerpc/include/asm/book3s/64/mmu.h | 7 +- arch/powerpc/include/asm/book3s/64/tlbflush-hash.h | 5 - .../powerpc/include/asm/book3s/64/tlbflush-radix.h | 16 +- arch/powerpc/include/asm/book3s/64/tlbflush.h | 27 +- arch/powerpc/include/asm/hugetlb.h | 2 +- arch/powerpc/include/asm/kvm_book3s_64.h | 3 +- arch/powerpc/include/asm/mmu.h | 18 +- arch/powerpc/include/asm/mmu_context.h | 5 +- arch/powerpc/include/asm/reg.h | 54 ++-- arch/powerpc/include/asm/tlb.h | 13 + arch/powerpc/include/asm/tlbflush.h | 1 - arch/powerpc/kernel/entry_64.S | 2 +- arch/powerpc/kernel/exceptions-64s.S | 63 +++- arch/powerpc/kernel/prom.c | 3 +- arch/powerpc/mm/hash_native_64.c | 6 +- arch/powerpc/mm/hash_utils_64.c | 86 ++++- arch/powerpc/mm/hugetlbpage-radix.c | 39 +-- arch/powerpc/mm/mmu_context_book3s64.c | 32 +- arch/powerpc/mm/pgtable-book3s64.c | 4 +- arch/powerpc/mm/pgtable.c | 2 +- arch/powerpc/mm/slb.c | 359 +++++++++++++++++++++ arch/powerpc/mm/tlb-radix.c | 104 +++++- arch/powerpc/mm/tlb_hash32.c | 11 - arch/powerpc/mm/tlb_nohash.c | 6 - arch/s390/include/asm/tlb.h | 22 +- arch/sh/include/asm/tlb.h | 20 +- arch/um/include/asm/tlb.h | 20 +- include/asm-generic/tlb.h | 59 +++- mm/huge_memory.c | 2 +- mm/hugetlb.c | 64 ++-- mm/memory.c | 27 +- 36 files changed, 981 insertions(+), 212 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/16 mm/hugetlb: Simplify hugetlb unmap
For hugetlb like THP (and unlike regular page), we do tlb flush after dropping ptl. Because of the above, we don't need to track force_flush like we do now. Instead we can simply call tlb_remove_page() which will do the flush if needed.
No functionality change in this patch.
--- mm/hugetlb.c | 54 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-)
mm/hugetlb.c +21 -33
@@ -3138,7 +3138,6 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long start, unsigned long end, struct page *ref_page) { - int force_flush = 0; struct mm_struct *mm = vma->vm_mm;unsigned long address;pte_t *ptep;
@@ -3157,19 +3156,22 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,tlb_start_vma (tlb, vma);mmu_notifier_invalidate_range_start (mm, mmun_start, mmun_end); address = start; -again:for (; address < end; address += sz) { ptep =huge_pte_offset (mm, address);if (!ptep)continue ; ptl =huge_pte_lock (h, mm, ptep); -if (huge_pmd_unshare (mm, &address, ptep)) - goto unlock; +if (huge_pmd_unshare (mm, &address, ptep)) { +spin_unlock (ptl); +continue ; + } pte =huge_ptep_get (ptep); -if (huge_pte_none (pte)) - goto unlock; +if (huge_pte_none (pte)) { +spin_unlock (ptl); +continue ; + }/* * Migrating hugepage or HWPoisoned hugepage is already
@@ -3177,7 +3179,8 @@ again:*/ if (unlikely (!pte_present (pte))) {huge_pte_clear (mm, address, ptep); - goto unlock; +spin_unlock (ptl); +continue ; } page =pte_page (pte);
@@ -3187,9 +3190,10 @@ again:* are about to unmap is the actual page of interest. */ if (ref_page) { -if (page != ref_page) - goto unlock; - +if (page != ref_page) { +spin_unlock (ptl); +continue ; + }/* * Mark the VMA as having unmapped its page so that * future faults in this VMA will fail rather than
@@ -3205,30 +3209,14 @@ again:hugetlb_count_sub (pages_per_huge_page (h), mm);page_remove_rmap (page, true); - force_flush = !__tlb_remove_page (tlb, page); -if (force_flush) { - address += sz; -spin_unlock (ptl); -break ; - } -/* Bail out after unmapping reference page if supplied */ -if (ref_page) { -spin_unlock (ptl); -break ; - } -unlock: +spin_unlock (ptl); - } -/* -* mmu_gather ran out of room to batch pages, we break out of -* the PTE lock to avoid doing the potential expensive TLB invalidate -* and page-free while holding it. -*/ -if (force_flush) { - force_flush =0 ; -tlb_flush_mmu (tlb); -if (address < end && !ref_page) - goto again; +tlb_remove_page (tlb, page); +/* +* Bail out after unmapping reference page if supplied +*/ +if (ref_page) +break ; }mmu_notifier_invalidate_range_end (mm, mmun_start, mmun_end);tlb_end_vma (tlb, vma);
Signature · 1 line
2.7.4
PATCH v2 2/16 mm: Change the interface for __tlb_remove_page
In reply to Aneesh Kumar K.VThis update the generic and arch specific implementation to return true if we need to do a tlb flush. That means if a __tlb_remove_page indicate a flush is needed, the page we try to remove need to be tracked and added again after the flush. We need to track it because we have already update the pte to none and we can't just loop back.
This changes is done to enable us to do a tlb_flush when we try to flush a range that consists of different page sizes. For architectures like ppc64, we can do a range based tlb flush and we need to track page size for that. When we try to remove a huge page, we will force a tlb flush and starts a new mmu gather.
--- arch/arm/include/asm/tlb.h | 17 +++++++++++++---- arch/ia64/include/asm/tlb.h | 19 ++++++++++++++----- arch/s390/include/asm/tlb.h | 9 +++++++-- arch/sh/include/asm/tlb.h | 8 +++++++- arch/um/include/asm/tlb.h | 8 +++++++- include/asm-generic/tlb.h | 44 +++++++++++++++++++++++++++++++++----------- mm/memory.c | 19 +++++++++++++------ 7 files changed, 94 insertions(+), 30 deletions(-)
arch/arm/include/asm/tlb.h +13 -4
@@ -209,17 +209,26 @@ tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)tlb_flush (tlb); } -static inline int __tlb_remove_page (struct mmu_gather *tlb,struct page *page) +static inline bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page) { +if (tlb->nr == tlb->max) +return true; tlb->pages[tlb->nr++] = page; -VM_BUG_ON (tlb->nr > tlb->max); -return tlb->max - tlb->nr; +return false; }static inline void tlb_remove_page (struct mmu_gather *tlb,struct page *page) { -if (!__tlb_remove_page (tlb, page)) +if (__tlb_remove_page (tlb, page)) {tlb_flush_mmu (tlb); +__tlb_remove_page (tlb, page); + } +} + +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb, +struct page *page) +{ +return __tlb_remove_page (tlb, page); } static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
arch/ia64/include/asm/tlb.h +14 -5
@@ -205,17 +205,18 @@ tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)* must be delayed until after the TLB has been flushed (see comments at the beginning of * this file). */ -static inline int __tlb_remove_page (struct mmu_gather *tlb,struct page *page) +static inline bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page) { +if (tlb->nr == tlb->max) +return true; + tlb->need_flush =1 ;if (!tlb->nr && tlb->pages == tlb->local)__tlb_alloc_page (tlb); tlb->pages[tlb->nr++] = page; -VM_BUG_ON (tlb->nr > tlb->max); - -return tlb->max - tlb->nr; +return false; }static inline void tlb_flush_mmu_tlbonly (struct mmu_gather *tlb)
@@ -235,8 +236,16 @@ static inline void tlb_flush_mmu(struct mmu_gather *tlb)static inline void tlb_remove_page (struct mmu_gather *tlb,struct page *page) { -if (!__tlb_remove_page (tlb, page)) +if (__tlb_remove_page (tlb, page)) {tlb_flush_mmu (tlb); +__tlb_remove_page (tlb, page); + } +} + +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb, +struct page *page) +{ +return __tlb_remove_page (tlb, page); }/*
arch/s390/include/asm/tlb.h +7 -2
@@ -87,10 +87,10 @@ static inline void tlb_finish_mmu(struct mmu_gather *tlb,* tlb_ptep_clear_flush. In both flush modes the tlb for a page cache page * has already been freed, so just do free_page_and_swap_cache. */ -static inline int __tlb_remove_page (struct mmu_gather *tlb,struct page *page) +static inline bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page) {free_page_and_swap_cache (page); -return 1 ;/* avoid calling tlb_flush_mmu */ +return false;/* avoid calling tlb_flush_mmu */ }static inline void tlb_remove_page (struct mmu_gather *tlb,struct page *page)
@@ -98,6 +98,11 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)free_page_and_swap_cache (page); } +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb, +struct page *page) +{ +return __tlb_remove_page (tlb, page); +}/* * pte_free_tlb frees a pte table and clears the CRSTE for the * page table from the tlb.
arch/sh/include/asm/tlb.h +7 -1
@@ -101,7 +101,7 @@ static inline void tlb_flush_mmu(struct mmu_gather *tlb)static inline int __tlb_remove_page (struct mmu_gather *tlb,struct page *page) {free_page_and_swap_cache (page); -return 1 ;/* avoid calling tlb_flush_mmu */ +return false;/* avoid calling tlb_flush_mmu */ }static inline void tlb_remove_page (struct mmu_gather *tlb,struct page *page)
@@ -109,6 +109,12 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)__tlb_remove_page (tlb, page); } +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb, +struct page *page) +{ +return __tlb_remove_page (tlb, page); +} +#define pte_free_tlb (tlb, ptep, addr) pte_free((tlb)->mm, ptep)#define pmd_free_tlb (tlb, pmdp, addr) pmd_free((tlb)->mm, pmdp)#define pud_free_tlb (tlb, pudp, addr) pud_free((tlb)->mm, pudp)
arch/um/include/asm/tlb.h +7 -1
@@ -102,7 +102,7 @@ static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page) { tlb->need_flush =1 ;free_page_and_swap_cache (page); -return 1 ;/* avoid calling tlb_flush_mmu */ +return false;/* avoid calling tlb_flush_mmu */ }static inline void tlb_remove_page (struct mmu_gather *tlb,struct page *page)
@@ -110,6 +110,12 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)__tlb_remove_page (tlb, page); } +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb, +struct page *page) +{ +return __tlb_remove_page (tlb, page); +} +/** * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation. *
include/asm-generic/tlb.h +33 -11
68 lines not on this page · raw message
mm/memory.c +13 -6
@@ -292,23 +292,24 @@ void tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long e* handling the additional races in SMP caused by other CPUs caching valid * mappings in their TLBs. Returns the number of free page slots left. * When out of page slots we must call tlb_flush_mmu(). +*returns true if the caller should flush. */ -int __tlb_remove_page (struct mmu_gather *tlb,struct page *page) +bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page) {struct mmu_gather_batch *batch;VM_BUG_ON (!tlb->end); batch = tlb->active; - batch->pages[batch->nr++] = page;if (batch->nr == batch->max) {if (!tlb_next_batch (tlb)) -return 0 ; +return true; batch = tlb->active; }VM_BUG_ON_PAGE (batch->nr > batch->max, page); -return batch->max - batch->nr; + batch->pages[batch->nr++] = page; +return false; }#endif /* HAVE_GENERIC_MMU_GATHER */
@@ -1109,6 +1110,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,pte_t *start_pte;pte_t *pte;swp_entry_t entry; +struct page *pending_page =NULL ; again:init_rss_vec (rss);
@@ -1160,8 +1162,9 @@ again:page_remove_rmap (page, false);if (unlikely (page_mapcount (page) <0 ))print_bad_pte (vma, addr, ptent, page); -if (unlikely (!__tlb_remove_page (tlb, page))) { +if (unlikely (__tlb_remove_page (tlb, page))) { force_flush =1 ; + pending_page = page; addr +=PAGE_SIZE ;break ; }
@@ -1202,7 +1205,11 @@ again:if (force_flush) { force_flush =0 ;tlb_flush_mmu_free (tlb); - +if (pending_page) { +/* remove the page with new size */ +__tlb_remove_pte_page (tlb, pending_page); + pending_page =NULL ; + }if (addr != end) goto again; }
Signature · 1 line
2.7.4
PATCH v2 3/16 mm/mmu_gather: Track page size with mmu gather and force flush if page size change
In reply to Aneesh Kumar K.VThis allows arch which need to do special handing with respect to different page size when flushing tlb to implement the same in mmu gather
--- arch/arm/include/asm/tlb.h | 12 ++++++++++++ arch/ia64/include/asm/tlb.h | 12 ++++++++++++ arch/s390/include/asm/tlb.h | 13 +++++++++++++ arch/sh/include/asm/tlb.h | 12 ++++++++++++ arch/um/include/asm/tlb.h | 12 ++++++++++++ include/asm-generic/tlb.h | 27 +++++++++++++++++++++------ mm/huge_memory.c | 2 +- mm/hugetlb.c | 2 +- mm/memory.c | 10 +++++++++- 9 files changed, 93 insertions(+), 9 deletions(-)
arch/arm/include/asm/tlb.h +12 -0
@@ -225,12 +225,24 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) } } +static inline bool __tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return __tlb_remove_page (tlb, page); +} +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb,struct page *page) {return __tlb_remove_page (tlb, page); } +static inline void tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return tlb_remove_page (tlb, page); +} +static inline void __pte_free_tlb (struct mmu_gather *tlb,pgtable_t pte,unsigned long addr) {
arch/ia64/include/asm/tlb.h +12 -0
@@ -242,12 +242,24 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) } } +static inline bool __tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return __tlb_remove_page (tlb, page); +} +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb,struct page *page) {return __tlb_remove_page (tlb, page); } +static inline void tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return tlb_remove_page (tlb, page); +} +/* * Remove TLB entry for PTE mapped at virtual address ADDRESS. This is called for any * PTE, not just those pointing to (normal) physical memory.
arch/s390/include/asm/tlb.h +13 -0
@@ -98,11 +98,24 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)free_page_and_swap_cache (page); } +static inline bool __tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return __tlb_remove_page (tlb, page); +} +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb,struct page *page) {return __tlb_remove_page (tlb, page); } + +static inline void tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return tlb_remove_page (tlb, page); +} +/* * pte_free_tlb frees a pte table and clears the CRSTE for the * page table from the tlb.
arch/sh/include/asm/tlb.h +12 -0
@@ -109,12 +109,24 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)__tlb_remove_page (tlb, page); } +static inline bool __tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return __tlb_remove_page (tlb, page); +} +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb,struct page *page) {return __tlb_remove_page (tlb, page); } +static inline void tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return tlb_remove_page (tlb, page); +} +#define pte_free_tlb (tlb, ptep, addr) pte_free((tlb)->mm, ptep)#define pmd_free_tlb (tlb, pmdp, addr) pmd_free((tlb)->mm, pmdp)#define pud_free_tlb (tlb, pudp, addr) pud_free((tlb)->mm, pudp)
arch/um/include/asm/tlb.h +12 -0
@@ -110,12 +110,24 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)__tlb_remove_page (tlb, page); } +static inline bool __tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return __tlb_remove_page (tlb, page); +} +static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb,struct page *page) {return __tlb_remove_page (tlb, page); } +static inline void tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +return tlb_remove_page (tlb, page); +} +/** * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation. *
include/asm-generic/tlb.h +21 -6
@@ -112,6 +112,7 @@ struct mmu_gather {* that that we can adjust the range after the flush */ unsigned long addr; +int page_size; };#define HAVE_GENERIC_MMU_GATHER
@@ -120,7 +121,8 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned longvoid tlb_flush_mmu (struct mmu_gather *tlb);void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end); -bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page); +extern bool __tlb_remove_page_size (struct mmu_gather *tlb,struct page *page, +int page_size);static inline void __tlb_adjust_range (struct mmu_gather *tlb,unsigned long address)
@@ -145,23 +147,36 @@ static inline void __tlb_reset_range(struct mmu_gather *tlb) } } +static inline void tlb_remove_page_size (struct mmu_gather *tlb, +struct page *page,int page_size) +{ +if (__tlb_remove_page_size (tlb, page, page_size)) { +tlb_flush_mmu (tlb); + tlb->page_size = page_size; +__tlb_adjust_range (tlb, tlb->addr); +__tlb_remove_page_size (tlb, page, page_size); + } +} + +static bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page) +{ +return __tlb_remove_page_size (tlb, page,PAGE_SIZE ); +} +/* tlb_remove_page * Similar to __tlb_remove_page but will call tlb_flush_mmu() itself when * required. */ static inline void tlb_remove_page (struct mmu_gather *tlb,struct page *page) { -if (__tlb_remove_page (tlb, page)) { -tlb_flush_mmu (tlb); -__tlb_adjust_range (tlb, tlb->addr); -__tlb_remove_page (tlb, page); - } +return tlb_remove_page_size (tlb, page,PAGE_SIZE ); }static inline bool __tlb_remove_pte_page (struct mmu_gather *tlb,struct page *page) {/* active->nr should be zero when we call this */ VM_BUG_ON_PAGE (tlb->active->nr, page); + tlb->page_size =PAGE_SIZE ;__tlb_adjust_range (tlb, tlb->addr);return __tlb_remove_page (tlb, page); }
mm/huge_memory.c +1 -1
@@ -1694,7 +1694,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,pte_free (tlb->mm,pgtable_trans_huge_withdraw (tlb->mm, pmd));atomic_long_dec (&tlb->mm->nr_ptes);spin_unlock (ptl); -tlb_remove_page (tlb, page); +tlb_remove_page_size (tlb, page,HPAGE_PMD_SIZE ); }return 1 ; }
mm/hugetlb.c +1 -1
@@ -3211,7 +3211,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,page_remove_rmap (page, true);spin_unlock (ptl); -tlb_remove_page (tlb, page); +tlb_remove_page_size (tlb, page,huge_page_size (h));/* * Bail out after unmapping reference page if supplied */
mm/memory.c +9 -1
@@ -233,6 +233,7 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long#ifdef CONFIG_HAVE_RCU_TABLE_FREE tlb->batch =NULL ;#endif + tlb->page_size =0 ;__tlb_reset_range (tlb); }
@@ -294,12 +295,19 @@ void tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long e* When out of page slots we must call tlb_flush_mmu(). *returns true if the caller should flush. */ -bool __tlb_remove_page (struct mmu_gather *tlb,struct page *page) +bool __tlb_remove_page_size (struct mmu_gather *tlb,struct page *page,int page_size) {struct mmu_gather_batch *batch;VM_BUG_ON (!tlb->end); +if (!tlb->page_size) + tlb->page_size = page_size; +else { +if (page_size != tlb->page_size) +return true; + } + batch = tlb->active;if (batch->nr == batch->max) {if (!tlb_next_batch (tlb))
Signature · 1 line
2.7.4
PATCH v2 4/16 powerpc/mm/radix: Implement tlb mmu gather flush efficiently
In reply to Aneesh Kumar K.VNow that we track page size in mmu_gather, we can use address based tlbie format when doing a tlb_flush(). We don't do this if we are invalidating the full address space.
--- .../powerpc/include/asm/book3s/64/tlbflush-radix.h | 2 + arch/powerpc/mm/tlb-radix.c | 73 +++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +2 -0
@@ -10,6 +10,8 @@ static inline int mmu_get_ap(int psize)return mmu_psize_defs[psize].ap; } +extern void radix__flush_tlb_range_psize (struct mm_struct *mm,unsigned long start, +unsigned long end,int psize);extern void radix__flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end);extern void radix__flush_tlb_kernel_range (unsigned long start,unsigned long end);
arch/powerpc/mm/tlb-radix.c +72 -1
81 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 5/16 powerpc/mm: Make MMU_FTR_RADIX a MMU family feature
In reply to Aneesh Kumar K.VMMU feature bits are defined such that we use the lower half to present MMU family features. Remove the strict split of half and also move Radix to a mmu family feature. Radix introduce a new MMU model and strictly speaking it is a new MMU family. This also free up bits which can be used for individual features later.
--- arch/powerpc/include/asm/book3s/64/mmu.h | 3 +-- arch/powerpc/include/asm/mmu.h | 16 +++++++--------- arch/powerpc/kernel/entry_64.S | 2 +- arch/powerpc/kernel/exceptions-64s.S | 8 ++++---- arch/powerpc/kernel/prom.c | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-)
arch/powerpc/include/asm/book3s/64/mmu.h +1 -2
@@ -24,12 +24,11 @@ struct mmu_psize_def {extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT ];#ifdef CONFIG_PPC_RADIX_MMU -#define radix_enabled () mmu_has_feature(MMU_FTR_RADIX) +#define radix_enabled () mmu_has_feature(MMU_FTR_TYPE_RADIX)#else #define radix_enabled () (0)#endif -#endif /* __ASSEMBLY__ */ /* 64-bit classic hash table MMU */
arch/powerpc/include/asm/mmu.h +7 -9
@@ -12,7 +12,7 @@*/ /* -* First half is MMU families +* MMU families */ #define MMU_FTR_HPTE_TABLE ASM_CONST(0x00000001)#define MMU_FTR_TYPE_8xx ASM_CONST(0x00000002)
@@ -20,9 +20,12 @@#define MMU_FTR_TYPE_44x ASM_CONST(0x00000008)#define MMU_FTR_TYPE_FSL_E ASM_CONST(0x00000010)#define MMU_FTR_TYPE_47x ASM_CONST(0x00000020) -/* -* This is individual features +* Radix page table available +*/ +#define MMU_FTR_TYPE_RADIX ASM_CONST(0x00000040) +/* +* individual features */ /* * We need to clear top 16bits of va (from the remaining 64 bits )in
@@ -93,11 +96,6 @@*/ #define MMU_FTR_1T_SEGMENT ASM_CONST(0x40000000) -/* -* Radix page table available -*/ -#define MMU_FTR_RADIX ASM_CONST(0x80000000) -/* MMU feature bit sets for various CPUs */ #define MMU_FTRS_DEFAULT_HPTE_ARCH_V2 \ MMU_FTR_HPTE_TABLE | MMU_FTR_PPCAS_ARCH_V2
@@ -132,7 +130,7 @@ enum { MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE | MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA |#ifdef CONFIG_PPC_RADIX_MMU -MMU_FTR_RADIX | +MMU_FTR_TYPE_RADIX | #endif 0, };
arch/powerpc/kernel/entry_64.S +1 -1
@@ -532,7 +532,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) #ifdef CONFIG_PPC_STD_MMU_64 BEGIN_MMU_FTR_SECTION b 2f -END_MMU_FTR_SECTION_IFSET(MMU_FTR_RADIX) +END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX) BEGIN_FTR_SECTION clrrdi r6,r8,28 /* get its ESID */ clrrdi r9,r1,28 /* get current sp ESID */
arch/powerpc/kernel/exceptions-64s.S +4 -4
@@ -945,7 +945,7 @@ BEGIN_MMU_FTR_SECTION b do_hash_page /* Try to handle as hpte fault */ MMU_FTR_SECTION_ELSE b handle_page_fault -ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_RADIX) +ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) .align 7 .globl h_data_storage_common
@@ -976,7 +976,7 @@ BEGIN_MMU_FTR_SECTION b do_hash_page /* Try to handle as hpte fault */ MMU_FTR_SECTION_ELSE b handle_page_fault -ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_RADIX) +ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) STD_EXCEPTION_COMMON(0xe20, h_instr_storage, unknown_exception)
@@ -1390,7 +1390,7 @@ slb_miss_realmode: #ifdef CONFIG_PPC_STD_MMU_64 BEGIN_MMU_FTR_SECTION bl slb_allocate_realmode -END_MMU_FTR_SECTION_IFCLR(MMU_FTR_RADIX) +END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) #endif /* All done -- return from exception. */
@@ -1401,7 +1401,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_RADIX) mtlr r10 BEGIN_MMU_FTR_SECTION b 2f -END_MMU_FTR_SECTION_IFSET(MMU_FTR_RADIX) +END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX) andi. r10,r12,MSR_RI /* check for unrecoverable exception */ beq- 2f
arch/powerpc/kernel/prom.c +1 -1
@@ -168,7 +168,7 @@ static struct ibm_pa_feature {*/ {CPU_FTR_TM_COMP ,0 ,0 , PPC_FEATURE2_HTM_COMP|PPC_FEATURE2_HTM_NOSC_COMP, 22, 0, 0}, - {0, MMU_FTR_RADIX, 0, 0, 40, 0, 0}, + {0, MMU_FTR_TYPE_RADIX, 0, 0, 40, 0, 0}, }; static void __init scan_features(unsigned long node, const unsigned char *ftrs,
Signature · 1 line
2.7.4
PATCH v2 6/16 powerpc/mm/hash: Add helper for finding SLBE LLP encoding
In reply to Aneesh Kumar K.VReplace opencoding of the same at multiple places with the helper. No functional change with this patch.
--- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 9 +++++++++ arch/powerpc/include/asm/kvm_book3s_64.h | 3 +-- arch/powerpc/mm/hash_native_64.c | 6 ++---- 3 files changed, 12 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/book3s/64/mmu-hash.h +9 -0
@@ -151,6 +151,15 @@ static inline unsigned int mmu_psize_to_shift(unsigned int mmu_psize) BUG(); } +static inline unsigned long get_sllp_encoding (int psize) +{ +unsigned long sllp; + + sllp = ((mmu_psize_defs[psize].sllp &SLB_VSID_L ) >>6 ) | + ((mmu_psize_defs[psize].sllp &SLB_VSID_LP ) >>4 ); +return sllp; +} +#endif /* __ASSEMBLY__ */ /*
arch/powerpc/include/asm/kvm_book3s_64.h +1 -2
@@ -181,8 +181,7 @@ static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,switch (b_psize) {case MMU_PAGE_4K : - sllp = ((mmu_psize_defs[a_psize].sllp &SLB_VSID_L ) >>6 ) | - ((mmu_psize_defs[a_psize].sllp &SLB_VSID_LP ) >>4 ); + sllp =get_sllp_encoding (a_psize); rb |= sllp <<5 ;/* AP field */ rb |= (va_low &0x7ff ) <<12 ;/* remaining 11 bits of AVA */ break ;
arch/powerpc/mm/hash_native_64.c +2 -4
@@ -72,8 +72,7 @@ static inline void __tlbie(unsigned long vpn, int psize, int apsize, int ssize)/* clear out bits after (52) [0....52.....63] */ va &= ~((1ul << (64 -52 )) -1 ); va |= ssize <<8 ; - sllp = ((mmu_psize_defs[apsize].sllp &SLB_VSID_L ) >>6 ) | - ((mmu_psize_defs[apsize].sllp &SLB_VSID_LP ) >>4 ); + sllp =get_sllp_encoding (apsize); va |= sllp <<5 ; asm volatile(ASM_FTR_IFCLR("tlbie %0,0", PPC_TLBIE(%1,%0), %2) : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206)
@@ -122,8 +121,7 @@ static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize)/* clear out bits after(52) [0....52.....63] */ va &= ~((1ul << (64 -52 )) -1 ); va |= ssize <<8 ; - sllp = ((mmu_psize_defs[apsize].sllp &SLB_VSID_L ) >>6 ) | - ((mmu_psize_defs[apsize].sllp &SLB_VSID_LP ) >>4 ); + sllp =get_sllp_encoding (apsize); va |= sllp <<5 ; asmvolatile (".long 0x7c000224 | (%0 << 11) | (0 << 21)" : :"r" (va) :"memory" );
Signature · 1 line
2.7.4
PATCH v2 7/16 powerpc/mm: Use hugetlb flush functions
In reply to Aneesh Kumar K.VUse flush_hugetlb_page instead of flush_tlb_page when we clear flush the pte.
--- arch/powerpc/include/asm/hugetlb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/hugetlb.h +1 -1
@@ -147,7 +147,7 @@ static inline void huge_ptep_clear_flush(struct vm_area_struct *vma, {pte_t pte; pte =huge_ptep_get_and_clear (vma->vm_mm, addr, ptep); -flush_tlb_page (vma, addr); +flush_hugetlb_page (vma, addr); }static inline int huge_pte_none (pte_t pte)
Signature · 1 line
2.7.4
PATCH v2 8/16 powerpc/mm: Drop multiple definition of mm_is_core_local
In reply to Aneesh Kumar K.V--- arch/powerpc/include/asm/tlb.h | 13 +++++++++++++ arch/powerpc/mm/tlb-radix.c | 6 ------ arch/powerpc/mm/tlb_nohash.c | 6 ------ 3 files changed, 13 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/tlb.h +13 -0
@@ -46,5 +46,18 @@ static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep,#endif } +#ifdef CONFIG_SMP +static inline int mm_is_core_local (struct mm_struct *mm) +{ +return cpumask_subset (mm_cpumask (mm), +topology_sibling_cpumask (smp_processor_id ())); +} +#else +static inline int mm_is_core_local (struct mm_struct *mm) +{ +return 1 ; +} +#endif +#endif /* __KERNEL__ */ #endif /* __ASM_POWERPC_TLB_H */
arch/powerpc/mm/tlb-radix.c +0 -6
@@ -163,12 +163,6 @@ void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddEXPORT_SYMBOL (radix__local_flush_tlb_page);#ifdef CONFIG_SMP -static int mm_is_core_local (struct mm_struct *mm) -{ -return cpumask_subset (mm_cpumask (mm), -topology_sibling_cpumask (smp_processor_id ())); -} -void radix__flush_tlb_mm (struct mm_struct *mm) {unsigned long pid;
arch/powerpc/mm/tlb_nohash.c +0 -6
@@ -215,12 +215,6 @@ EXPORT_SYMBOL(local_flush_tlb_page);static DEFINE_RAW_SPINLOCK (tlbivax_lock); -static int mm_is_core_local (struct mm_struct *mm) -{ -return cpumask_subset (mm_cpumask (mm), -topology_sibling_cpumask (smp_processor_id ())); -} -struct tlb_flush_param {unsigned long addr;unsigned int pid;
Signature · 1 line
2.7.4
PATCH v2 9/16 powerpc/mm/radix: Add tlb flush of THP ptes
In reply to Aneesh Kumar K.VInstead of flushing the entire mm, implement a flush_pmd_tlb_range
--- arch/powerpc/include/asm/book3s/64/tlbflush-radix.h | 2 ++ arch/powerpc/include/asm/book3s/64/tlbflush.h | 9 +++++++++ arch/powerpc/mm/pgtable-book3s64.c | 4 ++-- arch/powerpc/mm/tlb-radix.c | 7 +++++++ 4 files changed, 20 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +2 -0
@@ -12,6 +12,8 @@ static inline int mmu_get_ap(int psize)extern void radix__flush_tlb_range_psize (struct mm_struct *mm,unsigned long start,unsigned long end,int psize); +extern void radix__flush_pmd_tlb_range (struct vm_area_struct *vma, +unsigned long start,unsigned long end);extern void radix__flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end);extern void radix__flush_tlb_kernel_range (unsigned long start,unsigned long end);
arch/powerpc/include/asm/book3s/64/tlbflush.h +9 -0
@@ -7,6 +7,15 @@#include <asm/book3s/64/tlbflush-hash.h> #include <asm/book3s/64/tlbflush-radix.h> +#define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE +static inline void flush_pmd_tlb_range (struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +if (radix_enabled ()) +return radix__flush_pmd_tlb_range (vma, start, end); +return hash__flush_tlb_range (vma, start, end); +} +static inline void flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end) {
arch/powerpc/mm/pgtable-book3s64.c +2 -2
@@ -33,7 +33,7 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address, changed = !pmd_same (*(pmdp), entry);if (changed) {__ptep_set_access_flags (pmdp_ptep (pmdp),pmd_pte (entry)); -flush_tlb_range (vma, address, address +HPAGE_PMD_SIZE ); +flush_pmd_tlb_range (vma, address, address +HPAGE_PMD_SIZE ); }return changed; }
@@ -66,7 +66,7 @@ void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp) {pmd_hugepage_update (vma->vm_mm, address, pmdp, _PAGE_PRESENT,0 ); -flush_tlb_range (vma, address, address +HPAGE_PMD_SIZE ); +flush_pmd_tlb_range (vma, address, address +HPAGE_PMD_SIZE );/* * This ensures that generic code that rely on IRQ disabling * to prevent a parallel THP split work as expected.
arch/powerpc/mm/tlb-radix.c +7 -0
@@ -350,3 +350,10 @@ void radix__flush_tlb_range_psize(struct mm_struct *mm, unsigned long start, err_out:preempt_enable (); } + +void radix__flush_pmd_tlb_range (struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +radix__flush_tlb_range_psize (vma->vm_mm, start, end,MMU_PAGE_2M ); +} +EXPORT_SYMBOL (radix__flush_pmd_tlb_range);
Signature · 1 line
2.7.4
PATCH v2 10/16 powerpc/mm/radix: Rename function and drop unused arg
In reply to Aneesh Kumar K.V--- arch/powerpc/include/asm/book3s/64/tlbflush-radix.h | 10 +++++----- arch/powerpc/mm/hugetlbpage-radix.c | 4 ++-- arch/powerpc/mm/tlb-radix.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +5 -5
@@ -20,20 +20,20 @@ extern void radix__flush_tlb_kernel_range(unsigned long start, unsigned long endextern 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_page (struct mm_struct *mm,unsigned long vmaddr, -unsigned long ap,int nid);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);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_page (struct mm_struct *mm,unsigned long vmaddr, -unsigned long ap,int nid);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);#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) -#define radix___flush_tlb_page (mm,addr,p,i) radix___local_flush_tlb_page(mm,addr,p,i) +#define radix__flush_tlb_page_psize (mm,addr,p) radix__local_flush_tlb_page_psize(mm,addr,p)#define radix__flush_tlb_pwc (tlb, addr) radix__local_flush_tlb_pwc(tlb, addr)#endif
arch/powerpc/mm/hugetlbpage-radix.c +2 -2
@@ -20,7 +20,7 @@ void radix__flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)WARN (1 ,"Wrong huge page shift\n" );return ; } -radix___flush_tlb_page (vma->vm_mm, vmaddr, ap,0 ); +radix__flush_tlb_page_psize (vma->vm_mm, vmaddr, ap); }void radix__local_flush_hugetlb_page (struct vm_area_struct *vma,unsigned long vmaddr)
@@ -37,7 +37,7 @@ void radix__local_flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vWARN (1 ,"Wrong huge page shift\n" );return ; } -radix___local_flush_tlb_page (vma->vm_mm, vmaddr, ap,0 ); +radix__local_flush_tlb_page_psize (vma->vm_mm, vmaddr, ap); }/*
arch/powerpc/mm/tlb-radix.c +8 -8
@@ -138,8 +138,8 @@ 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 (struct mm_struct *mm,unsigned long vmaddr, -unsigned long ap,int nid) +void radix__local_flush_tlb_page_psize (struct mm_struct *mm,unsigned long vmaddr, +unsigned long ap) {unsigned long pid;
@@ -157,8 +157,8 @@ void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddif (vma &&is_vm_hugetlb_page (vma))return __local_flush_hugetlb_page (vma, vmaddr);#endif -radix___local_flush_tlb_page (vma ? vma->vm_mm :NULL , vmaddr, -mmu_get_ap (mmu_virtual_psize),0 ); +radix__local_flush_tlb_page_psize (vma ? vma->vm_mm :NULL , vmaddr, +mmu_get_ap (mmu_virtual_psize)); }EXPORT_SYMBOL (radix__local_flush_tlb_page);
@@ -212,8 +212,8 @@ no_context: }EXPORT_SYMBOL (radix__flush_tlb_pwc); -void radix___flush_tlb_page (struct mm_struct *mm,unsigned long vmaddr, -unsigned long ap,int nid) +void radix__flush_tlb_page_psize (struct mm_struct *mm,unsigned long vmaddr, +unsigned long ap) {unsigned long pid;
@@ -241,8 +241,8 @@ void radix__flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr)if (vma &&is_vm_hugetlb_page (vma))return flush_hugetlb_page (vma, vmaddr);#endif -radix___flush_tlb_page (vma ? vma->vm_mm :NULL , vmaddr, -mmu_get_ap (mmu_virtual_psize),0 ); +radix__flush_tlb_page_psize (vma ? vma->vm_mm :NULL , vmaddr, +mmu_get_ap (mmu_virtual_psize)); }EXPORT_SYMBOL (radix__flush_tlb_page);
Signature · 1 line
2.7.4
PATCH v2 11/16 powerpc/mm/radix/hugetlb: Add helper for finding page size from hstate
In reply to Aneesh Kumar K.VUse the helper instead of open coding the same at multiple place
--- arch/powerpc/include/asm/book3s/64/hugetlb-radix.h | 15 +++++++++++ .../powerpc/include/asm/book3s/64/tlbflush-radix.h | 4 +-- arch/powerpc/mm/hugetlbpage-radix.c | 29 ++++++---------------- arch/powerpc/mm/tlb-radix.c | 10 +++++--- 4 files changed, 30 insertions(+), 28 deletions(-)
arch/powerpc/include/asm/book3s/64/hugetlb-radix.h +15 -0
@@ -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
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +2 -2
@@ -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)
arch/powerpc/mm/hugetlbpage-radix.c +7 -22
@@ -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); }/*
arch/powerpc/mm/tlb-radix.c +6 -4
@@ -139,9 +139,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 ;
@@ -158,7 +159,7 @@ void radix__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddreturn __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);
@@ -213,9 +214,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 ;
@@ -242,7 +244,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);
Signature · 1 line
2.7.4
PATCH v2 12/16 powerpc/mm/hugetlb: Add flush_hugetlb_tlb_range
In reply to Aneesh Kumar K.VSome archs like ppc64 need to do special things when flushing tlb for hugepage. Add a new helper to flush hugetlb tlb range. This helps us to avoid flushing the entire tlb mapping for the pid.
--- arch/powerpc/include/asm/book3s/64/tlbflush-radix.h | 2 ++ arch/powerpc/include/asm/book3s/64/tlbflush.h | 10 ++++++++++ arch/powerpc/mm/hugetlbpage-radix.c | 10 ++++++++++ mm/hugetlb.c | 10 +++++++++- 4 files changed, 31 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/tlbflush-radix.h +2 -0
@@ -10,6 +10,8 @@ static inline int mmu_get_ap(int psize)return mmu_psize_defs[psize].ap; } +extern void radix__flush_hugetlb_tlb_range (struct vm_area_struct *vma, +unsigned long start,unsigned long end);extern void radix__flush_tlb_range_psize (struct mm_struct *mm,unsigned long start,unsigned long end,int psize); extern void radix__flush_pmd_tlb_range(struct vm_area_struct *vma,
arch/powerpc/include/asm/book3s/64/tlbflush.h +10 -0
@@ -16,6 +16,16 @@ static inline void flush_pmd_tlb_range(struct vm_area_struct *vma,return hash__flush_tlb_range (vma, start, end); } +#define __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE +static inline void flush_hugetlb_tlb_range (struct vm_area_struct *vma, +unsigned long start, +unsigned long end) +{ +if (radix_enabled ()) +return radix__flush_hugetlb_tlb_range (vma, start, end); +return hash__flush_tlb_range (vma, start, end); +} +static inline void flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end) {
arch/powerpc/mm/hugetlbpage-radix.c +10 -0
@@ -25,6 +25,16 @@ void radix__local_flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vradix__local_flush_tlb_page_psize (vma->vm_mm, vmaddr, psize); } +void radix__flush_hugetlb_tlb_range (struct vm_area_struct *vma,unsigned long start, +unsigned long end) +{ +int psize; +struct hstate *hstate =hstate_file (vma->vm_file); + + psize =hstate_get_psize (hstate); +radix__flush_tlb_range_psize (vma->vm_mm, start, end, psize); +} +/* * A vairant of hugetlb_get_unmapped_area doing topdown search * FIXME!! should we do as x86 does or non hugetlb area does ?
mm/hugetlb.c +9 -1
@@ -3897,6 +3897,14 @@ same_page:return i ? i : -EFAULT ; } +#ifndef __HAVE_ARCH_FLUSH_HUGETLB_TLB_RANGE +/* +* ARCHes with special requirements for evicting HUGETLB backing TLB entries can +* implement this. +*/ +#define flush_hugetlb_tlb_range (vma, addr, end) flush_tlb_range(vma, addr, end) +#endif +unsigned long hugetlb_change_protection (struct vm_area_struct *vma,unsigned long address,unsigned long end,pgprot_t newprot) {
@@ -3957,7 +3965,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,* once we release i_mmap_rwsem, another task can do the final put_page * and that page table be reused and filled with junk. */ -flush_tlb_range (vma, start, end); +flush_hugetlb_tlb_range (vma, start, end);mmu_notifier_invalidate_range (mm, start, end);i_mmap_unlock_write (vma->vm_file->f_mapping);mmu_notifier_invalidate_range_end (mm, start, end);
Signature · 1 line
2.7.4
PATCH v2 13/16 powerpc/mm: remove flush_tlb_page_nohash
In reply to Aneesh Kumar K.VThis should be same as flush_tlb_page except for hash32. For hash32 I guess the existing code is wrong, because we don't seem to be flushing tlb for Hash != 0 case at all. Fix this by switching to calling flush_tlb_page() which does the right thing by flushing tlb for both hash and nohash case with hash32
--- arch/powerpc/include/asm/book3s/64/tlbflush-hash.h | 5 ----- arch/powerpc/include/asm/book3s/64/tlbflush.h | 8 -------- arch/powerpc/include/asm/tlbflush.h | 1 - arch/powerpc/mm/pgtable.c | 2 +- arch/powerpc/mm/tlb_hash32.c | 11 ----------- 5 files changed, 1 insertion(+), 26 deletions(-)
arch/powerpc/include/asm/book3s/64/tlbflush-hash.h +0 -5
@@ -75,11 +75,6 @@ static inline void hash__flush_tlb_page(struct vm_area_struct *vma, { } -static inline void hash__flush_tlb_page_nohash (struct vm_area_struct *vma, -unsigned long vmaddr) -{ -} -static inline void hash__flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end) {
arch/powerpc/include/asm/book3s/64/tlbflush.h +0 -8
@@ -57,14 +57,6 @@ static inline void local_flush_tlb_page(struct vm_area_struct *vma,return hash__local_flush_tlb_page (vma, vmaddr); } -static inline void flush_tlb_page_nohash (struct vm_area_struct *vma, -unsigned long vmaddr) -{ -if (radix_enabled ()) -return radix__flush_tlb_page (vma, vmaddr); -return hash__flush_tlb_page_nohash (vma, vmaddr); -} -static inline void tlb_flush (struct mmu_gather *tlb) {if (radix_enabled ())
arch/powerpc/include/asm/tlbflush.h +0 -1
@@ -54,7 +54,6 @@ extern void __flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,#define flush_tlb_page (vma,addr) local_flush_tlb_page(vma,addr)#define __flush_tlb_page (mm,addr,p,i) __local_flush_tlb_page(mm,addr,p,i)#endif -#define flush_tlb_page_nohash (vma,addr) flush_tlb_page(vma,addr)#elif defined(CONFIG_PPC_STD_MMU_32)
arch/powerpc/mm/pgtable.c +1 -1
@@ -225,7 +225,7 @@ int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,if (!is_vm_hugetlb_page (vma))assert_pte_locked (vma->vm_mm, address);__ptep_set_access_flags (ptep, entry); -flush_tlb_page_nohash (vma, address); +flush_tlb_page (vma, address); }return changed; }
arch/powerpc/mm/tlb_hash32.c +0 -11
@@ -49,17 +49,6 @@ void flush_hash_entry(struct mm_struct *mm, pte_t *ptep, unsigned long addr)EXPORT_SYMBOL (flush_hash_entry);/* -* Called by ptep_set_access_flags, must flush on CPUs for which the -* DSI handler can't just "fixup" the TLB on a write fault -*/ -void flush_tlb_page_nohash (struct vm_area_struct *vma,unsigned long addr) -{ -if (Hash !=0 ) -return ; -_tlbie (addr); -} - -/* * Called at the end of a mmu_gather operation to make sure the * TLB flush is completely done. */
Signature · 1 line
2.7.4
PATCH v2 14/16 powerpc/mm: Cleanup LPCR defines
In reply to Aneesh Kumar K.VThis makes it easy to verify we are not overloading the bits. No functionality change by this patch.
--- arch/powerpc/include/asm/reg.h | 54 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-)
arch/powerpc/include/asm/reg.h +27 -27
@@ -314,41 +314,41 @@#define HFSCR_FP __MASK(FSCR_FP_LG)#define SPRN_TAR 0x32f/* Target Address Register */ #define SPRN_LPCR 0x13E/* LPAR Control Register */ -#define LPCR_VPM0 (1ul << (63-0)) -#define LPCR_VPM1 (1ul << (63-1)) -#define LPCR_ISL (1ul << (63-2)) +#define LPCR_VPM0 ASM_CONST(0x8000000000000000) +#define LPCR_VPM1 ASM_CONST(0x4000000000000000) +#define LPCR_ISL ASM_CONST(0x2000000000000000)#define LPCR_VC_SH (63-2)#define LPCR_DPFD_SH (63-11)#define LPCR_DPFD (7ul << LPCR_DPFD_SH)#define LPCR_VRMASD (0x1ful << (63-16)) -#define LPCR_VRMA_L (1ul << (63-12)) -#define LPCR_VRMA_LP0 (1ul << (63-15)) -#define LPCR_VRMA_LP1 (1ul << (63-16)) +#define LPCR_VRMA_L ASM_CONST(0x0008000000000000) +#define LPCR_VRMA_LP0 ASM_CONST(0x0001000000000000) +#define LPCR_VRMA_LP1 ASM_CONST(0x0000800000000000)#define LPCR_VRMASD_SH (63-16) -#define LPCR_RMLS 0x1C000000/* impl dependent rmo limit sel */ +#define LPCR_RMLS 0x1C000000/* impl dependent rmo limit sel */ #define LPCR_RMLS_SH (63-37) -#define LPCR_ILE 0x02000000/* !HV irqs set MSR:LE */ -#define LPCR_AIL 0x01800000/* Alternate interrupt location */ -#define LPCR_AIL_0 0x00000000/* MMU off exception offset 0x0 */ -#define LPCR_AIL_3 0x01800000/* MMU on exception offset 0xc00...4xxx */ -#define LPCR_ONL 0x00040000/* online - PURR/SPURR count */ -#define LPCR_PECE 0x0001f000/* powersave exit cause enable */ -#define LPCR_PECEDP 0x00010000/* directed priv dbells cause exit */ -#define LPCR_PECEDH 0x00008000/* directed hyp dbells cause exit */ -#define LPCR_PECE0 0x00004000/* ext. exceptions can cause exit */ -#define LPCR_PECE1 0x00002000/* decrementer can cause exit */ -#define LPCR_PECE2 0x00001000/* machine check etc can cause exit */ -#define LPCR_MER 0x00000800/* Mediated External Exception */ +#define LPCR_ILE ASM_CONST(0x0000000002000000)/* !HV irqs set MSR:LE */ +#define LPCR_AIL ASM_CONST(0x0000000001800000)/* Alternate interrupt location */ +#define LPCR_AIL_0 ASM_CONST(0x0000000000000000)/* MMU off exception offset 0x0 */ +#define LPCR_AIL_3 ASM_CONST(0x0000000001800000)/* MMU on exception offset 0xc00...4xxx */ +#define LPCR_ONL ASM_CONST(0x0000000000040000)/* online - PURR/SPURR count */ +#define LPCR_PECE ASM_CONST(0x000000000001f000)/* powersave exit cause enable */ +#define LPCR_PECEDP ASM_CONST(0x0000000000010000)/* directed priv dbells cause exit */ +#define LPCR_PECEDH ASM_CONST(0x0000000000008000)/* directed hyp dbells cause exit */ +#define LPCR_PECE0 ASM_CONST(0x0000000000004000)/* ext. exceptions can cause exit */ +#define LPCR_PECE1 ASM_CONST(0x0000000000002000)/* decrementer can cause exit */ +#define LPCR_PECE2 ASM_CONST(0x0000000000001000)/* machine check etc can cause exit */ +#define LPCR_MER ASM_CONST(0x0000000000000800)/* Mediated External Exception */ #define LPCR_MER_SH 11 -#define LPCR_TC 0x00000200/* Translation control */ -#define LPCR_LPES 0x0000000c -#define LPCR_LPES0 0x00000008/* LPAR Env selector 0 */ -#define LPCR_LPES1 0x00000004/* LPAR Env selector 1 */ +#define LPCR_TC ASM_CONST(0x0000000000000200)/* Translation control */ +#define LPCR_LPES 0x0000000c +#define LPCR_LPES0 ASM_CONST(0x0000000000000008)/* LPAR Env selector 0 */ +#define LPCR_LPES1 ASM_CONST(0x0000000000000004)/* LPAR Env selector 1 */ #define LPCR_LPES_SH 2 -#define LPCR_RMI 0x00000002/* real mode is cache inhibit */ -#define LPCR_HDICE 0x00000001/* Hyp Decr enable (HV,PR,EE) */ -#define LPCR_UPRT 0x00400000/* Use Process Table (ISA 3) */ -#define LPCR_HR 0x00100000 +#define LPCR_RMI ASM_CONST(0x0000000000000002)/* real mode is cache inhibit */ +#define LPCR_HDICE ASM_CONST(0x0000000000000001)/* Hyp Decr enable (HV,PR,EE) */ +#define LPCR_UPRT ASM_CONST(0x0000000000400000)/* Use Process Table (ISA 3) */ +#define LPCR_HR ASM_CONST(0x0000000000100000)#ifndef SPRN_LPID #define SPRN_LPID 0x13F/* Logical Partition Identifier */ #endif
Signature · 1 line
2.7.4
PATCH v2 15/16 powerpc/mm: Switch user slb fault handling to translation enabled
In reply to Aneesh Kumar K.VWe also handle fault with proper stack initialized. This enable us to callout to C in fault handling routines. We don't do this for kernel mapping, because of the possibility of taking recursive fault if kernel stack in not yet mapped by an slb entry.
This enable us to handle Power9 slb fault better. We will add bolted entries for the entire kernel mapping in segment table and user slb entries we take fault and insert on demand. With translation on, we should be able to access segment table from fault handler.
--- arch/powerpc/kernel/exceptions-64s.S | 55 ++++++++++++++++++++++++++++++++---- arch/powerpc/mm/slb.c | 11 ++++++++ 2 files changed, 61 insertions(+), 5 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +50 -5
@@ -794,7 +794,7 @@ data_access_slb_relon_pSeries: mfspr r3,SPRN_DAR mfspr r12,SPRN_SRR1 #ifndef CONFIG_RELOCATABLE - b slb_miss_realmode + b handle_slb_miss_relon #else /* * We can't just use a direct branch to slb_miss_realmode
@@ -803,7 +803,7 @@ data_access_slb_relon_pSeries: */ mfctr r11 ld r10,PACAKBASE(r13) - LOAD_HANDLER(r10, slb_miss_realmode) + LOAD_HANDLER(r10, handle_slb_miss_relon) mtctr r10 bctr #endif
@@ -819,11 +819,11 @@ instruction_access_slb_relon_pSeries: mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */ mfspr r12,SPRN_SRR1 #ifndef CONFIG_RELOCATABLE - b slb_miss_realmode + b handle_slb_miss_relon #else mfctr r11 ld r10,PACAKBASE(r13) - LOAD_HANDLER(r10, slb_miss_realmode) + LOAD_HANDLER(r10, handle_slb_miss_relon) mtctr r10 bctr #endif
@@ -961,7 +961,23 @@ h_data_storage_common: bl unknown_exception b ret_from_except +/* r3 point to DAR */ .align 7 + .globl slb_miss_user +slb_miss_user: + std r3,PACA_EXSLB+EX_DAR(r13) + /* Restore r3 as expected by PROLOG_COMMON below */ + ld r3,PACA_EXSLB+EX_R3(r13) + EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB) + RECONCILE_IRQ_STATE(r10, r11) + ld r4,PACA_EXSLB+EX_DAR(r13) + li r5,0x380 + std r4,_DAR(r1) + addi r3,r1,STACK_FRAME_OVERHEAD + bl handle_slb_miss + b ret_from_except_lite + + .align 7 .globl instruction_access_common instruction_access_common: EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
@@ -1379,11 +1395,17 @@ unrecover_mce: * We assume we aren't going to take any exceptions during this procedure. */ slb_miss_realmode: - mflr r10 #ifdef CONFIG_RELOCATABLE mtctr r11 #endif + /* + * Handle user slb miss with translation enabled + */ + cmpdi r3,0 + bge 3f +slb_miss_kernel: + mflr r10 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */ std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
@@ -1428,6 +1450,29 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX) mtspr SPRN_SRR1,r10 rfid b . +3: + /* + * Enable IR/DR and handle the fault + */ + EXCEPTION_PROLOG_PSERIES_1(slb_miss_user, EXC_STD) + /* + * handler with relocation on + */ +handle_slb_miss_relon: +#ifdef CONFIG_RELOCATABLE + mtctr r11 +#endif + /* + * Handle user slb miss with stack initialized. + */ + cmpdi r3,0 + bge 4f + /* + * go back to slb_miss_realmode + */ + b slb_miss_kernel +4: + EXCEPTION_RELON_PROLOG_PSERIES_1(slb_miss_user, EXC_STD) unrecov_slb: EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
arch/powerpc/mm/slb.c +11 -0
@@ -25,6 +25,8 @@#include <asm/udbg.h> #include <asm/code-patching.h> +#include <linux/context_tracking.h> +enum slb_index {LINEAR_INDEX =0 ,/* Kernel linear map (0xc000000000000000) */ VMALLOC_INDEX =1 ,/* Kernel virtual map (0xd000000000000000) */
@@ -346,3 +348,12 @@ void slb_initialize(void) asmvolatile ("isync" :::"memory" ); } + +void handle_slb_miss (struct pt_regs *regs, +unsigned long address,unsigned long trap) +{ +enum ctx_state prev_state =exception_enter (); + +slb_allocate (address); +exception_exit (prev_state); +}
Signature · 1 line
2.7.4
PATCH v2 16/16 powerpc/mm: Support segment table for Power9
In reply to Aneesh Kumar K.VPowerISA 3.0 adds an in memory table for storing segment translation information. In this mode, which is enabled by setting both HOST RADIX and GUEST RADIX bits in partition table to 0 and enabling UPRT to 1, we have a per process segment table. The segment table details are stored in the process table indexed by PID value.
Segment table mode also requires us to map the process table at the beginning of a 1TB segment.
On the linux kernel side we enable this model if we find that the radix is explicitily disabled by setting the ibm,pa-feature radix bit (byte 40 bit 0) set to 0. If the size of ibm,pa-feature node is less than 40 bytes, we enable the legacy HPT mode using SLB. If radix bit is set to 1, we use the radix mode.
With respect to SLB mapping, we bolt mapp the entire kernel range and and only handle user space segment fault.
We also have access to 4 SLB register in software. So we continue to use 3 of that for bolted kernel SLB entries as we use them currently.
--- arch/powerpc/include/asm/book3s/64/hash.h | 10 + arch/powerpc/include/asm/book3s/64/mmu-hash.h | 17 ++ arch/powerpc/include/asm/book3s/64/mmu.h | 4 + arch/powerpc/include/asm/mmu.h | 6 +- arch/powerpc/include/asm/mmu_context.h | 5 +- arch/powerpc/kernel/prom.c | 1 + arch/powerpc/mm/hash_utils_64.c | 86 ++++++- arch/powerpc/mm/mmu_context_book3s64.c | 32 ++- arch/powerpc/mm/slb.c | 350 +++++++++++++++++++++++++- 9 files changed, 493 insertions(+), 18 deletions(-)
arch/powerpc/include/asm/book3s/64/hash.h +10 -0
@@ -58,6 +58,16 @@#define H_VMALLOC_END (H_VMALLOC_START + H_VMALLOC_SIZE)/* +* Process table with ISA 3.0 need to be mapped at the beginning of a 1TB segment +* We put that in the top of VMALLOC region. For each region we can go upto 64TB +* for now. Hence we have space to put process table there. We should not get +* an SLB miss for this address, because the VSID for this is placed in the +* partition table. +*/ +#define H_SEG_PROC_TBL_START ASM_CONST(0xD000200000000000) +#define H_SEG_PROC_TBL_END ASM_CONST(0xD00020ffffffffff) + +/* * Region IDs */ #define REGION_SHIFT 60UL
arch/powerpc/include/asm/book3s/64/mmu-hash.h +17 -0
@@ -102,6 +102,18 @@#define HPTE_V_1TB_SEG ASM_CONST(0x4000000000000000)#define HPTE_V_VRMA_MASK ASM_CONST(0x4001ffffff000000) +/* segment table entry masks/bits */ +/* Upper 64 bit */ +#define STE_VALID ASM_CONST(0x8000000) +/* +* lower 64 bit +* 64th bit become 0 bit +*/ +/* +* Software defined bolted bit +*/ +#define STE_BOLTED ASM_CONST(0x1) +/* Values for PP (assumes Ks=0, Kp=1) */ #define PP_RWXX 0/* Supervisor read/write, User none */ #define PP_RWRX 1/* Supervisor read/write, User read */
@@ -129,6 +141,11 @@ struct hash_pte {__be64 r; }; +struct seg_entry { +__be64 ste_e; +__be64 ste_v; +}; +extern struct hash_pte *htab_address;extern unsigned long htab_size_bytes;extern unsigned long htab_hash_mask;
arch/powerpc/include/asm/book3s/64/mmu.h +4 -0
@@ -65,6 +65,7 @@ extern struct patb_entry *partition_tb;*/ #define PATB_SIZE_SHIFT 16 +extern unsigned long segment_table_initialize (struct prtb_entry *prtb);typedef unsigned long mm_context_id_t ;struct spinlock ;
@@ -94,6 +95,9 @@ typedef struct {#ifdef CONFIG_SPAPR_TCE_IOMMU struct list_head iommu_group_mem_list;#endif +unsigned long seg_table; +struct spinlock *seg_tbl_lock; + } mm_context_t;/*
arch/powerpc/include/asm/mmu.h +5 -1
@@ -24,6 +24,10 @@* Radix page table available */ #define MMU_FTR_TYPE_RADIX ASM_CONST(0x00000040) + +/* Seg table only supported for book3s 64 */ +#define MMU_FTR_TYPE_SEG_TABLE ASM_CONST(0x00000080) +/* * individual features */
@@ -130,7 +134,7 @@ enum { MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE | MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA |#ifdef CONFIG_PPC_RADIX_MMU -MMU_FTR_TYPE_RADIX | +MMU_FTR_TYPE_RADIX |MMU_FTR_TYPE_SEG_TABLE | #endif 0, };
arch/powerpc/include/asm/mmu_context.h +4 -1
@@ -38,13 +38,16 @@ extern void set_context(unsigned long id, pgd_t *pgd);#ifdef CONFIG_PPC_BOOK3S_64 extern void radix__switch_mmu_context (struct mm_struct *prev, -struct mm_struct *next); +struct mm_struct *next);static inline void switch_mmu_context (struct mm_struct *prev,struct mm_struct *next,struct task_struct *tsk) {if (radix_enabled ())return radix__switch_mmu_context (prev, next); +/* +* switch the pid before flushing the slb +*/ return switch_slb (tsk, next); }
arch/powerpc/kernel/prom.c +1 -0
@@ -169,6 +169,7 @@ static struct ibm_pa_feature { {CPU_FTR_TM_COMP ,0 ,0 , PPC_FEATURE2_HTM_COMP|PPC_FEATURE2_HTM_NOSC_COMP, 22, 0, 0}, {0, MMU_FTR_TYPE_RADIX, 0, 0, 40, 0, 0}, + {0, MMU_FTR_TYPE_SEG_TABLE, 0, 0, 58, 0, 0}, }; static void __init scan_features(unsigned long node, const unsigned char *ftrs,
arch/powerpc/mm/hash_utils_64.c +77 -9
129 lines not on this page · raw message
arch/powerpc/mm/mmu_context_book3s64.c +26 -6
@@ -102,12 +102,8 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm) mm->context.id = index;#ifdef CONFIG_PPC_ICSWX mm->context.cop_lockp =kmalloc (sizeof (spinlock_t),GFP_KERNEL ); -if (!mm->context.cop_lockp) { -__destroy_context (index); -subpage_prot_free (mm); - mm->context.id =MMU_NO_CONTEXT ; -return -ENOMEM ; - } +if (!mm->context.cop_lockp) + goto err_out;spin_lock_init (mm->context.cop_lockp);#endif /* CONFIG_PPC_ICSWX */
@@ -117,7 +113,31 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)#ifdef CONFIG_SPAPR_TCE_IOMMU mm_iommu_init (&mm->context);#endif +/* +* Setup segment table and update process table entry +*/ +if (!radix_enabled () &&mmu_has_feature (MMU_FTR_TYPE_SEG_TABLE )) { + mm->context.seg_tbl_lock =kmalloc (sizeof (spinlock_t),GFP_KERNEL ); +if (!mm->context.seg_tbl_lock) + goto err_out_free; +spin_lock_init (mm->context.seg_tbl_lock); + mm->context.seg_table =segment_table_initialize (&process_tb[index]); +if (!mm->context.seg_table) { +kfree (mm->context.seg_tbl_lock); + goto err_out_free; + } + }return 0 ; + +err_out_free: +#ifdef CONFIG_PPC_ICSWX +kfree (mm->context.cop_lockp); +err_out: +#endif +__destroy_context (index); +subpage_prot_free (mm); + mm->context.id =MMU_NO_CONTEXT ; +return -ENOMEM ; }void __destroy_context (int context_id)
arch/powerpc/mm/slb.c +349 -1
372 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH V2 16/16] powerpc/mm: Support segment table for Power9
Quoted 6 lines · Aneesh Kumar K.V
PowerISA 3.0 adds an in memory table for storing segment translation information. In this mode, which is enabled by setting both HOST RADIX and GUEST RADIX bits in partition table to 0 and enabling UPRT to 1, we have a per process segment table. The segment table details are stored in the process table indexed by PID value.
Quoted 8 lines
Segment table mode also requires us to map the process table at the beginning of a 1TB segment.
On the linux kernel side we enable this model if we find that the radix is explicitily disabled by setting the ibm,pa-feature radix bit (byte 40 bit 0) set to 0. If the size of ibm,pa-feature node is less than 40 bytes, we enable the legacy HPT mode using SLB. If radix bit is set to 1, we use the radix mode.
Missed updating the commit message.
On the linux kernel side we enable this model if we find hash mmu bit (byte 58 bit 0) of ibm,pa-feature device tree node set to 1. If the size of ibm,pa-feature node is less than 58 bytes or if the hash mmu bit is set to 0, we enable the legacy HPT mode using SLB. If radix bit (byte 40 bit 0) is set to 1, we use the radix mode.
Quoted 4 lines
With respect to SLB mapping, we bolt mapp the entire kernel range and and only handle user space segment fault.
-aneesh