Blame SOURCES/kvm-migration-ram.c-do-not-set-postcopy_running-in-POSTC.patch

4a2fec
From 50f063769cf74d2d37adbc5b568b545d2562af65 Mon Sep 17 00:00:00 2001
4a2fec
From: Laurent Vivier <lvivier@redhat.com>
4a2fec
Date: Tue, 28 Nov 2017 10:30:08 +0100
4a2fec
Subject: [PATCH 15/21] migration/ram.c: do not set 'postcopy_running' in
4a2fec
 POSTCOPY_INCOMING_END
4a2fec
4a2fec
RH-Author: Laurent Vivier <lvivier@redhat.com>
4a2fec
Message-id: <20171128103008.1150-1-lvivier@redhat.com>
4a2fec
Patchwork-id: 77931
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH] migration/ram.c: do not set 'postcopy_running' in POSTCOPY_INCOMING_END
4a2fec
Bugzilla: 1516956
4a2fec
RH-Acked-by: Peter Xu <peterx@redhat.com>
4a2fec
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
RH-Acked-by: Juan Quintela <quintela@redhat.com>
4a2fec
RH-Acked-by: David Gibson <dgibson@redhat.com>
4a2fec
4a2fec
From: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
4a2fec
4a2fec
When migrating a VM with 'migrate_set_capability postcopy-ram on'
4a2fec
a postcopy_state is set during the process, ending up with the
4a2fec
state POSTCOPY_INCOMING_END when the migration is over. This
4a2fec
postcopy_state is taken into account inside ram_load to check
4a2fec
how it will load the memory pages. This same ram_load is called when
4a2fec
in a loadvm command.
4a2fec
4a2fec
Inside ram_load, the logic to see if we're at postcopy_running state
4a2fec
is:
4a2fec
4a2fec
postcopy_running = postcopy_state_get() >= POSTCOPY_INCOMING_LISTENING
4a2fec
4a2fec
postcopy_state_get() returns this enum type:
4a2fec
4a2fec
typedef enum {
4a2fec
    POSTCOPY_INCOMING_NONE = 0,
4a2fec
    POSTCOPY_INCOMING_ADVISE,
4a2fec
    POSTCOPY_INCOMING_DISCARD,
4a2fec
    POSTCOPY_INCOMING_LISTENING,
4a2fec
    POSTCOPY_INCOMING_RUNNING,
4a2fec
    POSTCOPY_INCOMING_END
4a2fec
} PostcopyState;
4a2fec
4a2fec
In the case where ram_load is executed and postcopy_state is
4a2fec
POSTCOPY_INCOMING_END, postcopy_running will be set to 'true' and
4a2fec
ram_load will behave like a postcopy is in progress. This scenario isn't
4a2fec
achievable in a migration but it is reproducible when executing
4a2fec
savevm/loadvm after migrating with 'postcopy-ram on', causing loadvm
4a2fec
to fail with Error -22:
4a2fec
4a2fec
Source:
4a2fec
4a2fec
(qemu) migrate_set_capability postcopy-ram on
4a2fec
(qemu) migrate tcp:127.0.0.1:4444
4a2fec
4a2fec
Dest:
4a2fec
4a2fec
(qemu) migrate_set_capability postcopy-ram on
4a2fec
(qemu)
4a2fec
ubuntu1704-intel login:
4a2fec
Ubuntu 17.04 ubuntu1704-intel ttyS0
4a2fec
4a2fec
ubuntu1704-intel login: (qemu)
4a2fec
(qemu) savevm test1
4a2fec
(qemu) loadvm test1
4a2fec
Unknown combination of migration flags: 0x4 (postcopy mode)
4a2fec
error while loading state for instance 0x0 of device 'ram'
4a2fec
Error -22 while loading VM state
4a2fec
(qemu)
4a2fec
4a2fec
This patch fixes this problem by changing the existing logic for
4a2fec
postcopy_advised and postcopy_running in ram_load, making them
4a2fec
'false' if we're at POSTCOPY_INCOMING_END state.
4a2fec
4a2fec
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
4a2fec
CC: Juan Quintela <quintela@redhat.com>
4a2fec
CC: Dr. David Alan Gilbert <dgilbert@redhat.com>
4a2fec
Reviewed-by: Peter Xu <peterx@redhat.com>
4a2fec
Reviewed-by: Juan Quintela <quintela@redhat.com>
4a2fec
Reported-by: Balamuruhan S <bala24@linux.vnet.ibm.com>
4a2fec
Signed-off-by: Juan Quintela <quintela@redhat.com>
4a2fec
(cherry picked from commit acab30b85db0885ab161aff4c83c550628f6d8ca)
4a2fec
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 migration/ram.c | 16 ++++++++++++++--
4a2fec
 1 file changed, 14 insertions(+), 2 deletions(-)
4a2fec
4a2fec
diff --git a/migration/ram.c b/migration/ram.c
4a2fec
index e18b3e2..fef80fd 100644
4a2fec
--- a/migration/ram.c
4a2fec
+++ b/migration/ram.c
4a2fec
@@ -2484,6 +2484,18 @@ static int ram_load_postcopy(QEMUFile *f)
4a2fec
     return ret;
4a2fec
 }
4a2fec
 
4a2fec
+static bool postcopy_is_advised(void)
4a2fec
+{
4a2fec
+    PostcopyState ps = postcopy_state_get();
4a2fec
+    return ps >= POSTCOPY_INCOMING_ADVISE && ps < POSTCOPY_INCOMING_END;
4a2fec
+}
4a2fec
+
4a2fec
+static bool postcopy_is_running(void)
4a2fec
+{
4a2fec
+    PostcopyState ps = postcopy_state_get();
4a2fec
+    return ps >= POSTCOPY_INCOMING_LISTENING && ps < POSTCOPY_INCOMING_END;
4a2fec
+}
4a2fec
+
4a2fec
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
4a2fec
 {
4a2fec
     int flags = 0, ret = 0, invalid_flags = 0;
4a2fec
@@ -2493,9 +2505,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
4a2fec
      * If system is running in postcopy mode, page inserts to host memory must
4a2fec
      * be atomic
4a2fec
      */
4a2fec
-    bool postcopy_running = postcopy_state_get() >= POSTCOPY_INCOMING_LISTENING;
4a2fec
+    bool postcopy_running = postcopy_is_running();
4a2fec
     /* ADVISE is earlier, it shows the source has the postcopy capability on */
4a2fec
-    bool postcopy_advised = postcopy_state_get() >= POSTCOPY_INCOMING_ADVISE;
4a2fec
+    bool postcopy_advised = postcopy_is_advised();
4a2fec
 
4a2fec
     seq_iter++;
4a2fec
 
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec