Skip to content

Commit fa1463c

Browse files
committed
x86/boot: Explain how discard_initial_images() works
discard_initial_images() only works because init_domheap_pages() with ps==pe is a no-op. In dom0_construct(), explaining the significance of setting the initrd length to 0, and put an explicit check in discard_initial_images(). No functional change. Signed-off-by: Andrew Cooper <[email protected]> Reviewed-by: Daniel P. Smith <[email protected]>
1 parent 83892f6 commit fa1463c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

xen/arch/x86/pv/dom0_build.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,15 @@ static int __init dom0_construct(struct domain *d,
641641
if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) )
642642
BUG();
643643
}
644+
645+
/*
646+
* We have either:
647+
* - Mapped the initrd directly into dom0, or
648+
* - Copied it and freed the module.
649+
*
650+
* Either way, tell discard_initial_images() to not free it a second
651+
* time.
652+
*/
644653
initrd->mod_end = 0;
645654

646655
iommu_memory_setup(d, "initrd", mfn_to_page(_mfn(initrd_mfn)),

xen/arch/x86/setup.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,24 @@ unsigned long __init initial_images_nrpages(nodeid_t node)
340340
return nr;
341341
}
342342

343-
void __init discard_initial_images(void)
343+
void __init discard_initial_images(void) /* a.k.a. Free boot modules */
344344
{
345345
struct boot_info *bi = &xen_boot_info;
346346
unsigned int i;
347347

348348
for ( i = 0; i < bi->nr_modules; ++i )
349349
{
350350
uint64_t start = pfn_to_paddr(bi->mods[i].mod->mod_start);
351+
uint64_t size = bi->mods[i].mod->mod_end;
351352

352-
init_domheap_pages(start,
353-
start + PAGE_ALIGN(bi->mods[i].mod->mod_end));
353+
/*
354+
* Sometimes the initrd is mapped, rather than copied, into dom0.
355+
* Size being 0 is how we're instructed to leave the module alone.
356+
*/
357+
if ( size == 0 )
358+
continue;
359+
360+
init_domheap_pages(start, start + PAGE_ALIGN(size));
354361
}
355362

356363
bi->nr_modules = 0;

0 commit comments

Comments
 (0)