[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] hvmloader: probe memory below 4G before allocation for OVMF
The area just below 4G where OVMF image is originally relocated is not necessarily a hole - it might contain pages preallocated by device model or the toolstack. By unconditionally populating on top of this memory the original pages are getting lost while still potentially foreign mapped in Dom0. Signed-off-by: Igor Druzhinin <igor.druzhinin@xxxxxxxxxx> --- That doesn't seem necessary for at least upstream toolstack now. Alternative might be - to move population of this area to the toolstack where there is more control over memory layout. --- tools/firmware/hvmloader/ovmf.c | 3 ++- tools/firmware/hvmloader/util.c | 14 ++++++++++++++ tools/firmware/hvmloader/util.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/firmware/hvmloader/ovmf.c b/tools/firmware/hvmloader/ovmf.c index 23610a0..70d5f70 100644 --- a/tools/firmware/hvmloader/ovmf.c +++ b/tools/firmware/hvmloader/ovmf.c @@ -106,7 +106,8 @@ static void ovmf_load(const struct bios_config *config, { mfn = (uint32_t) (addr >> PAGE_SHIFT); addr += PAGE_SIZE; - mem_hole_populate_ram(mfn, 1); + if ( !mem_probe_ram(mfn) ) + mem_hole_populate_ram(mfn, 1); } /* Check that source and destination does not overlaps. */ diff --git a/tools/firmware/hvmloader/util.c b/tools/firmware/hvmloader/util.c index 0c3f2d2..724cea0 100644 --- a/tools/firmware/hvmloader/util.c +++ b/tools/firmware/hvmloader/util.c @@ -398,6 +398,20 @@ int get_mem_mapping_layout(struct e820entry entries[], uint32_t *max_entries) return rc; } +bool mem_probe_ram(xen_pfn_t mfn) +{ + uint32_t tmp, magic = 0xdeadbeef; + volatile uint32_t *addr = (volatile uint32_t *)(mfn << PAGE_SHIFT); + + tmp = *addr; + *addr = magic; + if ( *addr != magic ) + return 0; + + *addr = tmp; + return 1; +} + void mem_hole_populate_ram(xen_pfn_t mfn, uint32_t nr_mfns) { static int over_allocated; diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h index 7bca641..00a7c13 100644 --- a/tools/firmware/hvmloader/util.h +++ b/tools/firmware/hvmloader/util.h @@ -194,6 +194,9 @@ int vprintf(const char *fmt, va_list ap); /* Buffer output */ int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); +/* Probe whether a page is populated with RAM. */ +bool mem_probe_ram(xen_pfn_t mfn); + /* Populate specified memory hole with RAM. */ void mem_hole_populate_ram(xen_pfn_t mfn, uint32_t nr_mfns); -- 2.7.4
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |