]> git.ipfire.org Git - thirdparty/qemu.git/commit
virtio: Fix crash when sriov-pf is set for non-PCI-Express device
authorKevin Wolf <kwolf@redhat.com>
Thu, 4 Dec 2025 17:26:57 +0000 (18:26 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Thu, 5 Feb 2026 10:06:46 +0000 (05:06 -0500)
commit623db856476806124e9ae45fbc39e75012261570
tree07471a5342db9dbc0b5c26167aa2aacf41794c2a
parentfff77cfb8413190c6362b95203ef0973c83b50d2
virtio: Fix crash when sriov-pf is set for non-PCI-Express device

Setting the sriov-pf property on devices that aren't PCI Express causes
an assertion failure:

    $ qemu-system-x86_64 \
        -blockdev null-co,node-name=null \
        -blockdev null-co,node-name=null2 \
        -device virtio-blk,drive=null,id=pf \
        -device virtio-blk,sriov-pf=pf,drive=null2
    qemu-system-x86_64: ../hw/pci/pcie.c:1062: void pcie_add_capability(PCIDevice *, uint16_t, uint8_t, uint16_t, uint16_t): Assertion `offset >= PCI_CONFIG_SPACE_SIZE' failed.

This is because proxy->last_pcie_cap_offset is only initialised to a
non-zero value in virtio_pci_realize() if it's a PCI Express device, and
then virtio_pci_device_plugged() still tries to use it.

To fix this, just skip the SR-IOV code for !pci_is_express(). Then the
next thing pci_qdev_realize() does is call pcie_sriov_register_device(),
which returns the appropriate error.

Cc: qemu-stable@nongnu.org
Fixes: d0c280d3fac6 ('pcie_sriov: Make a PCI device with user-created VF ARI-capable')
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20251204172657.174391-1-kwolf@redhat.com>
hw/virtio/virtio-pci.c