Skip to content

Commit 6b0f68e

Browse files
mosaltertorvalds
authored andcommitted
mm: add utility for early copy from unmapped ram
When booting an arm64 kernel w/initrd using UEFI/grub, use of mem= will likely cut off part or all of the initrd. This leaves it outside the kernel linear map which leads to failure when unpacking. The x86 code has a similar need to relocate an initrd outside of mapped memory in some cases. The current x86 code uses early_memremap() to copy the original initrd from unmapped to mapped RAM. This patchset creates a generic copy_from_early_mem() utility based on that x86 code and has arm64 and x86 share it in their respective initrd relocation code. This patch (of 3): In some early boot circumstances, it may be necessary to copy from RAM outside the kernel linear mapping to mapped RAM. The need to relocate an initrd is one example in the x86 code. This patch creates a helper function based on current x86 code. Signed-off-by: Mark Salter <msalter@redhat.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Russell King <rmk@arm.linux.org.uk> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e659074 commit 6b0f68e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/asm-generic/early_ioremap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ extern void early_ioremap_setup(void);
3333
*/
3434
extern void early_ioremap_reset(void);
3535

36+
/*
37+
* Early copy from unmapped memory to kernel mapped memory.
38+
*/
39+
extern void copy_from_early_mem(void *dest, phys_addr_t src,
40+
unsigned long size);
41+
3642
#else
3743
static inline void early_ioremap_init(void) { }
3844
static inline void early_ioremap_setup(void) { }

mm/early_ioremap.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@ early_memremap(resource_size_t phys_addr, unsigned long size)
217217
return (__force void *)__early_ioremap(phys_addr, size,
218218
FIXMAP_PAGE_NORMAL);
219219
}
220+
221+
#define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
222+
223+
void __init copy_from_early_mem(void *dest, phys_addr_t src, unsigned long size)
224+
{
225+
unsigned long slop, clen;
226+
char *p;
227+
228+
while (size) {
229+
slop = src & ~PAGE_MASK;
230+
clen = size;
231+
if (clen > MAX_MAP_CHUNK - slop)
232+
clen = MAX_MAP_CHUNK - slop;
233+
p = early_memremap(src & PAGE_MASK, clen + slop);
234+
memcpy(dest, p + slop, clen);
235+
early_memunmap(p, clen + slop);
236+
dest += clen;
237+
src += clen;
238+
size -= clen;
239+
}
240+
}
241+
220242
#else /* CONFIG_MMU */
221243

222244
void __init __iomem *

0 commit comments

Comments
 (0)