Skip to content

Commit cf61e2a

Browse files
Brian Starkeytorvalds
authored andcommitted
memremap: don't modify flags
These patches implement a MEMREMAP_WC flag for memremap(), which can be used to obtain writecombine mappings. This is then used for setting up dma_coherent_mem regions which use the DMA_MEMORY_MAP flag. The motivation is to fix an alignment fault on arm64, and the suggestion to implement MEMREMAP_WC for this case was made at [1]. That particular issue is handled in patch 4, which makes sure that the appropriate memset function is used when zeroing allocations mapped as IO memory. This patch (of 4): Don't modify the flags input argument to memremap(). MEMREMAP_WB is already a special case so we can check for it directly instead of clearing flag bits in each mapper. Signed-off-by: Brian Starkey <brian.starkey@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 41b2715 commit cf61e2a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

kernel/memremap.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags)
6464
IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE);
6565
void *addr = NULL;
6666

67+
if (!flags)
68+
return NULL;
69+
6770
if (is_ram == REGION_MIXED) {
6871
WARN_ONCE(1, "memremap attempted on mixed range %pa size: %#lx\n",
6972
&offset, (unsigned long) size);
@@ -72,7 +75,6 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags)
7275

7376
/* Try all mapping types requested until one returns non-NULL */
7477
if (flags & MEMREMAP_WB) {
75-
flags &= ~MEMREMAP_WB;
7678
/*
7779
* MEMREMAP_WB is special in that it can be satisifed
7880
* from the direct map. Some archs depend on the
@@ -86,21 +88,19 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags)
8688
}
8789

8890
/*
89-
* If we don't have a mapping yet and more request flags are
90-
* pending then we will be attempting to establish a new virtual
91+
* If we don't have a mapping yet and other request flags are
92+
* present then we will be attempting to establish a new virtual
9193
* address mapping. Enforce that this mapping is not aliasing
9294
* System RAM.
9395
*/
94-
if (!addr && is_ram == REGION_INTERSECTS && flags) {
96+
if (!addr && is_ram == REGION_INTERSECTS && flags != MEMREMAP_WB) {
9597
WARN_ONCE(1, "memremap attempted on ram %pa size: %#lx\n",
9698
&offset, (unsigned long) size);
9799
return NULL;
98100
}
99101

100-
if (!addr && (flags & MEMREMAP_WT)) {
101-
flags &= ~MEMREMAP_WT;
102+
if (!addr && (flags & MEMREMAP_WT))
102103
addr = ioremap_wt(offset, size);
103-
}
104104

105105
return addr;
106106
}

0 commit comments

Comments
 (0)