Rework handling of PCI/PCIe "hybrid" devices
cover Rework handling of PCI/PCIe "hybrid" devices
A couple of devices - virtio-pci and XHCI - can present themselves to the guest as either PCI or PCIe devices depending on how they're attached. However, the logic is a little different between the two devices. In addition the logic in virtio makes it difficult to put a PCIe virtio device into a "pseries" guest because of the unusual way the paravirtualized PCI bus works there.
This series makes the logic more consistent, and allows per-machine overrides to address that.
Currently patch 3/3 shows a non-obvious side effect of this change. A PCIe virtio device is, by default, modern mode only, but the qtest logic doesn't handle modern-only virtio devices correctly. We work around this by explicitly adding disable-legacy=off to the testcases. It would probably be better to update libqos so that it can handle modern virtio devices.
David Gibson (3):
pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid"
devices
pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
pseries: Allow PCIe virtio and XHCI on pseries machine type
hw/pci/pci.c | 14 ++++++++++++++ hw/ppc/spapr_pci.c | 9 +++++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + include/hw/pci/pci_host.h | 1 + tests/virtio-9p-test.c | 2 +- tests/virtio-blk-test.c | 4 ++-- tests/virtio-net-test.c | 2 +- tests/virtio-scsi-test.c | 2 +- 10 files changed, 32 insertions(+), 8 deletions(-)
Signature · 1 line
2.9.3
RFC 1/3 pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new 'pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.
--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)
hw/pci/pci.c +7 -0
@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); } +bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
hw/usb/hcd-xhci.c +1 -1
@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem); -if (pci_bus_is_express (dev->bus) || +if (pci_allow_hybrid_pcie (dev) ||xhci_get_flag (xhci,XHCI_FLAG_FORCE_PCIE_ENDCAP )) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );
hw/virtio/virtio-pci.c +1 -2
@@ -1737,8 +1737,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) {VirtIOPCIProxy *proxy =VIRTIO_PCI (pci_dev);VirtioPCIClass *k =VIRTIO_PCI_GET_CLASS (pci_dev); -bool pcie_port =pci_bus_is_express (pci_dev->bus) && - !pci_bus_is_root (pci_dev->bus); +bool pcie_port =pci_allow_hybrid_pcie (pci_dev);if (!kvm_has_many_ioeventfds ()) { proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ;
include/hw/pci/pci.h +1 -0
@@ -453,6 +453,7 @@ void pci_for_each_bus(PCIBus *bus,PCIBus *pci_find_primary_bus (void );PCIBus *pci_device_root_bus (const PCIDevice *d); +bool pci_allow_hybrid_pcie (PCIDevice *pci_dev);const char *pci_root_bus_path (PCIDevice *dev);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);int pci_qdev_find_device (const char *id,PCIDevice **pdev);
Signature · 1 line
2.9.3
Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
Quoted 31 lines · David Gibson
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new '
pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)hw/pci/pci.c +0
-0
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 392
Quoted 3 lines
hw/pci/pci.c +0
-0@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); }
Hi David,
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 393
Quoted 1 line
hw/pci/pci.c +1
-0+bool pci_allow_hybrid_pcie (PCIDevice *pci_dev)
I agree with the patch but I think the function name may be better.
It actually queries if a hybrid device is pcie on this slot.
Quoted 14 lines
hw/pci/pci.c +6
-0+{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,hw/usb/hcd-xhci.c +0
-0
hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) · line 3622
Quoted 5 lines
hw/usb/hcd-xhci.c +1
-1@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem); - if (pci_bus_is_express(dev->bus) || + if (pci_allow_hybrid_pcie(dev) ||
Gerd agreed with this change, but I suppose we need a compat property since is a behavior change.
Thanks,
Marcel
Quoted 30 lines
hw/usb/hcd-xhci.c +0
-0xhci_get_flag(xhci, XHCI_FLAG_FORCE_PCIE_ENDCAP)) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );hw/virtio/virtio-pci.c +1
-2@@ -1737,8 +1737,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) {VirtIOPCIProxy *proxy =VIRTIO_PCI (pci_dev);VirtioPCIClass *k =VIRTIO_PCI_GET_CLASS (pci_dev); -bool pcie_port =pci_bus_is_express (pci_dev->bus) && - !pci_bus_is_root (pci_dev->bus); +bool pcie_port =pci_allow_hybrid_pcie (pci_dev);if (!kvm_has_many_ioeventfds ()) { proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ;include/hw/pci/pci.h +1
-0@@ -453,6 +453,7 @@ void pci_for_each_bus(PCIBus *bus,PCIBus *pci_find_primary_bus (void );PCIBus *pci_device_root_bus (const PCIDevice *d); +bool pci_allow_hybrid_pcie (PCIDevice *pci_dev);const char *pci_root_bus_path (PCIDevice *dev);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);int pci_qdev_find_device (const char *id,PCIDevice **pdev);
Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
In reply to David GibsonQuoted 34 lines · David Gibson
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new '
pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)hw/pci/pci.c +0
-0@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); }
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 402
Quoted 10 lines
hw/pci/pci.c +7
-0+bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
I'd prefer pci_allow_hybrid_pci_pcie.
hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) · line 3625
Quoted 13 lines
hw/usb/hcd-xhci.c +1
-1@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem); -if (pci_bus_is_express (dev->bus) || +if (pci_allow_hybrid_pcie (dev) ||xhci_get_flag (xhci,XHCI_FLAG_FORCE_PCIE_ENDCAP )) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );
This seems to change the behaviour for xhci on a root bus - what am I missing?
Quoted 5 lines
hw/virtio/virtio-pci.c +0
-0
hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1743
Quoted 9 lines
hw/virtio/virtio-pci.c +1
-2@@ -1737,8 +1737,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) {VirtIOPCIProxy *proxy =VIRTIO_PCI (pci_dev);VirtioPCIClass *k =VIRTIO_PCI_GET_CLASS (pci_dev); -bool pcie_port =pci_bus_is_express (pci_dev->bus) && - !pci_bus_is_root (pci_dev->bus); +bool pcie_port =pci_allow_hybrid_pcie (pci_dev);if (!kvm_has_many_ioeventfds ()) { proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ;
I don't actually remember why do we disable pcie on a root port. Marcel, do you happen to know?
Quoted 14 lines
include/hw/pci/pci.h +1
-0@@ -453,6 +453,7 @@ void pci_for_each_bus(PCIBus *bus,PCIBus *pci_find_primary_bus (void );PCIBus *pci_device_root_bus (const PCIDevice *d); +bool pci_allow_hybrid_pcie (PCIDevice *pci_dev);const char *pci_root_bus_path (PCIDevice *dev);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);int pci_qdev_find_device (const char *id,PCIDevice **pdev);Signature · 1 line
2.9.3
Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
Quoted 35 lines · Michael S. Tsirkin
Quoted 34 lines · David Gibson
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new '
pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)hw/pci/pci.c +0
-0@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); }
Quoted 12 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 402
Quoted 10 lines
hw/pci/pci.c +7
-0+bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,I'd prefer
pci_allow_hybrid_pci_pcie.
So, I agree the current name isn't great, but that suggestion doesn't make sense to me. The function is determining if the hybrid device should present as PCIe rather than PCI, not whether it's permitted at all.
Quoted 9 lines
Quoted 9 lines
hw/usb/hcd-xhci.c +0
-0@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem);
Quoted 8 lines
hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) · line 3625
Quoted 5 lines
hw/usb/hcd-xhci.c +1
-1-if (pci_bus_is_express (dev->bus) || +if (pci_allow_hybrid_pcie (dev) ||xhci_get_flag (xhci,XHCI_FLAG_FORCE_PCIE_ENDCAP )) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );This seems to change the behaviour for xhci on a root bus - what am I missing?
Nothing. I need to fix this for the next spin.
Quoted 13 lines
Quoted 13 lines
hw/virtio/virtio-pci.c +1
-2@@ -1737,8 +1737,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) {VirtIOPCIProxy *proxy =VIRTIO_PCI (pci_dev);VirtioPCIClass *k =VIRTIO_PCI_GET_CLASS (pci_dev); -bool pcie_port =pci_bus_is_express (pci_dev->bus) && - !pci_bus_is_root (pci_dev->bus); +bool pcie_port =pci_allow_hybrid_pcie (pci_dev);
Quoted 5 lines
hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1743
Quoted 2 lines
hw/virtio/virtio-pci.c +0
-0if (!kvm_has_many_ioeventfds ()) { proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD ;I don't actually remember why do we disable pcie on a root port. Marcel, do you happen to know?
I assume you mean on a root bus rather than on a root port (in the sense of under the root port's fake P2P bridge). I was told it breaks firmware and/or some guests on x86.
Quoted 13 lines
Quoted 12 lines
include/hw/pci/pci.h +1
-0@@ -453,6 +453,7 @@ void pci_for_each_bus(PCIBus *bus,PCIBus *pci_find_primary_bus (void );PCIBus *pci_device_root_bus (const PCIDevice *d); +bool pci_allow_hybrid_pcie (PCIDevice *pci_dev);const char *pci_root_bus_path (PCIDevice *dev);PCIDevice *pci_find_device (PCIBus *bus,int bus_num,uint8_t devfn);int pci_qdev_find_device (const char *id,PCIDevice **pdev);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
In reply to Michael S. TsirkinQuoted 35 lines · Michael S. Tsirkin
Quoted 34 lines · David Gibson
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new '
pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)hw/pci/pci.c +0
-0@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); }
Quoted 12 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 402
Quoted 10 lines
hw/pci/pci.c +7
-0+bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,I'd prefer
pci_allow_hybrid_pci_pcie.
Ok, I've made that change for the next spin (aimed at 2.11, obviously).
Quoted 9 lines
Quoted 9 lines
hw/usb/hcd-xhci.c +0
-0@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem);
Quoted 8 lines
hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) · line 3625
Quoted 5 lines
hw/usb/hcd-xhci.c +1
-1-if (pci_bus_is_express (dev->bus) || +if (pci_allow_hybrid_pcie (dev) ||xhci_get_flag (xhci,XHCI_FLAG_FORCE_PCIE_ENDCAP )) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );This seems to change the behaviour for xhci on a root bus - what am I missing?
Nothing. I didn't consider the backwards compat implications; I'll fix it for the next spin.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
Quoted 49 lines · David Gibson
Quoted 35 lines · Michael S. Tsirkin
Quoted 34 lines · David Gibson
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new '
pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)hw/pci/pci.c +0
-0@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); }Quoted 12 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 402
Quoted 10 lines
hw/pci/pci.c +7
-0+bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,I'd prefer
pci_allow_hybrid_pci_pcie.
Quoted 1 line
Ok, I've made that change for the next spin (aimed at 2.11, obviously).
I'm a bit confused by the naming: by looking at the function name, I don't know if "allow hybrid" means "this bus+device can (also) work as Conventional PCI" or "this bus+device can (also) work as PCI Express".
What about just naming it pci_allow_pcie() or pci_bus_allow_pcie()? It looks like the function doesn't care if the device is hybrid or PCIe-only: it's only checking if the device can work as PCIe on that bus. It's up to the device to decide if it should switch to Conventional PCI or report an error if the function returns false.
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
hw/usb/hcd-xhci.c +0
-0@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem);Quoted 8 lines
hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) · line 3625
Quoted 5 lines
hw/usb/hcd-xhci.c +1
-1-if (pci_bus_is_express (dev->bus) || +if (pci_allow_hybrid_pcie (dev) ||xhci_get_flag (xhci,XHCI_FLAG_FORCE_PCIE_ENDCAP )) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );This seems to change the behaviour for xhci on a root bus - what am I missing?
Nothing. I didn't consider the backwards compat implications; I'll fix it for the next spin.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Signature · 1 line
Eduardo
Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
Quoted 50 lines · Eduardo Habkost
Quoted 49 lines · David Gibson
Quoted 47 lines · Michael S. Tsirkin
Quoted 34 lines · David Gibson
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new '
pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)hw/pci/pci.c +0
-0@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); }hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 402
Quoted 10 lines
hw/pci/pci.c +7
-0+bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,I'd prefer
pci_allow_hybrid_pci_pcie.
Quoted 6 lines
Quoted 1 line
Ok, I've made that change for the next spin (aimed at 2.11, obviously).
I'm a bit confused by the naming: by looking at the function name, I don't know if "allow hybrid" means "this bus+device can (also) work as Conventional PCI" or "this bus+device can (also) work as PCI Express".
Neither, actually. It means "should this device, which is capable of both PCI and PCIe operation, operate as PCIe in this context". It's only expected to be called by devices which support both modes of operation.
I have yet to think of a succinct name which conveys that :(.
Quoted 6 lines
What about just naming it
pci_allow_pcie()orpci_bus_allow_pcie()? It looks like the function doesn't care if the device is hybrid or PCIe-only: it's only checking if the device can work as PCIe on that bus. It's up to the device to decide if it should switch to Conventional PCI or report an error if the function returns false.
Hmm.. that would mean changing *every* existing PCIe device to call this, which I don't think I want to do.
Also it's _not* really saying if a device can operate as PCIe. AIUI, a device _can_ operate as PCIe on a root bus (without a port) although it's unusual. Integrated PCIe devices would do so, IIUC. For that matter I believe current devices which only support PCIe mode will also operate in PCIe mode on a root bus right now; but doing so without inserting a root port might make guests unhappy, at least on PC.
Quoted 26 lines
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
hw/usb/hcd-xhci.c +0
-0@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem);Quoted 8 lines
hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) · line 3625
Quoted 5 lines
hw/usb/hcd-xhci.c +1
-1-if (pci_bus_is_express (dev->bus) || +if (pci_allow_hybrid_pcie (dev) ||xhci_get_flag (xhci,XHCI_FLAG_FORCE_PCIE_ENDCAP )) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );This seems to change the behaviour for xhci on a root bus - what am I missing?
Nothing. I didn't consider the backwards compat implications; I'll fix it for the next spin.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
Quoted 58 lines · David Gibson
Quoted 50 lines · Eduardo Habkost
Quoted 49 lines · David Gibson
Quoted 47 lines · Michael S. Tsirkin
Quoted 34 lines · David Gibson
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new '
pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)hw/pci/pci.c +0
-0@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); }hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 402
Quoted 10 lines
hw/pci/pci.c +7
-0+bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,I'd prefer
pci_allow_hybrid_pci_pcie.Quoted 6 lines
Quoted 1 line
Ok, I've made that change for the next spin (aimed at 2.11, obviously).
I'm a bit confused by the naming: by looking at the function name, I don't know if "allow hybrid" means "this bus+device can (also) work as Conventional PCI" or "this bus+device can (also) work as PCI Express".
Quoted 6 lines
Neither, actually. It means "should this device, which is capable of both PCI and PCIe operation, operate as PCIe in this context". It's only expected to be called by devices which support both modes of operation.
I have yet to think of a succinct name which conveys that :(.
Based on this description, maybe pci_hybrid_allow_pcie() would be clearer.
But based on the comments below, I have another suggestion:
Quoted 10 lines
Quoted 7 lines
What about just naming it
pci_allow_pcie()orpci_bus_allow_pcie()? It looks like the function doesn't care if the device is hybrid or PCIe-only: it's only checking if the device can work as PCIe on that bus. It's up to the device to decide if it should switch to Conventional PCI or report an error if the function returns false.Hmm.. that would mean changing *every* existing PCIe device to call this, which I don't think I want to do.
Maybe calling it from the common PCI realize function won't be a bad idea. But let's discuss that after we clean up the existing hybrid devices.
Quoted 8 lines
Also it's _not* really saying if a device can operate as PCIe. AIUI, a device _can_ operate as PCIe on a root bus (without a port) although it's unusual. Integrated PCIe devices would do so, IIUC. For that matter I believe current devices which only support PCIe mode will also operate in PCIe mode on a root bus right now; but doing so without inserting a root port might make guests unhappy, at least on PC.
If that's the case, I would change the name and documentation to say "defaults to", "should", "recommend", or "prefer".
What about pci_bus_prefers_pcie() or pci_hybrid_prefers_pcie()?
In either case, we really need a doc comment clearly explaining the function purpose and semantics.
Quoted 33 lines
Quoted 27 lines
Quoted 24 lines
Quoted 12 lines
Quoted 12 lines
hw/usb/hcd-xhci.c +0
-0@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem);Quoted 8 lines
hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) · line 3625
Quoted 5 lines
hw/usb/hcd-xhci.c +1
-1-if (pci_bus_is_express (dev->bus) || +if (pci_allow_hybrid_pcie (dev) ||xhci_get_flag (xhci,XHCI_FLAG_FORCE_PCIE_ENDCAP )) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );This seems to change the behaviour for xhci on a root bus - what am I missing?
Nothing. I didn't consider the backwards compat implications; I'll fix it for the next spin.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Signature · 1 line
Eduardo
Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
Quoted 95 lines · Eduardo Habkost
Quoted 58 lines · David Gibson
Quoted 50 lines · Eduardo Habkost
Quoted 49 lines · David Gibson
Quoted 47 lines · Michael S. Tsirkin
Quoted 34 lines · David Gibson
virtio-pci and XHCI are "hybrid" devices in the sense that they can present themselves as either PCIe or plain PCI devices depending on the machine and bus they're connected to.
For virtio-pci to present as PCIe it requires that it's connected to a PCIe bus and that it's not a root bus - this is to ensure that the device is connected via a PCIe root port or downstream port rather than being a integrated endpoint. Some guests (Windows in particular AIUI) don't really cope with PCIe integrated endpoints.
For XHCI it only checks that the bus is PCIe, but that probably means it would cause problems if attached as an integrated devices directly to a PCIe root bus.
This patch makes the test consistent between XHCI and virtio-pci, and clarifies things by having them both use a new '
pci_allow_hybrid_pcie()' helper which performs the same check as virtio-pci.Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 7 +++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)hw/pci/pci.c +0
-0@@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); }hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 402
Quoted 10 lines
hw/pci/pci.c +7
-0+bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +} + void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,I'd prefer
pci_allow_hybrid_pci_pcie.Quoted 6 lines
Quoted 1 line
Ok, I've made that change for the next spin (aimed at 2.11, obviously).
I'm a bit confused by the naming: by looking at the function name, I don't know if "allow hybrid" means "this bus+device can (also) work as Conventional PCI" or "this bus+device can (also) work as PCI Express".
Quoted 6 lines
Neither, actually. It means "should this device, which is capable of both PCI and PCIe operation, operate as PCIe in this context". It's only expected to be called by devices which support both modes of operation.
I have yet to think of a succinct name which conveys that :(.
Based on this description, maybe
pci_hybrid_allow_pcie()would be clearer.But based on the comments below, I have another suggestion:
Quoted 10 lines
Quoted 7 lines
What about just naming it
pci_allow_pcie()orpci_bus_allow_pcie()? It looks like the function doesn't care if the device is hybrid or PCIe-only: it's only checking if the device can work as PCIe on that bus. It's up to the device to decide if it should switch to Conventional PCI or report an error if the function returns false.Hmm.. that would mean changing *every* existing PCIe device to call this, which I don't think I want to do.
Maybe calling it from the common PCI realize function won't be a bad idea. But let's discuss that after we clean up the existing hybrid devices.
Quoted 8 lines
Also it's _not* really saying if a device can operate as PCIe. AIUI, a device _can_ operate as PCIe on a root bus (without a port) although it's unusual. Integrated PCIe devices would do so, IIUC. For that matter I believe current devices which only support PCIe mode will also operate in PCIe mode on a root bus right now; but doing so without inserting a root port might make guests unhappy, at least on PC.
Quoted 4 lines
If that's the case, I would change the name and documentation to say "defaults to", "should", "recommend", or "prefer".
What about
pci_bus_prefers_pcie()orpci_hybrid_prefers_pcie()?
Ok, I'm going with pci_hybrid_prefer_pcie() in the next spin.
Quoted 2 lines
In either case, we really need a doc comment clearly explaining the function purpose and semantics.
I've put something on the function itself. Possibly it should move to the header. Anyway, you can comment again on the next spin.
Quoted 32 lines
Quoted 29 lines
Quoted 28 lines
Quoted 25 lines
Quoted 13 lines
Quoted 13 lines
hw/usb/hcd-xhci.c +0
-0@@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)PCI_BASE_ADDRESS_SPACE_MEMORY |PCI_BASE_ADDRESS_MEM_TYPE_64 , &xhci->mem);Quoted 8 lines
hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice *dev, Error **errp) · line 3625
Quoted 5 lines
hw/usb/hcd-xhci.c +1
-1-if (pci_bus_is_express (dev->bus) || +if (pci_allow_hybrid_pcie (dev) ||xhci_get_flag (xhci,XHCI_FLAG_FORCE_PCIE_ENDCAP )) { ret =pcie_endpoint_cap_init (dev,0xa0 );assert (ret >=0 );This seems to change the behaviour for xhci on a root bus - what am I missing?
Nothing. I didn't consider the backwards compat implications; I'll fix it for the next spin.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
RFC 2/3 pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
In reply to David GibsonCurrently PCI/PCIe hybrid devices - that is, devices which can appear as either plain PCI or PCIe depending on where they're attached - will only appear in PCIe mode if they're attached to a PCIe bus via a root port or downstream port.
This is correct for "standard" PCIe setups, but there are some platforms which need different behaviour (notably "pseries" whose paravirtualized PCI host bridges have some idiosyncracies).
This patch allows the host bridge to override the normal behaviour.
--- hw/pci/pci.c | 11 +++++++++-- include/hw/pci/pci_host.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)
hw/pci/pci.c +9 -2
@@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) { -PCIBus *bus = pci_dev->bus; +PCIHostState *host_bridge =PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev)->qbus.parent); +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); + +if (hc->allow_hybrid_pcie) { +return hc->allow_hybrid_pcie (host_bridge, pci_dev); + }else { +PCIBus *bus = pci_dev->bus; -return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); + } } void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
include/hw/pci/pci_host.h +1 -0
@@ -54,6 +54,7 @@ typedef struct PCIHostBridgeClass {SysBusDeviceClass parent_class;const char *(*root_bus_path)(PCIHostState *,PCIBus *); +bool (*allow_hybrid_pcie)(PCIHostState *,PCIDevice *); } PCIHostBridgeClass;/* common internal helpers for PCI/PCIe hosts, cut off overflows */
Signature · 1 line
2.9.3
Re: [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
Quoted 22 lines · David Gibson
Currently PCI/PCIe hybrid devices - that is, devices which can appear as either plain PCI or PCIe depending on where they're attached - will only appear in PCIe mode if they're attached to a PCIe bus via a root port or downstream port.
This is correct for "standard" PCIe setups, but there are some platforms which need different behaviour (notably "pseries" whose paravirtualized PCI host bridges have some idiosyncracies).
This patch allows the host bridge to override the normal behaviour.
Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 11 +++++++++-- include/hw/pci/pci_host.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/pci/pci.c +0
-0
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 393
Quoted 2 lines
hw/pci/pci.c +0
-0@@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)bool pci_allow_hybrid_pcie (PCIDevice *pci_dev)
Why are we asking the device about allowing hybrid pcie, and not the bus itself? Shouldn't we be able to query this before the device is plugged, and before pci_dev->bus is even set?
In other words, why pci_allow_hyberid_pcie() and pci_device_get_bus() get a PCIDevice* argument instead of a PCIBus* argument?
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 395
Quoted 3 lines
hw/pci/pci.c +1
-1{ -PCIBus *bus = pci_dev->bus; +PCIHostState *host_bridge =PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev)->qbus.parent);
There's something I don't understand completely: what exactly guarantees that pci_device_root_bus(...)->qbus.parent is always going to be a PCI_HOST_BRIDGE?
Quoted 29 lines
hw/pci/pci.c +8
-1+PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); + +if (hc->allow_hybrid_pcie) { +return hc->allow_hybrid_pcie (host_bridge, pci_dev); + }else { +PCIBus *bus = pci_dev->bus; -return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); + } } void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,include/hw/pci/pci_host.h +1
-0@@ -54,6 +54,7 @@ typedef struct PCIHostBridgeClass {SysBusDeviceClass parent_class;const char *(*root_bus_path)(PCIHostState *,PCIBus *); +bool (*allow_hybrid_pcie)(PCIHostState *,PCIDevice *); } PCIHostBridgeClass;/* common internal helpers for PCI/PCIe hosts, cut off overflows */ Signature · 1 line
2.9.3
Signature · 1 line
Eduardo
Re: [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
Quoted 30 lines · Eduardo Habkost
Quoted 22 lines · David Gibson
Currently PCI/PCIe hybrid devices - that is, devices which can appear as either plain PCI or PCIe depending on where they're attached - will only appear in PCIe mode if they're attached to a PCIe bus via a root port or downstream port.
This is correct for "standard" PCIe setups, but there are some platforms which need different behaviour (notably "pseries" whose paravirtualized PCI host bridges have some idiosyncracies).
This patch allows the host bridge to override the normal behaviour.
Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 11 +++++++++-- include/hw/pci/pci_host.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/pci/pci.c +0
-0hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 393
Quoted 2 lines
hw/pci/pci.c +0
-0@@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)bool pci_allow_hybrid_pcie (PCIDevice *pci_dev)Why are we asking the device about allowing hybrid pcie, and not the bus itself? Shouldn't we be able to query this before the device is plugged, and before
pci_dev->busis even set?
Quoted 3 lines
In other words, why
pci_allow_hyberid_pcie()andpci_device_get_bus()get a PCIDevice* argument instead of a PCIBus* argument?
Ah good point. I made it a PCIDevice simply for convenience, but you're right we should be able to query before the device is plugged.
Quoted 8 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 395
Quoted 4 lines
hw/pci/pci.c +1
-1{ -PCIBus *bus = pci_dev->bus; +PCIHostState *host_bridge =PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev)->qbus.parent);There's something I don't understand completely: what exactly guarantees that pci_device_root_bus(...)->qbus.parent is always going to be a
PCI_HOST_BRIDGE?
Well, by definition whatever is above the root bus isn't PCI, which pretty much means it has to be a PCI host bridge. A machine could break this assumption, but I think that would be a bug. We use this same pattern to find a PCI device's (or bus's) host bridge in other places - there doesn't appear to be another way.
Quoted 26 lines
Quoted 25 lines
hw/pci/pci.c +8
-1+PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); + +if (hc->allow_hybrid_pcie) { +return hc->allow_hybrid_pcie (host_bridge, pci_dev); + }else { +PCIBus *bus = pci_dev->bus; -return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); + } } void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,include/hw/pci/pci_host.h +1
-0@@ -54,6 +54,7 @@ typedef struct PCIHostBridgeClass {SysBusDeviceClass parent_class;const char *(*root_bus_path)(PCIHostState *,PCIBus *); +bool (*allow_hybrid_pcie)(PCIHostState *,PCIDevice *); } PCIHostBridgeClass;/* common internal helpers for PCI/PCIe hosts, cut off overflows */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Eduardo Habkost
Reviewed-byRe: [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
Quoted 31 lines · David Gibson
Quoted 30 lines · Eduardo Habkost
Quoted 22 lines · David Gibson
Currently PCI/PCIe hybrid devices - that is, devices which can appear as either plain PCI or PCIe depending on where they're attached - will only appear in PCIe mode if they're attached to a PCIe bus via a root port or downstream port.
This is correct for "standard" PCIe setups, but there are some platforms which need different behaviour (notably "pseries" whose paravirtualized PCI host bridges have some idiosyncracies).
This patch allows the host bridge to override the normal behaviour.
Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 11 +++++++++-- include/hw/pci/pci_host.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/pci/pci.c +0
-0hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 393
Quoted 2 lines
hw/pci/pci.c +0
-0@@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)bool pci_allow_hybrid_pcie (PCIDevice *pci_dev)Why are we asking the device about allowing hybrid pcie, and not the bus itself? Shouldn't we be able to query this before the device is plugged, and before
pci_dev->busis even set?
Quoted 6 lines
Quoted 3 lines
In other words, why
pci_allow_hyberid_pcie()andpci_device_get_bus()get a PCIDevice* argument instead of a PCIBus* argument?Ah good point. I made it a PCIDevice simply for convenience, but you're right we should be able to query before the device is plugged.
Understood.
Quoted 10 lines
Quoted 9 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 395
Quoted 5 lines
hw/pci/pci.c +1
-1{ -PCIBus *bus = pci_dev->bus; +PCIHostState *host_bridge =PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev)->qbus.parent);There's something I don't understand completely: what exactly guarantees that pci_device_root_bus(...)->qbus.parent is always going to be a
PCI_HOST_BRIDGE?
Quoted 5 lines
Well, by definition whatever is above the root bus isn't PCI, which pretty much means it has to be a PCI host bridge. A machine could break this assumption, but I think that would be a bug. We use this same pattern to find a PCI device's (or bus's) host bridge in other places - there doesn't appear to be another way.
After taking a better look at the way PCI buses are created, I agree it's OK. Maybe a
PCIHostState *pci_host_bridge(PCIBus *bus)
helper would be useful?
Anyway, both pci_bus_root_bus() and pci_host_bridge() could be implemented as follow-ups if you prefer, so:
But I still have another suggestion:
Quoted 10 lines
Quoted 10 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 403
Quoted 10 lines
hw/pci/pci.c +7
-1+PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); + +if (hc->allow_hybrid_pcie) { +return hc->allow_hybrid_pcie (host_bridge, pci_dev); + }else { +PCIBus *bus = pci_dev->bus; -return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +return pci_bus_is_express (bus) && !pci_bus_is_root (bus);
Maybe it's a matter of personal taste, but instead of requiring an explicit check for NULL hc->allow_hybrid_pcie, why not set a default hc->allow_hybrid_pcie() implementation on TYPE_PCI_HOST_BRIDGE that returns (pci_bus_is_express(bus) && !pci_bus_is_root(bus))?
Signature · 1 line
Eduardo
Re: [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
Quoted 32 lines · Eduardo Habkost
Quoted 31 lines · David Gibson
Quoted 30 lines · Eduardo Habkost
Quoted 22 lines · David Gibson
Currently PCI/PCIe hybrid devices - that is, devices which can appear as either plain PCI or PCIe depending on where they're attached - will only appear in PCIe mode if they're attached to a PCIe bus via a root port or downstream port.
This is correct for "standard" PCIe setups, but there are some platforms which need different behaviour (notably "pseries" whose paravirtualized PCI host bridges have some idiosyncracies).
This patch allows the host bridge to override the normal behaviour.
Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 11 +++++++++-- include/hw/pci/pci_host.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/pci/pci.c +0
-0hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 393
Quoted 2 lines
hw/pci/pci.c +0
-0@@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)bool pci_allow_hybrid_pcie (PCIDevice *pci_dev)Why are we asking the device about allowing hybrid pcie, and not the bus itself? Shouldn't we be able to query this before the device is plugged, and before
pci_dev->busis even set?
Quoted 25 lines
Quoted 6 lines
Quoted 3 lines
In other words, why
pci_allow_hyberid_pcie()andpci_device_get_bus()get a PCIDevice* argument instead of a PCIBus* argument?Ah good point. I made it a PCIDevice simply for convenience, but you're right we should be able to query before the device is plugged.
Understood.
Quoted 15 lines
Quoted 9 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 395
Quoted 5 lines
hw/pci/pci.c +1
-1{ -PCIBus *bus = pci_dev->bus; +PCIHostState *host_bridge =PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev)->qbus.parent);There's something I don't understand completely: what exactly guarantees that pci_device_root_bus(...)->qbus.parent is always going to be a
PCI_HOST_BRIDGE?Well, by definition whatever is above the root bus isn't PCI, which pretty much means it has to be a PCI host bridge. A machine could break this assumption, but I think that would be a bug. We use this same pattern to find a PCI device's (or bus's) host bridge in other places - there doesn't appear to be another way.
Agreed, the root bus is always exposed by (some kind of) a host bridge.
Quoted 5 lines
After taking a better look at the way PCI buses are created, I agree it's OK. Maybe a
PCIHostState *pci_host_bridge(PCIBus *bus)
helper would be useful?
For sure.
Quoted 5 lines
Anyway, both
pci_bus_root_bus()andpci_host_bridge()could be implemented as follow-ups if you prefer, so:Reviewed-by Eduardo Habkost <[email protected]>
Thanks,
Marcel
Quoted 19 lines
But I still have another suggestion:
Quoted 10 lines
Quoted 10 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 403
Quoted 10 lines
hw/pci/pci.c +7
-1+PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); + +if (hc->allow_hybrid_pcie) { +return hc->allow_hybrid_pcie (host_bridge, pci_dev); + }else { +PCIBus *bus = pci_dev->bus; -return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +return pci_bus_is_express (bus) && !pci_bus_is_root (bus);Maybe it's a matter of personal taste, but instead of requiring an explicit check for NULL
hc->allow_hybrid_pcie, why not set a defaulthc->allow_hybrid_pcie()implementation onTYPE_PCI_HOST_BRIDGEthat returns (pci_bus_is_express(bus)&& !pci_bus_is_root(bus))?
Re: [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
In reply to David GibsonQuoted 30 lines · David Gibson
Currently PCI/PCIe hybrid devices - that is, devices which can appear as either plain PCI or PCIe depending on where they're attached - will only appear in PCIe mode if they're attached to a PCIe bus via a root port or downstream port.
This is correct for "standard" PCIe setups, but there are some platforms which need different behaviour (notably "pseries" whose paravirtualized PCI host bridges have some idiosyncracies).
This patch allows the host bridge to override the normal behaviour.
Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 11 +++++++++-- include/hw/pci/pci_host.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/pci/pci.c +4
-1@@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) { -PCIBus *bus = pci_dev->bus; +PCIHostState *host_bridge =PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev)->qbus.parent); +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); + +if (hc->allow_hybrid_pcie) {
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 407
Quoted 10 lines
hw/pci/pci.c +5
-1+return hc->allow_hybrid_pcie (host_bridge, pci_dev); + }else { +PCIBus *bus = pci_dev->bus; -return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); + } } void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
I think I'd prefer adding some flags in PCIBus. While we are at it, is_root can become a flag too.
Quoted 14 lines
include/hw/pci/pci_host.h +1
-0@@ -54,6 +54,7 @@ typedef struct PCIHostBridgeClass {SysBusDeviceClass parent_class;const char *(*root_bus_path)(PCIHostState *,PCIBus *); +bool (*allow_hybrid_pcie)(PCIHostState *,PCIDevice *); } PCIHostBridgeClass;/* common internal helpers for PCI/PCIe hosts, cut off overflows */ Signature · 1 line
2.9.3
Re: [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
Quoted 35 lines · Michael S. Tsirkin
Quoted 34 lines · David Gibson
Currently PCI/PCIe hybrid devices - that is, devices which can appear as either plain PCI or PCIe depending on where they're attached - will only appear in PCIe mode if they're attached to a PCIe bus via a root port or downstream port.
This is correct for "standard" PCIe setups, but there are some platforms which need different behaviour (notably "pseries" whose paravirtualized PCI host bridges have some idiosyncracies).
This patch allows the host bridge to override the normal behaviour.
Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 11 +++++++++-- include/hw/pci/pci_host.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/pci/pci.c +7
-1@@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) { -PCIBus *bus = pci_dev->bus; +PCIHostState *host_bridge =PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev)->qbus.parent); +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); + +if (hc->allow_hybrid_pcie) { +return hc->allow_hybrid_pcie (host_bridge, pci_dev); + }else { +PCIBus *bus = pci_dev->bus;
Quoted 8 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 407
Quoted 6 lines
hw/pci/pci.c +2
-1-return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); + } } void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,I think I'd prefer adding some flags in PCIBus
I'm not really sure what you have in mind from that. Remember that we need to be able to set this based on machine type for backwards compatibility.
Quoted 2 lines
While we are at it,
is_rootcan become a flag too.
Seems a bit odd to me, since it can be derived from the existing information.
Quoted 14 lines
Quoted 13 lines
include/hw/pci/pci_host.h +1
-0@@ -54,6 +54,7 @@ typedef struct PCIHostBridgeClass {SysBusDeviceClass parent_class;const char *(*root_bus_path)(PCIHostState *,PCIBus *); +bool (*allow_hybrid_pcie)(PCIHostState *,PCIDevice *); } PCIHostBridgeClass;/* common internal helpers for PCI/PCIe hosts, cut off overflows */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
In reply to Michael S. TsirkinQuoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · David Gibson
Currently PCI/PCIe hybrid devices - that is, devices which can appear as either plain PCI or PCIe depending on where they're attached - will only appear in PCIe mode if they're attached to a PCIe bus via a root port or downstream port.
This is correct for "standard" PCIe setups, but there are some platforms which need different behaviour (notably "pseries" whose paravirtualized PCI host bridges have some idiosyncracies).
This patch allows the host bridge to override the normal behaviour.
Signed-off-by David Gibson <[email protected]>--- hw/pci/pci.c | 11 +++++++++-- include/hw/pci/pci_host.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/pci/pci.c +9
-2@@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)bool pci_allow_hybrid_pcie (PCIDevice *pci_dev) { -PCIBus *bus = pci_dev->bus; +PCIHostState *host_bridge =PCI_HOST_BRIDGE (pci_device_root_bus (pci_dev)->qbus.parent); +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); + +if (hc->allow_hybrid_pcie) { +return hc->allow_hybrid_pcie (host_bridge, pci_dev); + }else { +PCIBus *bus = pci_dev->bus; -return pci_bus_is_express (bus) && !pci_bus_is_root (bus); +return pci_bus_is_express (bus) && !pci_bus_is_root (bus); + } }
Quoted 4 lines
hw/pci/pci.c bool pci_bus_is_root(PCIBus *bus) · line 407
Quoted 1 line
hw/pci/pci.c +0
-0void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,I think I'd prefer adding some flags in PCIBus. While we are at it,
is_rootcan become a flag too.
Good idea! Looking at it the is_root() method really is bogus, I have a draft patch which replaces it with a flag. (In fact the other PCIBusClass methods look kind of bogus too, I'll see if I can find time to do something about that).
Quoted 14 lines
Quoted 13 lines
include/hw/pci/pci_host.h +1
-0@@ -54,6 +54,7 @@ typedef struct PCIHostBridgeClass {SysBusDeviceClass parent_class;const char *(*root_bus_path)(PCIHostState *,PCIBus *); +bool (*allow_hybrid_pcie)(PCIHostState *,PCIDevice *); } PCIHostBridgeClass;/* common internal helpers for PCI/PCIe hosts, cut off overflows */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
RFC 3/3 pseries: Allow PCIe virtio and XHCI on pseries machine type
In reply to David Gibsonpseries now allows PCIe devices (both emulated and VFIO), although its PCI bus is in most respects a plain PCI bus - this uses paravirtualized access methods to PCIe extended config space defined in the PAPR spec.
However, because the bus is not PCIe, it means that virtio-pci and XHCI devices will present themselves as plain PCI rather than PCIe, which would be preferable.
This patch uses the new hook to override the behaviour for such PCI/PCIe "hybrid" devices to allow PCIe virtio-pci and XHCI on pseries.
--- hw/ppc/spapr_pci.c | 9 +++++++++ tests/virtio-9p-test.c | 2 +- tests/virtio-blk-test.c | 4 ++-- tests/virtio-net-test.c | 2 +- tests/virtio-scsi-test.c | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-)
hw/ppc/spapr_pci.c +9 -0
@@ -1979,6 +1979,14 @@ static const char *spapr_phb_root_bus_path(PCIHostState *host_bridge,return sphb->dtbusname; } +static bool spapr_phb_allow_hybrid_pcie (PCIHostState *host_bridge, +PCIDevice *pci_dev) +{ +sPAPRPHBState *sphb =SPAPR_PCI_HOST_BRIDGE (host_bridge); + +return sphb->pcie_ecs; +} +static void spapr_phb_class_init (ObjectClass *klass,void *data) {PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass);
@@ -1986,6 +1994,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data)HotplugHandlerClass *hp =HOTPLUG_HANDLER_CLASS (klass); hc->root_bus_path = spapr_phb_root_bus_path; + hc->allow_hybrid_pcie = spapr_phb_allow_hybrid_pcie; dc->realize = spapr_phb_realize; dc->props = spapr_phb_properties; dc->reset = spapr_phb_reset;
tests/virtio-9p-test.c +1 -1
@@ -32,7 +32,7 @@ static QVirtIO9P *qvirtio_9p_start(const char *driver) {const char *arch =qtest_get_arch ();const char *cmd ="-fsdev local,id=fsdev0,security_model=none,path=%s " -"-device %s,fsdev=fsdev0,mount_tag=%s" ; +"-device %s,fsdev=fsdev0,mount_tag=%s,disable-legacy=off" ;QVirtIO9P *v9p =g_new0 (QVirtIO9P,1 ); v9p->test_share =g_strdup ("/tmp/qtest.XXXXXX" );
tests/virtio-blk-test.c +2 -2
@@ -65,7 +65,7 @@ static QOSState *pci_test_start(void)const char *cmd ="-drive if=none,id=drive0,file=%s,format=raw " "-drive if=none,id=drive1,file=/dev/null,format=raw " "-device virtio-blk-pci,id=drv0,drive=drive0," -"addr=%x.%x" ; +"addr=%x.%x,disable-legacy=off" ; tmp_path =drive_create ();
@@ -656,7 +656,7 @@ static void pci_hotplug(void)/* plug secondary disk */ qpci_plug_device_test ("virtio-blk-pci" ,"drv1" ,PCI_SLOT_HP , -"'drive': 'drive1'" ); +"'drive': 'drive1', 'disable-legacy': 'off'" ); dev =virtio_blk_pci_init (qs->pcibus,PCI_SLOT_HP );g_assert (dev);
tests/virtio-net-test.c +1 -1
@@ -55,7 +55,7 @@ static QOSState *pci_test_start(int socket) {const char *arch =qtest_get_arch ();const char *cmd ="-netdev socket,fd=%d,id=hs0 -device " -"virtio-net-pci,netdev=hs0" ; +"virtio-net-pci,netdev=hs0,disable-legacy=off" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) {return qtest_pc_boot (cmd, socket);
tests/virtio-scsi-test.c +1 -1
@@ -36,7 +36,7 @@ static QOSState *qvirtio_scsi_start(const char *extra_opts) {const char *arch =qtest_get_arch ();const char *cmd ="-drive id=drv0,if=none,file=/dev/null,format=raw " -"-device virtio-scsi-pci,id=vs0 " +"-device virtio-scsi-pci,id=vs0,disable-legacy=off " "-device scsi-hd,bus=vs0.0,drive=drv0 %s" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) {
Signature · 1 line
2.9.3
Re: [Qemu-devel] [RFC for-2.10 3/3] pseries: Allow PCIe virtio and XHCI on pseries machine type
Quoted 10 lines · David Gibson
pseries now allows PCIe devices (both emulated and VFIO), although its PCI bus is in most respects a plain PCI bus - this uses paravirtualized access methods to PCIe extended config space defined in the PAPR spec.
However, because the bus is not PCIe, it means that virtio-pci and XHCI devices will present themselves as plain PCI rather than PCIe, which would be preferable.
This patch uses the new hook to override the behaviour for such PCI/PCIe "hybrid" devices to allow PCIe virtio-pci and XHCI on pseries.
Not clear what all these tests/virtio-*.c changes are for and why here - does "make check" break if you do not enforce disable-legacy=off?
Quoted 99 lines
Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr_pci.c | 9 +++++++++ tests/virtio-9p-test.c | 2 +- tests/virtio-blk-test.c | 4 ++-- tests/virtio-net-test.c | 2 +- tests/virtio-scsi-test.c | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-)hw/ppc/spapr_pci.c +9
-0@@ -1979,6 +1979,14 @@ static const char *spapr_phb_root_bus_path(PCIHostState *host_bridge,return sphb->dtbusname; } +static bool spapr_phb_allow_hybrid_pcie (PCIHostState *host_bridge, +PCIDevice *pci_dev) +{ +sPAPRPHBState *sphb =SPAPR_PCI_HOST_BRIDGE (host_bridge); + +return sphb->pcie_ecs; +} +static void spapr_phb_class_init (ObjectClass *klass,void *data) {PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass);@@ -1986,6 +1994,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data)HotplugHandlerClass *hp =HOTPLUG_HANDLER_CLASS (klass); hc->root_bus_path = spapr_phb_root_bus_path; + hc->allow_hybrid_pcie = spapr_phb_allow_hybrid_pcie; dc->realize = spapr_phb_realize; dc->props = spapr_phb_properties; dc->reset = spapr_phb_reset;tests/virtio-9p-test.c +1
-1@@ -32,7 +32,7 @@ static QVirtIO9P *qvirtio_9p_start(const char *driver) {const char *arch =qtest_get_arch ();const char *cmd ="-fsdev local,id=fsdev0,security_model=none,path=%s " -"-device %s,fsdev=fsdev0,mount_tag=%s" ; +"-device %s,fsdev=fsdev0,mount_tag=%s,disable-legacy=off" ;QVirtIO9P *v9p =g_new0 (QVirtIO9P,1 ); v9p->test_share =g_strdup ("/tmp/qtest.XXXXXX" );tests/virtio-blk-test.c +2
-2@@ -65,7 +65,7 @@ static QOSState *pci_test_start(void)const char *cmd ="-drive if=none,id=drive0,file=%s,format=raw " "-drive if=none,id=drive1,file=/dev/null,format=raw " "-device virtio-blk-pci,id=drv0,drive=drive0," -"addr=%x.%x" ; +"addr=%x.%x,disable-legacy=off" ; tmp_path =drive_create ();@@ -656,7 +656,7 @@ static void pci_hotplug(void)/* plug secondary disk */ qpci_plug_device_test ("virtio-blk-pci" ,"drv1" ,PCI_SLOT_HP , -"'drive': 'drive1'" ); +"'drive': 'drive1', 'disable-legacy': 'off'" ); dev =virtio_blk_pci_init (qs->pcibus,PCI_SLOT_HP );g_assert (dev);tests/virtio-net-test.c +1
-1@@ -55,7 +55,7 @@ static QOSState *pci_test_start(int socket) {const char *arch =qtest_get_arch ();const char *cmd ="-netdev socket,fd=%d,id=hs0 -device " -"virtio-net-pci,netdev=hs0" ; +"virtio-net-pci,netdev=hs0,disable-legacy=off" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) {return qtest_pc_boot (cmd, socket);tests/virtio-scsi-test.c +1
-1@@ -36,7 +36,7 @@ static QOSState *qvirtio_scsi_start(const char *extra_opts) {const char *arch =qtest_get_arch ();const char *cmd ="-drive id=drv0,if=none,file=/dev/null,format=raw " -"-device virtio-scsi-pci,id=vs0 " +"-device virtio-scsi-pci,id=vs0,disable-legacy=off " "-device scsi-hd,bus=vs0.0,drive=drv0 %s" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) {
Signature · 1 line
Alexey
Re: [Qemu-devel] [RFC for-2.10 3/3] pseries: Allow PCIe virtio and XHCI on pseries machine type
Quoted 9 lines · Alexey Kardashevskiy
Quoted 8 lines · David Gibson
pseries now allows PCIe devices (both emulated and VFIO), although its PCI bus is in most respects a plain PCI bus - this uses paravirtualized access methods to PCIe extended config space defined in the PAPR spec.
However, because the bus is not PCIe, it means that virtio-pci and XHCI devices will present themselves as plain PCI rather than PCIe, which would be preferable.
Quoted 6 lines
Quoted 2 lines
This patch uses the new hook to override the behaviour for such PCI/PCIe "hybrid" devices to allow PCIe virtio-pci and XHCI on pseries.
Not clear what all these
tests/virtio-*.cchanges are for and why here - does "make check" break if you do not enforce disable-legacy=off?
Yes it does. There's an explanation in the 0/3 message.
Quoted 100 lines
Quoted 98 lines
Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr_pci.c | 9 +++++++++ tests/virtio-9p-test.c | 2 +- tests/virtio-blk-test.c | 4 ++-- tests/virtio-net-test.c | 2 +- tests/virtio-scsi-test.c | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-)hw/ppc/spapr_pci.c +9
-0@@ -1979,6 +1979,14 @@ static const char *spapr_phb_root_bus_path(PCIHostState *host_bridge,return sphb->dtbusname; } +static bool spapr_phb_allow_hybrid_pcie (PCIHostState *host_bridge, +PCIDevice *pci_dev) +{ +sPAPRPHBState *sphb =SPAPR_PCI_HOST_BRIDGE (host_bridge); + +return sphb->pcie_ecs; +} +static void spapr_phb_class_init (ObjectClass *klass,void *data) {PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass);@@ -1986,6 +1994,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void *data)HotplugHandlerClass *hp =HOTPLUG_HANDLER_CLASS (klass); hc->root_bus_path = spapr_phb_root_bus_path; + hc->allow_hybrid_pcie = spapr_phb_allow_hybrid_pcie; dc->realize = spapr_phb_realize; dc->props = spapr_phb_properties; dc->reset = spapr_phb_reset;tests/virtio-9p-test.c +1
-1@@ -32,7 +32,7 @@ static QVirtIO9P *qvirtio_9p_start(const char *driver) {const char *arch =qtest_get_arch ();const char *cmd ="-fsdev local,id=fsdev0,security_model=none,path=%s " -"-device %s,fsdev=fsdev0,mount_tag=%s" ; +"-device %s,fsdev=fsdev0,mount_tag=%s,disable-legacy=off" ;QVirtIO9P *v9p =g_new0 (QVirtIO9P,1 ); v9p->test_share =g_strdup ("/tmp/qtest.XXXXXX" );tests/virtio-blk-test.c +2
-2@@ -65,7 +65,7 @@ static QOSState *pci_test_start(void)const char *cmd ="-drive if=none,id=drive0,file=%s,format=raw " "-drive if=none,id=drive1,file=/dev/null,format=raw " "-device virtio-blk-pci,id=drv0,drive=drive0," -"addr=%x.%x" ; +"addr=%x.%x,disable-legacy=off" ; tmp_path =drive_create ();@@ -656,7 +656,7 @@ static void pci_hotplug(void)/* plug secondary disk */ qpci_plug_device_test ("virtio-blk-pci" ,"drv1" ,PCI_SLOT_HP , -"'drive': 'drive1'" ); +"'drive': 'drive1', 'disable-legacy': 'off'" ); dev =virtio_blk_pci_init (qs->pcibus,PCI_SLOT_HP );g_assert (dev);tests/virtio-net-test.c +1
-1@@ -55,7 +55,7 @@ static QOSState *pci_test_start(int socket) {const char *arch =qtest_get_arch ();const char *cmd ="-netdev socket,fd=%d,id=hs0 -device " -"virtio-net-pci,netdev=hs0" ; +"virtio-net-pci,netdev=hs0,disable-legacy=off" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) {return qtest_pc_boot (cmd, socket);tests/virtio-scsi-test.c +1
-1@@ -36,7 +36,7 @@ static QOSState *qvirtio_scsi_start(const char *extra_opts) {const char *arch =qtest_get_arch ();const char *cmd ="-drive id=drv0,if=none,file=/dev/null,format=raw " -"-device virtio-scsi-pci,id=vs0 " +"-device virtio-scsi-pci,id=vs0,disable-legacy=off " "-device scsi-hd,bus=vs0.0,drive=drv0 %s" ;if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) {
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 6 lines · David Gibson
A couple of devices - virtio-pci and XHCI - can present themselves to the guest as either PCI or PCIe devices depending on how they're attached. However, the logic is a little different between the two devices. In addition the logic in virtio makes it difficult to put a PCIe virtio device into a "pseries" guest because of the unusual way the paravirtualized PCI bus works there.
virtio-pci and xhci are not the only hybrid devices. What about vmxnet3, pvscsi, and vfio-pci?
Quoted 33 lines
This series makes the logic more consistent, and allows per-machine overrides to address that.
Currently patch 3/3 shows a non-obvious side effect of this change. A PCIe virtio device is, by default, modern mode only, but the qtest logic doesn't handle modern-only virtio devices correctly. We work around this by explicitly adding disable-legacy=off to the testcases. It would probably be better to update libqos so that it can handle modern virtio devices.
David Gibson (3):
pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid"
devices
pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
pseries: Allow PCIe virtio and XHCI on pseries machine typehw/pci/pci.c | 14 ++++++++++++++ hw/ppc/spapr_pci.c | 9 +++++++++ hw/usb/hcd-xhci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/hw/pci/pci.h | 1 + include/hw/pci/pci_host.h | 1 + tests/virtio-9p-test.c | 2 +- tests/virtio-blk-test.c | 4 ++-- tests/virtio-net-test.c | 2 +- tests/virtio-scsi-test.c | 2 +- 10 files changed, 32 insertions(+), 8 deletions(-)Signature · 1 line
2.9.3
Signature · 1 line
Eduardo