linux-stable/arch/mips/mm
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
..
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
c-octeon.c
c-r3k.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
c-r4k.c MIPS: c-r4k: Fix data corruption related to cache coherence 2018-05-14 23:52:40 +01:00
c-tx39.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cache.c mm: fix races between swapoff and flush dcache 2018-04-05 21:36:26 -07:00
cerr-sb1.c
cex-gen.S
cex-oct.S
cex-sb1.S
dma-default.c dma-debug: move initialization to common code 2018-05-08 13:02:42 +02:00
extable.c
fault.c signal/mips: Use force_sig_fault where appropriate 2018-04-25 10:41:02 -05:00
gup.c mm/gup.c: document return value 2018-04-13 17:10:27 -07:00
highmem.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hugetlbpage.c mm/hugetlb: add size parameter to huge_pte_offset() 2017-07-06 16:24:34 -07:00
init.c MIPS: Remove duplicate includes 2018-02-19 10:55:35 +00:00
ioremap.c MIPS: Fix ioremap() RAM check 2018-07-05 14:43:21 -07:00
mmap.c exec: pass stack rlimit into mm layout functions 2018-04-11 10:28:37 -07:00
page-funcs.S
page.c
pgtable-32.c
pgtable-64.c
pgtable.c
sc-debugfs.c MIPS: Re-use kstrtobool_from_user() 2018-05-14 23:58:23 +01:00
sc-ip22.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sc-mips.c MIPS: JZ4770: Work around config2 misreporting associativity 2018-01-18 22:07:44 +00:00
sc-r5k.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sc-rm7k.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tlb-funcs.S
tlb-r3k.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tlb-r4k.c
tlb-r8k.c
tlbex-fault.S MIPS: Add DWARF unwinding to assembly 2017-09-06 11:01:52 +02:00
tlbex.c MIPS: Remove unused R6000 support 2017-08-29 15:21:51 +02:00
uasm-micromips.c MIPS: mm: Fix duplicate "const" on insn_table_MM 2018-01-10 16:47:55 +01:00
uasm-mips.c MIPS: mm: remove duplicate "const" qualifier on insn_table 2017-08-07 11:57:30 +02:00
uasm.c MIPS: Add some instructions to uasm. 2017-06-28 12:22:39 +02:00