All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
	rusty@rustcorp.com.au, kvm@vger.kernel.org,
	virtualization@lists.linux-foundation.org, qemu-devel@nongnu.org,
	avi@redhat.com, Anthony Liguori <aliguori@us.ibm.com>
Subject: Re: [Qemu-devel] [PATCH RFC] virtio-pci: add MMIO property
Date: Mon, 19 Mar 2012 14:19:33 -0500	[thread overview]
Message-ID: <4F6786C5.3080902@codemonkey.ws> (raw)
In-Reply-To: <20120319155650.GA6430@redhat.com>

On 03/19/2012 10:56 AM, Michael S. Tsirkin wrote:
> Currently virtio-pci is specified so that configuration of the device is
> done through a PCI IO space (via BAR 0 of the virtual PCI device).
> However, Linux guests happen to use ioread/iowrite/iomap primitives
> for access, and these work uniformly across memory/io BARs.
>
> While PCI IO accesses are faster than MMIO on x86 kvm,
> MMIO might be helpful on other systems which don't
> implement PIO or where PIO is slower than MMIO.
>
> Add a property to make it possible to tweak the BAR type.
>
> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
>
> This is harmless by default but causes segfaults in memory.c
> when enabled. Thus an RFC until I figure out what's wrong.

Doesn't this violate the virtio-pci spec?

Making the same vendor/device ID have different semantics depending on a magic 
flag in QEMU seems like a pretty bad idea to me.

Regards,

Anthony Liguori

