aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2012-01-09 14:01:39 +0200
committerAvi Kivity <avi@redhat.com>2012-01-09 14:01:39 +0200
commitc49450b98f7b9edd6690f34ae6ff15fe4a6131b9 (patch)
tree8752c01bca5ffcdeab5cab86988a14870a8e3258
parent637f7a6a01e09bc39f7b3a24257a9cd6ea396ca0 (diff)
vhost: improve region filtering
vhost memory management doesn't care about non-memory (e.g. PIO) or non-RAM regions. Adjust the filtering to reflect that, and move it earlier so it applies to mem_sections too. Signed-off-by: Avi Kivity <avi@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--hw/vhost.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/hw/vhost.c b/hw/vhost.c
index d924fb0e4d..19a7b5c820 100644
--- a/hw/vhost.c
+++ b/hw/vhost.c
@@ -15,6 +15,7 @@
#include "hw/hw.h"
#include "range.h"
#include <linux/vhost.h>
+#include "exec-memory.h"
static void vhost_dev_sync_region(struct vhost_dev *dev,
MemoryRegionSection *section,
@@ -365,10 +366,6 @@ static void vhost_set_memory(MemoryListener *listener,
int r;
void *ram;
- if (!memory_region_is_ram(section->mr)) {
- return;
- }
-
dev->mem = g_realloc(dev->mem, s);
if (log_dirty) {
@@ -430,12 +427,22 @@ static void vhost_set_memory(MemoryListener *listener,
}
}
+static bool vhost_section(MemoryRegionSection *section)
+{
+ return section->address_space == get_system_memory()
+ && memory_region_is_ram(section->mr);
+}
+
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);
@@ -450,6 +457,10 @@ static void vhost_region_del(MemoryListener *listener,
memory_listener);
int i;
+ if (!vhost_section(section)) {
+ return;
+ }
+
vhost_set_memory(listener, section, false);
for (i = 0; i < dev->n_mem_sections; ++i) {
if (dev->mem_sections[i].offset_within_address_space