linux-brain/arch/mips/kernel
Nick Desaulniers 0972c51f34 mips: avoid explicit UB in assignment of mips_io_port_base
[ Upstream commit 12051b318b ]

The code in question is modifying a variable declared const through
pointer manipulation.  Such code is explicitly undefined behavior, and
is the lone issue preventing malta_defconfig from booting when built
with Clang:

If an attempt is made to modify an object defined with a const-qualified
type through use of an lvalue with non-const-qualified type, the
behavior is undefined.

LLVM is removing such assignments. A simple fix is to not declare
variables const that you plan on modifying.  Limiting the scope would be
a better method of preventing unwanted writes to such a variable.

Further, the code in question mentions "compiler bugs" without any links
to bug reports, so it is difficult to know if the issue is resolved in
GCC. The patch was authored in 2006, which would have been GCC 4.0.3 or
4.1.1. The minimal supported version of GCC in the Linux kernel is
currently 4.6.

For what its worth, there was UB before the commit in question, it just
added a barrier and got lucky IRT codegen. I don't think there's any
actual compiler bugs related, just runtime bugs due to UB.

Link: https://github.com/ClangBuiltLinux/linux/issues/610
Fixes: 966f4406d9 ("[MIPS] Work around bad code generation for <asm/io.h>.")
Reported-by: Nathan Chancellor <natechancellor@gmail.com>
Debugged-by: Nathan Chancellor <natechancellor@gmail.com>
Suggested-by: Eli Friedman <efriedma@quicinc.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Paul Burton <paul.burton@mips.com>
Cc: ralf@linux-mips.org
Cc: jhogan@kernel.org
Cc: Maciej W. Rozycki <macro@linux-mips.org>
Cc: Hassan Naveed <hnaveed@wavecomp.com>
Cc: Stephen Kitt <steve@sk2.org>
Cc: Serge Semin <fancer.lancer@gmail.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: linux-mips@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: clang-built-linux@googlegroups.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-01-27 14:46:44 +01:00
..
.gitignore
8250-platform.c
asm-offsets.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
binfmt_elfn32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
binfmt_elfo32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
bmips_5xxx_init.S MIPS: BMIPS: Make whitespacely correct. 2016-05-09 12:00:01 +02:00
bmips_vec.S MIPS: BMIPS: Add Whirlwind (BMIPS5200) initialization code 2016-05-09 12:00:01 +02:00
branch.c MIPS: Use pr_debug' for messages from __compute_return_epc_for_insn' 2017-06-29 02:42:27 +02:00
cacheinfo.c mips: cacheinfo: report shared CPU map 2020-01-17 19:45:53 +01:00
cevt-bcm1480.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cevt-ds1287.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cevt-gt641xx.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cevt-r4k.c MIPS: cevt-r4k: Fix out-of-bounds array access 2017-04-10 13:31:12 +02:00
cevt-sb1250.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cevt-txx9.c MIPS: clockevent drivers: Set ->min_delta_ticks and ->max_delta_ticks 2017-04-14 13:11:16 -07:00
cmpxchg.c MIPS: fix truncation in __cmpxchg_small for short values 2019-03-05 17:58:03 +01:00
cps-vec-ns16550.S Update MIPS email addresses 2017-11-03 09:02:30 -07:00
cps-vec.S Update MIPS email addresses 2017-11-03 09:02:30 -07:00
cpu-bugs64.c MIPS: Fix printk continuations in cpu-bugs64.c 2017-01-24 18:30:34 +01:00
cpu-probe.c MIPS: Add CPU cluster number accessors 2017-08-30 00:57:27 +02:00
crash_dump.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
crash.c MIPS: kexec: Mark CPU offline before disabling local IRQ 2018-11-21 09:24:03 +01:00
csrc-bcm1480.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-ioasic.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-r4k.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
csrc-sb1250.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
early_printk_8250.c MIPS: Add 8250/16550 serial early printk driver 2013-10-29 21:24:36 +01:00
early_printk.c early_printk: consolidate random copies of identical code 2013-04-29 18:28:13 -07:00
elf.c Update MIPS email addresses 2017-11-03 09:02:30 -07:00
entry.S MIPS: Fix IRQ tracing & lockdep when rescheduling 2017-06-30 04:40:18 +02:00
ftrace.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
genex.S MIPS: Add DWARF unwinding to assembly 2017-09-06 11:01:52 +02:00
gpio_txx9.c MIPS: txx9: switch to gpiochip_add_data() 2016-02-19 09:51:44 +01:00
head.S MIPS: head: Reorder instructions missing a delay slot 2017-06-27 23:35:21 +02:00
i8253.c MIPS: kernel: only use i8253 clocksource with periodic clockevent 2019-08-29 08:26:37 +02:00
idle.c MIPS: Include linux/cpu.h for arch_cpu_idle() 2017-08-29 15:21:54 +02:00
irq_txx9.c MIPS: Whitespace cleanup. 2013-02-01 10:00:22 +01:00
irq-gt641xx.c MIPS: Whitespace cleanup. 2013-02-01 10:00:22 +01:00
irq-msc01.c MIPS: MSC: Prevent out-of-bounds writes to MIPS SC ioremap'd region 2014-06-26 10:48:23 +01:00
irq-rm7000.c MIPS: Whitespace cleanup. 2013-02-01 10:00:22 +01:00
irq.c MIPS: irq: Allocate accurate order pages for irq stack 2019-03-13 14:03:10 -07:00
jump_label.c jump_label: Reorder hotplug lock and jump_label_lock 2017-05-26 10:10:45 +02:00
kgdb.c MIPS: KGDB: fix kgdb support for SMP platforms. 2019-05-10 17:53:09 +02:00
kprobes.c MIPS: tracing: disable uprobe/kprobe on compact branch instructions 2016-10-06 17:37:40 +02:00
linux32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
machine_kexec.c MIPS: kexec: Mark CPU offline before disabling local IRQ 2018-11-21 09:24:03 +01:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mcount.S mips: ftrace: fix static function graph tracing 2018-07-03 11:24:48 +02:00
mips_machine.c MIPS: move mips_{set,get}_machine_name() to a more generic place 2013-05-08 01:19:07 +02:00
mips-cm.c mips: cm: reprime error cause 2019-02-15 08:09:12 +01:00
mips-cpc.c MIPS: CPC: Map registers using DT in mips_cpc_default_phys_base() 2018-03-15 10:54:35 +01:00
mips-mt-fpaff.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mips-mt.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mips-r2-to-r6-emul.c MIPS: Declare various variables & functions static 2017-08-29 15:21:55 +02:00
module.c Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2017-07-15 10:59:54 -07:00
octeon_switch.S MIPS: Move r4k FP code from r4k_switch.S to r4k_fpu.S 2017-08-29 15:21:51 +02:00
perf_event_mipsxx.c MIPS: Fix perf event init 2017-09-20 10:47:12 +02:00
perf_event.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
pm-cps.c Update MIPS email addresses 2017-11-03 09:02:30 -07:00
pm.c MIPS: Fix watchpoint restoration 2016-05-09 12:00:02 +02:00
probes-common.h MIPS: Update email address for Marcin Nowakowski 2017-11-02 10:58:43 +00:00
proc.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
process.c MIPS: Remove function size check in get_frame_info() 2019-03-13 14:03:22 -07:00
prom.c MIPS: Use early_init_fdt_reserve_self to protect DTB location 2017-01-03 16:34:45 +01:00
ptrace.c MIPS: Correct the 64-bit DSP accumulator register size 2018-09-05 09:26:41 +02:00
ptrace32.c MIPS: Correct the 64-bit DSP accumulator register size 2018-09-05 09:26:41 +02:00
r4k_fpu.S MIPS: Fix MIPS64 FP save/restore on 32-bit kernels 2017-11-30 08:40:43 +00:00
r4k_switch.S MIPS: Move r4k FP code from r4k_switch.S to r4k_fpu.S 2017-08-29 15:21:51 +02:00
r2300_fpu.S MIPS: Move r2300 FP code from r2300_switch.S to r2300_fpu.S 2017-08-29 15:21:51 +02:00
r2300_switch.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
relocate_kernel.S MIPS: Replace add and sub instructions in relocate_kernel.S with addiu 2015-08-03 15:26:30 +02:00
relocate.c Update MIPS email addresses 2017-11-03 09:02:30 -07:00
reset.c MIPS: Provide fallback reboot/poweroff/halt implementations 2015-04-01 17:21:58 +02:00
rtlx-cmp.c MIPS: APRP: Fix an issue when device_create() fails. 2014-08-01 17:30:35 +02:00
rtlx-mt.c MIPS: APRP: Fix an issue when device_create() fails. 2014-08-01 17:30:35 +02:00
rtlx.c sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
scall32-o32.S MIPS: Remove pt_regs adjustments in indirect syscall handler 2017-08-29 15:48:34 +02:00
scall64-64.S MIPS: Save static registers before sysmips 2017-06-28 12:22:40 +02:00
scall64-n32.S MIPS: Save static registers before sysmips 2017-06-28 12:22:40 +02:00
scall64-o32.S MIPS: scall64-o32: Fix indirect syscall number load 2019-05-02 09:40:28 +02:00
segment.c MIPS: Print segment physical address when EU=1 2016-07-28 11:44:30 +02:00
setup.c mips: avoid explicit UB in assignment of mips_io_port_base 2020-01-27 14:46:44 +01:00
signal_n32.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
signal_o32.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
signal-common.h MIPS: Save MSA extended context around signals 2015-09-03 12:07:59 +02:00
signal.c Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2016-08-06 09:13:11 -04:00
signal32.c signal: Remove kernel interal si_code magic 2017-07-24 14:30:28 -05:00
smp-bmips.c MIPS: bmips: mark exception vectors as char arrays 2019-11-10 11:25:18 +01:00
smp-cmp.c MIPS: smp-cmp: Fix vpe_id build error 2017-11-01 23:23:00 +00:00
smp-cps.c Update MIPS email addresses 2017-11-03 09:02:30 -07:00
smp-mt.c MIPS: Use mips_gic_present() in place of gic_present 2017-09-04 13:53:14 +02:00
smp-up.c MIPS: SMP: Allow boot_secondary SMP op to return errors 2017-08-30 00:57:27 +02:00
smp.c MIPS: SMP: Fix deadlock & online race 2017-11-01 00:09:17 +00:00
spinlock_test.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
spram.c MIPS: Add P6600 cases to CPU switch statements 2016-05-13 14:01:52 +02:00
stacktrace.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
sync-r4k.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
syscall.c MIPS: Branch straight to ll in mips_atomic_set() 2017-06-28 12:22:40 +02:00
sysrq.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
time.c MIPS: Remove plat_timer_setup() 2017-08-29 15:21:55 +02:00
topology.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
traps.c MIPS: Call dump_stack() from show_regs() 2018-07-17 11:39:23 +02:00
unaligned.c MIPS: Declare various variables & functions static 2017-08-29 15:21:55 +02:00
uprobes.c MIPS: uprobes: remove set but not used variable 'epc' 2019-06-25 11:36:52 +08:00
vdso.c MIPS: math-emu: Write-protect delay slot emulation pages 2019-01-09 17:14:51 +01:00
vmlinux.lds.S MIPS: Ensure ELF appended dtb is relocated 2019-03-27 14:13:52 +09:00
vpe-cmp.c MIPS: APRP: Add VPE loader support for CMP platforms. 2014-01-22 20:19:02 +01:00
vpe-mt.c MIPS: MT: Remove SMTC support 2014-05-24 00:07:01 +02:00
vpe.c module: use a structure to encapsulate layout. 2015-12-04 22:46:25 +01:00
watch.c MIPS: Add and use watch register field definitions 2016-05-13 14:02:13 +02:00