All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tools/libs/ctrl: fix dumping of ballooned guest
@ 2020-11-11 10:01 Juergen Gross
  2020-11-20 15:33 ` Jürgen Groß
  2020-12-04 13:35 ` Wei Liu
  0 siblings, 2 replies; 4+ messages in thread
From: Juergen Gross @ 2020-11-11 10:01 UTC (permalink / raw)
  To: xen-devel; +Cc: Juergen Gross, Ian Jackson, Wei Liu

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>
---
 tools/libs/ctrl/xc_core.c | 42 +++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 11 deletions(-)

diff --git a/tools/libs/ctrl/xc_core.c b/tools/libs/ctrl/xc_core.c
index e8c6fb96f9..b47ab2f6d8 100644
--- a/tools/libs/ctrl/xc_core.c
+++ b/tools/libs/ctrl/xc_core.c
@@ -439,6 +439,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
     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;
@@ -577,6 +578,10 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
                                    &p2m, &dinfo->p2m_size);
         if ( sts != 0 )
             goto out;
+
+        sts = xc_maximum_ram_page(xch, &max_mfn);
+        if ( sts != 0 )
+            goto out;
     }
     else
     {
@@ -818,19 +823,12 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
         {
             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) )
@@ -846,6 +844,14 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
                     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;
@@ -855,6 +861,12 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
                 if ( !xc_core_arch_gpfn_may_present(&arch_ctxt, i) )
                     continue;
 
+                if ( j >= nr_pages )
+                {
+                    j++;
+                    continue;
+                }
+
                 gmfn = i;
                 pfn_array[j] = i;
             }
@@ -879,7 +891,15 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
         }
     }
 
-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;
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] tools/libs/ctrl: fix dumping of ballooned guest
  2020-11-11 10:01 [PATCH v2] tools/libs/ctrl: fix dumping of ballooned guest Juergen Gross
@ 2020-11-20 15:33 ` Jürgen Groß
  2020-12-02  7:08   ` Jürgen Groß
  2020-12-04 13:35 ` Wei Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Jürgen Groß @ 2020-11-20 15:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Wei Liu


[-- Attachment #1.1.1: Type: text/plain, Size: 4187 bytes --]

On 11.11.20 11:01, Juergen Gross wrote:
> 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>

This is a real bug fix.

Can any maintainer please have a look?


Juergen

> ---
>   tools/libs/ctrl/xc_core.c | 42 +++++++++++++++++++++++++++++----------
>   1 file changed, 31 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/libs/ctrl/xc_core.c b/tools/libs/ctrl/xc_core.c
> index e8c6fb96f9..b47ab2f6d8 100644
> --- a/tools/libs/ctrl/xc_core.c
> +++ b/tools/libs/ctrl/xc_core.c
> @@ -439,6 +439,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>       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;
> @@ -577,6 +578,10 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>                                      &p2m, &dinfo->p2m_size);
>           if ( sts != 0 )
>               goto out;
> +
> +        sts = xc_maximum_ram_page(xch, &max_mfn);
> +        if ( sts != 0 )
> +            goto out;
>       }
>       else
>       {
> @@ -818,19 +823,12 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>           {
>               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) )
> @@ -846,6 +844,14 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>                       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;
> @@ -855,6 +861,12 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>                   if ( !xc_core_arch_gpfn_may_present(&arch_ctxt, i) )
>                       continue;
>   
> +                if ( j >= nr_pages )
> +                {
> +                    j++;
> +                    continue;
> +                }
> +
>                   gmfn = i;
>                   pfn_array[j] = i;
>               }
> @@ -879,7 +891,15 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>           }
>       }
>   
> -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;
> 


[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] tools/libs/ctrl: fix dumping of ballooned guest
  2020-11-20 15:33 ` Jürgen Groß
@ 2020-12-02  7:08   ` Jürgen Groß
  0 siblings, 0 replies; 4+ messages in thread
From: Jürgen Groß @ 2020-12-02  7:08 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Wei Liu


[-- Attachment #1.1.1: Type: text/plain, Size: 5226 bytes --]

On 20.11.20 16:33, Jürgen Groß wrote:
> On 11.11.20 11:01, Juergen Gross wrote:
>> 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>
> 
> This is a real bug fix.
> 
> Can any maintainer please have a look?

PING?


Juergen

> 
> 
> Juergen
> 
>> ---
>>   tools/libs/ctrl/xc_core.c | 42 +++++++++++++++++++++++++++++----------
>>   1 file changed, 31 insertions(+), 11 deletions(-)
>>
>> diff --git a/tools/libs/ctrl/xc_core.c b/tools/libs/ctrl/xc_core.c
>> index e8c6fb96f9..b47ab2f6d8 100644
>> --- a/tools/libs/ctrl/xc_core.c
>> +++ b/tools/libs/ctrl/xc_core.c
>> @@ -439,6 +439,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>>       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;
>> @@ -577,6 +578,10 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>>                                      &p2m, &dinfo->p2m_size);
>>           if ( sts != 0 )
>>               goto out;
>> +
>> +        sts = xc_maximum_ram_page(xch, &max_mfn);
>> +        if ( sts != 0 )
>> +            goto out;
>>       }
>>       else
>>       {
>> @@ -818,19 +823,12 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>>           {
>>               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) )
>> @@ -846,6 +844,14 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>>                       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;
>> @@ -855,6 +861,12 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>>                   if ( !xc_core_arch_gpfn_may_present(&arch_ctxt, i) )
>>                       continue;
>> +                if ( j >= nr_pages )
>> +                {
>> +                    j++;
>> +                    continue;
>> +                }
>> +
>>                   gmfn = i;
>>                   pfn_array[j] = i;
>>               }
>> @@ -879,7 +891,15 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
>>           }
>>       }
>> -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;
>>
> 


[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] tools/libs/ctrl: fix dumping of ballooned guest
  2020-11-11 10:01 [PATCH v2] tools/libs/ctrl: fix dumping of ballooned guest Juergen Gross
  2020-11-20 15:33 ` Jürgen Groß
@ 2020-12-04 13:35 ` Wei Liu
  1 sibling, 0 replies; 4+ messages in thread
From: Wei Liu @ 2020-12-04 13:35 UTC (permalink / raw)
  To: Juergen Gross; +Cc: xen-devel, Ian Jackson, Wei Liu

On Wed, Nov 11, 2020 at 11:01:43AM +0100, Juergen Gross wrote:
> 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>

Acked + applied.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-04 13:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11 10:01 [PATCH v2] tools/libs/ctrl: fix dumping of ballooned guest Juergen Gross
2020-11-20 15:33 ` Jürgen Groß
2020-12-02  7:08   ` Jürgen Groß
2020-12-04 13:35 ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.