From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Andrew Melnychenko <andrew@daynix.com>,
qemu-stable@nongnu.org
Subject: [PULL 9/9] virtio-pci: Changed vdev to proxy for VirtIO PCI BAR callbacks.
Date: Wed, 22 Jul 2020 08:09:37 -0400 [thread overview]
Message-ID: <20200722120853.9144-10-mst@redhat.com> (raw)
In-Reply-To: <20200722120853.9144-1-mst@redhat.com>
From: Andrew Melnychenko <andrew@daynix.com>
There is an issue when callback may be called with invalid vdev.
It happens on unplug when vdev already deleted and VirtIOPciProxy is not.
So now, callbacks accept proxy device, and vdev retrieved from it.
Technically memio callbacks should be removed during the flatview update,
but memoryregions remain til PCI device(and it's address space) completely deleted.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1716352
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
Message-Id: <20200706112123.971087-1-andrew@daynix.com>
Cc: qemu-stable@nongnu.org
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio-pci.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index db8b711b35..ada1101d07 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1333,11 +1333,12 @@ static uint64_t virtio_pci_notify_read(void *opaque, hwaddr addr,
static void virtio_pci_notify_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
- VirtIODevice *vdev = opaque;
- VirtIOPCIProxy *proxy = VIRTIO_PCI(DEVICE(vdev)->parent_bus->parent);
+ VirtIOPCIProxy *proxy = opaque;
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+
unsigned queue = addr / virtio_pci_queue_mem_mult(proxy);
- if (queue < VIRTIO_QUEUE_MAX) {
+ if (vdev != NULL && queue < VIRTIO_QUEUE_MAX) {
virtio_queue_notify(vdev, queue);
}
}
@@ -1345,10 +1346,12 @@ static void virtio_pci_notify_write(void *opaque, hwaddr addr,
static void virtio_pci_notify_write_pio(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
- VirtIODevice *vdev = opaque;
+ VirtIOPCIProxy *proxy = opaque;
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+
unsigned queue = val;
- if (queue < VIRTIO_QUEUE_MAX) {
+ if (vdev != NULL && queue < VIRTIO_QUEUE_MAX) {
virtio_queue_notify(vdev, queue);
}
}
@@ -1372,9 +1375,14 @@ static void virtio_pci_isr_write(void *opaque, hwaddr addr,
static uint64_t virtio_pci_device_read(void *opaque, hwaddr addr,
unsigned size)
{
- VirtIODevice *vdev = opaque;
+ VirtIOPCIProxy *proxy = opaque;
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
uint64_t val = 0;
+ if (vdev == NULL) {
+ return val;
+ }
+
switch (size) {
case 1:
val = virtio_config_modern_readb(vdev, addr);
@@ -1392,7 +1400,13 @@ static uint64_t virtio_pci_device_read(void *opaque, hwaddr addr,
static void virtio_pci_device_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
- VirtIODevice *vdev = opaque;
+ VirtIOPCIProxy *proxy = opaque;
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
+
+ if (vdev == NULL) {
+ return;
+ }
+
switch (size) {
case 1:
virtio_config_modern_writeb(vdev, addr, val);
@@ -1469,19 +1483,19 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy)
memory_region_init_io(&proxy->device.mr, OBJECT(proxy),
&device_ops,
- virtio_bus_get_device(&proxy->bus),
+ proxy,
"virtio-pci-device",
proxy->device.size);
memory_region_init_io(&proxy->notify.mr, OBJECT(proxy),
¬ify_ops,
- virtio_bus_get_device(&proxy->bus),
+ proxy,
"virtio-pci-notify",
proxy->notify.size);
memory_region_init_io(&proxy->notify_pio.mr, OBJECT(proxy),
¬ify_pio_ops,
- virtio_bus_get_device(&proxy->bus),
+ proxy,
"virtio-pci-notify-pio",
proxy->notify_pio.size);
}
--
MST
next prev parent reply other threads:[~2020-07-22 12:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-22 12:09 [PULL 0/9] acpi,virtio,pc: bugfixes Michael S. Tsirkin
2020-07-22 12:09 ` [PULL 1/9] acpi: accept byte and word access to core ACPI registers Michael S. Tsirkin
2020-07-22 12:09 ` [PULL 2/9] virtio: Drop broken and superfluous object_property_set_link() Michael S. Tsirkin
2020-07-22 12:09 ` [PULL 3/9] virtio-balloon: Prevent guest from starting a report when we didn't request one Michael S. Tsirkin
2020-07-22 12:09 ` [PULL 4/9] virtio-balloon: Add locking to prevent possible race when starting hinting Michael S. Tsirkin
2020-07-22 12:09 ` [PULL 5/9] virtio-balloon: Replace free page hinting references to 'report' with 'hint' Michael S. Tsirkin
2020-07-22 12:09 ` [PULL 6/9] virtio: list legacy-capable devices Michael S. Tsirkin
2020-07-22 12:09 ` [PULL 7/9] virtio: verify that legacy support is not accidentally on Michael S. Tsirkin
2020-07-22 12:09 ` [PULL 8/9] intel_iommu: Use correct shift for 256 bits qi descriptor Michael S. Tsirkin
2020-07-22 12:09 ` Michael S. Tsirkin [this message]
2020-07-23 18:00 ` [PULL 0/9] acpi,virtio,pc: bugfixes Peter Maydell
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=20200722120853.9144-10-mst@redhat.com \
--to=mst@redhat.com \
--cc=andrew@daynix.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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).