qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Melnychenko <andrew@daynix.com>
To: mst@redhat.com
Cc: qemu-devel@nongnu.org
Subject: [PATCH 2/3] virtio-pci: Added check for virtio device in PCI config cbs.
Date: Wed,  9 Jun 2021 12:58:42 +0300	[thread overview]
Message-ID: <20210609095843.141378-3-andrew@daynix.com> (raw)
In-Reply-To: <20210609095843.141378-1-andrew@daynix.com>

Now, if virtio device is not present on virtio-bus - pci config callbacks
will not lead to possible crush. The read will return "-1" which should be
interpreted by a driver that pci device may be unplugged.

Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 hw/virtio/virtio-pci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 05865b1fcb..186b7bc0f6 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -423,6 +423,11 @@ static uint64_t virtio_pci_config_read(void *opaque, hwaddr addr,
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
     uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
     uint64_t val = 0;
+
+    if (vdev == NULL) {
+        return UINT64_MAX;
+    }
+
     if (addr < config) {
         return virtio_ioport_read(proxy, addr);
     }
@@ -454,6 +459,11 @@ static void virtio_pci_config_write(void *opaque, hwaddr addr,
     VirtIOPCIProxy *proxy = opaque;
     uint32_t config = VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev);
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+
+    if (vdev == NULL) {
+        return;
+    }
+
     if (addr < config) {
         virtio_ioport_write(proxy, addr, val);
         return;
-- 
2.31.1



  parent reply	other threads:[~2021-06-09 10:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09  9:58 [PATCH 0/3] virtio-pci: Checks for virtio device presence on the bus Andrew Melnychenko
2021-06-09  9:58 ` [PATCH 1/3] virtio-pci: Added check for virtio device presence in mm callbacks Andrew Melnychenko
2021-06-09  9:58 ` Andrew Melnychenko [this message]
2021-06-09  9:58 ` [PATCH 3/3] virtio-pci: Changed return values for "notify", "device" and "isr" read Andrew Melnychenko

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=20210609095843.141378-3-andrew@daynix.com \
    --to=andrew@daynix.com \
    --cc=mst@redhat.com \
    --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).