linux-stable/arch/mips/mm
Paul Burton 6fce06b68b MIPS: Fix ioremap() RAM check
commit 523402fa91 upstream.

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/
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-17 11:39:23 +02:00
..
c-octeon.c MIPS: c-r4k: Split user/kernel flush_icache_range() 2016-10-04 16:13:57 +02:00
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-30 07:51:46 +02: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 MIPS: Remove __invalidate_kernel_vmap_range 2017-08-29 15:21:55 +02:00
cerr-sb1.c
cex-gen.S
cex-oct.S
cex-sb1.S
dma-default.c MIPS: Declare various variables & functions static 2017-08-29 15:21:55 +02:00
extable.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
fault.c MIPS: Remove confusing else statement in __do_page_fault() 2017-04-13 00:47:04 +02:00
gup.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01: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: Include linux/initrd.h for free_initrd_mem() 2017-08-29 15:21:54 +02:00
ioremap.c MIPS: Fix ioremap() RAM check 2018-07-17 11:39:23 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mmap.c MIPS: Include elf-randomize.h for arch_mmap_rnd() & arch_randomize_brk() 2017-08-29 15:21:54 +02:00
page-funcs.S MIPS: Export {copy, clear}_page functions alongside their definitions 2017-01-03 16:48:39 +01:00
page.c MIPS: Export {copy, clear}_page functions alongside their definitions 2017-01-03 16:48:39 +01:00
pgtable-32.c MIPS: mm: fixed mappings: correct initialisation 2017-06-08 14:51:58 +02:00
pgtable-64.c MIPS: Add 48-bit VA space (and 4-level page tables) for 4K pages. 2017-04-10 11:56:06 +02:00
pgtable.c MIPS: Move pgd_alloc() out of header 2017-02-02 15:06:26 +00:00
sc-debugfs.c Update MIPS email addresses 2017-11-03 09:02:30 -07: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 License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01: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 MIPS: Mask out limit field when calculating wired entry count 2016-11-24 16:44:16 +01:00
tlb-r8k.c MIPS: Retrieve ASID masks using function accepting struct cpuinfo_mips 2016-05-13 14:02:20 +02:00
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: microMIPS: Fix incorrect mask in insn_table_MM 2017-11-01 00:09:16 +00: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