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

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