All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] migration: incoming postcopy advise sanity checks
@ 2018-02-06  7:26 Greg Kurz
  2018-02-06  7:49 ` Vladimir Sementsov-Ogievskiy
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kurz @ 2018-02-06  7:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Dr. David Alan Gilbert, Juan Quintela, Vladimir Sementsov-Ogievskiy

If postcopy-ram was set on the source but not on the destination,
migration doesn't occur, the destination prints an error and boots
the guest:

qemu-system-ppc64: Expected vmdescription section, but got 0

We end up with two running instances.

This behaviour was introduced in 2.11 by commit 58110f0acb1a "migration:
split common postcopy out of ram postcopy" to prepare ground for the
upcoming dirty bitmap postcopy support. It adds a new case where the
source may send an empty postcopy advise because dirty bitmap doesn't
need to check page sizes like RAM postcopy does.

If the source has enabled postcopy-ram, then it sends an advise with
the page size values. If the destination hasn't enabled postcopy-ram,
then loadvm_postcopy_handle_advise() leaves the page size values on
the stream and returns. This confuses qemu_loadvm_state() later on
and causes the destination to start execution.

As discussed several times, postcopy-ram should be enabled both sides
to be functional. This patch changes the destination to perform some
extra checks on the advise length to ensure this is the case. Otherwise
an error is returned and migration is aborted.

Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
Signed-off-by: Greg Kurz <groug@kaod.org>
---
 migration/savevm.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/migration/savevm.c b/migration/savevm.c
index b7908f62be3c..1c516fcbb8d7 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1376,7 +1376,8 @@ static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
  * *might* happen - it might be skipped if precopy transferred everything
  * quickly.
  */
-static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
+static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,
+                                         uint16_t len)
 {
     PostcopyState ps = postcopy_state_set(POSTCOPY_INCOMING_ADVISE);
     uint64_t remote_pagesize_summary, local_pagesize_summary, remote_tps;
@@ -1387,8 +1388,19 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
         return -1;
     }
 
-    if (!migrate_postcopy_ram()) {
+    switch (len) {
+    case 0:
+        /* The source hasn't enabled postcopy-ram. Nothing to do. */
         return 0;
+    case 8 + 8:
+        if (!migrate_postcopy_ram()) {
+            error_report("RAM postcopy is disabled");
+            return -EINVAL;
+        }
+        break;
+    default:
+        error_report("CMD_POSTCOPY_ADVISE invalid length (%d)", len);
+        return -EINVAL;
     }
 
     if (!postcopy_ram_supported_by_host(mis)) {
@@ -1807,7 +1819,7 @@ static int loadvm_process_command(QEMUFile *f)
         return loadvm_handle_cmd_packaged(mis);
 
     case MIG_CMD_POSTCOPY_ADVISE:
-        return loadvm_postcopy_handle_advise(mis);
+        return loadvm_postcopy_handle_advise(mis, len);
 
     case MIG_CMD_POSTCOPY_LISTEN:
         return loadvm_postcopy_handle_listen(mis);

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

* Re: [Qemu-devel] [PATCH] migration: incoming postcopy advise sanity checks
  2018-02-06  7:26 [Qemu-devel] [PATCH] migration: incoming postcopy advise sanity checks Greg Kurz
@ 2018-02-06  7:49 ` Vladimir Sementsov-Ogievskiy
  2018-02-06  8:43   ` Greg Kurz
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2018-02-06  7:49 UTC (permalink / raw)
  To: Greg Kurz, qemu-devel; +Cc: Dr. David Alan Gilbert, Juan Quintela

06.02.2018 10:26, Greg Kurz wrote:
> If postcopy-ram was set on the source but not on the destination,
> migration doesn't occur, the destination prints an error and boots
> the guest:
>
> qemu-system-ppc64: Expected vmdescription section, but got 0
>
> We end up with two running instances.
>
> This behaviour was introduced in 2.11 by commit 58110f0acb1a "migration:
> split common postcopy out of ram postcopy" to prepare ground for the
> upcoming dirty bitmap postcopy support. It adds a new case where the
> source may send an empty postcopy advise because dirty bitmap doesn't
> need to check page sizes like RAM postcopy does.
>
> If the source has enabled postcopy-ram, then it sends an advise with
> the page size values. If the destination hasn't enabled postcopy-ram,
> then loadvm_postcopy_handle_advise() leaves the page size values on
> the stream and returns. This confuses qemu_loadvm_state() later on
> and causes the destination to start execution.
>
> As discussed several times, postcopy-ram should be enabled both sides
> to be functional. This patch changes the destination to perform some
> extra checks on the advise length to ensure this is the case. Otherwise
> an error is returned and migration is aborted.
>
> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
>   migration/savevm.c |   18 +++++++++++++++---
>   1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/migration/savevm.c b/migration/savevm.c
> index b7908f62be3c..1c516fcbb8d7 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -1376,7 +1376,8 @@ static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
>    * *might* happen - it might be skipped if precopy transferred everything
>    * quickly.
>    */
> -static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
> +static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,
> +                                         uint16_t len)
>   {
>       PostcopyState ps = postcopy_state_set(POSTCOPY_INCOMING_ADVISE);
>       uint64_t remote_pagesize_summary, local_pagesize_summary, remote_tps;
> @@ -1387,8 +1388,19 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
>           return -1;
>       }
>   
> -    if (!migrate_postcopy_ram()) {
> +    switch (len) {
> +    case 0:
> +        /* The source hasn't enabled postcopy-ram. Nothing to do. */

should we error-out here if (migrate_postcopy_ram()) ?

>           return 0;
> +    case 8 + 8:
> +        if (!migrate_postcopy_ram()) {
> +            error_report("RAM postcopy is disabled");
> +            return -EINVAL;
> +        }
> +        break;
> +    default:
> +        error_report("CMD_POSTCOPY_ADVISE invalid length (%d)", len);
> +        return -EINVAL;
>       }
>   
>       if (!postcopy_ram_supported_by_host(mis)) {
> @@ -1807,7 +1819,7 @@ static int loadvm_process_command(QEMUFile *f)
>           return loadvm_handle_cmd_packaged(mis);
>   
>       case MIG_CMD_POSTCOPY_ADVISE:
> -        return loadvm_postcopy_handle_advise(mis);
> +        return loadvm_postcopy_handle_advise(mis, len);
>   
>       case MIG_CMD_POSTCOPY_LISTEN:
>           return loadvm_postcopy_handle_listen(mis);
>


-- 
Best regards,
Vladimir

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

* Re: [Qemu-devel] [PATCH] migration: incoming postcopy advise sanity checks
  2018-02-06  7:49 ` Vladimir Sementsov-Ogievskiy
