|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 04/15] x86/setup: special treatment of initrd for PVH Dom0
Dealing with large initrd-s is problematic in two ways: We needlessly
copy around a large chunk of data, and our calculation of how much
memory to give Dom0 assumes the space taken by the initrd is actually
available at the time of populating Dom0's P2M.
As a first step, make effort during early boot to try to place the initrd
in a chunk of memory that's a multiple of 1Gb (or, if not available / not
possibly going to fit, in a chunk a multiple of 2Mb in size). This may
(but generally won't) result in more copying, which we simply need to
accept. Record (and use) the extra space allocated in (as) headroom, which
then needs accouting for in pvh_load_kernel().
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
Not being able to check bm->kind is of course not very nice. The field is
only set quite a bit later, and that setting can - afaict - not be moved
ahead of the call to xsm_multiboot_init().
The bumping of mask to L3's in __start_xen() transiently breaks booting of
Dom0 with overly much memory assigned to it. That'll be resolved when the
headroom space is properly dealt with (consumed into Dom0, or freed).
Therefore this patch and everything up to the one adding the consuming
code want committing together, or addition of that conditional wants
delaying until that later change.
Simply using nr_ram_pages()' return value is of course a pretty raw
estimate. We could e.g. also subtract Xen's image size and, perhaps more
relevant, an estimate of frame_table[].
--- a/xen/arch/x86/dom0_build.c
+++ b/xen/arch/x86/dom0_build.c
@@ -445,6 +445,20 @@ unsigned long __init dom0_compute_nr_pag
return nr_pages;
}
+/*
+ * A simplistic sibling of dom0_compute_nr_pages(), for obtaining a very early
+ * estimate.
+ */
+unsigned long __init get_dom0_size(unsigned long avail)
+{
+ if ( CONFIG_DOM0_MEM[0] && !dom0_mem_set )
+ parse_dom0_mem(CONFIG_DOM0_MEM);
+
+ return get_memsize(memsize_gt_zero(&dom0_size) ? &dom0_size
+ : &dom0_max_size,
+ avail);
+}
+
static void __init process_dom0_ioports_disable(struct domain *dom0)
{
unsigned long io_from, io_to;
--- a/xen/arch/x86/hvm/dom0_build.c
+++ b/xen/arch/x86/hvm/dom0_build.c
@@ -653,7 +653,8 @@ static int __init pvh_load_kernel(
void *image_base = bootstrap_map_bm(image);
void *image_start = image_base + image->arch.headroom;
unsigned long image_len = image->size;
- unsigned long initrd_len = initrd ? initrd->size : 0;
+ unsigned long initrd_len =
+ initrd ? initrd->size - initrd->arch.headroom : 0;
size_t cmdline_len = bd->cmdline ? strlen(bd->cmdline) + 1 : 0;
const char *initrd_cmdline = NULL;
struct elf_binary elf;
@@ -751,7 +752,8 @@ static int __init pvh_load_kernel(
if ( initrd != NULL )
{
- rc = hvm_copy_to_guest_phys(last_addr, __va(initrd->start),
+ rc = hvm_copy_to_guest_phys(last_addr,
+ __va(initrd->start +
initrd->arch.headroom),
initrd_len, v);
if ( rc )
{
--- a/xen/arch/x86/include/asm/setup.h
+++ b/xen/arch/x86/include/asm/setup.h
@@ -68,4 +68,6 @@ extern bool opt_dom0_verbose;
extern bool opt_dom0_cpuid_faulting;
extern bool opt_dom0_msr_relaxed;
+unsigned long get_dom0_size(unsigned long avail);
+
#endif
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -1608,6 +1608,40 @@ void asmlinkage __init noreturn __start_
struct boot_module *bm = &bi->mods[j];
unsigned long size = PAGE_ALIGN(bm->arch.headroom + bm->size);
+ /*
+ * For PVH Dom0 try to place the initrd in a full multi-Gb (or
+ * multi-2Mb) chunk, such that assigning the pages directly can
+ * be done while still using superpage mappings.
+ */
+ if ( opt_dom0_pvh && j == 1 /* bm->kind == BOOTMOD_RAMDISK */ )
+ {
+ if ( get_dom0_size(nr_ram_pages()) >= PFN_DOWN(GB(2)) )
+ mask = (1UL << L3_PAGETABLE_SHIFT) - 1;
+
+ for ( ; mask > PAGE_SIZE; mask >>= PAGETABLE_ORDER )
+ {
+ if ( !(bm->start & mask) && bm->arch.relocated )
+ break;
+
+ size = PAGE_ALIGN(bm->size - bm->arch.headroom);
+ end = e;
+ do {
+ end = consider_modules((s + mask) & ~mask, end & ~mask,
+ (size + mask) & ~mask, bi->mods,
+ bi->nr_modules + relocated, j);
+ } while ( (end & mask) && end > s );
+
+ if ( highmem_start && end > highmem_start )
+ break;
+
+ size = (size + mask) & ~mask;
+ bm->start += bm->arch.headroom;
+ bm->size -= bm->arch.headroom;
+ bm->arch.headroom = size - PAGE_ALIGN(bm->size);
+ goto move_module;
+ }
+ }
+
if ( bm->arch.relocated )
continue;
@@ -1620,6 +1654,7 @@ void asmlinkage __init noreturn __start_
if ( s < end && (bm->arch.headroom || (end - size) > bm->start) )
{
+ move_module:
move_memory(end - size + bm->arch.headroom, bm->start,
bm->size);
bm->start = (end - size);
bm->size += bm->arch.headroom;
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |