public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: Marcelo Tosatti <marcelo@kvack.org>
Cc: kvm-devel <kvm-devel@lists.sourceforge.net>
Subject: Re: PCI IO regions must be power of two
Date: Tue, 11 Mar 2008 15:19:52 -0500	[thread overview]
Message-ID: <47D6E968.6060601@us.ibm.com> (raw)
In-Reply-To: <20080311195241.GA14276@dmt>

Marcelo Tosatti wrote:
> 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:
>
>   

A quick grep of the source show that virtio seems to be the only device 
that isn't behaving here.  I suggest modifying the virtio.c to always 
use a power of two and then perhaps adding a check in hw/pci.c to 
validate that the registered region is a power of two in size.

Regards,

Anthony Liguori

> 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/

  reply	other threads:[~2008-03-11 20:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-11 19:52 PCI IO regions must be power of two Marcelo Tosatti
2008-03-11 20:19 ` Anthony Liguori [this message]
2008-03-12 15:39 ` Uri Lublin
2008-03-12 15:59   ` Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47D6E968.6060601@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=marcelo@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox