Blame SOURCES/kvm-memory-Fix-incorrect-calls-of-log_global_start-stop.patch

495e37
From b169059c8fbf15c3ffeec0f68b938cb9febd8db7 Mon Sep 17 00:00:00 2001
495e37
From: Peter Xu <peterx@redhat.com>
495e37
Date: Tue, 30 Nov 2021 16:00:28 +0800
495e37
Subject: [PATCH 5/6] memory: Fix incorrect calls of log_global_start/stop
495e37
MIME-Version: 1.0
495e37
Content-Type: text/plain; charset=UTF-8
495e37
Content-Transfer-Encoding: 8bit
495e37
495e37
RH-Author: Peter Xu <peterx@redhat.com>
495e37
RH-MergeRequest: 77: memory: Fix qemu crash on continuous migrations of stopped VM
495e37
RH-Commit: [1/2] 6271ee689266b24d29d4c87f60e5b096ef5f5d63 (peterx/qemu-kvm)
495e37
RH-Bugzilla: 2044818
495e37
RH-Acked-by: Paolo Bonzini <None>
495e37
RH-Acked-by: David Hildenbrand <david@redhat.com>
495e37
RH-Acked-by: quintela1 <quintela@redhat.com>
495e37
495e37
We should only call the log_global_start/stop when the global dirty track
495e37
bitmask changes from zero<->non-zero.
495e37
495e37
No real issue reported for this yet probably because no immediate user to
495e37
enable both dirty rate measurement and migration at the same time.  However
495e37
it'll be good to be prepared for it.
495e37
495e37
Fixes: 63b41db4bc ("memory: make global_dirty_tracking a bitmask")
495e37
Cc: qemu-stable@nongnu.org
495e37
Cc: Hyman Huang <huangy81@chinatelecom.cn>
495e37
Cc: Paolo Bonzini <pbonzini@redhat.com>
495e37
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
495e37
Cc: Juan Quintela <quintela@redhat.com>
495e37
Cc: David Hildenbrand <david@redhat.com>
495e37
Signed-off-by: Peter Xu <peterx@redhat.com>
495e37
Reviewed-by: David Hildenbrand <david@redhat.com>
495e37
Message-Id: <20211130080028.6474-1-peterx@redhat.com>
495e37
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
495e37
(cherry picked from commit 7b0538ed3a22ce30817f818449d10701fb0821f9)
495e37
Signed-off-by: Peter Xu <peterx@redhat.com>
495e37
---
495e37
 softmmu/memory.c | 27 ++++++++++++++-------------
495e37
 1 file changed, 14 insertions(+), 13 deletions(-)
495e37
495e37
diff --git a/softmmu/memory.c b/softmmu/memory.c
495e37
index 7340e19ff5..81d4bf1454 100644
495e37
--- a/softmmu/memory.c
495e37
+++ b/softmmu/memory.c
495e37
@@ -2773,6 +2773,8 @@ static VMChangeStateEntry *vmstate_change;
495e37
 
495e37
 void memory_global_dirty_log_start(unsigned int flags)
495e37
 {
495e37
+    unsigned int old_flags = global_dirty_tracking;
495e37
+
495e37
     if (vmstate_change) {
495e37
         qemu_del_vm_change_state_handler(vmstate_change);
495e37
         vmstate_change = NULL;
495e37
@@ -2781,15 +2783,14 @@ void memory_global_dirty_log_start(unsigned int flags)
495e37
     assert(flags && !(flags & (~GLOBAL_DIRTY_MASK)));
495e37
     assert(!(global_dirty_tracking & flags));
495e37
     global_dirty_tracking |= flags;
495e37
-
495e37
     trace_global_dirty_changed(global_dirty_tracking);
495e37
 
495e37
-    MEMORY_LISTENER_CALL_GLOBAL(log_global_start, Forward);
495e37
-
495e37
-    /* Refresh DIRTY_MEMORY_MIGRATION bit.  */
495e37
-    memory_region_transaction_begin();
495e37
-    memory_region_update_pending = true;
495e37
-    memory_region_transaction_commit();
495e37
+    if (!old_flags) {
495e37
+        MEMORY_LISTENER_CALL_GLOBAL(log_global_start, Forward);
495e37
+        memory_region_transaction_begin();
495e37
+        memory_region_update_pending = true;
495e37
+        memory_region_transaction_commit();
495e37
+    }
495e37
 }
495e37
 
495e37
 static void memory_global_dirty_log_do_stop(unsigned int flags)
495e37
@@ -2800,12 +2801,12 @@ static void memory_global_dirty_log_do_stop(unsigned int flags)
495e37
 
495e37
     trace_global_dirty_changed(global_dirty_tracking);
495e37
 
495e37
-    /* Refresh DIRTY_MEMORY_MIGRATION bit.  */
495e37
-    memory_region_transaction_begin();
495e37
-    memory_region_update_pending = true;
495e37
-    memory_region_transaction_commit();
495e37
-
495e37
-    MEMORY_LISTENER_CALL_GLOBAL(log_global_stop, Reverse);
495e37
+    if (!global_dirty_tracking) {
495e37
+        memory_region_transaction_begin();
495e37
+        memory_region_update_pending = true;
495e37
+        memory_region_transaction_commit();
495e37
+        MEMORY_LISTENER_CALL_GLOBAL(log_global_stop, Reverse);
495e37
+    }
495e37
 }
495e37
 
495e37
 static void memory_vm_change_state_handler(void *opaque, bool running,
495e37
-- 
495e37
2.27.0
495e37