kernel_optimize_test/arch/mips/kernel
Tiezhu Yang 269b3a9ac5 MIPS: Make sparse_init() using top-down allocation
In the current code, if CONFIG_SWIOTLB is set, when failed to get IO TLB
memory from the low pages by plat_swiotlb_setup(), it may lead to the boot
process failed with kernel panic.

(1) On the Loongson and SiByte platform
arch/mips/loongson64/dma.c
arch/mips/sibyte/common/dma.c
void __init plat_swiotlb_setup(void)
{
	swiotlb_init(1);
}

kernel/dma/swiotlb.c
void  __init
swiotlb_init(int verbose)
{
...
	vstart = memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE);
	if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, verbose))
		return;
...
	pr_warn("Cannot allocate buffer");
	no_iotlb_memory = true;
}

phys_addr_t swiotlb_tbl_map_single()
{
...
	if (no_iotlb_memory)
		panic("Can not allocate SWIOTLB buffer earlier ...");
...
}

(2) On the Cavium OCTEON platform
arch/mips/cavium-octeon/dma-octeon.c
void __init plat_swiotlb_setup(void)
{
...
	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
	if (!octeon_swiotlb)
		panic("%s: Failed to allocate %zu bytes align=%lx\n",
		      __func__, swiotlbsize, PAGE_SIZE);
...
}

Because IO_TLB_DEFAULT_SIZE is 64M, if the rest size of low memory is less
than 64M when call plat_swiotlb_setup(), we can easily reproduce the panic
case.

In order to reduce the possibility of kernel panic when failed to get IO
TLB memory under CONFIG_SWIOTLB, it is better to allocate low memory as
small as possible before plat_swiotlb_setup(), so make sparse_init() using
top-down allocation.

