original_kernel/arch/mips
Paul Burton 523402fa91
MIPS: Fix ioremap() RAM check
We currently attempt to check whether a physical address range provided
to __ioremap() may be in use by the page allocator by examining the
value of PageReserved for each page in the region - lowmem pages not
marked reserved are presumed to be in use by the page allocator, and
requests to ioremap them fail.

The way we check this has been broken since commit 92923ca3aa ("mm:
meminit: only set page reserved in the memblock region"), because
memblock will typically not have any knowledge of non-RAM pages and
therefore those pages will not have the PageReserved flag set. Thus when
we attempt to ioremap a region outside of RAM we incorrectly fail
believing that the region is RAM that may be in use.

In most cases ioremap() on MIPS will take a fast-path to use the
unmapped kseg1 or xkphys virtual address spaces and never hit this path,
so the only way to hit it is for a MIPS32 system to attempt to ioremap()
an address range in lowmem with flags other than _CACHE_UNCACHED.
Perhaps the most straightforward way to do this is using
ioremap_uncached_accelerated(), which is how the problem was discovered.

Fix this by making use of walk_system_ram_range() to test the address
range provided to __ioremap() against only RAM pages, rather than all
lowmem pages. This means that if we have a lowmem I/O region, which is
very common for MIPS systems, we're free to ioremap() address ranges
within it. A nice bonus is that the test is no longer limited to lowmem.

The approach here matches the way x86 performed the same test after
commit c81c8a1eee ("x86, ioremap: Speed up check for RAM pages") until
x86 moved towards a slightly more complicated check using walk_mem_res()
for unrelated reasons with commit 0e4c12b45a ("x86/mm, resource: Use
PAGE_KERNEL protection for ioremap of memory pages").

Signed-off-by: Paul Burton <paul.burton@mips.com>
Reported-by: Serge Semin <fancer.lancer@gmail.com>
Tested-by: Serge Semin <fancer.lancer@gmail.com>
Fixes: 92923ca3aa ("mm: meminit: only set page reserved in the memblock region")
Cc: James Hogan <jhogan@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: stable@vger.kernel.org # v4.2+
Patchwork: https://patchwork.linux-mips.org/patch/19786/
2018-07-05 14:43:21 -07:00
..
alchemy Merge branch 'i2c/for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux 2018-06-14 16:21:46 +09:00
ar7
ath25
ath79 MIPS: pb44: Fix i2c-gpio GPIO descriptor table 2018-06-18 22:19:50 +01:00
bcm47xx MIPS: BCM47XX: Enable 74K Core ExternalSync for PCIe erratum 2018-06-18 22:19:50 +01:00
bcm63xx
bmips treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
boot MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
cavium-octeon
cobalt
configs MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
crypto
dec
emma
fw
generic
include MIPS: Wire up io_pgetevents syscall 2018-06-19 21:14:29 -07:00
jazz
jz4740
kernel MIPS: Use async IPIs for arch_trigger_cpumask_backtrace() 2018-06-28 14:14:41 -07:00
kvm Small update for KVM. 2018-06-12 11:34:04 -07:00
lantiq
lasat
lib
loongson32
loongson64 MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
math-emu
mm MIPS: Fix ioremap() RAM check 2018-07-05 14:43:21 -07:00
mti-malta
net
netlogic
oprofile
paravirt
pci pci-v4.18-changes 2018-06-07 12:45:58 -07:00
pic32
pistachio
pmcs-msp71xx
pnx833x
power
ralink
rb532
sgi-ip22
sgi-ip27
sgi-ip32
sibyte MIPS changes for 4.18 2018-06-12 12:56:02 -07:00
sni
tools
txx9 treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
vdso
vr41xx
Kbuild
Kbuild.platforms
Kconfig MIPS: Add support for restartable sequences 2018-06-19 21:13:17 -07:00
Kconfig.debug
Makefile kbuild: add machine size to CHECKFLAGS 2018-06-01 11:36:58 +09:00
Makefile.postlink