linux-brain/arch/mips
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
..
alchemy License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ar7 MIPS: AR7: ensure the port type's FCR value is used 2018-01-23 19:58:21 +01:00
ath25 MIPS: ath25: Check for kzalloc allocation failure 2018-03-15 10:54:31 +01:00
ath79 Revert "MIPS: perf: ath79: Fix perfcount IRQ assignment" 2019-06-11 12:21:49 +02:00
bcm47xx MIPS: BCM47XX: Enable USB power on Netgear WNDR3400v3 2019-11-20 17:59:44 +01:00
bcm63xx MIPS: BCM63XX: drop unused and broken DSP platform device 2020-01-27 14:46:11 +01:00
bmips License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
boot MIPS: Prevent link failure with kcov instrumentation 2020-01-17 19:45:54 +01:00
cavium-octeon MIPS: OCTEON: cvmx_pko_mem_debug8: use oldest forward compatible definition 2019-12-17 20:38:35 +01:00
cobalt MIPS: Cobalt: Fix typo 2016-08-03 08:16:30 +02:00
configs USB: rio500: Remove Rio 500 kernel driver 2019-10-17 13:43:20 -07:00
dec License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
emma MIPS: Avoid old-style declaration 2017-01-25 02:51:11 +01:00
fw MIPS: fw: sni: Fix out of bounds init of o32 stack 2019-11-06 12:43:17 +01:00
generic MIPS: generic: fix missing of_node_put() 2018-09-19 22:43:43 +02:00
include mips: avoid explicit UB in assignment of mips_io_port_base 2020-01-27 14:46:44 +01:00
jazz MIPS: jazz: fix 64bit build 2019-02-27 10:08:04 +01:00
jz4740 MIPS: lb60: Fix pin mappings 2019-07-31 07:28:47 +02:00
kernel mips: avoid explicit UB in assignment of mips_io_port_base 2020-01-27 14:46:44 +01:00
kvm KVM: s390: Do not report unusabled IDs via KVM_CAP_MAX_VCPU_ID 2019-06-09 09:18:16 +02:00
lantiq MIPS: lantiq: Fix bitfield masking 2019-08-06 19:05:20 +02:00
lasat License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
lib MIPS: lib: Provide MIPS64r6 __multi3() for GCC < 7 2018-09-05 09:26:41 +02:00
loongson32 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
loongson64 mips: Loongson: Fix the link time qualifier of 'serial_exit()' 2019-10-29 09:16:58 +01:00
math-emu MIPS: math-emu: Write-protect delay slot emulation pages 2019-01-09 17:14:51 +01:00
mm MIPS: tlbex: Fix build_restore_pagemask KScratch restore 2019-10-29 09:17:30 +01:00
mti-malta Update MIPS email addresses 2017-11-03 09:02:30 -07:00
net bpf, mips: Limit to 33 tail calls 2020-01-12 12:11:54 +01:00
netlogic License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
oprofile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
paravirt License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pci MIPS: OCTEON: don't set octeon_dma_bar_type if PCI is disabled 2019-02-15 08:09:12 +01:00
pic32 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pistachio MIPS: pistachio: Build uImage.gz by default 2019-06-11 12:21:49 +02:00
pmcs-msp71xx License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pnx833x mtd: nand: Rename nand.h into rawnand.h 2017-08-13 10:11:49 +02:00
power License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ralink MIPS: ralink: Select CONFIG_CPU_MIPSR2_IRQ_VI on MT7620/8 2019-02-12 19:46:08 +01:00
rb532 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sgi-ip22 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sgi-ip27 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sgi-ip32 MIPS: Add missing include files 2017-03-08 10:38:06 +01:00
sibyte Revert "MIPS: SiByte: Enable swiotlb for SWARM, LittleSur and BigSur" 2019-09-19 09:08:03 +02:00
sni License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tools Update MIPS email addresses 2017-11-03 09:02:30 -07:00
txx9 mips: txx9: fix iounmap related issue 2019-11-20 17:59:48 +01:00
vdso MIPS: Disable Loongson MMI instructions for kernel build 2019-10-17 13:43:51 -07:00
vr41xx License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
xilfpga License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Kbuild MIPS: Disable Werror when W= is set 2017-04-10 11:56:07 +02:00
Kbuild.platforms MIPS: generic: Convert SEAD-3 to a generic board 2016-10-06 18:04:20 +02:00
Kconfig MIPS: SiByte: Enable ZONE_DMA32 for LittleSur 2019-12-17 20:37:52 +01:00
Kconfig.debug License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Makefile MIPS: Always use -march=<arch>, not -<arch> shortcuts 2018-09-05 09:26:41 +02:00
Makefile.postlink License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00