>
> ---
>   hw/virtio-pci.c |   16 ++++++++++++++--
>   hw/virtio-pci.h |    4 ++++
>   2 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 28498ec..6f338d2 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -655,6 +655,7 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
>   {
>       uint8_t *config;
>       uint32_t size;
> +    uint8_t bar0_type;
>
>       proxy->vdev = vdev;
>
> @@ -684,8 +685,14 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
>
>       memory_region_init_io(&proxy->bar,&virtio_pci_config_ops, proxy,
>                             "virtio-pci", size);
> -    pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
> -&proxy->bar);
> +
> +    if (proxy->flags&  VIRTIO_PCI_FLAG_USE_MMIO) {
> +        bar0_type = PCI_BASE_ADDRESS_SPACE_MEMORY;
> +    } else {
> +        bar0_type = PCI_BASE_ADDRESS_SPACE_IO;
> +    }
> +
> +    pci_register_bar(&proxy->pci_dev, 0, bar0_type,&proxy->bar);
>
>       if (!kvm_has_many_ioeventfds()) {
>           proxy->flags&= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
> @@ -823,6 +830,7 @@ static Property virtio_blk_properties[] = {
>       DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
>       DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
>       DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> @@ -856,6 +864,7 @@ static Property virtio_net_properties[] = {
>       DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy, net.txtimer, TX_TIMER_INTERVAL),
>       DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy, net.txburst, TX_BURST),
>       DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> @@ -888,6 +897,7 @@ static Property virtio_serial_properties[] = {
>       DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
>       DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
>       DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, serial.max_virtserial_ports, 31),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> @@ -915,6 +925,7 @@ static TypeInfo virtio_serial_info = {
>
>   static Property virtio_balloon_properties[] = {
>       DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> @@ -969,6 +980,7 @@ static int virtio_scsi_exit_pci(PCIDevice *pci_dev)
>   static Property virtio_scsi_properties[] = {
>       DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
>       DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, host_features, scsi),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index e560428..e6a8861 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -24,6 +24,10 @@
>   #define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
>   #define VIRTIO_PCI_FLAG_USE_IOEVENTFD   (1<<  VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
>
> +/* Some guests don't support port IO. Use MMIO instead. */
> +#define VIRTIO_PCI_FLAG_USE_MMIO_BIT 2
> +#define VIRTIO_PCI_FLAG_USE_MMIO   (1<<  VIRTIO_PCI_FLAG_USE_MMIO_BIT)
> +
>   typedef struct {
>       PCIDevice pci_dev;
>       VirtIODevice *vdev;


WARNING: multiple messages have this Message-ID (diff)
From: Anthony Liguori <anthony@codemonkey.ws>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	kvm@vger.kernel.org, Alexey Kardashevskiy <aik@ozlabs.ru>,
	rusty@rustcorp.com.au, qemu-devel@nongnu.org,
	virtualization@lists.linux-foundation.org, avi@redhat.com
Subject: Re: [Qemu-devel] [PATCH RFC] virtio-pci: add MMIO property
Date: Mon, 19 Mar 2012 14:19:33 -0500	[thread overview]
Message-ID: <4F6786C5.3080902@codemonkey.ws> (raw)
In-Reply-To: <20120319155650.GA6430@redhat.com>

On 03/19/2012 10:56 AM, Michael S. Tsirkin wrote:
> Currently virtio-pci is specified so that configuration of the device is
> done through a PCI IO space (via BAR 0 of the virtual PCI device).
> However, Linux guests happen to use ioread/iowrite/iomap primitives
> for access, and these work uniformly across memory/io BARs.
>
> While PCI IO accesses are faster than MMIO on x86 kvm,
> MMIO might be helpful on other systems which don't
> implement PIO or where PIO is slower than MMIO.
>
> Add a property to make it possible to tweak the BAR type.
>
> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
>
> This is harmless by default but causes segfaults in memory.c
> when enabled. Thus an RFC until I figure out what's wrong.

Doesn't this violate the virtio-pci spec?

Making the same vendor/device ID have different semantics depending on a magic 
flag in QEMU seems like a pretty bad idea to me.

Regards,

Anthony Liguori

>
> ---
>   hw/virtio-pci.c |   16 ++++++++++++++--
>   hw/virtio-pci.h |    4 ++++
>   2 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 28498ec..6f338d2 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -655,6 +655,7 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
>   {
>       uint8_t *config;
>       uint32_t size;
> +    uint8_t bar0_type;
>
>       proxy->vdev = vdev;
>
> @@ -684,8 +685,14 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
>
>       memory_region_init_io(&proxy->bar,&virtio_pci_config_ops, proxy,
>                             "virtio-pci", size);
> -    pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
> -&proxy->bar);
> +
> +    if (proxy->flags&  VIRTIO_PCI_FLAG_USE_MMIO) {
> +        bar0_type = PCI_BASE_ADDRESS_SPACE_MEMORY;
> +    } else {
> +        bar0_type = PCI_BASE_ADDRESS_SPACE_IO;
> +    }
> +
> +    pci_register_bar(&proxy->pci_dev, 0, bar0_type,&proxy->bar);
>
>       if (!kvm_has_many_ioeventfds()) {
>           proxy->flags&= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
> @@ -823,6 +830,7 @@ static Property virtio_blk_properties[] = {
>       DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
>       DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
>       DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> @@ -856,6 +864,7 @@ static Property virtio_net_properties[] = {
>       DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy, net.txtimer, TX_TIMER_INTERVAL),
>       DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy, net.txburst, TX_BURST),
>       DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> @@ -888,6 +897,7 @@ static Property virtio_serial_properties[] = {
>       DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
>       DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
>       DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, serial.max_virtserial_ports, 31),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> @@ -915,6 +925,7 @@ static TypeInfo virtio_serial_info = {
>
>   static Property virtio_balloon_properties[] = {
>       DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> @@ -969,6 +980,7 @@ static int virtio_scsi_exit_pci(PCIDevice *pci_dev)
>   static Property virtio_scsi_properties[] = {
>       DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
>       DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, host_features, scsi),
> +    DEFINE_PROP_BIT("mmio", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_MMIO_BIT, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index e560428..e6a8861 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -24,6 +24,10 @@
>   #define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
>   #define VIRTIO_PCI_FLAG_USE_IOEVENTFD   (1<<  VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
>
> +/* Some guests don't support port IO. Use MMIO instead. */
> +#define VIRTIO_PCI_FLAG_USE_MMIO_BIT 2
> +#define VIRTIO_PCI_FLAG_USE_MMIO   (1<<  VIRTIO_PCI_FLAG_USE_MMIO_BIT)
> +
>   typedef struct {
>       PCIDevice pci_dev;
>       VirtIODevice *vdev;

  parent reply	other threads:[~2012-03-19 19:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-19 15:56 [PATCH RFC] virtio-pci: add MMIO property Michael S. Tsirkin
2012-03-19 15:56 ` [Qemu-devel] " Michael S. Tsirkin
2012-03-19 17:58 ` Avi Kivity
2012-03-19 17:58   ` [Qemu-devel] " Avi Kivity
2012-03-19 18:57   ` Michael S. Tsirkin
2012-03-19 18:57     ` [Qemu-devel] " Michael S. Tsirkin
2012-03-20 14:49     ` Avi Kivity
2012-03-20 14:49       ` [Qemu-devel] " Avi Kivity
2012-03-19 19:19 ` Anthony Liguori
2012-03-19 19:19 ` Anthony Liguori [this message]
2012-03-19 19:19   ` Anthony Liguori
2012-03-19 20:49   ` Michael S. Tsirkin
2012-03-19 20:49     ` Michael S. Tsirkin
2012-03-19 21:07     ` Anthony Liguori
2012-03-19 21:07       ` [Qemu-devel] " Anthony Liguori
2012-03-19 21:20       ` Michael S. Tsirkin
2012-03-19 21:20         ` Michael S. Tsirkin
2012-03-19 21:29       ` Michael S. Tsirkin
2012-03-19 21:29         ` Michael S. Tsirkin
2012-03-19 22:13         ` Anthony Liguori
2012-03-19 22:13         ` Anthony Liguori
2012-03-19 23:52           ` Rusty Russell
2012-03-19 23:52             ` [Qemu-devel] " Rusty Russell
2012-03-20  0:39             ` Anthony Liguori
2012-03-20  0:39             ` Anthony Liguori
2012-03-20  0:39               ` Anthony Liguori
2012-06-18 12:05             ` Michael S. Tsirkin
2012-03-19 23:52           ` Rusty Russell
2012-03-19 21:07     ` Anthony Liguori

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=4F6786C5.3080902@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=aik@ozlabs.ru \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    --cc=virtualization@lists.linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.