summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2019-09-26 16:14:03 +0100
committerPeter Maydell <peter.maydell@linaro.org>2019-09-26 16:14:03 +0100
commit1329132d28bf14b9508f7a1f04a2c63422bc3f99 (patch)
treeff1527f32f493e9889ba4dfae5d06fe62380b136
parenteb13d1cf4a0478fc29f80abfbac8209479325f35 (diff)
parent3fc4a64cbaed2ddee4c60ddc06740b320e18ab82 (diff)
downloadfocaccia-qemu-1329132d28bf14b9508f7a1f04a2c63422bc3f99.tar.gz
focaccia-qemu-1329132d28bf14b9508f7a1f04a2c63422bc3f99.zip
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
vhost: fixes

Misc fixes related to memory region handling.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

# gpg: Signature made Wed 25 Sep 2019 15:28:23 BST
# gpg:                using RSA key 281F0DB8D28D5469
# gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [full]
# gpg:                 aka "Michael S. Tsirkin <mst@redhat.com>" [full]
# Primary key fingerprint: 0270 606B 6F3C DF3D 0B17  0970 C350 3912 AFBE 8E67
#      Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA  8A0D 281F 0DB8 D28D 5469

* remotes/mst/tags/for_upstream:
  vhost: Fix memory region section comparison
  memory: Provide an equality function for MemoryRegionSections
  memory: Align MemoryRegionSections fields

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--hw/virtio/vhost.c9
-rw-r--r--include/exec/memory.h14
2 files changed, 20 insertions, 3 deletions
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 34accdf615..2386b511f3 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -451,8 +451,13 @@ static void vhost_commit(MemoryListener *listener)
         changed = true;
     } else {
         /* Same size, lets check the contents */
-        changed = n_old_sections && memcmp(dev->mem_sections, old_sections,
-                         n_old_sections * sizeof(old_sections[0])) != 0;
+        for (int i = 0; i < n_old_sections; i++) {
+            if (!MemoryRegionSection_eq(&old_sections[i],
+                                        &dev->mem_sections[i])) {
+                changed = true;
+                break;
+            }
+        }
     }
 
     trace_vhost_commit(dev->started, changed);
diff --git a/include/exec/memory.h b/include/exec/memory.h
index a30245c25a..6e67043ee0 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -495,15 +495,27 @@ static inline FlatView *address_space_to_flatview(AddressSpace *as)
  * @nonvolatile: this section is non-volatile
  */
 struct MemoryRegionSection {
+    Int128 size;
     MemoryRegion *mr;
     FlatView *fv;
     hwaddr offset_within_region;
-    Int128 size;
     hwaddr offset_within_address_space;
     bool readonly;
     bool nonvolatile;
 };
 
+static inline bool MemoryRegionSection_eq(MemoryRegionSection *a,
+                                          MemoryRegionSection *b)
+{
+    return a->mr == b->mr &&
+           a->fv == b->fv &&
+           a->offset_within_region == b->offset_within_region &&
+           a->offset_within_address_space == b->offset_within_address_space &&
+           int128_eq(a->size, b->size) &&
+           a->readonly == b->readonly &&
+           a->nonvolatile == b->nonvolatile;
+}
+
 /**
  * memory_region_init: Initialize a memory region
  *