This is something I ran into while working on support for the UEFI
memory attributes and ESRT tables. In both cases, these tables are
passed to the kernel in memory which is guaranteed to be below 4 GB,
but may be outside of the kernel direct mapping. (UEFI typically
attempts to allocate from the top down, which means such tables are
highly likely to be in highmem for any system with more than 760 MB
of system RAM)
The recently introduced memremap() is a very useful abstraction for
accessing such tables, because it is generic, and already attempts to
do the right thing with respect to regions that may already have been
mapped directly. However, it falls back to ioremap_cache() for mapping
high memory, which is not allowed on ARM for system RAM, and also results
in the region to be mapped with different attributes depending on whether
it is covered by lowmem or not.
So instead, create an arch specific hook 'arch_memremap_wb(), and
implement it for ARM using the same memory attributes used for the
linear mapping. Note that memremap will only call this hook for regions
that are not already mapped permanently.
Since this change results in memremap() to use attributes different from
the ones used by ioremap_cache(), revert the change to pxa2xx-flash that
moved it to memremap.
Changes since v3:
- fix inadvertent logic change, where a arch_memremap_wb() would only be
attempted on a region that intersects System RAM
Changes since v2:
- add patch to bring back ioremap_cached() on ARM
- switch pxa2xx-flash back to ioremap_cached() not ioremap_cache()
- use arch_ioremap_caller not __arm_ioremap_caller() in patch #4
- deal with __iomem annotation of arch_ioremap_caller (patch #4)
Changes since v1/rfc:
- new patch #1 that reverts the ioremap_cache->memremap conversion for the
pxa2xx-flash driver
- added Dan's ack to patch #2
Ard Biesheuvel (4):
ARM: reintroduce ioremap_cached() for creating cached I/O mappings
mtd: pxa2xx-flash: switch back from memremap to ioremap_cached
memremap: add arch specific hook for MEMREMAP_WB mappings
ARM: memremap: implement arch_memremap_wb()
arch/arm/include/asm/io.h | 12 ++++++++++++
arch/arm/mm/ioremap.c | 16 ++++++++++++++--
drivers/mtd/maps/pxa2xx-flash.c | 6 +++---
kernel/memremap.c | 11 +++++++++--
4 files changed, 38 insertions(+), 7 deletions(-)
--
2.5.0
The original ARM-only ioremap flavor 'ioremap_cached' has been renamed
to 'ioremap_cache' to align with other architectures, and subsequently
abused in generic code to map things like firmware tables in memory.
For that reason, there is currently an effort underway to deprecate
ioremap_cache, whose semantics are poorly defined, and which is typed
with an __iomem annotation that is inappropriate for mappings of ordinary
memory.
However, original users of ioremap_cached() used it in a context where
the I/O connotation is appropriate, and replacing those instances with
memremap() does not make sense. So let's revive ioremap_cached(), so
that we can change back those original users before we drop ioremap_cache
entirely in favor of memremap.
Cc: Russell King <redacted>
Acked-by: Dan Williams <redacted>
Signed-off-by: Ard Biesheuvel <redacted>
---
arch/arm/include/asm/io.h | 6 ++++++
arch/arm/mm/ioremap.c | 4 ++++
2 files changed, 10 insertions(+)
This reverts commit 06968a54790d ("mtd: pxa2xx-flash: switch from
ioremap_cache to memremap"), since NOR with memory semantics in array mode
and RAM are not necessarily the same thing, and architectures may implement
ioremap_cached() and memremap() with different memory attributes.
For this reason, ioremap_cached() has been brought back from the dead on
the ARM side, so switch this driver back to using it instead of memremap().
Cc: David Woodhouse <dwmw2@infradead.org>
Acked-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Dan Williams <redacted>
Signed-off-by: Ard Biesheuvel <redacted>
---
drivers/mtd/maps/pxa2xx-flash.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Currently, the memremap code serves MEMREMAP_WB mappings directly from
the kernel direct mapping, unless the region is in high memory, in which
case it falls back to using ioremap_cache(). However, the semantics of
ioremap_cache() are not unambiguously defined, and on ARM, it will
actually result in a mapping type that differs from the attributes used
for the linear mapping, and for this reason, the ioremap_cache() call
fails if the region is part of the memory managed by the kernel.
So instead, implement an optional hook 'arch_memremap_wb' whose default
implementation calls ioremap_cache() as before, but which can be
overridden by the architecture to do what is appropriate for it.
Acked-by: Dan Williams <redacted>
Signed-off-by: Ard Biesheuvel <redacted>
---
kernel/memremap.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
@@ -34,7 +41,7 @@ static void *try_ram_remap(resource_size_t offset, size_t size)/* In the simple case just return the existing linear address */if(pfn_valid(pfn)&&!PageHighMem(pfn_to_page(pfn)))return__va(offset);-returnNULL;/* fallback to ioremap_cache */+returnNULL;/* fallback to arch_memremap_wb */}/**
The generic memremap() falls back to using ioremap_cache() to create
MEMREMAP_WB mappings if the requested region is not already covered
by the linear mapping, unless the architecture provides an implementation
of arch_memremap_wb().
Since ioremap_cache() is not appropriate on ARM to map memory with the
same attributes used for the linear mapping, implement arch_memremap_wb()
which does exactly that. Also, relax the WARN() check to allow MT_MEMORY_RW
mappings of pfn_valid() pages.
Cc: Russell King <redacted>
Acked-by: Dan Williams <redacted>
Signed-off-by: Ard Biesheuvel <redacted>
---
arch/arm/include/asm/io.h | 6 ++++++
arch/arm/mm/ioremap.c | 12 ++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)