From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: PCI IO regions must be power of two Date: Tue, 11 Mar 2008 16:52:41 -0300 Message-ID: <20080311195241.GA14276@dmt> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel To: Anthony Liguori Return-path: Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org Anthony, Both virtio-net and virtio-block currently register PCI IO space regions that are not power of two in size. The decoding process to discover the size of a PCI resource expects it to be a power of two. The PCI controller masks the size out of what is written into config_space + 0x10 + (4 * region_num) The result is that the size is calculated and registered erroneously by the OS: [root@localhost ~]# cat /proc/ioports | grep virtio c200-c203 : virtio-pci This is a virtio-block device whose BAR0 has length (16+20)-1, not 4. BAR0: I/O at 0xc200 [0xc223]. I suggest forcing the size to be power of two as follows: Index: kvm-userspace.hotplug2/qemu/hw/pci.c =================================================================== --- kvm-userspace.hotplug2.orig/qemu/hw/pci.c +++ kvm-userspace.hotplug2/qemu/hw/pci.c @@ -236,6 +236,13 @@ void pci_register_io_region(PCIDevice *p if ((unsigned int)region_num >= PCI_NUM_REGIONS) return; + + /* IO region size must be power of two */ + if (type == PCI_ADDRESS_SPACE_IO && (size & (size-1))) { + size = size << 1; + size &= size-1; + } + r = &pci_dev->io_regions[region_num]; r->addr = -1; r->size = size; ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/