Skip to content

Commit 4b9c153

Browse files
jgross1David Vrabel
authored andcommitted
xen: check for initrd conflicting with e820 map
Check whether the initrd is placed at a location which is conflicting with the target E820 map. If this is the case relocate it to a new area unused up to now and compliant to the E820 map. Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: David Vrabel <david.vrabel@citrix.com> Acked-by: Konrad Rzeszutek Wilk <Konrad.wilk@oracle.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
1 parent 04414ba commit 4b9c153

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎arch/x86/xen/setup.c‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,36 @@ phys_addr_t __init xen_find_free_area(phys_addr_t size)
631631
return 0;
632632
}
633633

634+
/*
635+
* Like memcpy, but with physical addresses for dest and src.
636+
*/
637+
static void __init xen_phys_memcpy(phys_addr_t dest, phys_addr_t src,
638+
phys_addr_t n)
639+
{
640+
phys_addr_t dest_off, src_off, dest_len, src_len, len;
641+
void *from, *to;
642+
643+
while (n) {
644+
dest_off = dest & ~PAGE_MASK;
645+
src_off = src & ~PAGE_MASK;
646+
dest_len = n;
647+
if (dest_len > (NR_FIX_BTMAPS << PAGE_SHIFT) - dest_off)
648+
dest_len = (NR_FIX_BTMAPS << PAGE_SHIFT) - dest_off;
649+
src_len = n;
650+
if (src_len > (NR_FIX_BTMAPS << PAGE_SHIFT) - src_off)
651+
src_len = (NR_FIX_BTMAPS << PAGE_SHIFT) - src_off;
652+
len = min(dest_len, src_len);
653+
to = early_memremap(dest - dest_off, dest_len + dest_off);
654+
from = early_memremap(src - src_off, src_len + src_off);
655+
memcpy(to, from, len);
656+
early_memunmap(to, dest_len + dest_off);
657+
early_memunmap(from, src_len + src_off);
658+
n -= len;
659+
dest += len;
660+
src += len;
661+
}
662+
}
663+
634664
/*
635665
* Reserve Xen mfn_list.
636666
* See comment above "struct start_info" in <xen/interface/xen.h>
@@ -810,6 +840,27 @@ char * __init xen_memory_setup(void)
810840

811841
xen_reserve_xen_mfnlist();
812842

843+
/* Check for a conflict of the initrd with the target E820 map. */
844+
if (xen_is_e820_reserved(boot_params.hdr.ramdisk_image,
845+
boot_params.hdr.ramdisk_size)) {
846+
phys_addr_t new_area, start, size;
847+
848+
new_area = xen_find_free_area(boot_params.hdr.ramdisk_size);
849+
if (!new_area) {
850+
xen_raw_console_write("Can't find new memory area for initrd needed due to E820 map conflict\n");
851+
BUG();
852+
}
853+
854+
start = boot_params.hdr.ramdisk_image;
855+
size = boot_params.hdr.ramdisk_size;
856+
xen_phys_memcpy(new_area, start, size);
857+
pr_info("initrd moved from [mem %#010llx-%#010llx] to [mem %#010llx-%#010llx]\n",
858+
start, start + size, new_area, new_area + size);
859+
memblock_free(start, size);
860+
boot_params.hdr.ramdisk_image = new_area;
861+
boot_params.ext_ramdisk_image = new_area >> 32;
862+
}
863+
813864
/*
814865
* Set identity map on non-RAM pages and prepare remapping the
815866
* underlying RAM.

0 commit comments

Comments
 (0)