[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v2 08/20] virtio-pci: Set PCIDeviceClass::is_express=1
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [RFC v2 08/20] virtio-pci: Set PCIDeviceClass::is_express=1 |
Date: |
Fri, 25 Nov 2016 20:05:44 -0200 |
virtio-pci has a custom DeviceClass::realize method to ensure
QEMU_PCI_CAP_EXPRESS is set before pci_qdev_realize() is called.
This is done because setting the QEMU_PCI_CAP_EXPRESS flag too
late can crash QEMU due to the PCI config space allocation logic.
Clearing QEMU_PCI_CAP_EXPRESS later, on the other hand, is
already safe, because the existing virtio-pci and vfio-pci code
already do that inside their PCIDeviceClass::realize methods. But
they are inconsistent: virtio-pci has is_express=0, and vfio-pci
has is_express=1.
To make all devices consistent, we can just set
PCIDeviceClass::is_express=1, and clear QEMU_PCI_CAP_EXPRESS on
virtio_pci_realize() if necessary. This makes the device code
simpler, and make the PCIDeviceClass::is_express field reflect
the fact that virtio-pci can be a PCIe device.
Cc: Shmulik Ladkani <address@hidden>
Cc: Michael S. Tsirkin <address@hidden>
Cc: Marcel Apfelbaum <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
Changes series v1 -> v2:
* (new patch added to series)
---
hw/virtio/virtio-pci.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 521ba0b..df2b26a 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1723,6 +1723,11 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error
**errp)
bool pcie_port = pci_bus_is_express(pci_dev->bus) &&
!pci_bus_is_root(pci_dev->bus);
+ if ((proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) ||
+ !virtio_pci_modern(proxy)) {
+ pci_dev->cap_present &= ~QEMU_PCI_CAP_EXPRESS;
+ }
+
if (!kvm_has_many_ioeventfds()) {
proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
}
@@ -1855,25 +1860,10 @@ static Property virtio_pci_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static void virtio_pci_dc_realize(DeviceState *qdev, Error **errp)
-{
- VirtioPCIClass *vpciklass = VIRTIO_PCI_GET_CLASS(qdev);
- VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
- PCIDevice *pci_dev = &proxy->pci_dev;
-
- if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_PCIE) &&
- virtio_pci_modern(proxy)) {
- pci_dev->cap_present |= QEMU_PCI_CAP_EXPRESS;
- }
-
- vpciklass->parent_dc_realize(qdev, errp);
-}
-
static void virtio_pci_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
- VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass);
dc->props = virtio_pci_properties;
k->realize = virtio_pci_realize;
@@ -1881,8 +1871,7 @@ static void virtio_pci_class_init(ObjectClass *klass,
void *data)
k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
k->revision = VIRTIO_PCI_ABI_VERSION;
k->class_id = PCI_CLASS_OTHERS;
- vpciklass->parent_dc_realize = dc->realize;
- dc->realize = virtio_pci_dc_realize;
+ k->is_express = 1;
dc->reset = virtio_pci_reset;
}
--
2.7.4
- [Qemu-devel] [RFC v2 00/20] qmp: Report bus information on 'query-machines', Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 01/20] qemu.py: Make logging optional, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 02/20] qtest.py: Support QTEST_LOG environment variable, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 03/20] qtest.py: make logging optional, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 04/20] qtest.py: Make 'binary' parameter optional, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 05/20] tests: Add rules to non-gtester qtest test cases, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 06/20] qdev: Add 'accepted-device-types' property to BusClass, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 08/20] virtio-pci: Set PCIDeviceClass::is_express=1,
Eduardo Habkost <=
- [Qemu-devel] [RFC v2 07/20] qmp: Add 'always-available-buses' field to 'query-machines', Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 09/20] vmxnet3: Set PCIDeviceClass::is_express=1, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 10/20] pvscsi: Set PCIDeviceClass::is_express=1, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 11/20] pci: INTERFACE_LEGACY_PCI_DEVICE and INTERFACE_PCIE_DEVICE interfaces, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 13/20] [trivial] edu: Move edu_info outside function, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 12/20] pci: Replace is_express with INTERFACE_PCIE_DEVICE, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 15/20] eepro100: Add INTERFACE_LEGACY_PCI_DEVICE, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 16/20] [incomplete] remove INTERFACE_LEGACY_PCI_DEVICE from PCIe-only devices, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 17/20] pci: Set device_type on bus classes, Eduardo Habkost, 2016/11/25
- [Qemu-devel] [RFC v2 14/20] [automated] Add INTERFACE_LEGACY_PCI_DEVICE to all PCI device subclasses, Eduardo Habkost, 2016/11/25