Commit 6b0f68e3 authored by Mark Salter's avatar Mark Salter Committed by Linus Torvalds
Browse files

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: default avatarMark Salter <>
Cc: Catalin Marinas <>
Cc: Will Deacon <>
Cc: Arnd Bergmann <>
Cc: Ard Biesheuvel <>
Cc: Mark Rutland <>
Cc: Russell King <>
Cc: Ingo Molnar <>
Cc: Thomas Gleixner <>
Cc: "H. Peter Anvin" <>
Cc: Yinghai Lu <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent e6590740
......@@ -33,6 +33,12 @@ extern void early_ioremap_setup(void);
extern void early_ioremap_reset(void);
* Early copy from unmapped memory to kernel mapped memory.
extern void copy_from_early_mem(void *dest, phys_addr_t src,
unsigned long size);
static inline void early_ioremap_init(void) { }
static inline void early_ioremap_setup(void) { }
......@@ -217,6 +217,28 @@ early_memremap(resource_size_t phys_addr, unsigned long size)
return (__force void *)__early_ioremap(phys_addr, size,
void __init copy_from_early_mem(void *dest, phys_addr_t src, unsigned long size)
unsigned long slop, clen;
char *p;
while (size) {
slop = src & ~PAGE_MASK;
clen = size;
if (clen > MAX_MAP_CHUNK - slop)
clen = MAX_MAP_CHUNK - slop;
p = early_memremap(src & PAGE_MASK, clen + slop);
memcpy(dest, p + slop, clen);
early_memunmap(p, clen + slop);
dest += clen;
src += clen;
size -= clen;
#else /* CONFIG_MMU */
void __init __iomem *
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment