[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v2 8/8] vhost: Move mem_sections maintenance into comm
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [RFC v2 8/8] vhost: Move mem_sections maintenance into commit/update routines |
Date: |
Fri, 8 Dec 2017 20:32:57 +0000 |
From: "Dr. David Alan Gilbert" <address@hidden>
Mvoe the maintenance of mem_sections into the vhost_update_mem routines,
this removes the need for the vhost_region_add/del callbacks.
Suggested-by: Igor Mammedov <address@hidden>
(and mostly written by Igor!)
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
hw/virtio/vhost.c | 58 +++++++++++++++----------------------------------------
1 file changed, 16 insertions(+), 42 deletions(-)
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 2cfb13272f..79927ab93d 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -408,6 +408,13 @@ static int vhost_update_mem_cb(MemoryRegionSection *mrs,
void *opaque)
if (!vhost_section(mrs)) {
return 0;
}
+ ++vtmp->dev->n_mem_sections;
+ vtmp->dev->mem_sections = g_renew(MemoryRegionSection,
+ vtmp->dev->mem_sections,
+ vtmp->dev->n_mem_sections);
+ vtmp->dev->mem_sections[vtmp->dev->n_mem_sections - 1] = *mrs;
+ memory_region_ref(mrs->mr);
+
mrs_size = int128_get64(mrs->size);
mrs_gpa = mrs->offset_within_address_space;
mrs_host = (uintptr_t)memory_region_get_ram_ptr(mrs->mr) +
@@ -461,6 +468,7 @@ static int vhost_update_mem_cb(MemoryRegionSection *mrs,
void *opaque)
static int vhost_update_mem(struct vhost_dev *dev, bool *changed)
{
int res;
+ unsigned i;
struct vhost_update_mem_tmp vtmp;
size_t mem_size;
vtmp.regions = 0;
@@ -469,6 +477,14 @@ static int vhost_update_mem(struct vhost_dev *dev, bool
*changed)
trace_vhost_update_mem();
*changed = false;
+ /* Clear out the section list, it'll get rebuilt */
+ for (i = 0; i < dev->n_mem_sections; i++) {
+ memory_region_unref(dev->mem_sections[i].mr);
+ }
+ g_free(dev->mem_sections);
+ dev->mem_sections = NULL;
+ dev->n_mem_sections = 0;
+
res = address_space_iterate(&address_space_memory,
vhost_update_mem_cb, &vtmp);
if (res) {
@@ -553,46 +569,6 @@ static void vhost_commit(MemoryListener *listener)
}
}
-static void vhost_region_add(MemoryListener *listener,
- MemoryRegionSection *section)
-{
- struct vhost_dev *dev = container_of(listener, struct vhost_dev,
- memory_listener);
-
- if (!vhost_section(section)) {
- return;
- }
-
- ++dev->n_mem_sections;
- dev->mem_sections = g_renew(MemoryRegionSection, dev->mem_sections,
- dev->n_mem_sections);
- dev->mem_sections[dev->n_mem_sections - 1] = *section;
- memory_region_ref(section->mr);
-}
-
-static void vhost_region_del(MemoryListener *listener,
- MemoryRegionSection *section)
-{
- struct vhost_dev *dev = container_of(listener, struct vhost_dev,
- memory_listener);
- int i;
-
- if (!vhost_section(section)) {
- return;
- }
-
- memory_region_unref(section->mr);
- for (i = 0; i < dev->n_mem_sections; ++i) {
- if (dev->mem_sections[i].offset_within_address_space
- == section->offset_within_address_space) {
- --dev->n_mem_sections;
- memmove(&dev->mem_sections[i], &dev->mem_sections[i+1],
- (dev->n_mem_sections - i) * sizeof(*dev->mem_sections));
- break;
- }
- }
-}
-
static void vhost_iommu_unmap_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
{
struct vhost_iommu *iommu = container_of(n, struct vhost_iommu, n);
@@ -1161,8 +1137,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
hdev->memory_listener = (MemoryListener) {
.commit = vhost_commit,
- .region_add = vhost_region_add,
- .region_del = vhost_region_del,
.region_nop = vhost_region_nop,
.log_start = vhost_log_start,
.log_stop = vhost_log_stop,
--
2.14.3
- [Qemu-devel] [RFC v2 0/8] Rework vhost memory region updates, Dr. David Alan Gilbert (git), 2017/12/08
- [Qemu-devel] [RFC v2 1/8] memory: address_space_iterate, Dr. David Alan Gilbert (git), 2017/12/08
- [Qemu-devel] [RFC v2 2/8] vhost: Move log_dirty check, Dr. David Alan Gilbert (git), 2017/12/08
- [Qemu-devel] [RFC v2 3/8] vhost: Simplify ring verification checks, Dr. David Alan Gilbert (git), 2017/12/08
- [Qemu-devel] [RFC v2 4/8] vhost: New memory update functions, Dr. David Alan Gilbert (git), 2017/12/08
- [Qemu-devel] [RFC v2 6/8] vhost: Compare and copy updated region data into device state, Dr. David Alan Gilbert (git), 2017/12/08
- [Qemu-devel] [RFC v2 5/8] vhost: update_mem_cb implementation, Dr. David Alan Gilbert (git), 2017/12/08
- [Qemu-devel] [RFC v2 7/8] vhost: Remove old vhost_set_memory etc, Dr. David Alan Gilbert (git), 2017/12/08
- [Qemu-devel] [RFC v2 8/8] vhost: Move mem_sections maintenance into commit/update routines,
Dr. David Alan Gilbert (git) <=
- Re: [Qemu-devel] [RFC v2 0/8] Rework vhost memory region updates, Igor Mammedov, 2017/12/11