Skip to content

Commit 172dcd9

Browse files
committed
MIPS: Always allocate exception vector for MIPSr2+
Currently we allocate the exception vector on systems which use a vectored interrupt mode, but otherwise attempt to reuse whatever exception vector the bootloader uses. This can be problematic for a number of reasons: 1) The memory isn't properly marked reserved in the memblock allocator. We've relied on the fact that EBase is generally in the memory below the kernel image which we don't free, but this is about to change. 2) Recent versions of U-Boot place their exception vector high in kseg0, in memory which isn't protected by being lower than the kernel anyway & can end up being clobbered. 3) We are unnecessarily reliant upon there being memory at the address EBase points to upon entry to the kernel. This is often the case, but if the bootloader doesn't configure EBase & leaves it with its default value then we rely upon there being memory at physical address 0 for no good reason. Improve this situation by allocating the exception vector in all cases when running on MIPSr2 or higher, and reserving the memory for MIPSr1 or lower. This ensures we don't clobber the exception vector in any configuration, and for MIPSr2 & higher removes the need for memory at physical address 0. Signed-off-by: Paul Burton <paul.burton@mips.com> Reviewed-by: Serge Semin <fancer.lancer@gmail.com> Tested-by: Serge Semin <fancer.lancer@gmail.com> Cc: linux-mips@vger.kernel.org
1 parent f995adb commit 172dcd9

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

arch/mips/kernel/traps.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,18 +2284,27 @@ void __init trap_init(void)
22842284
extern char except_vec3_generic;
22852285
extern char except_vec4;
22862286
extern char except_vec3_r4000;
2287-
unsigned long i;
2287+
unsigned long i, vec_size;
2288+
phys_addr_t ebase_pa;
22882289

22892290
check_wait();
22902291

2291-
if (cpu_has_veic || cpu_has_vint) {
2292-
unsigned long size = 0x200 + VECTORSPACING*64;
2293-
phys_addr_t ebase_pa;
2292+
if (!cpu_has_mips_r2_r6) {
2293+
ebase = CAC_BASE;
2294+
ebase_pa = virt_to_phys((void *)ebase);
2295+
vec_size = 0x400;
2296+
2297+
memblock_reserve(ebase_pa, vec_size);
2298+
} else {
2299+
if (cpu_has_veic || cpu_has_vint)
2300+
vec_size = 0x200 + VECTORSPACING*64;
2301+
else
2302+
vec_size = PAGE_SIZE;
22942303

2295-
ebase_pa = memblock_phys_alloc(size, 1 << fls(size));
2304+
ebase_pa = memblock_phys_alloc(vec_size, 1 << fls(vec_size));
22962305
if (!ebase_pa)
22972306
panic("%s: Failed to allocate %lu bytes align=0x%x\n",
2298-
__func__, size, 1 << fls(size));
2307+
__func__, vec_size, 1 << fls(vec_size));
22992308

23002309
/*
23012310
* Try to ensure ebase resides in KSeg0 if possible.
@@ -2312,20 +2321,6 @@ void __init trap_init(void)
23122321
ebase = CKSEG0ADDR(ebase_pa);
23132322
else
23142323
ebase = (unsigned long)phys_to_virt(ebase_pa);
2315-
} else {
2316-
ebase = CAC_BASE;
2317-
2318-
if (cpu_has_mips_r2_r6) {
2319-
if (cpu_has_ebase_wg) {
2320-
#ifdef CONFIG_64BIT
2321-
ebase = (read_c0_ebase_64() & ~0xfff);
2322-
#else
2323-
ebase = (read_c0_ebase() & ~0xfff);
2324-
#endif
2325-
} else {
2326-
ebase += (read_c0_ebase() & 0x3ffff000);
2327-
}
2328-
}
23292324
}
23302325

23312326
if (cpu_has_mmips) {

0 commit comments

Comments
 (0)