* [PATCH 2/2] hugetlb: use lightweight tlb flush when update huge tlb on mips
2020-06-29 13:15 [PATCH 1/2] hugetlb: clear huge pte during flush function on mips platform bibo mao
@ 2020-06-29 13:15 ` bibo mao
2021-05-11 21:03 ` [PATCH 1/2] hugetlb: clear huge pte during flush function on mips platform Thomas Bogendoerfer
1 sibling, 0 replies; 3+ messages in thread
From: bibo mao @ 2020-06-29 13:15 UTC (permalink / raw)
To: Thomas Bogendoerfer, Anshuman Khandual, Andrew Morton, Mike Kravetz
Cc: linux-mips, linux-kernel, linux-mm, Bibo Mao
From: Bibo Mao <maobibo@loongson.cn>
On mips platform huge pte pointers to invalid_pte_table if
huge_pte_none return true. TLB entry with normal page size is
added if huge pte entry is none. When updating huge pte entry,
older tlb entry with normal page needs to be invalid.
This patch uses lightweight tlb flush function local_flush_tlb_page,
rather than flush_tlb_range which will flush all tlb entries instead.
Also this patch adds new huge tlb update function named
update_mmu_cache_huge, page faulting address is passed rather than
huge page start address.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/mips/include/asm/hugetlb.h | 17 ++++++++++++-----
include/linux/hugetlb.h | 9 +++++++++
mm/hugetlb.c | 12 +++++++-----
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/arch/mips/include/asm/hugetlb.h b/arch/mips/include/asm/hugetlb.h
index c214440..fce09b4 100644
--- a/arch/mips/include/asm/hugetlb.h
+++ b/arch/mips/include/asm/hugetlb.h
@@ -72,15 +72,22 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
if (changed) {
set_pte_at(vma->vm_mm, addr, ptep, pte);
- /*
- * There could be some standard sized pages in there,
- * get them all.
- */
- flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
}
return changed;
}
+#define update_mmu_cache_huge update_mmu_cache_huge
+static inline void update_mmu_cache_huge(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
+{
+ /*
+ * There could be some standard sized page in there,
+ * parameter address must be page faulting address rather than
+ * start address of huge page
+ */
+ local_flush_tlb_page(vma, address);
+ update_mmu_cache(vma, address & huge_page_mask(hstate_vma(vma)), ptep);
+}
#include <asm-generic/hugetlb.h>
#endif /* __ASM_HUGETLB_H */
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 858522e..2f3f9eb 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -746,6 +746,15 @@ static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
}
#endif
+#ifndef update_mmu_cache_huge
+#define update_mmu_cache_huge update_mmu_cache_huge
+static inline void update_mmu_cache_huge(struct vm_area_struct *vma,
+ unsigned long address, pte_t *ptep)
+{
+ update_mmu_cache(vma, address & huge_page_mask(hstate_vma(vma)), ptep);
+}
+#endif
+
#else /* CONFIG_HUGETLB_PAGE */
struct hstate {};
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 1410e62..96faad7 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3757,10 +3757,12 @@ static void set_huge_ptep_writable(struct vm_area_struct *vma,
unsigned long address, pte_t *ptep)
{
pte_t entry;
+ struct hstate *h = hstate_vma(vma);
+ unsigned long haddr = address & huge_page_mask(h);
entry = huge_pte_mkwrite(huge_pte_mkdirty(huge_ptep_get(ptep)));
- if (huge_ptep_set_access_flags(vma, address, ptep, entry, 1))
- update_mmu_cache(vma, address, ptep);
+ if (huge_ptep_set_access_flags(vma, haddr, ptep, entry, 1))
+ update_mmu_cache_huge(vma, address, ptep);
}
bool is_hugetlb_entry_migration(pte_t pte)
@@ -4128,7 +4130,7 @@ static vm_fault_t hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
* and just make the page writable */
if (page_mapcount(old_page) == 1 && PageAnon(old_page)) {
page_move_anon_rmap(old_page, vma);
- set_huge_ptep_writable(vma, haddr, ptep);
+ set_huge_ptep_writable(vma, address, ptep);
return 0;
}
@@ -4630,7 +4632,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
entry = pte_mkyoung(entry);
if (huge_ptep_set_access_flags(vma, haddr, ptep, entry,
flags & FAULT_FLAG_WRITE))
- update_mmu_cache(vma, haddr, ptep);
+ update_mmu_cache_huge(vma, address, ptep);
out_put_page:
if (page != pagecache_page)
unlock_page(page);
@@ -4770,7 +4772,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm,
hugetlb_count_add(pages_per_huge_page(h), dst_mm);
/* No need to invalidate - it was non-present before */
- update_mmu_cache(dst_vma, dst_addr, dst_pte);
+ update_mmu_cache_huge(dst_vma, dst_addr, dst_pte);
spin_unlock(ptl);
set_page_huge_active(page);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] hugetlb: clear huge pte during flush function on mips platform
2020-06-29 13:15 [PATCH 1/2] hugetlb: clear huge pte during flush function on mips platform bibo mao
2020-06-29 13:15 ` [PATCH 2/2] hugetlb: use lightweight tlb flush when update huge tlb on mips bibo mao
@ 2021-05-11 21:03 ` Thomas Bogendoerfer
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Bogendoerfer @ 2021-05-11 21:03 UTC (permalink / raw)
To: bibo mao
Cc: Anshuman Khandual, Andrew Morton, Mike Kravetz, linux-mips,
linux-kernel, linux-mm
On Mon, Jun 29, 2020 at 09:15:32PM +0800, bibo mao wrote:
> From: Bibo Mao <maobibo@loongson.cn>
>
> If multiple threads are accessing the same huge page at the same
> time, hugetlb_cow will be called if one thread write the COW huge
> page. And function huge_ptep_clear_flush is called to notify other
> threads to clear the huge pte tlb entry. The other threads clear
> the huge pte tlb entry and reload it from page table, the reload
> huge pte entry may be old.
>
> This patch fixes this issue on mips platform, and it clears huge
> pte entry before notifying other threads to flush current huge
> page entry, it is similar with other architectures.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> arch/mips/include/asm/hugetlb.h | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
applied to mips-next.
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]
^ permalink raw reply [flat|nested] 3+ messages in thread