Skip to content

Commit 2d1af1b

Browse files
chenhuacaigregkh
authored andcommitted
MIPS: Flush wrong invalid FTLB entry for huge page
commit 0115f6cbf26663c86496bc56eeea293f85b77897 upstream. On VTLB+FTLB platforms (such as Loongson-3A R2), FTLB's pagesize is usually configured the same as PAGE_SIZE. In such a case, Huge page entry is not suitable to write in FTLB. Unfortunately, when a huge page is created, its page table entries haven't created immediately. Then the TLB refill handler will fetch an invalid page table entry which has no "HUGE" bit, and this entry may be written to FTLB. Since it is invalid, TLB load/store handler will then use tlbwi to write the valid entry at the same place. However, the valid entry is a huge page entry which isn't suitable for FTLB. Our solution is to modify build_huge_handler_tail. Flush the invalid old entry (whether it is in FTLB or VTLB, this is in order to reduce branches) and use tlbwr to write the valid new entry. Signed-off-by: Rui Wang <wangr@lemote.com> Signed-off-by: Huacai Chen <chenhc@lemote.com> Cc: John Crispin <john@phrozen.org> Cc: Steven J . Hill <Steven.Hill@caviumnetworks.com> Cc: Fuxin Zhang <zhangfx@lemote.com> Cc: Zhangjin Wu <wuzhangjin@gmail.com> Cc: Huacai Chen <chenhc@lemote.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/15754/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 55f67b9 commit 2d1af1b

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

arch/mips/mm/tlbex.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ static void build_huge_update_entries(u32 **p, unsigned int pte,
757757
static void build_huge_handler_tail(u32 **p, struct uasm_reloc **r,
758758
struct uasm_label **l,
759759
unsigned int pte,
760-
unsigned int ptr)
760+
unsigned int ptr,
761+
unsigned int flush)
761762
{
762763
#ifdef CONFIG_SMP
763764
UASM_i_SC(p, pte, 0, ptr);
@@ -766,6 +767,22 @@ static void build_huge_handler_tail(u32 **p, struct uasm_reloc **r,
766767
#else
767768
UASM_i_SW(p, pte, 0, ptr);
768769
#endif
770+
if (cpu_has_ftlb && flush) {
771+
BUG_ON(!cpu_has_tlbinv);
772+
773+
UASM_i_MFC0(p, ptr, C0_ENTRYHI);
774+
uasm_i_ori(p, ptr, ptr, MIPS_ENTRYHI_EHINV);
775+
UASM_i_MTC0(p, ptr, C0_ENTRYHI);
776+
build_tlb_write_entry(p, l, r, tlb_indexed);
777+
778+
uasm_i_xori(p, ptr, ptr, MIPS_ENTRYHI_EHINV);
779+
UASM_i_MTC0(p, ptr, C0_ENTRYHI);
780+
build_huge_update_entries(p, pte, ptr);
781+
build_huge_tlb_write_entry(p, l, r, pte, tlb_random, 0);
782+
783+
return;
784+
}
785+
769786
build_huge_update_entries(p, pte, ptr);
770787
build_huge_tlb_write_entry(p, l, r, pte, tlb_indexed, 0);
771788
}
@@ -2082,7 +2099,7 @@ static void build_r4000_tlb_load_handler(void)
20822099
uasm_l_tlbl_goaround2(&l, p);
20832100
}
20842101
uasm_i_ori(&p, wr.r1, wr.r1, (_PAGE_ACCESSED | _PAGE_VALID));
2085-
build_huge_handler_tail(&p, &r, &l, wr.r1, wr.r2);
2102+
build_huge_handler_tail(&p, &r, &l, wr.r1, wr.r2, 1);
20862103
#endif
20872104

20882105
uasm_l_nopage_tlbl(&l, p);
@@ -2137,7 +2154,7 @@ static void build_r4000_tlb_store_handler(void)
21372154
build_tlb_probe_entry(&p);
21382155
uasm_i_ori(&p, wr.r1, wr.r1,
21392156
_PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID | _PAGE_DIRTY);
2140-
build_huge_handler_tail(&p, &r, &l, wr.r1, wr.r2);
2157+
build_huge_handler_tail(&p, &r, &l, wr.r1, wr.r2, 1);
21412158
#endif
21422159

21432160
uasm_l_nopage_tlbs(&l, p);
@@ -2193,7 +2210,7 @@ static void build_r4000_tlb_modify_handler(void)
21932210
build_tlb_probe_entry(&p);
21942211
uasm_i_ori(&p, wr.r1, wr.r1,
21952212
_PAGE_ACCESSED | _PAGE_MODIFIED | _PAGE_VALID | _PAGE_DIRTY);
2196-
build_huge_handler_tail(&p, &r, &l, wr.r1, wr.r2);
2213+
build_huge_handler_tail(&p, &r, &l, wr.r1, wr.r2, 0);
21972214
#endif
21982215

21992216
uasm_l_nopage_tlbm(&l, p);

0 commit comments

Comments
 (0)