Skip to content

Commit

Permalink
virtio-pci: Added check for virtio device in PCI config cbs.
Browse files Browse the repository at this point in the history
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>
Message-Id: <20210609095843.141378-3-andrew@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
AndrewAtDaynix authored and mstsirkin committed Jul 3, 2021
1 parent 80ebfd6 commit bf69737
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions hw/virtio/virtio-pci.c
Expand Up @@ -424,6 +424,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);
}
Expand Down Expand Up @@ -455,6 +460,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;
Expand Down

0 comments on commit bf69737

Please sign in to comment.