From patchwork Mon Jan 9 14:41:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 135030 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2966CB6FA5 for ; Tue, 10 Jan 2012 01:41:33 +1100 (EST) Received: from localhost ([::1]:51471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkGPh-0005lu-4a for incoming@patchwork.ozlabs.org; Mon, 09 Jan 2012 09:41:29 -0500 Received: from eggs.gnu.org ([140.186.70.92]:49998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkGPW-0005iq-7p for qemu-devel@nongnu.org; Mon, 09 Jan 2012 09:41:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RkGPU-0004uu-RO for qemu-devel@nongnu.org; Mon, 09 Jan 2012 09:41:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkGPU-0004ug-IC for qemu-devel@nongnu.org; Mon, 09 Jan 2012 09:41:16 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q09EfDRj023125 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 9 Jan 2012 09:41:14 -0500 Received: from balrog.usersys.redhat.com (dhcp-4-24.tlv.redhat.com [10.35.4.24]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q09Ef9Jo030128; Mon, 9 Jan 2012 09:41:10 -0500 Message-ID: <4F0AFC85.4010609@redhat.com> Date: Mon, 09 Jan 2012 16:41:09 +0200 From: Avi Kivity User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: Anthony Liguori , qemu-devel X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL] Fix vhost-net after the MemoryListener trauma X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Please pull from: git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git fix-vhost-after-memory-listener to fix vhost-net after the MemoryListener changes. Michael reviewed and acked all three patches. Avi Kivity (3): vhost: fix incorrect userspace address vhost: fix mem_sections memory corruption vhost: improve region filtering hw/vhost.c | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-) if (!vhost_dev_cmp_memory(dev, start_addr, size, (uintptr_t)ram)) { /* Region exists with same address. Nothing to do. */ @@ -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,13 +457,17 @@ 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 == section->offset_within_address_space) { --dev->n_mem_sections; memmove(&dev->mem_sections[i], &dev->mem_sections[i+1], - dev->n_mem_sections - i); + (dev->n_mem_sections - i) * sizeof(*dev->mem_sections)); break; } } diff --git a/hw/vhost.c b/hw/vhost.c index cd56e75..19a7b5c 100644 --- a/hw/vhost.c +++ b/hw/vhost.c @@ -15,6 +15,7 @@ #include "hw/hw.h" #include "range.h" #include +#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) { @@ -378,7 +375,7 @@ static void vhost_set_memory(MemoryListener *listener, assert(size); /* Optimize no-change case. At least cirrus_vga does this a lot at this time. */ - ram = memory_region_get_ram_ptr(section->mr); + ram = memory_region_get_ram_ptr(section->mr) + section->offset_within_region; if (add) {