migration/ram.c: do not set 'postcopy_running' in POSTCOPY_INCOMING_END
PATCH 1/1 migration/ram.c: do not set 'postcopy_running' in POSTCOPY_INCOMING_END
When migrating a VM with 'migrate_set_capability postcopy-ram on' a postcopy_state is set during the process, ending up with the state POSTCOPY_INCOMING_END when the migration is over. This postcopy_state is taken into account inside ram_load to check how it will load the memory pages. This same ram_load is called when in a loadvm command.
Inside ram_load, the logic to see if we're at postcopy_running state is:
postcopy_running = postcopy_state_get() >= POSTCOPY_INCOMING_LISTENING
postcopy_state_get() returns this enum type:
typedef enum {
POSTCOPY_INCOMING_NONE = 0,
POSTCOPY_INCOMING_ADVISE,
POSTCOPY_INCOMING_DISCARD,
POSTCOPY_INCOMING_LISTENING,
POSTCOPY_INCOMING_RUNNING,
POSTCOPY_INCOMING_END
} PostcopyState;
In the case where ram_load is executed and postcopy_state is POSTCOPY_INCOMING_END, postcopy_running will be set to 'true' and ram_load will behave like a postcopy is in progress. This scenario isn't achievable in a migration but it is reproducible when executing savevm/loadvm after migrating with 'postcopy-ram on', causing loadvm to fail with Error -22:
Source:
(qemu) migrate_set_capability postcopy-ram on
(qemu) migrate tcp:127.0.0.1:4444
Dest:
(qemu) migrate_set_capability postcopy-ram on
(qemu)
ubuntu1704-intel login:
Ubuntu 17.04 ubuntu1704-intel ttyS0
ubuntu1704-intel login: (qemu)
(qemu) savevm test1
(qemu) loadvm test1
Unknown combination of migration flags: 0x4 (postcopy mode) error while loading state for instance 0x0 of device 'ram' Error -22 while loading VM state
(qemu)
This patch fixes this problem by changing a bit the semantics of postcopy_running inside ram_load, verifying first if we're not in the POSTCOPY_INCOMING_END state. In this case, postcopy_running is set to 'false'.
--- migration/ram.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
migration/ram.c +15 -7
@@ -2803,13 +2803,21 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 , invalid_flags =0 ;static uint64_t seq_iter;int len =0 ; -/* -* If system is running in postcopy mode, page inserts to host memory must -* be atomic -*/ -bool postcopy_running =postcopy_state_get () >=POSTCOPY_INCOMING_LISTENING ; -/* ADVISE is earlier, it shows the source has the postcopy capability on */ -bool postcopy_advised =postcopy_state_get () >=POSTCOPY_INCOMING_ADVISE ; +bool postcopy_advised = false, postcopy_running = false; +uint8_t postcopy_state =postcopy_state_get (); + +if (postcopy_state !=POSTCOPY_INCOMING_END ) { +/* +* If system is running in postcopy mode, page inserts to host memory +* must be atomic +*/ + postcopy_running = postcopy_state >=POSTCOPY_INCOMING_LISTENING ; + +/* ADVISE is earlier, it shows the source has the postcopy +* capability on +*/ + postcopy_advised = postcopy_state >=POSTCOPY_INCOMING_ADVISE ; + } seq_iter++;
Signature · 1 line
2.13.6
Quoted 80 lines · Daniel Henrique Barboza
When migrating a VM with '
migrate_set_capabilitypostcopy-ram on' apostcopy_stateis set during the process, ending up with the statePOSTCOPY_INCOMING_ENDwhen the migration is over. Thispostcopy_stateis taken into account insideram_loadto check how it will load the memory pages. This sameram_loadis called when in a loadvm command.Inside
ram_load, the logic to see if we're atpostcopy_runningstate is:
postcopy_running=postcopy_state_get()>=POSTCOPY_INCOMING_LISTENING
postcopy_state_get()returns this enum type:typedef enum {
POSTCOPY_INCOMING_NONE= 0,
POSTCOPY_INCOMING_ADVISE,
POSTCOPY_INCOMING_DISCARD,
POSTCOPY_INCOMING_LISTENING,
POSTCOPY_INCOMING_RUNNING,
POSTCOPY_INCOMING_END
} PostcopyState;In the case where
ram_loadis executed andpostcopy_stateisPOSTCOPY_INCOMING_END,postcopy_runningwill be set to 'true' andram_loadwill behave like a postcopy is in progress. This scenario isn't achievable in a migration but it is reproducible when executing savevm/loadvm after migrating with 'postcopy-ram on', causing loadvm to fail with Error -22:Source:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu) migrate tcp:127.0.0.1:4444Dest:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu)
ubuntu1704-intel login:
Ubuntu 17.04 ubuntu1704-intel ttyS0ubuntu1704-intel login: (qemu)
(qemu) savevm test1
(qemu) loadvm test1
Unknown combination of migration flags:0x4(postcopy mode) error while loading state for instance0x0of device 'ram' Error -22 while loading VM state
(qemu)This patch fixes this problem by changing a bit the semantics of
postcopy_runninginsideram_load, verifying first if we're not in thePOSTCOPY_INCOMING_ENDstate. In this case,postcopy_runningis set to 'false'.Signed-off-by Daniel Henrique Barboza <[email protected]>--- migration/ram.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)migration/ram.c +5
-7@@ -2803,13 +2803,21 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 , invalid_flags =0 ;static uint64_t seq_iter;int len =0 ; -/* -* If system is running in postcopy mode, page inserts to host memory must -* be atomic -*/ -bool postcopy_running =postcopy_state_get () >=POSTCOPY_INCOMING_LISTENING ; -/* ADVISE is earlier, it shows the source has the postcopy capability on */ -bool postcopy_advised =postcopy_state_get () >=POSTCOPY_INCOMING_ADVISE ; +bool postcopy_advised = false, postcopy_running = false; +uint8_t postcopy_state =postcopy_state_get (); + +if (postcopy_state !=POSTCOPY_INCOMING_END ) { +/*
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2820
Quoted 10 lines
migration/ram.c +10
-0+* If system is running in postcopy mode, page inserts to host memory +* must be atomic +*/ + postcopy_running = postcopy_state >=POSTCOPY_INCOMING_LISTENING ; + +/* ADVISE is earlier, it shows the source has the postcopy +* capability on +*/ + postcopy_advised = postcopy_state >=POSTCOPY_INCOMING_ADVISE ; + }
For me, this is not that clear. I would prefer something simpler like:
PostcopyState state = postcopy_state_get();
bool postcopy_running = state >= POSTCOPY_INCOMING_LISTENING && \
state < POSTCOPY_INCOMING_END;Or we can introduce postcopy_is_running() helper. Same thing to postcopy_advised. Thanks,
Quoted 7 lines
migration/ram.c +0
-0seq_iter++;Signature · 1 line
2.13.6
Signature · 1 line
Peter Xu
Hi Peter,
Quoted 93 lines · Peter Xu
Quoted 80 lines · Daniel Henrique Barboza
When migrating a VM with '
migrate_set_capabilitypostcopy-ram on' apostcopy_stateis set during the process, ending up with the statePOSTCOPY_INCOMING_ENDwhen the migration is over. Thispostcopy_stateis taken into account insideram_loadto check how it will load the memory pages. This sameram_loadis called when in a loadvm command.Inside
ram_load, the logic to see if we're atpostcopy_runningstate is:
postcopy_running=postcopy_state_get()>=POSTCOPY_INCOMING_LISTENING
postcopy_state_get()returns this enum type:typedef enum {
POSTCOPY_INCOMING_NONE= 0,
POSTCOPY_INCOMING_ADVISE,
POSTCOPY_INCOMING_DISCARD,
POSTCOPY_INCOMING_LISTENING,
POSTCOPY_INCOMING_RUNNING,
POSTCOPY_INCOMING_END
} PostcopyState;In the case where
ram_loadis executed andpostcopy_stateisPOSTCOPY_INCOMING_END,postcopy_runningwill be set to 'true' andram_loadwill behave like a postcopy is in progress. This scenario isn't achievable in a migration but it is reproducible when executing savevm/loadvm after migrating with 'postcopy-ram on', causing loadvm to fail with Error -22:Source:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu) migrate tcp:127.0.0.1:4444Dest:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu)
ubuntu1704-intel login:
Ubuntu 17.04 ubuntu1704-intel ttyS0ubuntu1704-intel login: (qemu)
(qemu) savevm test1
(qemu) loadvm test1
Unknown combination of migration flags:0x4(postcopy mode) error while loading state for instance0x0of device 'ram' Error -22 while loading VM state
(qemu)This patch fixes this problem by changing a bit the semantics of
postcopy_runninginsideram_load, verifying first if we're not in thePOSTCOPY_INCOMING_ENDstate. In this case,postcopy_runningis set to 'false'.Signed-off-by Daniel Henrique Barboza <[email protected]>--- migration/ram.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)migration/ram.c +5
-7@@ -2803,13 +2803,21 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 , invalid_flags =0 ;static uint64_t seq_iter;int len =0 ; -/* -* If system is running in postcopy mode, page inserts to host memory must -* be atomic -*/ -bool postcopy_running =postcopy_state_get () >=POSTCOPY_INCOMING_LISTENING ; -/* ADVISE is earlier, it shows the source has the postcopy capability on */ -bool postcopy_advised =postcopy_state_get () >=POSTCOPY_INCOMING_ADVISE ; +bool postcopy_advised = false, postcopy_running = false; +uint8_t postcopy_state =postcopy_state_get (); + +if (postcopy_state !=POSTCOPY_INCOMING_END ) { +/* migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2820
Quoted 10 lines
migration/ram.c +10
-0+* If system is running in postcopy mode, page inserts to host memory +* must be atomic +*/ + postcopy_running = postcopy_state >=POSTCOPY_INCOMING_LISTENING ; + +/* ADVISE is earlier, it shows the source has the postcopy +* capability on +*/ + postcopy_advised = postcopy_state >=POSTCOPY_INCOMING_ADVISE ; + }For me, this is not that clear. I would prefer something simpler like:
Quoted 6 lines
PostcopyState state = postcopy_state_get(); bool postcopy_running = state >= POSTCOPY_INCOMING_LISTENING && \ state < POSTCOPY_INCOMING_END;Or we can introduce
postcopy_is_running()helper. Same thing topostcopy_advised. Thanks,
I like the idea of creating helpers to make the logic simpler. I'll make this change in the next spin.
Thanks,
Daniel
Quoted 8 lines
Quoted 8 lines
migration/ram.c +0
-0seq_iter++;Signature · 1 line
2.13.6
Quoted 50 lines · Daniel Henrique Barboza
When migrating a VM with '
migrate_set_capabilitypostcopy-ram on' apostcopy_stateis set during the process, ending up with the statePOSTCOPY_INCOMING_ENDwhen the migration is over. Thispostcopy_stateis taken into account insideram_loadto check how it will load the memory pages. This sameram_loadis called when in a loadvm command.Inside
ram_load, the logic to see if we're atpostcopy_runningstate is:
postcopy_running=postcopy_state_get()>=POSTCOPY_INCOMING_LISTENING
postcopy_state_get()returns this enum type:typedef enum {
POSTCOPY_INCOMING_NONE= 0,
POSTCOPY_INCOMING_ADVISE,
POSTCOPY_INCOMING_DISCARD,
POSTCOPY_INCOMING_LISTENING,
POSTCOPY_INCOMING_RUNNING,
POSTCOPY_INCOMING_END
} PostcopyState;In the case where
ram_loadis executed andpostcopy_stateisPOSTCOPY_INCOMING_END,postcopy_runningwill be set to 'true' andram_loadwill behave like a postcopy is in progress. This scenario isn't achievable in a migration but it is reproducible when executing savevm/loadvm after migrating with 'postcopy-ram on', causing loadvm to fail with Error -22:Source:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu) migrate tcp:127.0.0.1:4444Dest:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu)
ubuntu1704-intel login:
Ubuntu 17.04 ubuntu1704-intel ttyS0ubuntu1704-intel login: (qemu)
(qemu) savevm test1
(qemu) loadvm test1
Unknown combination of migration flags:0x4(postcopy mode) error while loading state for instance0x0of device 'ram' Error -22 while loading VM state
(qemu)
Quoted 6 lines
This patch fixes this problem by changing a bit the semantics of
postcopy_runninginsideram_load, verifying first if we're not in thePOSTCOPY_INCOMING_ENDstate. In this case,postcopy_runningis set to 'false'.Signed-off-by Daniel Henrique Barboza <[email protected]>
queued
Quoted 36 lines
--- migration/ram.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)migration/ram.c +15
-7@@ -2803,13 +2803,21 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 , invalid_flags =0 ;static uint64_t seq_iter;int len =0 ; -/* -* If system is running in postcopy mode, page inserts to host memory must -* be atomic -*/ -bool postcopy_running =postcopy_state_get () >=POSTCOPY_INCOMING_LISTENING ; -/* ADVISE is earlier, it shows the source has the postcopy capability on */ -bool postcopy_advised =postcopy_state_get () >=POSTCOPY_INCOMING_ADVISE ; +bool postcopy_advised = false, postcopy_running = false; +uint8_t postcopy_state =postcopy_state_get (); + +if (postcopy_state !=POSTCOPY_INCOMING_END ) { +/* +* If system is running in postcopy mode, page inserts to host memory +* must be atomic +*/ + postcopy_running = postcopy_state >=POSTCOPY_INCOMING_LISTENING ; + +/* ADVISE is earlier, it shows the source has the postcopy +* capability on +*/ + postcopy_advised = postcopy_state >=POSTCOPY_INCOMING_ADVISE ; + } seq_iter++;
Quoted 56 lines · * Juan Quintela ([email protected]) wrote:
Quoted 55 lines · Daniel Henrique Barboza
When migrating a VM with '
migrate_set_capabilitypostcopy-ram on' apostcopy_stateis set during the process, ending up with the statePOSTCOPY_INCOMING_ENDwhen the migration is over. Thispostcopy_stateis taken into account insideram_loadto check how it will load the memory pages. This sameram_loadis called when in a loadvm command.Inside
ram_load, the logic to see if we're atpostcopy_runningstate is:
postcopy_running=postcopy_state_get()>=POSTCOPY_INCOMING_LISTENING
postcopy_state_get()returns this enum type:typedef enum {
POSTCOPY_INCOMING_NONE= 0,
POSTCOPY_INCOMING_ADVISE,
POSTCOPY_INCOMING_DISCARD,
POSTCOPY_INCOMING_LISTENING,
POSTCOPY_INCOMING_RUNNING,
POSTCOPY_INCOMING_END
} PostcopyState;In the case where
ram_loadis executed andpostcopy_stateisPOSTCOPY_INCOMING_END,postcopy_runningwill be set to 'true' andram_loadwill behave like a postcopy is in progress. This scenario isn't achievable in a migration but it is reproducible when executing savevm/loadvm after migrating with 'postcopy-ram on', causing loadvm to fail with Error -22:Source:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu) migrate tcp:127.0.0.1:4444Dest:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu)
ubuntu1704-intel login:
Ubuntu 17.04 ubuntu1704-intel ttyS0ubuntu1704-intel login: (qemu)
(qemu) savevm test1
(qemu) loadvm test1
Unknown combination of migration flags:0x4(postcopy mode) error while loading state for instance0x0of device 'ram' Error -22 while loading VM state
(qemu)This patch fixes this problem by changing a bit the semantics of
postcopy_runninginsideram_load, verifying first if we're not in thePOSTCOPY_INCOMING_ENDstate. In this case,postcopy_runningis set to 'false'.
Quoted 5 lines
Quoted 1 line
Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Juan Quintela <[email protected]>queued
Wrong version; v3 is:
http://lists.nongnu.org/archive/html/qemu-devel/2017-11/msg03188.html
Dave
Quoted 35 lines
Quoted 35 lines
--- migration/ram.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)migration/ram.c +15
-7@@ -2803,13 +2803,21 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 , invalid_flags =0 ;static uint64_t seq_iter;int len =0 ; -/* -* If system is running in postcopy mode, page inserts to host memory must -* be atomic -*/ -bool postcopy_running =postcopy_state_get () >=POSTCOPY_INCOMING_LISTENING ; -/* ADVISE is earlier, it shows the source has the postcopy capability on */ -bool postcopy_advised =postcopy_state_get () >=POSTCOPY_INCOMING_ADVISE ; +bool postcopy_advised = false, postcopy_running = false; +uint8_t postcopy_state =postcopy_state_get (); + +if (postcopy_state !=POSTCOPY_INCOMING_END ) { +/* +* If system is running in postcopy mode, page inserts to host memory +* must be atomic +*/ + postcopy_running = postcopy_state >=POSTCOPY_INCOMING_LISTENING ; + +/* ADVISE is earlier, it shows the source has the postcopy +* capability on +*/ + postcopy_advised = postcopy_state >=POSTCOPY_INCOMING_ADVISE ; + }
Quoted 1 line
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2822
Quoted 1 line
migration/ram.c +0
-0seq_iter++;
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 57 lines · Dr. David Alan Gilbert
Quoted 56 lines · * Juan Quintela ([email protected]) wrote:
Quoted 55 lines · Daniel Henrique Barboza
When migrating a VM with '
migrate_set_capabilitypostcopy-ram on' apostcopy_stateis set during the process, ending up with the statePOSTCOPY_INCOMING_ENDwhen the migration is over. Thispostcopy_stateis taken into account insideram_loadto check how it will load the memory pages. This sameram_loadis called when in a loadvm command.Inside
ram_load, the logic to see if we're atpostcopy_runningstate is:
postcopy_running=postcopy_state_get()>=POSTCOPY_INCOMING_LISTENING
postcopy_state_get()returns this enum type:typedef enum {
POSTCOPY_INCOMING_NONE= 0,
POSTCOPY_INCOMING_ADVISE,
POSTCOPY_INCOMING_DISCARD,
POSTCOPY_INCOMING_LISTENING,
POSTCOPY_INCOMING_RUNNING,
POSTCOPY_INCOMING_END
} PostcopyState;In the case where
ram_loadis executed andpostcopy_stateisPOSTCOPY_INCOMING_END,postcopy_runningwill be set to 'true' andram_loadwill behave like a postcopy is in progress. This scenario isn't achievable in a migration but it is reproducible when executing savevm/loadvm after migrating with 'postcopy-ram on', causing loadvm to fail with Error -22:Source:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu) migrate tcp:127.0.0.1:4444Dest:
(qemu)
migrate_set_capabilitypostcopy-ram on
(qemu)
ubuntu1704-intel login:
Ubuntu 17.04 ubuntu1704-intel ttyS0ubuntu1704-intel login: (qemu)
(qemu) savevm test1
(qemu) loadvm test1
Unknown combination of migration flags:0x4(postcopy mode) error while loading state for instance0x0of device 'ram' Error -22 while loading VM state
(qemu)This patch fixes this problem by changing a bit the semantics of
postcopy_runninginsideram_load, verifying first if we're not in thePOSTCOPY_INCOMING_ENDstate. In this case,postcopy_runningis set to 'false'.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Juan Quintela <[email protected]>queued
Wrong version; v3 is:
My bad, sorry. Got a new one.
No clue why search on my INBOX didn't found this version.
compiling a new pull request.
Quoted 43 lines
http://lists.nongnu.org/archive/html/qemu-devel/2017-11/msg03188.html
Dave
Quoted 35 lines
Quoted 35 lines
--- migration/ram.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)migration/ram.c +15
-7@@ -2803,13 +2803,21 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)int flags =0 , ret =0 , invalid_flags =0 ;static uint64_t seq_iter;int len =0 ; -/* -* If system is running in postcopy mode, page inserts to host memory must -* be atomic -*/ -bool postcopy_running =postcopy_state_get () >=POSTCOPY_INCOMING_LISTENING ; -/* ADVISE is earlier, it shows the source has the postcopy capability on */ -bool postcopy_advised =postcopy_state_get () >=POSTCOPY_INCOMING_ADVISE ; +bool postcopy_advised = false, postcopy_running = false; +uint8_t postcopy_state =postcopy_state_get (); + +if (postcopy_state !=POSTCOPY_INCOMING_END ) { +/* +* If system is running in postcopy mode, page inserts to host memory +* must be atomic +*/ + postcopy_running = postcopy_state >=POSTCOPY_INCOMING_LISTENING ; + +/* ADVISE is earlier, it shows the source has the postcopy +* capability on +*/ + postcopy_advised = postcopy_state >=POSTCOPY_INCOMING_ADVISE ; + }Quoted 1 line
migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2822
Quoted 1 line
migration/ram.c +0
-0seq_iter++;--
Dr. David Alan Gilbert / [email protected] / Manchester, UK