[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/26] vhost: Regenerate region list from changed sec
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 07/26] vhost: Regenerate region list from changed sections list |
Date: |
Thu, 8 Feb 2018 21:09:02 +0200 |
From: "Dr. David Alan Gilbert" <address@hidden>
Compare the sections list that's just been generated, and if it's
different from the old one regenerate the region list.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Igor Mammedov <address@hidden>
---
hw/virtio/vhost.c | 39 +++++++++++++++++++++++++++++++++++----
hw/virtio/trace-events | 1 +
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 351c691..f3badc4 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -643,21 +643,52 @@ static void vhost_commit(MemoryListener *listener)
MemoryRegionSection *old_sections;
int n_old_sections;
uint64_t log_size;
+ size_t regions_size;
int r;
int i;
+ bool changed = false;
+ /* Note we can be called before the device is started, but then
+ * starting the device calls set_mem_table, so we need to have
+ * built the data structures.
+ */
old_sections = dev->mem_sections;
n_old_sections = dev->n_mem_sections;
dev->mem_sections = dev->tmp_sections;
dev->n_mem_sections = dev->n_tmp_sections;
- if (!dev->memory_changed) {
- goto out;
+ if (dev->n_mem_sections != n_old_sections) {
+ 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;
}
- if (!dev->started) {
+
+ trace_vhost_commit(dev->started, changed);
+ if (!changed) {
goto out;
}
- if (dev->mem_changed_start_addr > dev->mem_changed_end_addr) {
+
+ /* Rebuild the regions list from the new sections list */
+ regions_size = offsetof(struct vhost_memory, regions) +
+ dev->n_mem_sections * sizeof dev->mem->regions[0];
+ dev->mem = g_realloc(dev->mem, regions_size);
+ dev->mem->nregions = dev->n_mem_sections;
+ used_memslots = dev->mem->nregions;
+ for (i = 0; i < dev->n_mem_sections; i++) {
+ struct vhost_memory_region *cur_vmr = dev->mem->regions + i;
+ struct MemoryRegionSection *mrs = dev->mem_sections + i;
+
+ cur_vmr->guest_phys_addr = mrs->offset_within_address_space;
+ cur_vmr->memory_size = int128_get64(mrs->size);
+ cur_vmr->userspace_addr =
+ (uintptr_t)memory_region_get_ram_ptr(mrs->mr) +
+ mrs->offset_within_region;
+ cur_vmr->flags_padding = 0;
+ }
+
+ if (!dev->started) {
goto out;
}
diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index ab9da06..606e4fc 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -1,6 +1,7 @@
# See docs/devel/tracing.txt for syntax documentation.
# hw/virtio/vhost.c
+vhost_commit(bool started, bool changed) "Started: %d Changed: %d"
vhost_region_add_section(const char *name, uint64_t gpa, uint64_t size,
uint64_t host) "%s: 0x%"PRIx64"+0x%"PRIx64" @ 0x%"PRIx64
vhost_region_add_section_abut(const char *name, uint64_t new_size) "%s:
0x%"PRIx64
--
MST
- [Qemu-devel] [PULL 00/26] virtio, vhost, pci, pc: features, fixes and cleanups, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 01/26] Revert "vhost: add traces for memory listeners", Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 04/26] vhost: Build temporary section list and deref after commit, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 02/26] virtio: remove event notifier cleanup call on de-assign, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 05/26] vhost: Simplify ring verification checks, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 06/26] vhost: Merge sections added to temporary list, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 07/26] vhost: Regenerate region list from changed sections list,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 09/26] vhost: Merge and delete unused callbacks, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 10/26] vhost: Move log_dirty check, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 11/26] pci-bridge/i82801b11: clear bridge registers on platform reset, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 08/26] vhost: Clean out old vhost_set_memory and friends, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 13/26] virtio-blk: enable multiple vectors when using multiple I/O queues, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 12/26] pci/bus: let it has higher migration priority, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 17/26] cryptodev-vhost-user: add crypto session handler, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 16/26] cryptodev: add vhost support, Michael S. Tsirkin, 2018/02/08
- [Qemu-devel] [PULL 15/26] cryptodev: add vhost-user as a new cryptodev backend, Michael S. Tsirkin, 2018/02/08