@ 2018-02-06  8:43   ` Greg Kurz
  2018-02-06  9:24     ` Vladimir Sementsov-Ogievskiy
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kurz @ 2018-02-06  8:43 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy
  Cc: qemu-devel, Dr. David Alan Gilbert, Juan Quintela

On Tue, 6 Feb 2018 10:49:47 +0300
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> wrote:

> 06.02.2018 10:26, Greg Kurz wrote:
> > If postcopy-ram was set on the source but not on the destination,
> > migration doesn't occur, the destination prints an error and boots
> > the guest:
> >
> > qemu-system-ppc64: Expected vmdescription section, but got 0
> >
> > We end up with two running instances.
> >
> > This behaviour was introduced in 2.11 by commit 58110f0acb1a "migration:
> > split common postcopy out of ram postcopy" to prepare ground for the
> > upcoming dirty bitmap postcopy support. It adds a new case where the
> > source may send an empty postcopy advise because dirty bitmap doesn't
> > need to check page sizes like RAM postcopy does.
> >
> > If the source has enabled postcopy-ram, then it sends an advise with
> > the page size values. If the destination hasn't enabled postcopy-ram,
> > then loadvm_postcopy_handle_advise() leaves the page size values on
> > the stream and returns. This confuses qemu_loadvm_state() later on
> > and causes the destination to start execution.
> >
> > As discussed several times, postcopy-ram should be enabled both sides
> > to be functional. This patch changes the destination to perform some
> > extra checks on the advise length to ensure this is the case. Otherwise
> > an error is returned and migration is aborted.
> >
> > Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> >   migration/savevm.c |   18 +++++++++++++++---
> >   1 file changed, 15 insertions(+), 3 deletions(-)
> >
> > diff --git a/migration/savevm.c b/migration/savevm.c
> > index b7908f62be3c..1c516fcbb8d7 100644
> > --- a/migration/savevm.c
> > +++ b/migration/savevm.c
> > @@ -1376,7 +1376,8 @@ static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
> >    * *might* happen - it might be skipped if precopy transferred everything
> >    * quickly.
> >    */
> > -static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
> > +static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,
> > +                                         uint16_t len)
> >   {
> >       PostcopyState ps = postcopy_state_set(POSTCOPY_INCOMING_ADVISE);
> >       uint64_t remote_pagesize_summary, local_pagesize_summary, remote_tps;
> > @@ -1387,8 +1388,19 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
> >           return -1;
> >       }
> >   
> > -    if (!migrate_postcopy_ram()) {
> > +    switch (len) {
> > +    case 0:
> > +        /* The source hasn't enabled postcopy-ram. Nothing to do. */  
> 
> should we error-out here if (migrate_postcopy_ram()) ?
> 

I was also thinking so at first, but if the source hasn't enabled postcopy-ram,
then RAM postcopy won't happen. Not sure why we should error out...

> >           return 0;
> > +    case 8 + 8:
> > +        if (!migrate_postcopy_ram()) {
> > +            error_report("RAM postcopy is disabled");
> > +            return -EINVAL;
> > +        }
> > +        break;
> > +    default:
> > +        error_report("CMD_POSTCOPY_ADVISE invalid length (%d)", len);
> > +        return -EINVAL;
> >       }
> >   
> >       if (!postcopy_ram_supported_by_host(mis)) {
> > @@ -1807,7 +1819,7 @@ static int loadvm_process_command(QEMUFile *f)
> >           return loadvm_handle_cmd_packaged(mis);
> >   
> >       case MIG_CMD_POSTCOPY_ADVISE:
> > -        return loadvm_postcopy_handle_advise(mis);
> > +        return loadvm_postcopy_handle_advise(mis, len);
> >   
> >       case MIG_CMD_POSTCOPY_LISTEN:
> >           return loadvm_postcopy_handle_listen(mis);
> >  
> 
> 

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

* Re: [Qemu-devel] [PATCH] migration: incoming postcopy advise sanity checks
  2018-02-06  8:43   ` Greg Kurz
@ 2018-02-06  9:24     ` Vladimir Sementsov-Ogievskiy
  2018-02-06  9:46       ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2018-02-06  9:24 UTC (permalink / raw)
  To: Greg Kurz; +Cc: qemu-devel, Dr. David Alan Gilbert, Juan Quintela

06.02.2018 11:43, Greg Kurz wrote:
> On Tue, 6 Feb 2018 10:49:47 +0300
> Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> wrote:
>
>> 06.02.2018 10:26, Greg Kurz wrote:
>>> If postcopy-ram was set on the source but not on the destination,
>>> migration doesn't occur, the destination prints an error and boots
>>> the guest:
>>>
>>> qemu-system-ppc64: Expected vmdescription section, but got 0
>>>
>>> We end up with two running instances.
>>>
>>> This behaviour was introduced in 2.11 by commit 58110f0acb1a "migration:
>>> split common postcopy out of ram postcopy" to prepare ground for the
>>> upcoming dirty bitmap postcopy support. It adds a new case where the
>>> source may send an empty postcopy advise because dirty bitmap doesn't
>>> need to check page sizes like RAM postcopy does.
>>>
>>> If the source has enabled postcopy-ram, then it sends an advise with
>>> the page size values. If the destination hasn't enabled postcopy-ram,
>>> then loadvm_postcopy_handle_advise() leaves the page size values on
>>> the stream and returns. This confuses qemu_loadvm_state() later on
>>> and causes the destination to start execution.
>>>
>>> As discussed several times, postcopy-ram should be enabled both sides
>>> to be functional. This patch changes the destination to perform some
>>> extra checks on the advise length to ensure this is the case. Otherwise
>>> an error is returned and migration is aborted.
>>>
>>> Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
>>> Signed-off-by: Greg Kurz <groug@kaod.org>
>>> ---
>>>    migration/savevm.c |   18 +++++++++++++++---
>>>    1 file changed, 15 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/migration/savevm.c b/migration/savevm.c
>>> index b7908f62be3c..1c516fcbb8d7 100644
>>> --- a/migration/savevm.c
>>> +++ b/migration/savevm.c
>>> @@ -1376,7 +1376,8 @@ static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
>>>     * *might* happen - it might be skipped if precopy transferred everything
>>>     * quickly.
>>>     */
>>> -static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
>>> +static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,
>>> +                                         uint16_t len)
>>>    {
>>>        PostcopyState ps = postcopy_state_set(POSTCOPY_INCOMING_ADVISE);
>>>        uint64_t remote_pagesize_summary, local_pagesize_summary, remote_tps;
>>> @@ -1387,8 +1388,19 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
>>>            return -1;
>>>        }
>>>    
>>> -    if (!migrate_postcopy_ram()) {
>>> +    switch (len) {
>>> +    case 0:
>>> +        /* The source hasn't enabled postcopy-ram. Nothing to do. */
>> should we error-out here if (migrate_postcopy_ram()) ?
>>
> I was also thinking so at first, but if the source hasn't enabled postcopy-ram,
> then RAM postcopy won't happen. Not sure why we should error out...

if user enables dirty-bitmaps postcopy on source, and enables 
postcopy-ram on target,
we will be here, with migrate_postcopy_ram()=true. and it should be error.

>
>>>            return 0;
>>> +    case 8 + 8:
>>> +        if (!migrate_postcopy_ram()) {
>>> +            error_report("RAM postcopy is disabled");
>>> +            return -EINVAL;
>>> +        }
>>> +        break;
>>> +    default:
>>> +        error_report("CMD_POSTCOPY_ADVISE invalid length (%d)", len);
>>> +        return -EINVAL;
>>>        }
>>>    
>>>        if (!postcopy_ram_supported_by_host(mis)) {
>>> @@ -1807,7 +1819,7 @@ static int loadvm_process_command(QEMUFile *f)
>>>            return loadvm_handle_cmd_packaged(mis);
>>>    
>>>        case MIG_CMD_POSTCOPY_ADVISE:
>>> -        return loadvm_postcopy_handle_advise(mis);
>>> +        return loadvm_postcopy_handle_advise(mis, len);
>>>    
>>>        case MIG_CMD_POSTCOPY_LISTEN:
>>>            return loadvm_postcopy_handle_listen(mis);
>>>   
>>


-- 
Best regards,
Vladimir

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

* Re: [Qemu-devel] [PATCH] migration: incoming postcopy advise sanity checks
  2018-02-06  9:24     ` Vladimir Sementsov-Ogievskiy
@ 2018-02-06  9:46       ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 5+ messages in thread
From: Dr. David Alan Gilbert @ 2018-02-06  9:46 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy; +Cc: Greg Kurz, qemu-devel, Juan Quintela

* Vladimir Sementsov-Ogievskiy (vsementsov@virtuozzo.com) wrote:
> 06.02.2018 11:43, Greg Kurz wrote:
> > On Tue, 6 Feb 2018 10:49:47 +0300
> > Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> wrote:
> > 
> > > 06.02.2018 10:26, Greg Kurz wrote:
> > > > If postcopy-ram was set on the source but not on the destination,
> > > > migration doesn't occur, the destination prints an error and boots
> > > > the guest:
> > > > 
> > > > qemu-system-ppc64: Expected vmdescription section, but got 0
> > > > 
> > > > We end up with two running instances.
> > > > 
> > > > This behaviour was introduced in 2.11 by commit 58110f0acb1a "migration:
> > > > split common postcopy out of ram postcopy" to prepare ground for the
> > > > upcoming dirty bitmap postcopy support. It adds a new case where the
> > > > source may send an empty postcopy advise because dirty bitmap doesn't
> > > > need to check page sizes like RAM postcopy does.
> > > > 
> > > > If the source has enabled postcopy-ram, then it sends an advise with
> > > > the page size values. If the destination hasn't enabled postcopy-ram,
> > > > then loadvm_postcopy_handle_advise() leaves the page size values on
> > > > the stream and returns. This confuses qemu_loadvm_state() later on
> > > > and causes the destination to start execution.
> > > > 
> > > > As discussed several times, postcopy-ram should be enabled both sides
> > > > to be functional. This patch changes the destination to perform some
> > > > extra checks on the advise length to ensure this is the case. Otherwise
> > > > an error is returned and migration is aborted.
> > > > 
> > > > Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
> > > > Signed-off-by: Greg Kurz <groug@kaod.org>
> > > > ---
> > > >    migration/savevm.c |   18 +++++++++++++++---
> > > >    1 file changed, 15 insertions(+), 3 deletions(-)
> > > > 
> > > > diff --git a/migration/savevm.c b/migration/savevm.c
> > > > index b7908f62be3c..1c516fcbb8d7 100644
> > > > --- a/migration/savevm.c
> > > > +++ b/migration/savevm.c
> > > > @@ -1376,7 +1376,8 @@ static int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
> > > >     * *might* happen - it might be skipped if precopy transferred everything
> > > >     * quickly.
> > > >     */
> > > > -static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
> > > > +static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,
> > > > +                                         uint16_t len)
> > > >    {
> > > >        PostcopyState ps = postcopy_state_set(POSTCOPY_INCOMING_ADVISE);
> > > >        uint64_t remote_pagesize_summary, local_pagesize_summary, remote_tps;
> > > > @@ -1387,8 +1388,19 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
> > > >            return -1;
> > > >        }
> > > > -    if (!migrate_postcopy_ram()) {
> > > > +    switch (len) {
> > > > +    case 0:
> > > > +        /* The source hasn't enabled postcopy-ram. Nothing to do. */
> > > should we error-out here if (migrate_postcopy_ram()) ?
> > > 
> > I was also thinking so at first, but if the source hasn't enabled postcopy-ram,
> > then RAM postcopy won't happen. Not sure why we should error out...
> 
> if user enables dirty-bitmaps postcopy on source, and enables postcopy-ram
> on target,
> we will be here, with migrate_postcopy_ram()=true. and it should be error.

In that case it's probably worth it.

> > 
> > > >            return 0;
> > > > +    case 8 + 8:
> > > > +        if (!migrate_postcopy_ram()) {
> > > > +            error_report("RAM postcopy is disabled");

Can you make that a little bit more descriptive please:
    error_report("RAM postcopy is disabled but have 16 byte advise");
should do.

Thanks,

Dave

> > > > +            return -EINVAL;
> > > > +        }
> > > > +        break;
> > > > +    default:
> > > > +        error_report("CMD_POSTCOPY_ADVISE invalid length (%d)", len);
> > > > +        return -EINVAL;
> > > >        }
> > > >        if (!postcopy_ram_supported_by_host(mis)) {
> > > > @@ -1807,7 +1819,7 @@ static int loadvm_process_command(QEMUFile *f)
> > > >            return loadvm_handle_cmd_packaged(mis);
> > > >        case MIG_CMD_POSTCOPY_ADVISE:
> > > > -        return loadvm_postcopy_handle_advise(mis);
> > > > +        return loadvm_postcopy_handle_advise(mis, len);
> > > >        case MIG_CMD_POSTCOPY_LISTEN:
> > > >            return loadvm_postcopy_handle_listen(mis);
> > > 
> 
> 
> -- 
> Best regards,
> Vladimir
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

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

end of thread, other threads:[~2018-02-06  9:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-06  7:26 [Qemu-devel] [PATCH] migration: incoming postcopy advise sanity checks Greg Kurz
2018-02-06  7:49 ` Vladimir Sementsov-Ogievskiy
2018-02-06  8:43   ` Greg Kurz
2018-02-06  9:24     ` Vladimir Sementsov-Ogievskiy
2018-02-06  9:46       ` Dr. David Alan Gilbert

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.