From patchwork Wed Jun 10 10:46:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 29249 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5AAnsjT015587 for ; Wed, 10 Jun 2009 10:49:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755157AbZFJKtZ (ORCPT ); Wed, 10 Jun 2009 06:49:25 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752396AbZFJKtZ (ORCPT ); Wed, 10 Jun 2009 06:49:25 -0400 Received: from mx2.redhat.com ([66.187.237.31]:57585 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751809AbZFJKtY (ORCPT ); Wed, 10 Jun 2009 06:49:24 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5AAlGwo014368; Wed, 10 Jun 2009 06:47:16 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5AAlFXQ002809; Wed, 10 Jun 2009 06:47:15 -0400 Received: from redhat.com (dhcp-0-223.tlv.redhat.com [10.35.0.223]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5AAl845000772; Wed, 10 Jun 2009 06:47:09 -0400 Date: Wed, 10 Jun 2009 13:46:17 +0300 From: "Michael S. Tsirkin" To: Glauber Costa Cc: Paul Brook , Avi Kivity , qemu-devel@nongnu.org, Carsten Otte , kvm@vger.kernel.org, Rusty Russell , virtualization@lists.linux-foundation.org, Christian Borntraeger , Blue Swirl , Anthony Liguori Subject: Re: [Qemu-devel] [PATCHv3 08/13] qemu: add support for resizing regions Message-ID: <20090610104617.GJ6844@redhat.com> References: <20090605102355.GI26770@redhat.com> <20090609173621.GC19375@poweredge.glommer> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090609173621.GC19375@poweredge.glommer> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Tue, Jun 09, 2009 at 02:36:21PM -0300, Glauber Costa wrote: > On Fri, Jun 05, 2009 at 01:23:55PM +0300, Michael S. Tsirkin wrote: > > Make it possible to resize PCI regions. This will be used by virtio > > with MSI-X, where the region size depends on whether MSI-X is enabled, > > and can change across load/save. > > > > Signed-off-by: Michael S. Tsirkin > > --- > > hw/pci.c | 54 ++++++++++++++++++++++++++++++++++++------------------ > > hw/pci.h | 3 +++ > > 2 files changed, 39 insertions(+), 18 deletions(-) > > > > diff --git a/hw/pci.c b/hw/pci.c > > index ed011b5..042a216 100644 > > --- a/hw/pci.c > > +++ b/hw/pci.c > > @@ -392,6 +392,41 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num, > > *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask); > > } > > > > +static void pci_unmap_region(PCIDevice *d, PCIIORegion *r) > > +{ > > + if (r->addr == -1) > > + return; > > + if (r->type & PCI_ADDRESS_SPACE_IO) { > > + int class; > > + /* NOTE: specific hack for IDE in PC case: > > + only one byte must be mapped. */ > > + class = pci_get_word(d->config + PCI_CLASS_DEVICE); > > + if (class == 0x0101 && r->size == 4) { > > + isa_unassign_ioport(r->addr + 2, 1); > > + } else { > > + isa_unassign_ioport(r->addr, r->size); > > + } > > + } else { > > + cpu_register_physical_memory(pci_to_cpu_addr(r->addr), > > + r->size, > > + IO_MEM_UNASSIGNED); > > + qemu_unregister_coalesced_mmio(r->addr, r->size); > > + } > > +} > > + > this is a good cleanup... > > > +void pci_resize_io_region(PCIDevice *pci_dev, int region_num, > > + uint32_t size) > > +{ > > + > > + PCIIORegion *r = &pci_dev->io_regions[region_num]; > > + if (r->size == size) > > + return; > > + r->size = size; > > + pci_unmap_region(pci_dev, r); > > + r->addr = -1; > > + pci_update_mappings(pci_dev); > > +} > > + > but the only user of this one seem to be commented out, and later removed. > Why is this needed? > This was the missing bit: Set correct size for msi-x memory region when loading the device. Signed-off-by: Michael S. Tsirkin diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 589fbb1..f657364 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -133,6 +133,8 @@ static int virtio_pci_load_config(void * opaque, QEMUFile *f) return ret; if (msix_present(&proxy->pci_dev)) qemu_get_be16s(f, &proxy->vdev->config_vector); + + pci_resize_io_region(&proxy->pci_dev, 1, msix_bar_size(&proxy->pci_dev)); return 0; }