memory: Fix up memory_region_{add|del}_coalescing
commitb960fc1796fb078c21121abf01499603b66b3f57
authorPeter Xu <peterx@redhat.com>
Tue, 20 Aug 2019 14:13:28 +0000 (20 22:13 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 21 Aug 2019 14:31:58 +0000 (21 16:31 +0200)
treeabada0bbf5bac90aff7e066c1a89fcc1984dc993
parent264ef5a5c52c249ff51a16d141fc03df71714a13
memory: Fix up memory_region_{add|del}_coalescing

The old memory_region_{add|clear}_coalescing() has some defects
because they both changed mr->coalesced before updating the regions
using memory_region_update_coalesced_range_as().  Then when the
regions were updated in memory_region_update_coalesced_range_as() the
mr->coalesced will always be either one more or one less.  So:

- For memory_region_add_coalescing: it'll always trying to remove the
  newly added coalesced region while it shouldn't, and,

- For memory_region_clear_coalescing: when it calls the update there
  will be no coalesced ranges on mr->coalesced because they were all
  removed before hand so the update will probably do nothing for real.

Let's fix this.  Now we've got flat_range_coalesced_io_notify() to
notify a single CoalescedMemoryRange instance change, so use it in the
existing memory_region_update_coalesced_range() logic by only notify
either an addition or deletion.  Then we hammer both the
memory_region_{add|clear}_coalescing() to use it.

Fixes: 3ac7d43a6fbb5d4a3
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20190820141328.10009-5-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
memory.c