qemu-e2k/softmmu
Peter Xu a5c90c61a1 memory: Fix qemu crash on starting dirty log twice with stopped VM
QEMU can now easily crash with two continuous migration carried out:

(qemu) migrate -d exec:cat>out
(qemu) migrate_cancel
(qemu) migrate -d exec:cat>out
[crash] ../softmmu/memory.c:2782: memory_global_dirty_log_start: Assertion
`!(global_dirty_tracking & flags)' failed.

It's because memory API provides a way to postpone dirty log stop if the VM is
stopped, and that'll be re-done until the next VM start.  It was added in 2017
with commit 1931076077 ("migration: optimize the downtime", 2017-08-01).

However the recent work on allowing dirty tracking to be bitmask broke it,
which is commit 63b41db4bc ("memory: make global_dirty_tracking a bitmask",
2021-11-01).

The fix proposed in this patch contains two things:

  (1) Instead of passing over the flags to postpone stop dirty track, we add a
      global variable (along with current vmstate_change variable) to record
      what flags to stop dirty tracking.

  (2) When start dirty tracking, instead if remove the vmstate hook directly,
      we also execute the postponed stop process so that we make sure all the
      starts and stops will be paired.

This procedure is overlooked in the bitmask-ify work in 2021.

Cc: Hyman Huang <huangy81@chinatelecom.cn>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2044818
Fixes: 63b41db4bc ("memory: make global_dirty_tracking a bitmask")
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20220207123019.27223-1-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-02-16 15:01:33 +01:00
..
arch_init.c meson.build: Define QEMU_ARCH in config-target.h 2021-08-26 17:02:00 +01:00
balloon.c qapi: Restrict balloon-related commands to machine code 2020-09-29 15:41:35 +02:00
bootdevice.c softmmu: move more files to softmmu/ 2020-10-12 11:50:21 -04:00
cpu-throttle.c cpu-throttle: Remove timer_mod() from cpu_throttle_set() 2021-02-08 15:15:32 +01:00
cpu-timers.c icount: get rid of static variable 2021-04-01 09:40:45 +02:00
cpus.c softmmu/cpus: Check if the cpu work list is empty atomically 2022-02-09 08:55:02 +11:00
datadir.c vl: extract softmmu/datadir.c 2020-12-10 12:15:18 -05:00
device_tree.c softmmu/device_tree: Remove redundant pointer assignment 2022-01-21 15:52:56 +10:00
dma-helpers.c exec/memory: Extract address_space_set() from dma_memory_set() 2022-01-20 09:09:37 +01:00
globals.c qmp: generalize watchdog-set-action to -no-reboot/-no-shutdown 2020-12-15 12:51:57 -05:00
icount.c icount: get rid of static variable 2021-04-01 09:40:45 +02:00
ioport.c softmmu: Add missing trace-events file 2020-09-09 17:15:18 +01:00
main.c meson: move SDL and SDL-image detection to meson 2020-08-21 06:30:44 -04:00
memory.c memory: Fix qemu crash on starting dirty log twice with stopped VM 2022-02-16 15:01:33 +01:00
memory_mapping.c softmmu/memory_mapping: optimize for RamDiscardManager sections 2021-10-02 08:43:22 +02:00
meson.build seccomp: convert to meson 2021-01-06 10:21:20 +01:00
physmem.c exec/memory: Extract address_space_set() from dma_memory_set() 2022-01-20 09:09:37 +01:00
qdev-monitor.c pci,pc,virtio: bugfixes 2021-11-15 21:56:15 +01:00
qemu-seccomp.c seccomp: don't block getters for resource control syscalls 2021-07-14 14:15:52 +01:00
qtest.c qtest: add a QOM object for qtest 2021-05-26 14:49:45 +02:00
rtc.c rtc: Move RTC function prototypes to their own header 2022-01-28 14:29:46 +00:00
runstate-action.c runstate: cleanup reboot and panic actions 2021-01-21 13:00:41 +01:00
runstate.c runstate: Initialize Error * to NULL 2021-06-15 17:17:09 +02:00
timers-state.h qemu/atomic: Add aligned_{int64,uint64}_t types 2021-07-21 07:45:38 -10:00
tpm.c qapi: More complex uses of QAPI_LIST_APPEND 2021-01-28 08:08:45 +01:00
trace-events memory: make global_dirty_tracking a bitmask 2021-11-01 22:56:43 +01:00
trace.h softmmu: Add missing trace-events file 2020-09-09 17:15:18 +01:00
vl.c softmmu: fix device deletion events with -device JSON syntax 2022-01-14 12:03:16 +01:00