All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>
Subject: [Qemu-devel] [PULL 09/13] memory: Split zones when do coalesced_io_del()
Date: Wed, 21 Aug 2019 19:28:17 +0200	[thread overview]
Message-ID: <1566408501-48680-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1566408501-48680-1-git-send-email-pbonzini@redhat.com>

From: Peter Xu <peterx@redhat.com>

It is a workaround of current KVM's KVM_UNREGISTER_COALESCED_MMIO
interface.  The kernel interface only allows to unregister an mmio
device with exactly the zone size when registered, or any smaller zone
that is included in the device mmio zone.  It does not support the
userspace to specify a very large zone to remove all the small mmio
devices within the zone covered.

Logically speaking it would be nicer to fix this from KVM side, though
in all cases we still need to coop with old kernels so let's do this.

Fixes: 3ac7d43a6fbb5d4a3
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20190820141328.10009-2-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 memory.c | 49 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/memory.c b/memory.c
index 9a1193a..7124274 100644
--- a/memory.c
+++ b/memory.c
@@ -855,8 +855,39 @@ static void address_space_update_ioeventfds(AddressSpace *as)
     flatview_unref(view);
 }
 
+/*
+ * Notify the memory listeners about the coalesced IO change events of
+ * range `cmr'.  Only the part that has intersection of the specified
+ * FlatRange will be sent.
+ */
+static void flat_range_coalesced_io_notify(FlatRange *fr, AddressSpace *as,
+                                           CoalescedMemoryRange *cmr, bool add)
+{
+    AddrRange tmp;
+
+    tmp = addrrange_shift(cmr->addr,
+                          int128_sub(fr->addr.start,
+                                     int128_make64(fr->offset_in_region)));
+    if (!addrrange_intersects(tmp, fr->addr)) {
+        return;
+    }
+    tmp = addrrange_intersection(tmp, fr->addr);
+
+    if (add) {
+        MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, coalesced_io_add,
+                                      int128_get64(tmp.start),
+                                      int128_get64(tmp.size));
+    } else {
+        MEMORY_LISTENER_UPDATE_REGION(fr, as, Reverse, coalesced_io_del,
+                                      int128_get64(tmp.start),
+                                      int128_get64(tmp.size));
+    }
+}
+
 static void flat_range_coalesced_io_del(FlatRange *fr, AddressSpace *as)
 {
+    CoalescedMemoryRange *cmr;
+
     if (!fr->has_coalesced_range) {
         return;
     }
@@ -865,16 +896,15 @@ static void flat_range_coalesced_io_del(FlatRange *fr, AddressSpace *as)
         return;
     }
 
-    MEMORY_LISTENER_UPDATE_REGION(fr, as, Reverse, coalesced_io_del,
-                                  int128_get64(fr->addr.start),
-                                  int128_get64(fr->addr.size));
+    QTAILQ_FOREACH(cmr, &fr->mr->coalesced, link) {
+        flat_range_coalesced_io_notify(fr, as, cmr, false);
+    }
 }
 
 static void flat_range_coalesced_io_add(FlatRange *fr, AddressSpace *as)
 {
     MemoryRegion *mr = fr->mr;
     CoalescedMemoryRange *cmr;
-    AddrRange tmp;
 
     if (QTAILQ_EMPTY(&mr->coalesced)) {
         return;
@@ -885,16 +915,7 @@ static void flat_range_coalesced_io_add(FlatRange *fr, AddressSpace *as)
     }
 
     QTAILQ_FOREACH(cmr, &mr->coalesced, link) {
-        tmp = addrrange_shift(cmr->addr,
-                              int128_sub(fr->addr.start,
-                                         int128_make64(fr->offset_in_region)));
-        if (!addrrange_intersects(tmp, fr->addr)) {
-            continue;
-        }
-        tmp = addrrange_intersection(tmp, fr->addr);
-        MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, coalesced_io_add,
-                                      int128_get64(tmp.start),
-                                      int128_get64(tmp.size));
+        flat_range_coalesced_io_notify(fr, as, cmr, true);
     }
 }
 
-- 
1.8.3.1




  parent reply	other threads:[~2019-08-21 17:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21 17:28 [Qemu-devel] [PULL 00/13] Misc patches for 2019-08-21 Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 01/13] qemu-ga: clean up TOOLS variable Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 02/13] configure: define CONFIG_TOOLS here Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 03/13] module: use g_hash_table_add() Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 04/13] module: return success on module load Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 05/13] tests: add module loading test Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 06/13] configure: remove AUTOCONF_HOST Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 07/13] minikconf: don't print CONFIG_FOO=n lines Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 08/13] memory: Refactor memory_region_clear_coalescing Paolo Bonzini
2019-08-21 17:28 ` Paolo Bonzini [this message]
2019-08-21 17:28 ` [Qemu-devel] [PULL 10/13] memory: Remove has_coalesced_range counter Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 11/13] memory: Fix up memory_region_{add|del}_coalescing Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 12/13] main-loop: Fix GSource leak in qio_task_thread_worker() Paolo Bonzini
2019-08-21 17:28 ` [Qemu-devel] [PULL 13/13] char-socket: Lock tcp_chr_disconnect() and socket_reconnect_timeout() Paolo Bonzini
2019-08-22 13:16 ` [Qemu-devel] [PULL 00/13] Misc patches for 2019-08-21 Peter Maydell
2019-08-22 17:22 ` Peter Maydell

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=1566408501-48680-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=peterx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.