MIPS: tlb-r3k: TLB handling fixes
cover MIPS: tlb-r3k: TLB handling fixes
Hi Ralf,
This is a bunch of fixes for R3k TLB handlers the need for which I
discovered while testing James's recent `dump_tlb' improvements. Especially 1/3 is important as it corrects an initialisation issue that may be lethal in some cases; it may be worth backporting.
Please apply.
Thanks,
Maciej
PATCH 1/3 MIPS: tlb-r3k: Also invalidate wired TLB entries on boot
Most R3k processor implementations have their 8 first TLB entries fixed as wired, so we always skip them in TLB invalidation. That however means any leftover entries present there at boot will stay throughout the life of the kernel, unless replaced with new ones.
So rename local_flush_tlb_all' to local_flush_tlb_from' and make it accept the TLB entry to start from. Then use 0 initially at bootstrap, and the first regular entry later on, bypassing any wired entries. Wrap the latter arrangement into a new `local_flush_tlb_all' entry point.
There is no need to disable interrupts in the call made from tlb_init' because it's made before the interrupt subsystem has been initialised; this is also true for secondary processors, should we ever support R3k SMP. So move this piece of code to new local_flush_tlb_all'.
---
Hi,
In testing James's SysRq TLB dump feature I noticed these suspicious
entries:
Index: 0 va=7ffff000 asid=00000dc0
[pa=ff6fe000 n=1 d=1 v=1 g=1]
Index: 1 va=7ffff000 asid=00000dc0
[pa=ff6fe000 n=1 d=1 v=1 g=1]
Index: 4 va=7ffff000 asid=00000fc0
[pa=fefff000 n=1 d=1 v=1 g=1]
Index: 7 va=7ffff000 asid=00000fc0
[pa=fffff000 n=1 d=1 v=1 g=1]
On further inspection I realised we never actually invalidate wired entries on classic R3k processors. We escaped the issue with multiple global mappings for the last KUSEG page seen here (that would inevitably lead to a TLB shutdown if ever referenced) as we avoid the last 32kB of KUSEG page to avoid address wraparound issues with CP0.Status.UX set on 64-bit processors.
Maciej
linux-mips-tlb-r3k-init-flush-wired.diff
arch/mips/mm/tlb-r3k.c +13 -11
@@ -39,20 +39,12 @@ extern void build_tlb_refill_handler(voiint r3k_have_wired_reg;/* should be in cpu_data? */ /* TLB operations. */ -void local_flush_tlb_all (void ) +static void local_flush_tlb_from (int entry) { -unsigned long flags;unsigned long old_ctx; -int entry; - -#ifdef DEBUG_TLB -printk ("[tlball]" ); -#endif -local_irq_save (flags); old_ctx =read_c0_entryhi () &ASID_MASK ;write_c0_entrylo0 (0 ); - entry = r3k_have_wired_reg ?read_c0_wired () :8 ;for (; entry < current_cpu_data.tlbsize; entry++) {write_c0_index (entry <<8 );write_c0_entryhi ((entry |0x80000 ) <<12 );
@@ -60,6 +52,17 @@ void local_flush_tlb_all(void)tlb_write_indexed (); }write_c0_entryhi (old_ctx); +} + +void local_flush_tlb_all (void ) +{ +unsigned long flags; + +#ifdef DEBUG_TLB +printk ("[tlball]" ); +#endif +local_irq_save (flags); +local_flush_tlb_from (r3k_have_wired_reg ?read_c0_wired () :8 );local_irq_restore (flags); }
@@ -277,7 +280,6 @@ void add_wired_entry(unsigned long entryvoid tlb_init (void ) { -local_flush_tlb_all (); - +local_flush_tlb_from (0 );build_tlb_refill_handler (); }
PATCH 2/3 MIPS: tlb-r3k: Move CP0.Wired register initialisation to `tlb_init'
In reply to Maciej W. RozyckiMove the initialisation of the CP0.Wired register implemented by Toshiba TX3922 and TX3927 processors from tx39_cache_init' to tlb_init' where it belongs, correcting code structure and making sure initialisation does not rely on tx39_cache_init' being called before tlb_init' to work correctly.
Make `r3k_have_wired_reg' static as it's no longer externally referred to; remove a stale declaration too.
---
James,
You may have to reexport `r3k_have_wired_reg' if you implement R3k
SysRq-x changes I suggested and this change goes in first. In that case I suggest that you put the declaration in a header, having them scattered across .c files is asking for trouble.
Maciej
linux-mips-tlb-r3k-init-wired.diff
arch/mips/lib/r3k_dump_tlb.c +0 -2
@@ -14,8 +14,6 @@#include <asm/pgtable.h> #include <asm/tlbdebug.h> -extern int r3k_have_wired_reg;/* defined in tlb-r3k.c */ -static void dump_tlb (int first,int last) {int i;
arch/mips/mm/c-tx39.c +0 -4
@@ -28,8 +28,6 @@ static unsigned long icache_size, dcache#include <asm/r4kcache.h> -extern int r3k_have_wired_reg;/* in r3k-tlb.c */ -/* This sequence is required to ensure icache is disabled immediately */ #define TX39_STOP_STREAMING () \ __asm__ __volatile__( \
@@ -383,8 +381,6 @@ void tx39_cache_init(void)case CPU_TX3927 :default :/* TX39/H2,H3 core (writeback 2way-set-associative cache) */ - r3k_have_wired_reg =1 ; -write_c0_wired (0 );/* set 8 on reset... */ /* board-dependent init code may set WBON */ __flush_cache_vmap = tx39__flush_cache_vmap;
arch/mips/mm/tlb-r3k.c +8 -1
@@ -36,7 +36,7 @@ extern void build_tlb_refill_handler(voi "nop\n\t" \ ".set pop\n\t") -int r3k_have_wired_reg;/* should be in cpu_data? */ +static int r3k_have_wired_reg;/* Should be in cpu_data? */ /* TLB operations. */ static void local_flush_tlb_from (int entry)
@@ -280,6 +280,13 @@ void add_wired_entry(unsigned long entryvoid tlb_init (void ) { +switch (current_cpu_type ()) { +case CPU_TX3922 : +case CPU_TX3927 : + r3k_have_wired_reg =1 ; +write_c0_wired (0 );/* Set to 8 on reset... */ +break ; + }local_flush_tlb_from (0 );build_tlb_refill_handler (); }
PATCH 3/3 MIPS: tlb-r3k: Optimise a TLBWI barrier in TLB invalidation
In reply to Maciej W. RozyckiReplace an explicit barrier with a useful processor instruction in TLB invalidation, following several other such cases elsewhere in `tlb-r3k.c'.
---
linux-mips-tlb-r3k-flush-barrier.diff
arch/mips/mm/tlb-r3k.c +2 -2
@@ -45,10 +45,10 @@ static void local_flush_tlb_from(int ent old_ctx =read_c0_entryhi () &ASID_MASK ;write_c0_entrylo0 (0 ); -for (; entry < current_cpu_data.tlbsize; entry++) { +while (entry < current_cpu_data.tlbsize) {write_c0_index (entry <<8 );write_c0_entryhi ((entry |0x80000 ) <<12 ); -BARRIER ; + entry++;/* BARRIER */ tlb_write_indexed (); }write_c0_entryhi (old_ctx);