qemu-cr16/hw/virtio
Kevin Wolf a440980876 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: d0c280d3fa ('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>
(cherry picked from commit 623db856476806124e9ae45fbc39e75012261570)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2026-02-06 00:44:47 +03:00
..
cbor-helpers.c device/virtio-nsm: Support for Nitro Secure Module device 2024-10-31 18:28:32 +01:00
iothread-vq-mapping.c virtio: extract iothread-vq-mapping.h API 2025-03-13 17:57:23 +01:00
Kconfig hw/virtio: rename vhost-user-device and make user creatable 2025-10-05 09:01:08 -04:00
meson.build hw/virtio: Compile virtio-mem.c once 2025-10-21 20:09:56 +02:00
trace-events virtio: unify virtio_notify_irqfd() and virtio_notify() 2025-10-05 09:01:08 -04:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
vdpa-dev-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vdpa-dev.c vdpa-dev: add get_vhost() callback for vhost-vdpa device 2025-10-05 16:13:02 -04:00
vhost-backend.c vhost-backend: implement extended features support 2025-10-04 10:50:37 -04:00
vhost-iova-tree.c vhost-iova-tree: Update documentation 2025-02-21 07:18:42 -05:00
vhost-iova-tree.h include/system: Move exec/memory.h to system/memory.h 2025-04-23 14:08:21 -07:00
vhost-scsi-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-shadow-virtqueue.c vdpa: Fix endian bugs in shadow virtqueue 2025-02-21 07:18:42 -05:00
vhost-shadow-virtqueue.h vhost-iova-tree, svq: Implement GPA->IOVA & partial IOVA->HVA trees 2025-02-21 07:18:42 -05:00
vhost-stub.c char: rename CharBackend->CharFrontend 2025-10-28 14:49:52 +01:00
vhost-user-base.c vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
vhost-user-blk-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-fs-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-fs.c vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
vhost-user-gpio-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-gpio.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-i2c-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-i2c.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-input-pci.c hw/virtio: derive vhost-user-input from vhost-user-base 2024-02-14 06:09:32 -05:00
vhost-user-input.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-rng-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-rng.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-scmi-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-scmi.c vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
vhost-user-scsi-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-snd-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-snd.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-test-device-pci.c hw/virtio: rename vhost-user-device and make user creatable 2025-10-05 09:01:08 -04:00
vhost-user-test-device.c hw/virtio: rename vhost-user-device and make user creatable 2025-10-05 09:01:08 -04:00
vhost-user-vsock-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-user-vsock.c vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
vhost-user.c vhost-user: make vhost_set_vring_file() synchronous 2025-11-09 08:24:29 -05:00
vhost-vdpa.c vdpa: fix vhost-vdpa suspended state not be shared 2026-02-06 00:31:38 +03:00
vhost-vsock-common.c vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
vhost-vsock-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
vhost-vsock.c hw/virtio: Use error_setg_file_open() for a better error message 2025-11-25 22:41:52 +01:00
vhost.c vhost: Always initialize cached vring data 2025-12-09 20:48:39 +01:00
virtio-9p-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-acpi.c license: Update deprecated SPDX tag GPL-2.0+ to GPL-2.0-or-later 2024-09-20 10:11:59 +03:00
virtio-balloon-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-balloon.c system/ramblock: Move ram_block_discard_*_range() declarations 2025-10-07 03:37:03 +02:00
virtio-blk-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-bus.c virtio: add support for negotiating extended features 2025-10-04 10:50:37 -04:00
virtio-config-io.c hw/virtio: Build various files once 2025-07-15 02:56:39 -04:00
virtio-crypto-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-crypto.c vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
virtio-hmp-cmds.c qmp: update virtio features map to support extended features 2025-10-04 10:50:37 -04:00
virtio-input-host-pci.c hw/virtio: move virtio-pci.h into shared include space 2022-05-16 04:38:40 -04:00
virtio-input-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-iommu-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-iommu.c vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
virtio-md-pci.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
virtio-md-stubs.c hw/virtio: move stubs out of stubs/ 2024-04-18 11:17:27 +02:00
virtio-mem-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-mem-pci.h virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci 2023-07-12 09:27:25 +02:00
virtio-mem.c hw/virtio/virtio-mem: Convert VIRTIO_MEM_HAS_LEGACY_GUESTS to runtime 2025-10-21 20:09:56 +02:00
virtio-mmio.c migration: Fix regression of passing error_fatal into vmstate_load_state() 2025-11-03 16:04:10 -05:00
virtio-net-pci.c virtio-net: Implement SR-IOV VF 2025-05-14 05:39:14 -04:00
virtio-nsm-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-nsm.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-pci.c virtio: Fix crash when sriov-pf is set for non-PCI-Express device 2026-02-06 00:44:47 +03:00
virtio-pmem-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-pmem-pci.h virtio-md-pci: New parent type for virtio-mem-pci and virtio-pmem-pci 2023-07-12 09:27:25 +02:00
virtio-pmem.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-qmp.c qmp: Fix a typo for a USO feature 2025-11-21 15:47:58 +03:00
virtio-qmp.h qmp: update virtio features map to support extended features 2025-10-04 10:50:37 -04:00
virtio-rng-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-rng.c vhost-user: return failure if backend crash when live migration 2025-05-14 05:39:15 -04:00
virtio-scsi-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-serial-pci.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
virtio-stub.c qmp: add QMP command x-query-virtio-queue-element 2022-10-09 16:38:45 -04:00
virtio.c migration: Fix regression of passing error_fatal into vmstate_load_state() 2025-11-03 16:04:10 -05:00