From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, peterx@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] memory: Replace has_coalesced_range with add/del flags
Date: Sat, 17 Aug 2019 17:32:36 +0800 [thread overview]
Message-ID: <20190817093237.27967-2-peterx@redhat.com> (raw)
In-Reply-To: <20190817093237.27967-1-peterx@redhat.com>
The previous has_coalesced_range counter has a problem in that it only
works for additions of coalesced mmio ranges but not deletions. The
reason is that has_coalesced_range information can be lost when the
FlatView updates the topology again when the updated region is not
covering the coalesced regions. When that happens, due to
flatrange_equal() is not checking against has_coalesced_range, the new
FlatRange will be seen as the same one as the old and the new
instance (whose has_coalesced_range will be zero) will replace the old
instance (whose has_coalesced_range _could_ be non-zero).
To fix it, we don't cache has_coalesced_range at all in the FlatRange.
Instead we introduce two flags to make sure the coalesced_io_{add|del}
will only be called once for every FlatRange instance. This will even
work if another FlatRange replaces current one.
Without this patch, MemoryListener.coalesced_io_del is hardly being
called due to has_coalesced_range will be mostly zero in
flat_range_coalesced_io_del() when topologies frequently change for
the "memory" address space.
Fixes: 3ac7d43a6fbb5d4a3
Signed-off-by: Peter Xu <peterx@redhat.com>
---
memory.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/memory.c b/memory.c
index 8141486832..1a2b465a96 100644
--- a/memory.c
+++ b/memory.c
@@ -217,7 +217,13 @@ struct FlatRange {
bool romd_mode;
bool readonly;
bool nonvolatile;
- int has_coalesced_range;
+ /*
+ * Flags to show whether we have delievered the
+ * coalesced_io_{add|del} events to the listeners for this
+ * FlatRange.
+ */
+ bool coalesced_mmio_add_done;
+ bool coalesced_mmio_del_done;
};
#define FOR_EACH_FLAT_RANGE(var, view) \
@@ -654,7 +660,8 @@ static void render_memory_region(FlatView *view,
fr.romd_mode = mr->romd_mode;
fr.readonly = readonly;
fr.nonvolatile = nonvolatile;
- fr.has_coalesced_range = 0;
+ fr.coalesced_mmio_add_done = false;
+ fr.coalesced_mmio_del_done = false;
/* Render the region itself into any gaps left by the current view. */
for (i = 0; i < view->nr && int128_nz(remain); ++i) {
@@ -857,14 +864,16 @@ static void address_space_update_ioeventfds(AddressSpace *as)
static void flat_range_coalesced_io_del(FlatRange *fr, AddressSpace *as)
{
- if (!fr->has_coalesced_range) {
+ if (QTAILQ_EMPTY(&fr->mr->coalesced)) {
return;
}
- if (--fr->has_coalesced_range > 0) {
+ if (fr->coalesced_mmio_del_done) {
return;
}
+ fr->coalesced_mmio_del_done = true;
+
MEMORY_LISTENER_UPDATE_REGION(fr, as, Reverse, coalesced_io_del,
int128_get64(fr->addr.start),
int128_get64(fr->addr.size));
@@ -880,10 +889,12 @@ static void flat_range_coalesced_io_add(FlatRange *fr, AddressSpace *as)
return;
}
- if (fr->has_coalesced_range++) {
+ if (fr->coalesced_mmio_add_done) {
return;
}
+ fr->coalesced_mmio_add_done = true;
+
QTAILQ_FOREACH(cmr, &mr->coalesced, link) {
tmp = addrrange_shift(cmr->addr,
int128_sub(fr->addr.start,
--
2.21.0
next prev parent reply other threads:[~2019-08-17 9:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-17 9:32 [Qemu-devel] [PATCH 0/2] memory: Fix up coalesced_io_del not working for KVM Peter Xu
2019-08-17 9:32 ` Peter Xu [this message]
2019-08-19 14:30 ` [Qemu-devel] [PATCH 1/2] memory: Replace has_coalesced_range with add/del flags Paolo Bonzini
2019-08-20 4:52 ` Peter Xu
2019-08-17 9:32 ` [Qemu-devel] [PATCH 2/2] memory: Split zones when do coalesced_io_del() Peter Xu
2019-08-19 14:24 ` Paolo Bonzini
2019-08-19 9:32 ` [Qemu-devel] [PATCH 0/2] memory: Fix up coalesced_io_del not working for KVM Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190817093237.27967-2-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).