File 5fca3b32-tools-libs-ctrl-fix-dumping-of-ballooned-guest.patch of Package xen.21118
Subject: tools/libs/ctrl: fix dumping of ballooned guest
From: Juergen Gross jgross@suse.com Wed Nov 11 11:01:43 2020 +0100
Date: Fri Dec 4 13:35:46 2020 +0000:
Git: 5e666356a9d55fbd9eb5b8506088aa760e107b5b
A guest with memory < maxmem often can't be dumped via xl dump-core
without an error message today:
xc: info: exceeded nr_pages (262144) losing pages
In case the last page of the guest isn't allocated the loop in
xc_domain_dumpcore_via_callback() will always spit out this message,
as the number of already dumped pages is tested before the next page
is checked to be valid.
The guest's p2m_size might be lower than expected, so this should be
tested in order to avoid reading past the end of it.
The guest might use high bits in p2m entries to flag special cases like
foreign mappings. Entries with an MFN larger than the highest MFN of
the host should be skipped.
Signed-off-by: Juergen Gross <jgross@suse.com>
--- xen-4.12.4-testing.orig/tools/libxc/xc_core.c
+++ xen-4.12.4-testing/tools/libxc/xc_core.c
@@ -438,6 +438,7 @@ xc_domain_dumpcore_via_callback(xc_inter
unsigned long i;
unsigned long j;
unsigned long nr_pages;
+ unsigned long max_mfn;
xc_core_memory_map_t *memory_map = NULL;
unsigned int nr_memory_map;
@@ -576,6 +577,10 @@ xc_domain_dumpcore_via_callback(xc_inter
&p2m, &dinfo->p2m_size);
if ( sts != 0 )
goto out;
+
+ sts = xc_maximum_ram_page(xch, &max_mfn);
+ if ( sts != 0 )
+ goto out;
}
else
{
@@ -817,19 +822,12 @@ xc_domain_dumpcore_via_callback(xc_inter
{
uint64_t gmfn;
void *vaddr;
-
- if ( j >= nr_pages )
- {
- /*
- * When live dump-mode (-L option) is specified,
- * guest domain may increase memory.
- */
- IPRINTF("exceeded nr_pages (%ld) losing pages", nr_pages);
- goto copy_done;
- }
if ( !auto_translated_physmap )
{
+ if ( i >= dinfo->p2m_size )
+ break;
+
if ( dinfo->guest_width >= sizeof(unsigned long) )
{
if ( dinfo->guest_width == sizeof(unsigned long) )
@@ -845,6 +843,14 @@ xc_domain_dumpcore_via_callback(xc_inter
if ( gmfn == (uint32_t)INVALID_PFN )
continue;
}
+ if ( gmfn > max_mfn )
+ continue;
+
+ if ( j >= nr_pages )
+ {
+ j++;
+ continue;
+ }
p2m_array[j].pfn = i;
p2m_array[j].gmfn = gmfn;
@@ -854,6 +860,12 @@ xc_domain_dumpcore_via_callback(xc_inter
if ( !xc_core_arch_gpfn_may_present(&arch_ctxt, i) )
continue;
+ if ( j >= nr_pages )
+ {
+ j++;
+ continue;
+ }
+
gmfn = i;
pfn_array[j] = i;
}
@@ -878,7 +890,15 @@ xc_domain_dumpcore_via_callback(xc_inter
}
}
-copy_done:
+ if ( j > nr_pages )
+ {
+ /*
+ * When live dump-mode (-L option) is specified,
+ * guest domain may increase memory.
+ */
+ IPRINTF("exceeded nr_pages (%ld) losing %ld pages", nr_pages, j - nr_pages);
+ }
+
sts = dump_rtn(xch, args, dump_mem_start, dump_mem - dump_mem_start);
if ( sts != 0 )
goto out;