Reported-by: Juxin Gao <gaojuxin@loongson.cn>
Co-developed-by: Juxin Gao <gaojuxin@loongson.cn>
Signed-off-by: Juxin Gao <gaojuxin@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
2020-04-21 16:07:27 +02:00
..
syscalls asm-generic: fix unistd_32.h generation format 2020-04-07 10:43:42 -07:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
8250-platform.c
asm-offsets.c
binfmt_elfn32.c y2038: elfcore: Use __kernel_old_timeval for process times 2019-11-15 14:38:29 +01:00
binfmt_elfo32.c y2038: elfcore: Use __kernel_old_timeval for process times 2019-11-15 14:38:29 +01:00
bmips_5xxx_init.S
bmips_vec.S
branch.c MIPS: Don't use bc_false uninitialized in __mm_isBranchInstr 2019-08-11 21:44:24 -07:00
cacheinfo.c mips: cacheinfo: report shared CPU map 2019-11-26 10:33:08 -08:00
cevt-bcm1480.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cevt-ds1287.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cevt-gt641xx.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cevt-r4k.c MIPS: pass non-NULL dev_id on shared request_irq() 2020-03-16 16:04:49 +01:00
cevt-sb1250.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cevt-txx9.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
cmpxchg.c
cps-vec-ns16550.S
cps-vec.S
cpu-probe.c Use ELF_BASE_PLATFORM to pass ISA level 2020-03-19 13:09:33 +01:00
crash_dump.c
crash.c
csrc-bcm1480.c
csrc-ioasic.c
csrc-r4k.c mips: vdso: Use generic VDSO clock mode storage 2020-02-17 20:12:16 +01:00
csrc-sb1250.c
early_printk_8250.c
early_printk.c
elf.c
entry.S sched/rt, MIPS: Use CONFIG_PREEMPTION 2019-12-08 14:37:34 +01:00
ftrace.c MIPS: ftrace: Reword prepare_ftrace_return() comment block 2019-06-11 15:46:21 -07:00
genex.S MIPS: genex: Don't reload address unnecessarily 2019-10-07 09:43:10 -07:00
gpio_txx9.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
head.S
i8253.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
idle.c MIPS: Loongson: Rename LOONGSON1 to LOONGSON32 2019-11-11 10:43:13 -08:00
irq_txx9.c
irq-gt641xx.c
irq-msc01.c
irq-rm7000.c
irq.c
jump_label.c
kgdb.c
kprobes.c mm, kprobes: generalize and rename notify_page_fault() as kprobe_page_fault() 2019-07-16 19:23:22 -07:00
linux32.c
machine_kexec.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 230 2019-06-19 17:09:06 +02:00
Makefile MIPS: r4k-bugs64: Limit R4k bug checks to affected systems 2019-10-07 09:38:53 -07:00
mcount.S
mips_machine.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
mips-cm.c remove ioremap_nocache and devm_ioremap_nocache 2020-01-06 09:45:59 +01:00
mips-cpc.c remove ioremap_nocache and devm_ioremap_nocache 2020-01-06 09:45:59 +01:00
mips-mt-fpaff.c
mips-mt.c
mips-r2-to-r6-emul.c
module.c
octeon_switch.S
perf_event_mipsxx.c MIPS: Loongson: Rename LOONGSON1 to LOONGSON32 2019-11-11 10:43:13 -08:00
perf_event.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
pm-cps.c MIPS: barrier: Add __SYNC() infrastructure 2019-10-07 09:42:17 -07:00
pm.c
probes-common.h
proc.c MIPS: Treat Loongson Extensions as ASEs 2019-08-26 11:42:40 +01:00
process.c MIPS: Exclude more dsemul code when CONFIG_MIPS_FP_SUPPORT=n 2020-03-25 16:07:14 +01:00
prom.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ptrace.c
ptrace32.c
r4k_fpu.S
r4k_switch.S
r4k-bugs64.c MIPS: r4k-bugs64: Drop CONFIG_CPU_MIPSR6 checks 2019-10-07 09:38:54 -07:00
r2300_fpu.S
r2300_switch.S
relocate_kernel.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 230 2019-06-19 17:09:06 +02:00
relocate.c
reset.c
rtlx-cmp.c
rtlx-mt.c MIPS: Replace setup_irq() by request_irq() 2020-03-05 16:47:35 +01:00
rtlx.c
scall32-o32.S mips: remove nargs from __SYSCALL 2019-07-30 10:50:30 -07:00
scall64-n32.S mips: remove nargs from __SYSCALL 2019-07-30 10:50:30 -07:00
scall64-n64.S mips: remove nargs from __SYSCALL 2019-07-30 10:50:30 -07:00
scall64-o32.S mips: remove nargs from __SYSCALL 2019-07-30 10:50:30 -07:00
segment.c
setup.c MIPS: Make sparse_init() using top-down allocation 2020-04-21 16:07:27 +02:00
signal_n32.c Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2019-07-08 21:48:15 -07:00
signal_o32.c
signal-common.h
signal.c
signal32.c
smp-bmips.c MIPS: Drop pmon.h 2019-11-11 10:44:52 -08:00
smp-cmp.c
smp-cps.c
smp-mt.c
smp-up.c
smp.c MIPS updates for v5.7: 2020-03-31 08:51:45 -07:00
spinlock_test.c
spram.c
stacktrace.c
sync-r4k.c MIPS: sync-r4k: do slave counter synchronization with disabled HW interrupts 2020-01-22 10:16:18 -08:00
syscall.c MIPS: syscall: Emit Loongson3 sync workarounds within asm 2019-10-07 09:43:05 -07:00
sysrq.c
time.c
topology.c
traps.c MIPS: kdb: Remove old workaround for backtracing on other CPUs 2020-01-31 17:33:51 +00:00
unaligned.c MIPS: make CPU_HAS_LOAD_STORE_LR opt-out 2020-01-22 10:16:47 -08:00
uprobes.c
vdso.c MIPS: Exclude more dsemul code when CONFIG_MIPS_FP_SUPPORT=n 2020-03-25 16:07:14 +01:00
vmlinux.lds.S vmlinux.lds.h: Replace RODATA with RO_DATA 2019-11-04 15:53:15 +01:00
vpe-cmp.c
vpe-mt.c
vpe.c MIPS: VPE: Fix a double free and a memory leak in 'release_vpe()' 2020-02-15 12:44:03 -08:00
watch.c