Skip to content

Commit 5a34133

Browse files
chenhuacairalfbaechle
authored andcommitted
MIPS: Check TLB before handle_ri_rdhwr() for Loongson-3
Loongson-3's micro TLB (ITLB) is not strictly a subset of JTLB. That means: when a JTLB entry is replaced by hardware, there may be an old valid entry exists in ITLB. So, a TLB miss exception may occur while handle_ri_rdhwr() is running because it try to access EPC's content. However, handle_ri_rdhwr() doesn't clear EXL, which makes a TLB Refill exception be treated as a TLB Invalid exception and tlbp may fail. In this case, if FTLB (which is usually set-associative instead of set- associative) is enabled, a tlbp failure will cause an invalid tlbwi, which will hang the whole system. This patch rename handle_ri_rdhwr_vivt to handle_ri_rdhwr_tlbp and use it for Loongson-3. It try to solve the same problem described as below, but more straightforwards. https://patchwork.linux-mips.org/patch/12591/ I think Loongson-2 has the same problem, but it has no FTLB, so we just keep it as is. Signed-off-by: Huacai Chen <chenhc@lemote.com> Cc: Rui Wang <wangr@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 Cc: stable@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/15753/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 033cffe commit 5a34133

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

arch/mips/kernel/genex.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ NESTED(nmi_handler, PT_SIZE, sp)
519519
BUILD_HANDLER reserved reserved sti verbose /* others */
520520

521521
.align 5
522-
LEAF(handle_ri_rdhwr_vivt)
522+
LEAF(handle_ri_rdhwr_tlbp)
523523
.set push
524524
.set noat
525525
.set noreorder
@@ -538,7 +538,7 @@ NESTED(nmi_handler, PT_SIZE, sp)
538538
.set pop
539539
bltz k1, handle_ri /* slow path */
540540
/* fall thru */
541-
END(handle_ri_rdhwr_vivt)
541+
END(handle_ri_rdhwr_tlbp)
542542

543543
LEAF(handle_ri_rdhwr)
544544
.set push

arch/mips/kernel/traps.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extern asmlinkage void handle_dbe(void);
8383
extern asmlinkage void handle_sys(void);
8484
extern asmlinkage void handle_bp(void);
8585
extern asmlinkage void handle_ri(void);
86-
extern asmlinkage void handle_ri_rdhwr_vivt(void);
86+
extern asmlinkage void handle_ri_rdhwr_tlbp(void);
8787
extern asmlinkage void handle_ri_rdhwr(void);
8888
extern asmlinkage void handle_cpu(void);
8989
extern asmlinkage void handle_ov(void);
@@ -2408,9 +2408,18 @@ void __init trap_init(void)
24082408

24092409
set_except_vector(EXCCODE_SYS, handle_sys);
24102410
set_except_vector(EXCCODE_BP, handle_bp);
2411-
set_except_vector(EXCCODE_RI, rdhwr_noopt ? handle_ri :
2412-
(cpu_has_vtag_icache ?
2413-
handle_ri_rdhwr_vivt : handle_ri_rdhwr));
2411+
2412+
if (rdhwr_noopt)
2413+
set_except_vector(EXCCODE_RI, handle_ri);
2414+
else {
2415+
if (cpu_has_vtag_icache)
2416+
set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp);
2417+
else if (current_cpu_type() == CPU_LOONGSON3)
2418+
set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp);
2419+
else
2420+
set_except_vector(EXCCODE_RI, handle_ri_rdhwr);
2421+
}
2422+
24142423
set_except_vector(EXCCODE_CPU, handle_cpu);
24152424
set_except_vector(EXCCODE_OV, handle_ov);
24162425
set_except_vector(EXCCODE_TR, handle_tr);

0 commit comments

Comments
 (0)