From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alexander Graf <agraf@suse.de>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] [Also for STABLE-0.12] Don't check for bus master for old guests
Date: Tue, 16 Mar 2010 22:44:59 +0200 [thread overview]
Message-ID: <20100316204459.GA30666@redhat.com> (raw)
In-Reply-To: <1268771774-27877-1-git-send-email-agraf@suse.de>
On Tue, Mar 16, 2010 at 09:36:14PM +0100, Alexander Graf wrote:
> Older Linux guests don't activate the bus master enable bit. So for those we
> can just try to be clever and track if they set the DEVICE_OK bit even though
> bus mastering is still disabled.
>
> Under that condition we can disable the windows safety check. With that logic
> in place both guests should work just fine. Without PCI hotplug breaks
> virtio-net in Linux < 2.6.34 guests.
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> CC: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> v1 -> v2:
>
> - Fix state loading
> - Reduce if nesting
> ---
> hw/virtio-pci.c | 24 +++++++++++++++++++++++-
> 1 files changed, 23 insertions(+), 1 deletions(-)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 3594152..dbbaf42 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -76,6 +76,10 @@
> * 12 is historical, and due to x86 page size. */
> #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
>
> +/* We can catch some guest bugs inside here so we continue supporting older
> + guests. */
> +#define VIRTIO_PCI_BUG_BUS_MASTER (1 << 0)
> +
> /* QEMU doesn't strictly need write barriers since everything runs in
> * lock-step. We'll leave the calls to wmb() in though to make it obvious for
> * KVM or if kqemu gets SMP support.
> @@ -87,6 +91,7 @@
> typedef struct {
> PCIDevice pci_dev;
> VirtIODevice *vdev;
> + uint32_t bugs;
> uint32_t addr;
> uint32_t class_code;
> uint32_t nvectors;
> @@ -138,6 +143,13 @@ static int virtio_pci_load_config(void * opaque, QEMUFile *f)
> if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
> return msix_vector_use(&proxy->pci_dev, proxy->vdev->config_vector);
> }
> +
> + /* Try to find out if the guest has bus master disabled, but is
> + in ready state. Then we have a buggy guest OS. */
> + if ((proxy->vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
> + !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
> + proxy->bugs |= VIRTIO_PCI_BUG_BUS_MASTER;
> + }
> return 0;
> }
>
> @@ -162,6 +174,7 @@ static void virtio_pci_reset(DeviceState *d)
> VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
> virtio_reset(proxy->vdev);
> msix_reset(&proxy->pci_dev);
> + proxy->bugs = 0;
> }
>
> static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
> @@ -205,6 +218,14 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
> virtio_reset(proxy->vdev);
> msix_unuse_all_vectors(&proxy->pci_dev);
> }
> +
> + /* Linux before 2.6.34 sets the device as OK without enabling
> + the PCI device bus master bit. In this case we need to disable
> + some safety checks. */
> + if ((val & VIRTIO_CONFIG_S_DRIVER_OK) &&
> + !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
> + proxy->bugs |= VIRTIO_PCI_BUG_BUS_MASTER;
> + }
> break;
> case VIRTIO_MSI_CONFIG_VECTOR:
> msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
> @@ -371,7 +392,8 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
> VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
>
> if (PCI_COMMAND == address) {
> - if (!(val & PCI_COMMAND_MASTER)) {
> + if (!(val & PCI_COMMAND_MASTER) &&
> + !(proxy->bugs & VIRTIO_PCI_BUG_BUS_MASTER)) {
> proxy->vdev->status &= ~VIRTIO_CONFIG_S_DRIVER_OK;
> }
> }
> --
> 1.6.0.2
next prev parent reply other threads:[~2010-03-16 20:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-16 20:36 [Qemu-devel] [PATCH] [Also for STABLE-0.12] Don't check for bus master for old guests Alexander Graf
2010-03-16 20:44 ` Michael S. Tsirkin [this message]
-- strict thread matches above, loose matches on Subject: below --
2010-03-16 18:18 Alexander Graf
2010-03-16 20:21 ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 20:26 ` Alexander Graf
2010-03-16 20:27 ` Michael S. Tsirkin
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=20100316204459.GA30666@redhat.com \
--to=mst@redhat.com \
--cc=agraf@suse.de \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).