docs: add PCIe devices placement guidelines
PATCH RESEND v2 1/1 docs: add PCIe devices placement guidelines
Proposes best practices on how to use PCI Express/PCI device in PCI Express based machines and explain the reasoning behind them.
---
Hi,
I am sending the doc twice, it appears the first time didn't make it to qemu-devel list.
RFC->v2:
- Addressed a lot of comments from the reviewers (many thanks to all, especially to Laszlo)
Since the RFC mail-thread was relatively long and already has passed a lot of time from the RFC, I post this version even if is very possible that I left some of the comments out, my apologies if so.
I will go over the comments again, in the meantime please feel free to comment on this version, even if on something you've already pointed out.
It may take a day or two until I'll be able to respond, but I will do my best to address all comments.
Thanks,
Marcel
docs/pcie.txt | 273 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 docs/pcie.txt
docs/pcie.txt new file +273 -0
@@ -0,0 +1,273 @@ +PCI EXPRESS GUIDELINES +====================== + +1. Introduction +================ +The doc proposes best practices on how to use PCI Express/PCI device +in PCI Express based machines and explains the reasoning behind them. + + +2. Device placement strategy +============================ +QEMU does not have a clear socket-device matching mechanism +and allows any PCI/PCI Express device to be plugged into any PCI/PCI Express slot. +Plugging a PCI device into a PCI Express slot might not always work and +is weird anyway since it cannot be done for "bare metal". +Plugging a PCI Express device into a PCI slot will hide the Extended +Configuration Space thus is also not recommended. + +The recommendation is to separate the PCI Express and PCI hierarchies. +PCI Express devices should be plugged only into PCI Express Root Ports and +PCI Express Downstream ports. + +2.1 Root Bus (pcie.0) +===================== +Place only the following kinds of devices directly on the Root Complex: + (1) Devices with dedicated, specific functionality (network card, + graphics card, IDE controller, etc); place only legacy PCI devices on + the Root Complex. These will be considered Integrated Endpoints. + Note: Integrated devices are not hot-pluggable. + + Although the PCI Express spec does not forbid PCI Express devices as + Integrated Endpoints, existing hardware mostly integrates legacy PCI + devices with the Root Complex. Guest OSes are suspected to behave + strangely when PCI Express devices are integrated with the Root Complex. + + (2) PCI Express Root Ports (ioh3420), for starting exclusively PCI Express + hierarchies. + + (3) DMI-PCI bridges (i82801b11-bridge), for starting legacy PCI hierarchies. + + (4) Extra Root Complexes (pxb-pcie), if multiple PCIe Root Buses are needed. + + pcie.0 bus + ----------------------------------------------------------------------------- + | | | | + ----------- ------------------ ------------------ -------------- + | PCI Dev | | PCIe Root Port | | DMI-PCI bridge | | pxb-pcie | + ----------- ------------------ ------------------ -------------- + +2.1.1 To plug a device into a pcie.0 as Root Complex Integrated Device use: + -device <dev>[,bus=pcie.0] +2.1.2 To expose a new PCI Express Root Bus use: + -device pxb-pcie,id=pcie.1,bus_nr=x,[numa_node=y],[addr=z] + Only PCI Express Root Ports and DMI-PCI bridges can be connected to the pcie.1 bus: + -device ioh3420,id=root_port1[,bus=pcie.1][,chassis=x][,slot=y][,addr=z] \ + -device i82801b11-bridge,id=dmi_pci_bridge1,bus=pcie.1 + + +2.2 PCI Express only hierarchy +============================== +Always use PCI Express Root Ports to start PCI Express hierarchies. + +A PCI Express Root bus supports up to 32 devices. Since each +PCI Express Root Port is a function and a multi-function +device may support up to 8 functions, the maximum possible +PCI Express Root Ports per PCI Express Root Bus is 256. + +Prefer coupling PCI Express Root Ports into multi-function devices +to keep a simple flat hierarchy that is enough for most scenarios. +Only use PCI Express Switches (x3130-upstream, xio3130-downstream) +if there is no more room for PCI Express Root Ports. +Please see section 4. for further justifications. + +Plug only PCI Express devices into PCI Express Ports. + + + pcie.0 bus + ---------------------------------------------------------------------------------- + | | | + ------------- ------------- ------------- + | Root Port | | Root Port | | Root Port | + ------------ ------------- ------------- + | -------------------------|------------------------ + ------------ | ----------------- | + | PCIe Dev | | PCI Express | Upstream Port | | + ------------ | Switch ----------------- | + | | | | + | ------------------- ------------------- | + | | Downstream Port | | Downstream Port | | + | ------------------- ------------------- | + -------------|-----------------------|------------ + ------------ + | PCIe Dev | + ------------ + +2.2.1 Plugging a PCI Express device into a PCI Express Root Port: + -device ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \ + -device <dev>,bus=root_port1 + Note that chassis parameter is compulsory, and must be unique + for each PCI Express Root Port. +2.2.2 Using multi-function PCI Express Root Ports: + -device ioh3420,id=root_port1,multifunction=on,chassis=x[,bus=pcie.0][,slot=y][,addr=z.0] \ + -device ioh3420,id=root_port2,,chassis=x1[,bus=pcie.0][,slot=y1][,addr=z.1] \ + -device ioh3420,id=root_port3,,chassis=x2[,bus=pcie.0][,slot=y2][,addr=z.2] \ +2.2.2 Plugging a PCI Express device into a Switch: + -device ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \ + -device x3130-upstream,id=upstream_port1,bus=root_port1[,addr=x] \ + -device xio3130-downstream,id=downstream_port1,bus=upstream_port1,chassis=x1[,slot=y1][,addr=z1]] \ + -device <dev>,bus=downstream_port1 + + +2.3 PCI only hierarchy +====================== +Legacy PCI devices can be plugged into pcie.0 as Integrated Devices. +Besides that use DMI-PCI bridges (i82801b11-bridge) to start PCI hierarchies. + +Prefer flat hierarchies. For most scenarios a single DMI-PCI bridge (having 32 slots) +and several PCI-PCI bridges attached to it (each supporting also 32 slots) will support +hundreds of legacy devices. The recommendation is to populate one PCI-PCI bridge +under the DMI-PCI bridge until is full and then plug a new PCI-PCI bridge... + + pcie.0 bus + ---------------------------------------------- + | | + ----------- ------------------ + | PCI Dev | | DMI-PCI BRIDGE | + ---------- ------------------ + | | + ----------- ------------------ + | PCI Dev | | PCI-PCI Bridge | + ----------- ------------------ + | | + ----------- ----------- + | PCI Dev | | PCI Dev | + ----------- ----------- + +2.3.1 To plug a PCI device into a pcie.0 as Integrated Device use: + -device <dev>[,bus=pcie.0] +2.3.2 Plugging a PCI device into a DMI-PCI bridge: + -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device <dev>,bus=dmi_pci_bridge1[,addr=x] +2.3.3 Plugging a PCI device into a PCI-PCI bridge: + -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device pci-bridge,id=pci_bridge1,bus=dmi_pci_bridge1[,chassis_nr=x][,addr=y] \ + -device <dev>,bus=pci_bridge1[,addr=x] + + +3. IO space issues +=================== +The PCI Express Root Ports and PCI Express Downstream ports are seen by +Firmware/Guest OS as PCI-PCI bridges and, as required by PCI spec, +should reserve a 4K IO range for each even if only one (multifunction) +device can be plugged into them, resulting in poor IO space utilization. + +The firmware used by QEMU (SeaBIOS/OVMF) may try further optimizations +by not allocating IO space if possible: + (1) - For empty PCI Express Root Ports/PCI Express Downstream ports. + (2) - If the device behind the PCI Express Root Ports/PCI Express + Downstream has no IO BARs. + +The IO space is very limited, 65536 byte-wide IO ports, but it's fragmented +resulting in ~10 PCI Express Root Ports (or PCI Express Downstream/Upstream ports) +ports per system if devices with IO BARs are used in the PCI Express hierarchy. + +Using the proposed device placing strategy solves this issue +by using only PCI Express devices within PCI Express hierarchy. + +The PCI Express spec requires the PCI Express devices to work without using IO. +The PCI hierarchy has no such limitations. + + +4. Bus numbers issues +====================== +Each PCI domain can have up to only 256 buses and the QEMU PCI Express +machines do not support multiple PCI domains even if extra Root +Complexes (pxb-pcie) are used. + +Each element of the PCI Express hierarchy (Root Complexes, +PCI Express Root Ports, PCI Express Downstream/Upstream ports) +takes up bus numbers. Since only one (multifunction) device +can be attached to a PCI Express Root Port or PCI Express Downstream +Port it is advised to plan in advance for the expected number of +devices to prevent bus numbers starvation. + + +5. Hot Plug +============ +The PCI Express root buses (pcie.0 and the buses exposed by pxb-pcie devices) +do not support hot-plug, so any devices plugged into Root Complexes +cannot be hot-plugged/hot-unplugged: + (1) PCI Express Integrated Devices + (2) PCI Express Root Ports + (3) DMI-PCI bridges + (4) pxb-pcie + +PCI devices can be hot-plugged into PCI-PCI bridges, however cannot +be hot-plugged into DMI-PCI bridges. +The PCI hotplug is ACPI based and can work side by side with the +PCI Express native hotplug. + +PCI Express devices can be natively hot-plugged/hot-unplugged into/from +PCI Express Root Ports (and PCI Express Downstream Ports). + +5.1 Planning for hotplug: + (1) PCI hierarchy + Leave enough PCI-PCI bridge slots empty or add one + or more empty PCI-PCI bridges to the DMI-PCI bridge. + + For each such bridge the Guest Firmware is expected to reserve 4K IO + space and 2M MMIO range to be used for all devices behind it. + + Because of the hard IO limit of around 10 PCI bridges (~ 40K space) per system + don't use more than 9 bridges, leaving 4K for the Integrated devices + and none for the PCI Express Hierarchy. + + (2) PCI Express hierarchy: + Leave enough PCI Express Root Ports empty. Use multifunction + PCI Express Root Ports to prevent going out of PCI bus numbers. + Don't use PCI Express Switches if you don't have too, they use + an extra PCI bus that may handy to plug another device id it comes to it. + +5.3 Hot plug example: +Using HMP: (add -monitor stdio to QEMU command line) + device_add <dev>,id=<id>,bus=<pcie.0/PCI Express Root Port Id/PCI-PCI bridge Id/pxb-pcie Id> + + +6. Device assignment +==================== +Host devices are mostly PCI Express and should be plugged only into +PCI Express Root Ports or PCI Express Downstream Ports. +PCI-PCI bridge slots can be used for legacy PCI host devices. + +6.1 How to detect if a device is PCI Express: + > lspci -s 03:00.0 -v (as root) + + 03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83) + Subsystem: Intel Corporation Dual Band Wireless-AC 7260 + Flags: bus master, fast devsel, latency 0, IRQ 50 + Memory at f0400000 (64-bit, non-prefetchable) [size=8K] + Capabilities: [c8] Power Management version 3 + Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ + Capabilities: [40] Express Endpoint, MSI 00 + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Capabilities: [100] Advanced Error Reporting + Capabilities: [140] Device Serial Number 7c-7a-91-ff-ff-90-db-20 + Capabilities: [14c] Latency Tolerance Reporting + Capabilities: [154] Vendor Specific Information: ID=cafe Rev=1 Len=014 + + +7. Virtio devices +================= +Virtio devices plugged into the PCI hierarchy or as Integrated Devices +will remain PCI and have transitional behaviour as default. +Transitional virtio devices work in both IO and MMIO modes depending on +the guest support. + +Virtio devices plugged into PCI Express ports are PCI Express devices and +have "1.0" behavior by default without IO support. +In both case disable-* properties can be used to override the behaviour. + +Note that setting disable-legacy=off will enable legacy mode (enabling +legacy behavior) for PCI Express virtio devices causing them to +require IO space, which, given our PCI Express hierarchy, may quickly +lead to resource exhaustion, and is therefore strongly discouraged. + + +8. Conclusion +============== +The proposal offers a usage model that is easy to understand and follow +and in the same time overcomes the PCI Express architecture limitations. +
Signature · 1 line
2.5.5
Quoted 9 lines · Marcel Apfelbaum
Proposes best practices on how to use PCI Express/PCI device in PCI Express based machines and explain the reasoning behind them.
Signed-off-by Marcel Apfelbaum <[email protected]>---
Hi,
I am sending the doc twice, it appears the first time didn't make it to qemu-devel list.
Hi,
Adding people to CC. Sorry for the earlier noise.
Thanks,
Marcel
Quoted 304 lines
RFC->v2:
- Addressed a lot of comments from the reviewers (many thanks to all, especially to Laszlo)Since the RFC mail-thread was relatively long and already has passed a lot of time from the RFC, I post this version even if is very possible that I left some of the comments out, my apologies if so.
I will go over the comments again, in the meantime please feel free to comment on this version, even if on something you've already pointed out.
It may take a day or two until I'll be able to respond, but I will do my best to address all comments.
Thanks,
Marceldocs/pcie.txt | 273 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 docs/pcie.txtdocs/pcie.txt new file +273
-0@@ -0,0 +1,273 @@ +PCI EXPRESS GUIDELINES +====================== + +1. Introduction +================ +The doc proposes best practices on how to use PCI Express/PCI device +in PCI Express based machines and explains the reasoning behind them. + + +2. Device placement strategy +============================ +QEMU does not have a clear socket-device matching mechanism +and allows any PCI/PCI Express device to be plugged into any PCI/PCI Express slot. +Plugging a PCI device into a PCI Express slot might not always work and +is weird anyway since it cannot be done for "bare metal". +Plugging a PCI Express device into a PCI slot will hide the Extended +Configuration Space thus is also not recommended. + +The recommendation is to separate the PCI Express and PCI hierarchies. +PCI Express devices should be plugged only into PCI Express Root Ports and +PCI Express Downstream ports. + +2.1 Root Bus (pcie.0) +===================== +Place only the following kinds of devices directly on the Root Complex: + (1) Devices with dedicated, specific functionality (network card, + graphics card, IDE controller, etc); place only legacy PCI devices on + the Root Complex. These will be considered Integrated Endpoints. + Note: Integrated devices are not hot-pluggable. + + Although the PCI Express spec does not forbid PCI Express devices as + Integrated Endpoints, existing hardware mostly integrates legacy PCI + devices with the Root Complex. Guest OSes are suspected to behave + strangely when PCI Express devices are integrated with the Root Complex. + + (2) PCI Express Root Ports (ioh3420), for starting exclusively PCI Express + hierarchies. + + (3) DMI-PCI bridges (i82801b11-bridge), for starting legacy PCI hierarchies. + + (4) Extra Root Complexes (pxb-pcie), if multiple PCIe Root Buses are needed. + + pcie.0 bus + ----------------------------------------------------------------------------- + | | | | + ----------- ------------------ ------------------ -------------- + | PCI Dev | | PCIe Root Port | | DMI-PCI bridge | | pxb-pcie | + ----------- ------------------ ------------------ -------------- + +2.1.1 To plug a device into a pcie.0 as Root Complex Integrated Device use: + -device <dev>[,bus=pcie.0] +2.1.2 To expose a new PCI Express Root Bus use: + -device pxb-pcie,id=pcie.1,bus_nr=x,[numa_node=y],[addr=z] + Only PCI Express Root Ports and DMI-PCI bridges can be connected to the pcie.1 bus: + -device ioh3420,id=root_port1[,bus=pcie.1][,chassis=x][,slot=y][,addr=z] \ + -device i82801b11-bridge,id=dmi_pci_bridge1,bus=pcie.1 + + +2.2 PCI Express only hierarchy +============================== +Always use PCI Express Root Ports to start PCI Express hierarchies. + +A PCI Express Root bus supports up to 32 devices. Since each +PCI Express Root Port is a function and a multi-function +device may support up to 8 functions, the maximum possible +PCI Express Root Ports per PCI Express Root Bus is 256. + +Prefer coupling PCI Express Root Ports into multi-function devices +to keep a simple flat hierarchy that is enough for most scenarios. +Only use PCI Express Switches (x3130-upstream, xio3130-downstream) +if there is no more room for PCI Express Root Ports. +Please see section 4. for further justifications. + +Plug only PCI Express devices into PCI Express Ports. + + + pcie.0 bus + ---------------------------------------------------------------------------------- + | | | + ------------- ------------- ------------- + | Root Port | | Root Port | | Root Port | + ------------ ------------- ------------- + | -------------------------|------------------------ + ------------ | ----------------- | + | PCIe Dev | | PCI Express | Upstream Port | | + ------------ | Switch ----------------- | + | | | | + | ------------------- ------------------- | + | | Downstream Port | | Downstream Port | | + | ------------------- ------------------- | + -------------|-----------------------|------------ + ------------ + | PCIe Dev | + ------------ + +2.2.1 Plugging a PCI Express device into a PCI Express Root Port: + -device ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \ + -device <dev>,bus=root_port1 + Note that chassis parameter is compulsory, and must be unique + for each PCI Express Root Port. +2.2.2 Using multi-function PCI Express Root Ports: + -device ioh3420,id=root_port1,multifunction=on,chassis=x[,bus=pcie.0][,slot=y][,addr=z.0] \ + -device ioh3420,id=root_port2,,chassis=x1[,bus=pcie.0][,slot=y1][,addr=z.1] \ + -device ioh3420,id=root_port3,,chassis=x2[,bus=pcie.0][,slot=y2][,addr=z.2] \ +2.2.2 Plugging a PCI Express device into a Switch: + -device ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \ + -device x3130-upstream,id=upstream_port1,bus=root_port1[,addr=x] \ + -device xio3130-downstream,id=downstream_port1,bus=upstream_port1,chassis=x1[,slot=y1][,addr=z1]] \ + -device <dev>,bus=downstream_port1 + + +2.3 PCI only hierarchy +====================== +Legacy PCI devices can be plugged into pcie.0 as Integrated Devices. +Besides that use DMI-PCI bridges (i82801b11-bridge) to start PCI hierarchies. + +Prefer flat hierarchies. For most scenarios a single DMI-PCI bridge (having 32 slots) +and several PCI-PCI bridges attached to it (each supporting also 32 slots) will support +hundreds of legacy devices. The recommendation is to populate one PCI-PCI bridge +under the DMI-PCI bridge until is full and then plug a new PCI-PCI bridge... + + pcie.0 bus + ---------------------------------------------- + | | + ----------- ------------------ + | PCI Dev | | DMI-PCI BRIDGE | + ---------- ------------------ + | | + ----------- ------------------ + | PCI Dev | | PCI-PCI Bridge | + ----------- ------------------ + | | + ----------- ----------- + | PCI Dev | | PCI Dev | + ----------- ----------- + +2.3.1 To plug a PCI device into a pcie.0 as Integrated Device use: + -device <dev>[,bus=pcie.0] +2.3.2 Plugging a PCI device into a DMI-PCI bridge: + -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device <dev>,bus=dmi_pci_bridge1[,addr=x] +2.3.3 Plugging a PCI device into a PCI-PCI bridge: + -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device pci-bridge,id=pci_bridge1,bus=dmi_pci_bridge1[,chassis_nr=x][,addr=y] \ + -device <dev>,bus=pci_bridge1[,addr=x] + + +3. IO space issues +=================== +The PCI Express Root Ports and PCI Express Downstream ports are seen by +Firmware/Guest OS as PCI-PCI bridges and, as required by PCI spec, +should reserve a 4K IO range for each even if only one (multifunction) +device can be plugged into them, resulting in poor IO space utilization. + +The firmware used by QEMU (SeaBIOS/OVMF) may try further optimizations +by not allocating IO space if possible: + (1) - For empty PCI Express Root Ports/PCI Express Downstream ports. + (2) - If the device behind the PCI Express Root Ports/PCI Express + Downstream has no IO BARs. + +The IO space is very limited, 65536 byte-wide IO ports, but it's fragmented +resulting in ~10 PCI Express Root Ports (or PCI Express Downstream/Upstream ports) +ports per system if devices with IO BARs are used in the PCI Express hierarchy. + +Using the proposed device placing strategy solves this issue +by using only PCI Express devices within PCI Express hierarchy. + +The PCI Express spec requires the PCI Express devices to work without using IO. +The PCI hierarchy has no such limitations. + + +4. Bus numbers issues +====================== +Each PCI domain can have up to only 256 buses and the QEMU PCI Express +machines do not support multiple PCI domains even if extra Root +Complexes (pxb-pcie) are used. + +Each element of the PCI Express hierarchy (Root Complexes, +PCI Express Root Ports, PCI Express Downstream/Upstream ports) +takes up bus numbers. Since only one (multifunction) device +can be attached to a PCI Express Root Port or PCI Express Downstream +Port it is advised to plan in advance for the expected number of +devices to prevent bus numbers starvation. + + +5. Hot Plug +============ +The PCI Express root buses (pcie.0 and the buses exposed by pxb-pcie devices) +do not support hot-plug, so any devices plugged into Root Complexes +cannot be hot-plugged/hot-unplugged: + (1) PCI Express Integrated Devices + (2) PCI Express Root Ports + (3) DMI-PCI bridges + (4) pxb-pcie + +PCI devices can be hot-plugged into PCI-PCI bridges, however cannot +be hot-plugged into DMI-PCI bridges. +The PCI hotplug is ACPI based and can work side by side with the +PCI Express native hotplug. + +PCI Express devices can be natively hot-plugged/hot-unplugged into/from +PCI Express Root Ports (and PCI Express Downstream Ports). + +5.1 Planning for hotplug: + (1) PCI hierarchy + Leave enough PCI-PCI bridge slots empty or add one + or more empty PCI-PCI bridges to the DMI-PCI bridge. + + For each such bridge the Guest Firmware is expected to reserve 4K IO + space and 2M MMIO range to be used for all devices behind it. + + Because of the hard IO limit of around 10 PCI bridges (~ 40K space) per system + don't use more than 9 bridges, leaving 4K for the Integrated devices + and none for the PCI Express Hierarchy. + + (2) PCI Express hierarchy: + Leave enough PCI Express Root Ports empty. Use multifunction + PCI Express Root Ports to prevent going out of PCI bus numbers. + Don't use PCI Express Switches if you don't have too, they use + an extra PCI bus that may handy to plug another device id it comes to it. + +5.3 Hot plug example: +Using HMP: (add -monitor stdio to QEMU command line) + device_add <dev>,id=<id>,bus=<pcie.0/PCI Express Root Port Id/PCI-PCI bridge Id/pxb-pcie Id> + + +6. Device assignment +==================== +Host devices are mostly PCI Express and should be plugged only into +PCI Express Root Ports or PCI Express Downstream Ports. +PCI-PCI bridge slots can be used for legacy PCI host devices. + +6.1 How to detect if a device is PCI Express: + > lspci -s 03:00.0 -v (as root) + + 03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83) + Subsystem: Intel Corporation Dual Band Wireless-AC 7260 + Flags: bus master, fast devsel, latency 0, IRQ 50 + Memory at f0400000 (64-bit, non-prefetchable) [size=8K] + Capabilities: [c8] Power Management version 3 + Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ + Capabilities: [40] Express Endpoint, MSI 00 + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Capabilities: [100] Advanced Error Reporting + Capabilities: [140] Device Serial Number 7c-7a-91-ff-ff-90-db-20 + Capabilities: [14c] Latency Tolerance Reporting + Capabilities: [154] Vendor Specific Information: ID=cafe Rev=1 Len=014 + + +7. Virtio devices +================= +Virtio devices plugged into the PCI hierarchy or as Integrated Devices +will remain PCI and have transitional behaviour as default. +Transitional virtio devices work in both IO and MMIO modes depending on +the guest support. + +Virtio devices plugged into PCI Express ports are PCI Express devices and +have "1.0" behavior by default without IO support. +In both case disable-* properties can be used to override the behaviour. + +Note that setting disable-legacy=off will enable legacy mode (enabling +legacy behavior) for PCI Express virtio devices causing them to +require IO space, which, given our PCI Express hierarchy, may quickly +lead to resource exhaustion, and is therefore strongly discouraged. + + +8. Conclusion +============== +The proposal offers a usage model that is easy to understand and follow +and in the same time overcomes the PCI Express architecture limitations. +
Quoted 57 lines · Marcel Apfelbaum
Quoted 10 lines · Marcel Apfelbaum
Proposes best practices on how to use PCI Express/PCI device in PCI Express based machines and explain the reasoning behind them.
Signed-off-by Marcel Apfelbaum <[email protected]>---
Hi,
I am sending the doc twice, it appears the first time didn't make it to qemu-devel list.
Hi,
Adding people to CC. Sorry for the earlier noise.
Thanks,
MarcelQuoted 38 lines
RFC->v2:
- Addressed a lot of comments from the reviewers (many thanks to all,
especially to Laszlo)Since the RFC mail-thread was relatively long and already has passed a lot of time from the RFC, I post this version even if is very possible that I left some of the comments out, my apologies if so.
I will go over the comments again, in the meantime please feel free to comment on this version, even if on something you've already pointed out.
It may take a day or two until I'll be able to respond, but I will do my best to address all comments.
Thanks,
Marceldocs/pcie.txt | 273 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 docs/pcie.txtdocs/pcie.txt new file +6
-0@@ -0,0 +1,273 @@ +PCI EXPRESS GUIDELINES +====================== + +1. Introduction +================ +The doc proposes best practices on how to use PCI Express/PCI device
Quoted 8 lines
Quoted 8 lines
docs/pcie.txt new file +7
-0+in PCI Express based machines and explains the reasoning behind them. + + +2. Device placement strategy +============================ +QEMU does not have a clear socket-device matching mechanism +and allows any PCI/PCI Express device to be plugged into any PCI/PCIExpress slot.
{1} This line seems too long; I suggest to rewrap the entire document at 79 chars (except command line fragments where the wrapping would be impractical).
Quoted 7 lines
Quoted 7 lines
docs/pcie.txt new file +7
-0+Plugging a PCI device into a PCI Express slot might not always work and +is weird anyway since it cannot be done for "bare metal". +Plugging a PCI Express device into a PCI slot will hide the Extended +Configuration Space thus is also not recommended. + +The recommendation is to separate the PCI Express and PCI hierarchies. +PCI Express devices should be plugged only into PCI Express Root
Quoted 8 lines
docs/pcie.txt
Quoted 8 lines
Ports and
docs/pcie.txt new file +7
-0+PCI Express Downstream ports. + +2.1 Root Bus (pcie.0) +===================== +Place only the following kinds of devices directly on the Root Complex: + (1) Devices with dedicated, specific functionality (network card, + graphics card, IDE controller, etc); place only legacy PCI
{2} I recommend to replace the semicolon (;) with a colon (:) here.
Quoted 14 lines
Quoted 14 lines
devices on
docs/pcie.txt new file +4
-0+ the Root Complex. These will be considered Integrated Endpoints. + Note: Integrated devices are not hot-pluggable. + + Although the PCI Express spec does not forbid PCI Expressdevices as
+ Integrated Endpoints, existing hardware mostly integrates
legacy PCI
+ devices with the Root Complex. Guest OSes are suspected to
behave
+ strangely when PCI Express devices are integrated with the
Root Complex.docs/pcie.txt new file +2
-0+ + (2) PCI Express Root Ports (ioh3420), for starting exclusively
Quoted 8 lines
Quoted 8 lines
PCI Express
docs/pcie.txt new file +3
-0+ hierarchies. + + (3) DMI-PCI bridges (i82801b11-bridge), for starting legacy PCIhierarchies.
docs/pcie.txt new file +2
-0+ + (4) Extra Root Complexes (pxb-pcie), if multiple PCIe Root Busesare needed.
{3} s/PCIe/PCI Express/, please :)
Quoted 5 lines
Quoted 5 lines
docs/pcie.txt new file +3
-1+ + pcie.0 bus + -----------------------------------------------------------------------------
Quoted 9 lines
docs/pcie.txt
Quoted 9 lines
docs/pcie.txt new file +3
-1+ | | | | + ----------- ------------------ ------------------ -------------- + | PCI Dev | | PCIe Root Port | | DMI-PCI bridge | |pxb-pcie |
docs/pcie.txt new file +3
-1+ ----------- ------------------ ------------------ -------------- + +2.1.1 To plug a device into a pcie.0 as Root Complex Integrated
{4} s/a pcie.0 as/pcie.0 as a/
Quoted 4 lines
docs/pcie.txt line 53
Quoted 4 lines
Device use:
docs/pcie.txt new file +3
-0+ -device <dev>[,bus=pcie.0] +2.1.2 To expose a new PCI Express Root Bus use: + -device pxb-pcie,id=pcie.1,bus_nr=x,[numa_node=y],[addr=z]
{5} I think the commas should be moved into the brackets (like below).
Quoted 7 lines
Quoted 7 lines
+ Only PCI Express Root Ports and DMI-PCI bridges can be
connected to the pcie.1 bus:
+ -device
ioh3420,id=root_port1[,bus=pcie.1][,chassis=x][,slot=y][,addr=z] \docs/pcie.txt new file +3
-0+ -device i82801b11-bridge,id=dmi_pci_bridge1,bus=pcie.1 + +
Quoted 8 lines
docs/pcie.txt line 66
Quoted 8 lines
+2.2 PCI Express only hierarchy
+==============================docs/pcie.txt new file +6
-0+Always use PCI Express Root Ports to start PCI Express hierarchies. + +A PCI Express Root bus supports up to 32 devices. Since each +PCI Express Root Port is a function and a multi-function +device may support up to 8 functions, the maximum possible +PCI Express Root Ports per PCI Express Root Bus is 256.
{6} s/maximum possible/maximum possible number of/, I suggest
Quoted 38 lines
Quoted 38 lines
docs/pcie.txt new file +19
-3+ +Prefer coupling PCI Express Root Ports into multi-function devices +to keep a simple flat hierarchy that is enough for most scenarios. +Only use PCI Express Switches (x3130-upstream, xio3130-downstream) +if there is no more room for PCI Express Root Ports. +Please see section 4. for further justifications. + +Plug only PCI Express devices into PCI Express Ports. + + + pcie.0 bus + ---------------------------------------------------------------------------------- + | | | + ------------- ------------- ------------- + | Root Port | | Root Port | | Root Port | + ------------ ------------- ------------- + | -------------------------|------------------------ + ------------ | ----------------- | + | PCIe Dev | | PCI Express | UpstreamPort | |
docs/pcie.txt new file +2
-1+ ------------ | Switch ----------------- | + | || |
docs/pcie.txt new file +2
-1+ | ------------------- ------------------- | + | | Downstream Port | |Downstream Port | |
docs/pcie.txt new file +4
-2+ | ------------------- ------------------- | + -------------|-----------------------|------------ + ------------ + | PCIe Dev |
Quoted 8 lines
docs/pcie.txt line 100
Quoted 8 lines
docs/pcie.txt new file +4
-0+ ------------ + +2.2.1 Plugging a PCI Express device into a PCI Express Root Port: + -deviceioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \
docs/pcie.txt new file +3
-0+ -device <dev>,bus=root_port1 + Note that chassis parameter is compulsory, and must be unique + for each PCI Express Root Port.
{7} Hmmm, I think it's rather that the (chassis, slot) *pair* must be unique. You can get away with leaving the default chassis=0 unspecified, and spell out just the slots, I think.
Quoted 8 lines
Quoted 8 lines
+2.2.2 Using multi-function PCI Express Root Ports:
+ -device
ioh3420,id=root_port1,multifunction=on,chassis=x[,bus=pcie.0][,slot=y][,addr=z.0] \
+ -device
ioh3420,id=root_port2,,chassis=x1[,bus=pcie.0][,slot=y1][,addr=z.1] \
+ -device
ioh3420,id=root_port3,,chassis=x2[,bus=pcie.0][,slot=y2][,addr=z.2] \
{8} This looks good to me, except for the double-comma typos: ",,".
Quoted 10 lines
docs/pcie.txt
Quoted 10 lines
+2.2.2 Plugging a PCI Express device into a Switch:
+ -device
ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \
+ -device
x3130-upstream,id=upstream_port1,bus=root_port1[,addr=x] \
+ -device
xio3130-downstream,id=downstream_port1,bus=upstream_port1,chassis=x1[,slot=y1][,addr=z1]] \docs/pcie.txt new file +2
-0+ -device <dev>,bus=downstream_port1 +
{9} For all of these command lines, can you specify if z=0 (that is, device#0) is valid or not in the addr=z properties?
Earlier discussion on this question:
Quoted 12 lines · Laine Stump
Quoted 2 lines · Alex Williamson
Same with the restriction from using slot
0 on PCI bridges, there's no basis for that except on the root bus.I tried allowing devices to be plugged into slot 0 of a pci-bridge in libvirt - qemu barfed, so I moved the "minSlot" for pci-bridge back up to 1. Slot 0 is completely usable on a dmi-to-pci-bridge though (and libvirt allows it). At this point, even if qemu enabled using slot 0 of a pci-bridge, libvirt wouldn't be able to expose that to users (unless the min/max slot of each PCI controller was made visible somewhere via QMP)
Quoted 4 lines · Marcel Apfelbaum
The reason for not being able to plug a device into slot 0 of a PCI Bridge is the SHPC (Hot-plug controller) device embedded in the PCI bridge by default. The SHPC spec requires this. If one disables it with shpc=false, he should be able to use the slot 0.
For simplicity's sake I guess we should just recommend >=1 slot numbers.
Back to the patch:
Quoted 27 lines · Marcel Apfelbaum
Quoted 25 lines · Marcel Apfelbaum
docs/pcie.txt new file +5
-0+ +2.3 PCI only hierarchy +====================== +Legacy PCI devices can be plugged into pcie.0 as Integrated Devices. +Besides that use DMI-PCI bridges (i82801b11-bridge) to start PCIhierarchies.
docs/pcie.txt new file +2
-0+ +Prefer flat hierarchies. For most scenarios a single DMI-PCI bridge(having 32 slots)
+and several PCI-PCI bridges attached to it (each supporting also 32 slots) will support
+hundreds of legacy devices. The recommendation is to populate one PCI-PCI bridge
+under the DMI-PCI bridge until is full and then plug a new PCI-PCI bridge...docs/pcie.txt new file +10
-0+ + pcie.0 bus + ---------------------------------------------- + | | + ----------- ------------------ + | PCI Dev | | DMI-PCI BRIDGE | + ---------- ------------------ + | | + ----------- ------------------ + | PCI Dev | | PCI-PCI Bridge |
Quoted 8 lines
docs/pcie.txt line 138
Quoted 8 lines
docs/pcie.txt new file +8
-0+ ----------- ------------------ + | | + ----------- ----------- + | PCI Dev | | PCI Dev | + ----------- ----------- + +2.3.1 To plug a PCI device into a pcie.0 as Integrated Device use: + -device <dev>[,bus=pcie.0]
(This is repeated from 2.1.1, but I guess it doesn't hurt, for completeness in this chapter.)
Quoted 3 lines
docs/pcie.txt line 141
Quoted 3 lines
+2.3.2 Plugging a PCI device into a DMI-PCI bridge:
docs/pcie.txt new file +2
-0+ -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device <dev>,bus=dmi_pci_bridge1[,addr=x]
{10} I recall that we discussed this at length, that is, placing PCI (non-express) devices directly on the DMI-PCI bridge. IIRC the argument was that it's technically possible, it just won't support hot-plug.
I'd like if we removed this use case from the document. It might be possible, but for simplicity's sake, we shouldn't advertise it, in my opinion. (Unless someone strongly disagrees with this idea, of course.) I recall esp. Laine, Alex and Daniel focusing on this, but I don't remember if (and what for) they wanted this option. Personally I'd like to see it disappear (unless convinced otherwise).
... Actually, going through the RFC thread again, it seems that the use case that I'm arguing against -- i.e., "use DMI-PCI as a generic PCIe-to-PCI bridge" -- makes Alex cringe as well. So there's that :)
{11} Syntax remark, should we keep this section: the commas are not right in ",[,bus=pcie.0]".
Quoted 4 lines
Quoted 4 lines
+2.3.3 Plugging a PCI device into a PCI-PCI bridge:
+ -device
i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \
{12} double comma again
Quoted 4 lines
Quoted 4 lines
+ -device
pci-bridge,id=pci_bridge1,bus=dmi_pci_bridge1[,chassis_nr=x][,addr=y] \
+ -device <dev>,bus=pci_bridge1[,addr=x]
{13} It would be nice to spell out the valid device addresses (y and x) here too -- can we use 0 for them? SHPC again?
Can we / should we simply go with >=1 device addresses?
Quoted 8 lines
docs/pcie.txt line 153
Quoted 8 lines
docs/pcie.txt new file +8
-0+ + +3. IO space issues +=================== +The PCI Express Root Ports and PCI Express Downstream ports are seen by +Firmware/Guest OS as PCI-PCI bridges and, as required by PCI spec, +should reserve a 4K IO range for each even if only one (multifunction) +device can be plugged into them, resulting in poor IO space utilization.
{14} I completely agree with this paragraph, I'd just recommend to allow the reader more time to digest it. Something like:
----
The PCI Express Root Ports and PCI Express Downstream ports are seen by Firmware/Guest OS as PCI-PCI bridges. As required by the PCI spec, each such Port should be reserved a 4K IO range for, even though only one (multifunction) device can be plugged into each Port. This results in poor IO space utilization.
----
Quoted 6 lines
docs/pcie.txt line 159
Quoted 6 lines
docs/pcie.txt new file +6
-0+ +The firmware used by QEMU (SeaBIOS/OVMF) may try further optimizations +by not allocating IO space if possible: + (1) - For empty PCI Express Root Ports/PCI Express Downstream ports. + (2) - If the device behind the PCI Express Root Ports/PCI Express + Downstream has no IO BARs.
{15} I'd say:
... by not allocating IO space for each PCI Express Root / PCI Express Downstream port if:
(1) the port is empty, or
(2) the device behind the port has no IO BARs.
Quoted 3 lines
Quoted 3 lines
docs/pcie.txt new file +2
-0+ +The IO space is very limited, 65536 byte-wide IO ports, but it'sfragmented
{16} Suggestion: "The IO space is very limited, to 65536 byte-wide IO ports, and may even be fragmented by fixed IO ports owned by platform devices."
Quoted 1 line
Quoted 1 line
+resulting in ~10 PCI Express Root Ports (or PCI Express
{17} s/resulting in/resulting in at most/
Quoted 1 line
Quoted 1 line
Downstream/Upstream ports)
{18} Whoa, upstream ports? Why do we need to spell them out here? Upstream ports need their own bus numbers, but their IO space assignment only collects the IO space assignments of their downstream ports. Isn't that right?
(I believe spelling out upstream ports here was recommended by Alex, but I don't understand why.)
Quoted 1 line
Quoted 1 line
+ports per system if devices with IO BARs are used in the PCI Express
{19} The word "ports" is unnecessary here.
Quoted 8 lines
Quoted 8 lines
hierarchy.
docs/pcie.txt new file +5
-0+ +Using the proposed device placing strategy solves this issue +by using only PCI Express devices within PCI Express hierarchy. + +The PCI Express spec requires the PCI Express devices to work withoutusing IO.
+The PCI hierarchy has no such limitations.
{20} There should be no empty line (or even a line break) between the two above paragraphs: the second paragraph explains the first one.
Quoted 6 lines
Quoted 6 lines
docs/pcie.txt new file +6
-0+ + +4. Bus numbers issues +====================== +Each PCI domain can have up to only 256 buses and the QEMU PCI Express +machines do not support multiple PCI domains even if extra Root
Quoted 8 lines
docs/pcie.txt line 183
Quoted 8 lines
docs/pcie.txt new file +8
-0+Complexes (pxb-pcie) are used. + +Each element of the PCI Express hierarchy (Root Complexes, +PCI Express Root Ports, PCI Express Downstream/Upstream ports) +takes up bus numbers. Since only one (multifunction) device +can be attached to a PCI Express Root Port or PCI Express Downstream +Port it is advised to plan in advance for the expected number of +devices to prevent bus numbers starvation.
{21} Please add:
"""
In particular:
- Avoiding PCI Express Switches (and thereby striving for a flat PCI Express hierarchy) enables the hierarchy to not spend bus numbers on Upstream Ports.
- The bus_nr properties of the pxb-pcie devices partition the 0..255 bus number space. All bus numbers assigned to the buses recursively behind a given pxb-pcie device's root bus must fit between the bus_nr property of that pxb-pcie device, and the lowest of the higher bus_nr properties that the command line sets for other pxb-pcie devices.
"""
(You do mention switches being more bus number-hungry, under chapter 5, hotplug; however, saving bus numbers makes sense for a purely cold-plugged scenario as well, especially in combination with pxb-pcie, where the partitioning can become a limiting factor.)
Quoted 7 lines
Quoted 7 lines
docs/pcie.txt new file +5
-0+ + +5. Hot Plug +============ +The PCI Express root buses (pcie.0 and the buses exposed by pxb-pciedevices)
+do not support hot-plug, so any devices plugged into Root Complexes
Quoted 8 lines
docs/pcie.txt line 197
Quoted 8 lines
docs/pcie.txt new file +8
-0+cannot be hot-plugged/hot-unplugged: + (1) PCI Express Integrated Devices + (2) PCI Express Root Ports + (3) DMI-PCI bridges + (4) pxb-pcie + +PCI devices can be hot-plugged into PCI-PCI bridges, however cannot +be hot-plugged into DMI-PCI bridges.
{22} If you agree with my suggestion to remove 2.3.2, that is, the "PCI device cold-plugged directly into DMI-PCI bridge" case, then the second half of the sentence can be dropped.
Quoted 12 lines
Quoted 12 lines
docs/pcie.txt new file +12
-0+The PCI hotplug is ACPI based and can work side by side with the +PCI Express native hotplug. + +PCI Express devices can be natively hot-plugged/hot-unplugged into/from +PCI Express Root Ports (and PCI Express Downstream Ports). + +5.1 Planning for hotplug: + (1) PCI hierarchy + Leave enough PCI-PCI bridge slots empty or add one + or more empty PCI-PCI bridges to the DMI-PCI bridge. + + For each such bridge the Guest Firmware is expected to
Quoted 8 lines
Quoted 8 lines
reserve 4K IO
docs/pcie.txt new file +3
-0+ space and 2M MMIO range to be used for all devices behind it. + + Because of the hard IO limit of around 10 PCI bridges (~ 40Kspace) per system
+ don't use more than 9 bridges, leaving 4K for the Integrated
devices
+ and none for the PCI Express Hierarchy.
{23} s/9 bridges/9 PCI-PCI bridges/
Quoted 4 lines
docs/pcie.txt line 218
Quoted 4 lines
docs/pcie.txt new file +4
-0+ + (2) PCI Express hierarchy: + Leave enough PCI Express Root Ports empty. Use multifunction + PCI Express Root Ports to prevent going out of PCI bus numbers.
{24} I agree, but I'd put it a bit differently: use multifunction PCI Express Root Ports on the Root Complex(es), for keeping the hierarchy as flat as possible, thereby saving PCI bus numbers.
Quoted 4 lines
Quoted 4 lines
docs/pcie.txt new file +2
-0+ Don't use PCI Express Switches if you don't have too, they use + an extra PCI bus that may handy to plug another device id itcomes to it.
+
{25} I'd put it as: Don't use PCI Express Switches if you don't have too, each one of those uses an extra PCI bus (for its Upstream Port) that could be put to better use with another Root Port or Downstream Port, which may come handy for hotplugging another device.
{26} Another remark (important to me) in this section: the document doesn't state firmware expectations. It's clear the firmware is expected to reserve no IO space for PCI Express Downstream Ports and Root Ports, but what about MMIO?
We discussed this at length with Alex, but I think we didn't conclude anything. It would be nice if firmware received some instructions from this document in this regard, even before we implement our own ports and bridges in QEMU.
<digression>
If we think such recommendations are out of scope at this point, *and* noone disagrees strongly (Gerd?), then I could add some experimental fw_cfg knobs to OVMF for this, such as (units in MB):
-fw_cfg opt/org.tianocore.ovmf/X-ReservePciE/PrefMmio32Mb,string=... -fw_cfg opt/org.tianocore.ovmf/X-ReservePciE/NonPrefMmio32Mb,string=... -fw_cfg opt/org.tianocore.ovmf/X-ReservePciE/PrefMmio64Mb,string=.. -fw_cfg opt/org.tianocore.ovmf/X-ReservePciE/NonPrefMmio64Mb,string=..
Under this idea, I would reserve no resources at all for Downstream Ports and Root Ports in OVMF by default; but users could influence those reservations. I think that would be enough to kick things off. It also needs no modifications for QEMU.
</digression>
Quoted 4 lines
Quoted 4 lines
+5.3 Hot plug example:
docs/pcie.txt new file +2
-0+Using HMP: (add -monitor stdio to QEMU command line) + device_add <dev>,id=<id>,bus=<pcie.0/PCI Express Root PortId/PCI-PCI bridge Id/pxb-pcie Id>
{27} I think the bus=<...> part is incorrect here. Based on the rest of the guidelines, we have to specify the ID of:
- a PCI Express Root Port, or
- a PCI Express Downstream Port, or
- a PCI-PCI bridge.
Quoted 26 lines
Quoted 26 lines
docs/pcie.txt new file +25
-0+ + +6. Device assignment +==================== +Host devices are mostly PCI Express and should be plugged only into +PCI Express Root Ports or PCI Express Downstream Ports. +PCI-PCI bridge slots can be used for legacy PCI host devices. + +6.1 How to detect if a device is PCI Express: + > lspci -s 03:00.0 -v (as root) + + 03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83) + Subsystem: Intel Corporation Dual Band Wireless-AC 7260 + Flags: bus master, fast devsel, latency 0, IRQ 50 + Memory at f0400000 (64-bit, non-prefetchable) [size=8K] + Capabilities: [c8] Power Management version 3 + Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ + Capabilities: [40] Express Endpoint, MSI 00 + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Capabilities: [100] Advanced Error Reporting + Capabilities: [140] Device Serial Number 7c-7a-91-ff-ff-90-db-20 + Capabilities: [14c] Latency Tolerance Reporting + Capabilities: [154] Vendor Specific Information: ID=cafe Rev=1Len=014
Quoted 8 lines
docs/pcie.txt line 257
Quoted 8 lines
docs/pcie.txt new file +8
-0+ + +7. Virtio devices +================= +Virtio devices plugged into the PCI hierarchy or as Integrated Devices +will remain PCI and have transitional behaviour as default. +Transitional virtio devices work in both IO and MMIO modes depending on +the guest support.
{28} Suggest to add: firmware will assign both IO and MMIO resources to transitional virtio devices.
Quoted 5 lines
docs/pcie.txt line 261
Quoted 5 lines
docs/pcie.txt new file +2
-0+ +Virtio devices plugged into PCI Express ports are PCI Express devicesand
docs/pcie.txt new file +2
-0+have "1.0" behavior by default without IO support. +In both case disable-* properties can be used to override the behaviour.
{29} s/case/cases/; also, please spell out the disable-* properties fully.
Quoted 4 lines
docs/pcie.txt line 265
Quoted 4 lines
docs/pcie.txt new file +4
-0+ +Note that setting disable-legacy=off will enable legacy mode (enabling +legacy behavior) for PCI Express virtio devices causing them to +require IO space, which, given our PCI Express hierarchy, may quickly
{30} s/given our PCI Express hierarchy/given the limited available IO space/
Quoted 11 lines
docs/pcie.txt line 273
Quoted 9 lines
docs/pcie.txt new file +8
-0+lead to resource exhaustion, and is therefore strongly discouraged. + + +8. Conclusion +============== +The proposal offers a usage model that is easy to understand and follow +and in the same time overcomes the PCI Express architecture limitations. +
I think this version has seen big improvements, and I think it's structurally complete. While composing this review, I went through the entire RFC thread again, and I *think* you didn't miss anything from that. Great job again!
My comments vary in importance. I trust you to take each comment with an appropriately sized grain of salt ;)
Thank you!
Laszlo
Hi,
Quoted 9 lines
{26} Another remark (important to me) in this section: the document doesn't state firmware expectations. It's clear the firmware is expected to reserve no IO space for PCI Express Downstream Ports and Root Ports, but what about MMIO?
We discussed this at length with Alex, but I think we didn't conclude anything. It would be nice if firmware received some instructions from this document in this regard, even before we implement our own ports and bridges in QEMU.
Where do we stand in terms of generic pcie ports btw?
I think the plan is still to communicate suggestions to the firmware via pci config space, either by using reset defaults of the limit register, or of that doesn't work due to initialization order issues using some vendor specific pcie capability.
As long as we don't have that there is nothing do document, other than maybe briefly mentioning the plans we have and documenting the current state (2M mmio in seabios, and I think the same for ovmf).
The patches adding the generic ports can also update the documentation of course.
Quoted 5 lines
<digression>
If we think such recommendations are out of scope at this point, *and* noone disagrees strongly (Gerd?), then I could add some experimental
fw_cfgknobs to OVMF for this, such as (units in MB):
Why? Given that the virtio mmio bar size issue is solved I don't see a strong reason to hurry with this. Just wait until the generic ports are there.
cheers,
Gerd
Quoted 7 lines · Gerd Hoffmann
Hi,
Quoted 5 lines
{26} Another remark (important to me) in this section: the document doesn't state firmware expectations. It's clear the firmware is expected to reserve no IO space for PCI Express Downstream Ports and Root Ports, but what about MMIO?
Quoted 6 lines
Quoted 4 lines
We discussed this at length with Alex, but I think we didn't conclude anything. It would be nice if firmware received some instructions from this document in this regard, even before we implement our own ports and bridges in QEMU.
Where do we stand in terms of generic pcie ports btw?
"planning phase", AFAIR
Quoted 15 lines
I think the plan is still to communicate suggestions to the firmware via pci config space, either by using reset defaults of the limit register, or of that doesn't work due to initialization order issues using some vendor specific pcie capability.
As long as we don't have that there is nothing do document, other than maybe briefly mentioning the plans we have and documenting the current state (2M mmio in seabios, and I think the same for ovmf).
The patches adding the generic ports can also update the documentation of course.
Quoted 2 lines
<digression>
Quoted 7 lines
Quoted 3 lines
If we think such recommendations are out of scope at this point, *and* noone disagrees strongly (Gerd?), then I could add some experimental
fw_cfgknobs to OVMF for this, such as (units in MB):Why? Given that the virtio mmio bar size issue is solved I don't see a strong reason to hurry with this. Just wait until the generic ports are there.
Fine.
Quoted 8 lines · Laszlo Ersek
Quoted 7 lines · Gerd Hoffmann
Hi,
Quoted 5 lines
{26} Another remark (important to me) in this section: the document doesn't state firmware expectations. It's clear the firmware is expected to reserve no IO space for PCI Express Downstream Ports and Root Ports, but what about MMIO?
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
We discussed this at length with Alex, but I think we didn't conclude anything. It would be nice if firmware received some instructions from this document in this regard, even before we implement our own ports and bridges in QEMU.
Where do we stand in terms of generic pcie ports btw?
"planning phase", AFAIR
Indeed, I'll start working on it once this doc is finished. Thanks,
Marcel
Quoted 25 lines
Quoted 15 lines
I think the plan is still to communicate suggestions to the firmware via pci config space, either by using reset defaults of the limit register, or of that doesn't work due to initialization order issues using some vendor specific pcie capability.
As long as we don't have that there is nothing do document, other than maybe briefly mentioning the plans we have and documenting the current state (2M mmio in seabios, and I think the same for ovmf).
The patches adding the generic ports can also update the documentation of course.
Quoted 2 lines
<digression>
Quoted 7 lines
Quoted 3 lines
If we think such recommendations are out of scope at this point, *and* noone disagrees strongly (Gerd?), then I could add some experimental
fw_cfgknobs to OVMF for this, such as (units in MB):Why? Given that the virtio mmio bar size issue is solved I don't see a strong reason to hurry with this. Just wait until the generic ports are there.
Fine.
Quoted 13 lines · Laszlo Ersek
Quoted 12 lines · Marcel Apfelbaum
Quoted 10 lines · Marcel Apfelbaum
Proposes best practices on how to use PCI Express/PCI device in PCI Express based machines and explain the reasoning behind them.
Signed-off-by Marcel Apfelbaum <[email protected]>---
Hi,
I am sending the doc twice, it appears the first time didn't make it to qemu-devel list.
Quoted 8 lines
Quoted 8 lines
Hi,
Adding people to CC. Sorry for the earlier noise.
Thanks,
MarcelQuoted 1 line
Hi Laszlo,
Thanks for the review, I'll do my best to address all the comments in nest version.
[...]
Quoted 8 lines
Quoted 7 lines
docs/pcie.txt line 100
Quoted 7 lines
docs/pcie.txt new file +3
-0+ +2.2.1 Plugging a PCI Express device into a PCI Express Root Port: + -deviceioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \
docs/pcie.txt new file +3
-0+ -device <dev>,bus=root_port1 + Note that chassis parameter is compulsory, and must be unique + for each PCI Express Root Port.
Quoted 4 lines
{7} Hmmm, I think it's rather that the (chassis, slot) *pair* must be unique. You can get away with leaving the default chassis=0 unspecified, and spell out just the slots, I think.
Yes you can, I wanted to let the "slot" out of the equation and use the chassis as a known parameter from the PCI bridge - easier to digest. However your comment make sense, I'll update the doc.
Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
+2.2.2 Using multi-function PCI Express Root Ports:
+ -device
ioh3420,id=root_port1,multifunction=on,chassis=x[,bus=pcie.0][,slot=y][,addr=z.0] \
+ -device
ioh3420,id=root_port2,,chassis=x1[,bus=pcie.0][,slot=y1][,addr=z.1] \
+ -device
ioh3420,id=root_port3,,chassis=x2[,bus=pcie.0][,slot=y2][,addr=z.2] \{8} This looks good to me, except for the double-comma typos: ",,".
Quoted 10 lines
Review
Quoted 10 lines
+2.2.2 Plugging a PCI Express device into a Switch:
+ -device
ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \
+ -device
x3130-upstream,id=upstream_port1,bus=root_port1[,addr=x] \
+ -device
xio3130-downstream,id=downstream_port1,bus=upstream_port1,chassis=x1[,slot=y1][,addr=z1]] \(quoted diff) +2
-0+ -device <dev>,bus=downstream_port1 +
Quoted 3 lines
{9} For all of these command lines, can you specify if z=0 (that is, device#0) is valid or not in the addr=z properties?
Address 0 is valid for all PCI bridges (we see PCI Express Root/Upstream/Downstream/Ports as PCI bridges) that do not have an SHPC component.
Even the "regular" pci bridge can use slot 0 if we pass shpc=off as parameter.
For PCI Express slot 0 is always valid, this is why I didn't add it to the doc.
Quoted 16 lines
Earlier discussion on this question:
Quoted 5 lines · Laine Stump
Quoted 2 lines · Alex Williamson
Same with the restriction from using slot
0 on PCI bridges, there's no basis for that except on the root bus.Quoted 7 lines
I tried allowing devices to be plugged into slot 0 of a pci-bridge in libvirt - qemu barfed, so I moved the "minSlot" for pci-bridge back up to 1. Slot 0 is completely usable on a dmi-to-pci-bridge though (and libvirt allows it). At this point, even if qemu enabled using slot 0 of a pci-bridge, libvirt wouldn't be able to expose that to users (unless the min/max slot of each PCI controller was made visible somewhere via QMP)
Quoted 8 lines
Quoted 4 lines · Marcel Apfelbaum
The reason for not being able to plug a device into slot 0 of a PCI Bridge is the SHPC (Hot-plug controller) device embedded in the PCI bridge by default. The SHPC spec requires this. If one disables it with shpc=false, he should be able to use the slot 0.
For simplicity's sake I guess we should just recommend >=1 slot numbers.
Is a pity to skip slot 0 for PCI Express bridges.
- Root ports and Downstream ports have only slot 0 :)
- Root Complexes (pice.0 and pxb-pcies) can use slot 0
Quoted 42 lines
Back to the patch:
Quoted 27 lines · Marcel Apfelbaum
Quoted 25 lines · Marcel Apfelbaum
docs/pcie.txt new file +5
-0+ +2.3 PCI only hierarchy +====================== +Legacy PCI devices can be plugged into pcie.0 as Integrated Devices. +Besides that use DMI-PCI bridges (i82801b11-bridge) to start PCIhierarchies.
(quoted diff) +2
-0+ +Prefer flat hierarchies. For most scenarios a single DMI-PCI bridge(having 32 slots)
+and several PCI-PCI bridges attached to it (each supporting also 32 slots) will support
+hundreds of legacy devices. The recommendation is to populate one PCI-PCI bridge
+under the DMI-PCI bridge until is full and then plug a new PCI-PCI bridge...docs/pcie.txt new file +10
-0+ + pcie.0 bus + ---------------------------------------------- + | | + ----------- ------------------ + | PCI Dev | | DMI-PCI BRIDGE | + ---------- ------------------ + | | + ----------- ------------------ + | PCI Dev | | PCI-PCI Bridge |Quoted 8 lines
docs/pcie.txt line 138
Quoted 8 lines
docs/pcie.txt new file +8
-0+ ----------- ------------------ + | | + ----------- ----------- + | PCI Dev | | PCI Dev | + ----------- ----------- + +2.3.1 To plug a PCI device into a pcie.0 as Integrated Device use: + -device <dev>[,bus=pcie.0](This is repeated from 2.1.1, but I guess it doesn't hurt, for completeness in this chapter.)
Quoted 8 lines
Quoted 3 lines
docs/pcie.txt line 141
Quoted 3 lines
+2.3.2 Plugging a PCI device into a DMI-PCI bridge:
docs/pcie.txt new file +2
-0+ -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device <dev>,bus=dmi_pci_bridge1[,addr=x]{10} I recall that we discussed this at length, that is, placing PCI (non-express) devices directly on the DMI-PCI bridge. IIRC the argument was that it's technically possible, it just won't support hot-plug.
Exactly
Quoted 11 lines
I'd like if we removed this use case from the document. It might be possible, but for simplicity's sake, we shouldn't advertise it, in my opinion. (Unless someone strongly disagrees with this idea, of course.) I recall esp. Laine, Alex and Daniel focusing on this, but I don't remember if (and what for) they wanted this option. Personally I'd like to see it disappear (unless convinced otherwise).
... Actually, going through the RFC thread again, it seems that the use case that I'm arguing against -- i.e., "use DMI-PCI as a generic PCIe-to-PCI bridge" -- makes Alex cringe as well. So there's that :)
I can do that, even if for non-hotplug scenarios we don't have any reason to avoid that. On the other hand, not advertising is not a big crime.
Quoted 15 lines
{11} Syntax remark, should we keep this section: the commas are not right in ",[,bus=pcie.0]".
Quoted 4 lines
Quoted 4 lines
+2.3.3 Plugging a PCI device into a PCI-PCI bridge:
+ -device
i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \{12} double comma again
Quoted 4 lines
Quoted 4 lines
+ -device
pci-bridge,id=pci_bridge1,bus=dmi_pci_bridge1[,chassis_nr=x][,addr=y] \
+ -device <dev>,bus=pci_bridge1[,addr=x]
Quoted 5 lines
{13} It would be nice to spell out the valid device addresses (y and x) here too -- can we use 0 for them? SHPC again?
Can we / should we simply go with >=1 device addresses?
For pci-bridges only - yes. A better idea (I think) is to disable SHPC by default from the next QEMU version. Make this slot usable. Sounds OK?
Quoted 44 lines
Quoted 8 lines
docs/pcie.txt line 153
Quoted 8 lines
docs/pcie.txt new file +8
-0+ + +3. IO space issues +=================== +The PCI Express Root Ports and PCI Express Downstream ports are seen by +Firmware/Guest OS as PCI-PCI bridges and, as required by PCI spec, +should reserve a 4K IO range for each even if only one (multifunction) +device can be plugged into them, resulting in poor IO space utilization.{14} I completely agree with this paragraph, I'd just recommend to allow the reader more time to digest it. Something like:
----
The PCI Express Root Ports and PCI Express Downstream ports are seen by Firmware/Guest OS as PCI-PCI bridges. As required by the PCI spec, each such Port should be reserved a 4K IO range for, even though only one (multifunction) device can be plugged into each Port. This results in poor IO space utilization.
----Quoted 6 lines
docs/pcie.txt line 159
Quoted 6 lines
docs/pcie.txt new file +6
-0+ +The firmware used by QEMU (SeaBIOS/OVMF) may try further optimizations +by not allocating IO space if possible: + (1) - For empty PCI Express Root Ports/PCI Express Downstream ports. + (2) - If the device behind the PCI Express Root Ports/PCI Express + Downstream has no IO BARs.{15} I'd say:
... by not allocating IO space for each PCI Express Root / PCI Express Downstream port if:
(1) the port is empty, or
(2) the device behind the port has no IO BARs.Quoted 3 lines
Quoted 3 lines
(quoted diff) +2
-0+ +The IO space is very limited, 65536 byte-wide IO ports, but it'sfragmented
{16} Suggestion: "The IO space is very limited, to 65536 byte-wide IO ports, and may even be fragmented by fixed IO ports owned by platform devices."
Quoted 1 line
Quoted 1 line
+resulting in ~10 PCI Express Root Ports (or PCI Express
Quoted 9 lines
{17} s/resulting in/resulting in at most/
Quoted 1 line
Quoted 1 line
Downstream/Upstream ports)
{18} Whoa, upstream ports? Why do we need to spell them out here? Upstream ports need their own bus numbers, but their IO space assignment only collects the IO space assignments of their downstream ports. Isn't that right?
Yes, I wad referring to the "couple", if you have an Upstream port you obviously have at least a Downstream one.
Quoted 3 lines
(I believe spelling out upstream ports here was recommended by Alex, but I don't understand why.)
Maybe to understand the connection between them? Usage?
Quoted 119 lines
Quoted 1 line
Quoted 1 line
+ports per system if devices with IO BARs are used in the PCI Express
{19} The word "ports" is unnecessary here.
Quoted 8 lines
Quoted 8 lines
hierarchy.
docs/pcie.txt new file +5
-0+ +Using the proposed device placing strategy solves this issue +by using only PCI Express devices within PCI Express hierarchy. + +The PCI Express spec requires the PCI Express devices to work withoutusing IO.
+The PCI hierarchy has no such limitations.{20} There should be no empty line (or even a line break) between the two above paragraphs: the second paragraph explains the first one.
Quoted 6 lines
Quoted 6 lines
docs/pcie.txt new file +6
-0+ + +4. Bus numbers issues +====================== +Each PCI domain can have up to only 256 buses and the QEMU PCI Express +machines do not support multiple PCI domains even if extra RootQuoted 8 lines
docs/pcie.txt line 183
Quoted 8 lines
docs/pcie.txt new file +8
-0+Complexes (pxb-pcie) are used. + +Each element of the PCI Express hierarchy (Root Complexes, +PCI Express Root Ports, PCI Express Downstream/Upstream ports) +takes up bus numbers. Since only one (multifunction) device +can be attached to a PCI Express Root Port or PCI Express Downstream +Port it is advised to plan in advance for the expected number of +devices to prevent bus numbers starvation.{21} Please add:
"""
In particular:- Avoiding PCI Express Switches (and thereby striving for a flat PCI Express hierarchy) enables the hierarchy to not spend bus numbers on Upstream Ports.
- The
bus_nrproperties of the pxb-pcie devices partition the 0..255 bus number space. All bus numbers assigned to the buses recursively behind a given pxb-pcie device's root bus must fit between thebus_nrproperty of that pxb-pcie device, and the lowest of the higherbus_nrproperties that the command line sets for other pxb-pcie devices.
"""(You do mention switches being more bus number-hungry, under chapter 5, hotplug; however, saving bus numbers makes sense for a purely cold-plugged scenario as well, especially in combination with pxb-pcie, where the partitioning can become a limiting factor.)
Quoted 7 lines
Quoted 7 lines
docs/pcie.txt new file +5
-0+ + +5. Hot Plug +============ +The PCI Express root buses (pcie.0 and the buses exposed by pxb-pciedevices)
+do not support hot-plug, so any devices plugged into Root ComplexesQuoted 8 lines
docs/pcie.txt line 197
Quoted 8 lines
docs/pcie.txt new file +8
-0+cannot be hot-plugged/hot-unplugged: + (1) PCI Express Integrated Devices + (2) PCI Express Root Ports + (3) DMI-PCI bridges + (4) pxb-pcie + +PCI devices can be hot-plugged into PCI-PCI bridges, however cannot +be hot-plugged into DMI-PCI bridges.{22} If you agree with my suggestion to remove 2.3.2, that is, the "PCI device cold-plugged directly into DMI-PCI bridge" case, then the second half of the sentence can be dropped.
Quoted 12 lines
Quoted 12 lines
docs/pcie.txt new file +12
-0+The PCI hotplug is ACPI based and can work side by side with the +PCI Express native hotplug. + +PCI Express devices can be natively hot-plugged/hot-unplugged into/from +PCI Express Root Ports (and PCI Express Downstream Ports). + +5.1 Planning for hotplug: + (1) PCI hierarchy + Leave enough PCI-PCI bridge slots empty or add one + or more empty PCI-PCI bridges to the DMI-PCI bridge. + + For each such bridge the Guest Firmware is expected toQuoted 8 lines
Quoted 8 lines
reserve 4K IO
docs/pcie.txt new file +3
-0+ space and 2M MMIO range to be used for all devices behind it. + + Because of the hard IO limit of around 10 PCI bridges (~ 40Kspace) per system
+ don't use more than 9 bridges, leaving 4K for the Integrated
devices
+ and none for the PCI Express Hierarchy.{23} s/9 bridges/9 PCI-PCI bridges/
Quoted 4 lines
docs/pcie.txt line 218
Quoted 4 lines
docs/pcie.txt new file +4
-0+ + (2) PCI Express hierarchy: + Leave enough PCI Express Root Ports empty. Use multifunction + PCI Express Root Ports to prevent going out of PCI bus numbers.{24} I agree, but I'd put it a bit differently: use multifunction PCI Express Root Ports on the Root Complex(es), for keeping the hierarchy as flat as possible, thereby saving PCI bus numbers.
Quoted 4 lines
Quoted 4 lines
(quoted diff) +2
-0+ Don't use PCI Express Switches if you don't have too, they use + an extra PCI bus that may handy to plug another device id itcomes to it.
+{25} I'd put it as: Don't use PCI Express Switches if you don't have too, each one of those uses an extra PCI bus (for its Upstream Port) that could be put to better use with another Root Port or Downstream Port, which may come handy for hotplugging another device.
{26} Another remark (important to me) in this section: the document doesn't state firmware expectations. It's clear the firmware is expected to reserve no IO space for PCI Express Downstream Ports and Root Ports, but what about MMIO?
Quoted 5 lines
We discussed this at length with Alex, but I think we didn't conclude anything. It would be nice if firmware received some instructions from this document in this regard, even before we implement our own ports and bridges in QEMU.
Hmm, I have no idea what to add here, except:
The firmware is expected to reserve at least 2M for each pci bridge?
Quoted 23 lines
<digression>
If we think such recommendations are out of scope at this point, *and* noone disagrees strongly (Gerd?), then I could add some experimental
fw_cfgknobs to OVMF for this, such as (units in MB):(quoted diff) +0
-4-fw_cfg opt/org.tianocore.ovmf/X-ReservePciE/PrefMmio32Mb,string=... -fw_cfg opt/org.tianocore.ovmf/X-ReservePciE/NonPrefMmio32Mb,string=... -fw_cfg opt/org.tianocore.ovmf/X-ReservePciE/PrefMmio64Mb,string=.. -fw_cfg opt/org.tianocore.ovmf/X-ReservePciE/NonPrefMmio64Mb,string=..Under this idea, I would reserve no resources at all for Downstream Ports and Root Ports in OVMF by default; but users could influence those reservations. I think that would be enough to kick things off. It also needs no modifications for QEMU.
</digression>
Quoted 4 lines
Quoted 4 lines
+5.3 Hot plug example:
(quoted diff) +2
-0+Using HMP: (add -monitor stdio to QEMU command line) + device_add <dev>,id=<id>,bus=<pcie.0/PCI Express Root PortId/PCI-PCI bridge Id/pxb-pcie Id>
Quoted 6 lines
{27} I think the bus=<...> part is incorrect here. Based on the rest of the guidelines, we have to specify the ID of:
- a PCI Express Root Port, or
- a PCI Express Downstream Port, or
- a PCI-PCI bridge.
I don't get it, you specify what you wrote above as the bus, right? For example if you start the machine with
.... -device ioh3420,id=root_port1,
you hotplug with: device_add e1000,bus=root_port1.
Quoted 65 lines
Quoted 26 lines
Quoted 26 lines
docs/pcie.txt new file +25
-0+ + +6. Device assignment +==================== +Host devices are mostly PCI Express and should be plugged only into +PCI Express Root Ports or PCI Express Downstream Ports. +PCI-PCI bridge slots can be used for legacy PCI host devices. + +6.1 How to detect if a device is PCI Express: + > lspci -s 03:00.0 -v (as root) + + 03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83) + Subsystem: Intel Corporation Dual Band Wireless-AC 7260 + Flags: bus master, fast devsel, latency 0, IRQ 50 + Memory at f0400000 (64-bit, non-prefetchable) [size=8K] + Capabilities: [c8] Power Management version 3 + Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ + Capabilities: [40] Express Endpoint, MSI 00 + + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Capabilities: [100] Advanced Error Reporting + Capabilities: [140] Device Serial Number 7c-7a-91-ff-ff-90-db-20 + Capabilities: [14c] Latency Tolerance Reporting + Capabilities: [154] Vendor Specific Information: ID=cafe Rev=1Len=014
Quoted 8 lines
docs/pcie.txt line 257
Quoted 8 lines
docs/pcie.txt new file +8
-0+ + +7. Virtio devices +================= +Virtio devices plugged into the PCI hierarchy or as Integrated Devices +will remain PCI and have transitional behaviour as default. +Transitional virtio devices work in both IO and MMIO modes depending on +the guest support.{28} Suggest to add: firmware will assign both IO and MMIO resources to transitional virtio devices.
Quoted 5 lines
docs/pcie.txt line 261
Quoted 5 lines
(quoted diff) +2
-0+ +Virtio devices plugged into PCI Express ports are PCI Express devicesand
docs/pcie.txt new file +2
-0+have "1.0" behavior by default without IO support. +In both case disable-* properties can be used to override the behaviour.{29} s/case/cases/; also, please spell out the disable-* properties fully.
Quoted 4 lines
docs/pcie.txt line 265
Quoted 4 lines
docs/pcie.txt new file +4
-0+ +Note that setting disable-legacy=off will enable legacy mode (enabling +legacy behavior) for PCI Express virtio devices causing them to +require IO space, which, given our PCI Express hierarchy, may quickly{30} s/given our PCI Express hierarchy/given the limited available IO space/
Quoted 11 lines
docs/pcie.txt line 273
Quoted 9 lines
docs/pcie.txt new file +8
-0+lead to resource exhaustion, and is therefore strongly discouraged. + + +8. Conclusion +============== +The proposal offers a usage model that is easy to understand and follow +and in the same time overcomes the PCI Express architecture limitations. +
Quoted 5 lines
I think this version has seen big improvements, and I think it's structurally complete. While composing this review, I went through the entire RFC thread again, and I *think* you didn't miss anything from that. Great job again!
Thanks!
Quoted 3 lines
My comments vary in importance. I trust you to take each comment with an appropriately sized grain of salt ;)
Sure, thanks
Marcel
Quoted 3 lines
Thank you!
Laszlo
Quoted 12 lines · Marcel Apfelbaum
Quoted 11 lines · Laszlo Ersek
Quoted 6 lines · Marcel Apfelbaum
Quoted 4 lines · Marcel Apfelbaum
+ -device
pci-bridge,id=pci_bridge1,bus=dmi_pci_bridge1[,chassis_nr=x][,addr=y] \
+ -device <dev>,bus=pci_bridge1[,addr=x]{13} It would be nice to spell out the valid device addresses (y and x) here too -- can we use 0 for them? SHPC again?
Quoted 6 lines
Quoted 2 lines
Can we / should we simply go with >=1 device addresses?
For pci-bridges only - yes. A better idea (I think) is to disable SHPC by default
from the next QEMU version. Make this slot usable. Sounds OK?
Sure.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +2
-0+ Don't use PCI Express Switches if you don't have too, they use + an extra PCI bus that may handy to plug another device id itcomes to it.
+{25} I'd put it as: Don't use PCI Express Switches if you don't have too, each one of those uses an extra PCI bus (for its Upstream Port) that could be put to better use with another Root Port or Downstream Port, which may come handy for hotplugging another device.
{26} Another remark (important to me) in this section: the document doesn't state firmware expectations. It's clear the firmware is expected to reserve no IO space for PCI Express Downstream Ports and Root Ports, but what about MMIO?
Quoted 8 lines
Quoted 5 lines
We discussed this at length with Alex, but I think we didn't conclude anything. It would be nice if firmware received some instructions from this document in this regard, even before we implement our own ports and bridges in QEMU.
Hmm, I have no idea what to add here, except:
The firmware is expected to reserve at least 2M for each pci bridge?
Just ignore {26} for now please. I'll come back to this later when we have our own (generic) ports.
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
+5.3 Hot plug example:
(quoted diff) +2
-0+Using HMP: (add -monitor stdio to QEMU command line) + device_add <dev>,id=<id>,bus=<pcie.0/PCI Express Root PortId/PCI-PCI bridge Id/pxb-pcie Id>
{27} I think the bus=<...> part is incorrect here. Based on the rest of the guidelines, we have to specify the ID of:
- a PCI Express Root Port, or
- a PCI Express Downstream Port, or
- a PCI-PCI bridge.
Quoted 4 lines
I don't get it, you specify what you wrote above as the bus, right? For example if you start the machine with
.... -device ioh3420,id=root_port1,you hotplug with:
device_adde1000,bus=root_port1.
My point is that your example names
bus=<pcie.0/PCI Express Root Port Id/PCI-PCI bridge Id/pxb-pcie Id>
which suggests that the following bus *types* can receive hotplugged devices:
(a) main root bus ("pcie.0")
(c) root port ("PCI Express Root Port Id")
(c) PCI-PCI bridge ("PCI-PCI bridge Id")
(d) extra root bus ("pxb-pcie Id")
Based on the rest of the guidelines, suggestions (a) and (d) are invalid -- those bus types cannot accept hotplugged devices --, plus option (e) is missing, namely:
(e) downstream port.
In other words, your example IDs *infer* bus types, and the set of bus types inferred is both wrong (incorrect elements) and incomplete (one correct element missing).
Therefore my proposal is to provide the following example:
bus=<PCI Express Root Port Id/PCI Express Downstream Port Id/PCI-PCI
bridge Id>
That's all.
Cheers
Laszlo
Quoted 82 lines · Laszlo Ersek
Quoted 12 lines · Marcel Apfelbaum
Quoted 11 lines · Laszlo Ersek
Quoted 6 lines · Marcel Apfelbaum
Quoted 4 lines · Marcel Apfelbaum
+ -device
pci-bridge,id=pci_bridge1,bus=dmi_pci_bridge1[,chassis_nr=x][,addr=y] \
+ -device <dev>,bus=pci_bridge1[,addr=x]{13} It would be nice to spell out the valid device addresses (y and x) here too -- can we use 0 for them? SHPC again?
Quoted 6 lines
Quoted 2 lines
Can we / should we simply go with >=1 device addresses?
For pci-bridges only - yes. A better idea (I think) is to disable SHPC by default
from the next QEMU version. Make this slot usable. Sounds OK?Sure.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +2
-0+ Don't use PCI Express Switches if you don't have too, they use + an extra PCI bus that may handy to plug another device id itcomes to it.
+{25} I'd put it as: Don't use PCI Express Switches if you don't have too, each one of those uses an extra PCI bus (for its Upstream Port) that could be put to better use with another Root Port or Downstream Port, which may come handy for hotplugging another device.
{26} Another remark (important to me) in this section: the document doesn't state firmware expectations. It's clear the firmware is expected to reserve no IO space for PCI Express Downstream Ports and Root Ports, but what about MMIO?
Quoted 8 lines
Quoted 5 lines
We discussed this at length with Alex, but I think we didn't conclude anything. It would be nice if firmware received some instructions from this document in this regard, even before we implement our own ports and bridges in QEMU.
Hmm, I have no idea what to add here, except:
The firmware is expected to reserve at least 2M for each pci bridge?Just ignore {26} for now please. I'll come back to this later when we have our own (generic) ports.
Quoted 12 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
+5.3 Hot plug example:
(quoted diff) +2
-0+Using HMP: (add -monitor stdio to QEMU command line) + device_add <dev>,id=<id>,bus=<pcie.0/PCI Express Root PortId/PCI-PCI bridge Id/pxb-pcie Id>
{27} I think the bus=<...> part is incorrect here. Based on the rest of the guidelines, we have to specify the ID of:
- a PCI Express Root Port, or
- a PCI Express Downstream Port, or
- a PCI-PCI bridge.Quoted 4 lines
I don't get it, you specify what you wrote above as the bus, right? For example if you start the machine with
.... -device ioh3420,id=root_port1,you hotplug with:
device_adde1000,bus=root_port1.My point is that your example names
bus=<pcie.0/PCI Express Root Port Id/PCI-PCI bridge Id/pxb-pcie Id>
which suggests that the following bus *types* can receive hotplugged devices:
(a) main root bus ("pcie.0")
(c) root port ("PCI Express Root Port Id")
(c) PCI-PCI bridge ("PCI-PCI bridge Id")
(d) extra root bus ("pxb-pcie Id")Based on the rest of the guidelines, suggestions (a) and (d) are invalid -- those bus types cannot accept hotplugged devices --, plus option (e) is missing, namely:
(e) downstream port.
Quoted 9 lines
In other words, your example IDs *infer* bus types, and the set of bus types inferred is both wrong (incorrect elements) and incomplete (one correct element missing).
Therefore my proposal is to provide the following example:
bus=<PCI Express Root Port Id/PCI Express Downstream Port Id/PCI-PCI
bridge Id>
And now I understood the 'bug' :)
Thanks,
Marcel
Quoted 5 lines
That's all.
Cheers
Laszlo
Quoted 21 lines · Marcel Apfelbaum
Quoted 21 lines
docs/pcie.txt new file +21
-0+PCI EXPRESS GUIDELINES +====================== + +1. Introduction +================ +The doc proposes best practices on how to use PCI Express/PCI device +in PCI Express based machines and explains the reasoning behind them. + + +2. Device placement strategy +============================ +QEMU does not have a clear socket-device matching mechanism +and allows any PCI/PCI Express device to be plugged into any PCI/PCI Express slot. +Plugging a PCI device into a PCI Express slot might not always work and +is weird anyway since it cannot be done for "bare metal". +Plugging a PCI Express device into a PCI slot will hide the Extended +Configuration Space thus is also not recommended. + +The recommendation is to separate the PCI Express and PCI hierarchies. +PCI Express devices should be plugged only into PCI Express Root Ports and +PCI Express Downstream ports.
Quoted 8 lines
docs/pcie.txt line 29
Quoted 8 lines
docs/pcie.txt new file +8
-0+ +2.1 Root Bus (pcie.0) +===================== +Place only the following kinds of devices directly on the Root Complex: + (1) Devices with dedicated, specific functionality (network card, + graphics card, IDE controller, etc); place only legacy PCI devices on + the Root Complex. These will be considered Integrated Endpoints. + Note: Integrated devices are not hot-pluggable.
s/Integrated devices/Integrated Endpoints/ (which I assume is a Spec-Originated Term) in the last sentence, to be consistent with the one right before it.
I'm also not sure what you mean by devices with "dedicated, specific functionality", and unfortunately the examples don't seem to be helping me.
Quoted 12 lines
Quoted 12 lines
+ Although the PCI Express spec does not forbid PCI Express devices as + Integrated Endpoints, existing hardware mostly integrates legacy PCI + devices with the Root Complex. Guest OSes are suspected to behave + strangely when PCI Express devices are integrated with the Root Complex.
docs/pcie.txt new file +8
-0+ + (2) PCI Express Root Ports (ioh3420), for starting exclusively PCI Express + hierarchies. + + (3) DMI-PCI bridges (i82801b11-bridge), for starting legacy PCI hierarchies. + + (4) Extra Root Complexes (pxb-pcie), if multiple PCIe Root Buses are needed. +
Quoted 8 lines
Quoted 8 lines
+ pcie.0 bus
+ ----------------------------------------------------------------------------- + | | | | + ----------- ------------------ ------------------ -------------- + | PCI Dev | | PCIe Root Port | | DMI-PCI bridge | | pxb-pcie | + ----------- ------------------ ------------------ -------------- +
+2.1.1 To plug a device into a pcie.0 as Root Complex Integrated Device use:
s/Root Complex Integrated Device/Integrated Endpoint/ ?
I don't know how much any of these terms can be used interchangeably, but it would be good IMHO if we could choose a single term and stick to it throughout the document.
Quoted 1 line
Quoted 1 line
+ -device <dev>[,bus=pcie.0]
Is the bus=pcie.0 bit really optional? Will QEMU just assign devices to pcie.0 automatically unless you provide an explicit bus= option telling it otherwise?
Quoted 5 lines
Quoted 5 lines
+2.1.2 To expose a new PCI Express Root Bus use:
+ -device pxb-pcie,id=pcie.1,bus_nr=x,[numa_node=y],[addr=z]
+ Only PCI Express Root Ports and DMI-PCI bridges can be connected to the pcie.1 bus:
+ -device ioh3420,id=root_port1[,bus=pcie.1][,chassis=x][,slot=y][,addr=z] \
+ -device i82801b11-bridge,id=dmi_pci_bridge1,bus=pcie.1
Here I really can't see how the bus= option would be optional for ioh3420 but mandatory for i82801b11-bridge.
Neither for <dev> above nor for i82801b11-bridge you show that the slot= option exists. Of course these are merely usage examples and are not intended to replace the full
documentation: since this is the case, I think we should make that very explicit and possibly avoid listing options we don't use at all, eg.
-device e1000,bus=pcie.0
This will plug a e1000 Ethernet adapter into pcie.0 as an Integrated Endpoint.
and so on.
Quoted 10 lines
docs/pcie.txt line 68
Quoted 10 lines
+2.2 PCI Express only hierarchy
+==============================docs/pcie.txt new file +8
-0+Always use PCI Express Root Ports to start PCI Express hierarchies. + +A PCI Express Root bus supports up to 32 devices. Since each +PCI Express Root Port is a function and a multi-function +device may support up to 8 functions, the maximum possible +PCI Express Root Ports per PCI Express Root Bus is 256. + +Prefer coupling PCI Express Root Ports into multi-function devices
s/coupling/grouping/
Quoted 23 lines
Quoted 23 lines
docs/pcie.txt new file +23
-0+to keep a simple flat hierarchy that is enough for most scenarios. +Only use PCI Express Switches (x3130-upstream, xio3130-downstream) +if there is no more room for PCI Express Root Ports. +Please see section 4. for further justifications. + +Plug only PCI Express devices into PCI Express Ports. + + + pcie.0 bus + ---------------------------------------------------------------------------------- + | | | + ------------- ------------- ------------- + | Root Port | | Root Port | | Root Port | + ------------ ------------- ------------- + | -------------------------|------------------------ + ------------ | ----------------- | + | PCIe Dev | | PCI Express | Upstream Port | | + ------------ | Switch ----------------- | + | | | | + | ------------------- ------------------- | + | | Downstream Port | | Downstream Port | | + | ------------------- ------------------- | + -------------|-----------------------|------------
Quoted 8 lines
Quoted 8 lines
+ ------------
+ | PCIe Dev |
+ ------------
+
+2.2.1 Plugging a PCI Express device into a PCI Express Root Port:
+ -device ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \
+ -device <dev>,bus=root_port1
+ Note that chassis parameter is compulsory, and must be unique
s/compulsory/mandatory/
Quoted 7 lines
Quoted 7 lines
+ for each PCI Express Root Port.
+2.2.2 Using multi-function PCI Express Root Ports:
+ -device ioh3420,id=root_port1,multifunction=on,chassis=x[,bus=pcie.0][,slot=y][,addr=z.0] \
+ -device ioh3420,id=root_port2,,chassis=x1[,bus=pcie.0][,slot=y1][,addr=z.1] \
+ -device ioh3420,id=root_port3,,chassis=x2[,bus=pcie.0][,slot=y2][,addr=z.2] \
+2.2.2 Plugging a PCI Express device into a Switch:
+ -device ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \
Quoted 8 lines
docs/pcie.txt line 114
Quoted 8 lines
+ -device x3130-upstream,id=upstream_port1,bus=root_port1[,addr=x] \
+ -device xio3130-downstream,id=downstream_port1,bus=upstream_port1,chassis=x1[,slot=y1][,addr=z1]] \
+ -device <dev>,bus=downstream_port1docs/pcie.txt new file +5
-0+ + +2.3 PCI only hierarchy +====================== +Legacy PCI devices can be plugged into pcie.0 as Integrated Devices.
Maybe we could add something like
but, as mentioned above, doing so means the legacy PCI device in question will be incapable of hot-unplugging.
just to stress the fact.
Aside: "device" or "endpoint"? My understanding is that endpoints are things like Ethernet adapters, and devices are endpoints *or* controller, but I might be way off base here ;)
Quoted 47 lines
Quoted 47 lines
docs/pcie.txt new file +47
-0+Besides that use DMI-PCI bridges (i82801b11-bridge) to start PCI hierarchies. + +Prefer flat hierarchies. For most scenarios a single DMI-PCI bridge (having 32 slots) +and several PCI-PCI bridges attached to it (each supporting also 32 slots) will support +hundreds of legacy devices. The recommendation is to populate one PCI-PCI bridge +under the DMI-PCI bridge until is full and then plug a new PCI-PCI bridge... + + pcie.0 bus + ---------------------------------------------- + | | + ----------- ------------------ + | PCI Dev | | DMI-PCI BRIDGE | + ---------- ------------------ + | | + ----------- ------------------ + | PCI Dev | | PCI-PCI Bridge | + ----------- ------------------ + | | + ----------- ----------- + | PCI Dev | | PCI Dev | + ----------- ----------- + +2.3.1 To plug a PCI device into a pcie.0 as Integrated Device use: + -device <dev>[,bus=pcie.0] +2.3.2 Plugging a PCI device into a DMI-PCI bridge: + -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device <dev>,bus=dmi_pci_bridge1[,addr=x] +2.3.3 Plugging a PCI device into a PCI-PCI bridge: + -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device pci-bridge,id=pci_bridge1,bus=dmi_pci_bridge1[,chassis_nr=x][,addr=y] \ + -device <dev>,bus=pci_bridge1[,addr=x] + + +3. IO space issues +=================== +The PCI Express Root Ports and PCI Express Downstream ports are seen by +Firmware/Guest OS as PCI-PCI bridges and, as required by PCI spec, +should reserve a 4K IO range for each even if only one (multifunction) +device can be plugged into them, resulting in poor IO space utilization. + +The firmware used by QEMU (SeaBIOS/OVMF) may try further optimizations +by not allocating IO space if possible: + (1) - For empty PCI Express Root Ports/PCI Express Downstream ports. + (2) - If the device behind the PCI Express Root Ports/PCI Express + Downstream has no IO BARs. + +The IO space is very limited, 65536 byte-wide IO ports, but it's fragmented
Quoted 8 lines
docs/pcie.txt line 169
Quoted 8 lines
docs/pcie.txt new file +8
-0+resulting in ~10 PCI Express Root Ports (or PCI Express Downstream/Upstream ports) +ports per system if devices with IO BARs are used in the PCI Express hierarchy. + +Using the proposed device placing strategy solves this issue +by using only PCI Express devices within PCI Express hierarchy. + +The PCI Express spec requires the PCI Express devices to work without using IO. +The PCI hierarchy has no such limitations.
After reading this section and piecing all bits together, my understanding is that
a) the spec requires firmware and OS to allocate 4K of IO space for each PCI Express Root Port or PCI Express Switch Downstream Port
b) that's necessary because legacy PCI Devices require IO space to operate
c) however, IO space is a very limited resource
d) the spec also requires PCI Express Devices (or rather Endpoints?) to work without using any IO space
e) if we stick to the plan outlined in this document, there will never be legacy PCI Devices plugged into PCI Express Root Ports or PCI Express Switch Downstream Ports (only PCI Express Endpoints or PCI Express Switch Upstream Ports)
f) thanks to d) and e), the firmware (and OS? IIRC Linux currently doesn't do this) can ignore a) and allocate no IO space for PCI Express Root Ports and PCI Express Switch Downstream Ports
g) thus effectively making c) irrelevant
If my reading is correct, I think we should put more emphasis on the fact that our device placement strategy is effective in avoiding IO space exaustion because we stick to PCI Express Devices only which, unlike legacy PCI Devices, require no IO space to operate.
Quoted 7 lines
Quoted 7 lines
+4. Bus numbers issues
+======================docs/pcie.txt new file +5
-0+Each PCI domain can have up to only 256 buses and the QEMU PCI Express +machines do not support multiple PCI domains even if extra Root +Complexes (pxb-pcie) are used. + +Each element of the PCI Express hierarchy (Root Complexes,
Quoted 8 lines
docs/pcie.txt line 186
Quoted 8 lines
docs/pcie.txt new file +8
-0+PCI Express Root Ports, PCI Express Downstream/Upstream ports) +takes up bus numbers. Since only one (multifunction) device +can be attached to a PCI Express Root Port or PCI Express Downstream +Port it is advised to plan in advance for the expected number of +devices to prevent bus numbers starvation. + + +5. Hot Plug
Hot Plug, hot-plug or hotplug?
Pick one and stick with it :)
Quoted 20 lines
Quoted 20 lines
+============
docs/pcie.txt new file +19
-0+The PCI Express root buses (pcie.0 and the buses exposed by pxb-pcie devices) +do not support hot-plug, so any devices plugged into Root Complexes +cannot be hot-plugged/hot-unplugged: + (1) PCI Express Integrated Devices + (2) PCI Express Root Ports + (3) DMI-PCI bridges + (4) pxb-pcie + +PCI devices can be hot-plugged into PCI-PCI bridges, however cannot +be hot-plugged into DMI-PCI bridges. +The PCI hotplug is ACPI based and can work side by side with the +PCI Express native hotplug. + +PCI Express devices can be natively hot-plugged/hot-unplugged into/from +PCI Express Root Ports (and PCI Express Downstream Ports). + +5.1 Planning for hotplug: + (1) PCI hierarchy + Leave enough PCI-PCI bridge slots empty or add one
Quoted 8 lines
docs/pcie.txt line 214
Quoted 8 lines
+ or more empty PCI-PCI bridges to the DMI-PCI bridge.
docs/pcie.txt new file +7
-0+ + For each such bridge the Guest Firmware is expected to reserve 4K IO + space and 2M MMIO range to be used for all devices behind it. + + Because of the hard IO limit of around 10 PCI bridges (~ 40K space) per system + don't use more than 9 bridges, leaving 4K for the Integrated devices + and none for the PCI Express Hierarchy.
I would rewrite the last line as
(the PCI Express hierarchy needs no IO space).
or something like that. Unless I misunderstood :)
Quoted 3 lines
Quoted 3 lines
+ (2) PCI Express hierarchy:
+ Leave enough PCI Express Root Ports empty. Use multifunction + PCI Express Root Ports to prevent going out of PCI bus numbers.
When you say "multifunction PCI Express Root Ports", are you suggesting the user should take advantage of all 8 functions in a PCI Express Root Port, eg. by plugging 4 Ethernet adapters into the same PCI Express Root Port instead of using a single PCI Express Root Port for each one of them, or that multiple PCI Express Root Ports should be plugged into functions of the same pcie.0 slot?
Either way, I don't see how doing so would prevent you from running out of PCI bus numbers - if anything, not doing the latter will make it so you'll run out of ports way before you come anywhere close to 256 PCI buses.
Point is, being less terse here could be very helpful.
Quoted 2 lines
Quoted 2 lines
+ Don't use PCI Express Switches if you don't have too, they use + an extra PCI bus that may handy to plug another device id it comes to it.
s/too/to/
s/may handy/may come handy/
s/id it comes/if it comes/
Quoted 14 lines
Quoted 14 lines
+5.3 Hot plug example:
docs/pcie.txt new file +13
-0+Using HMP: (add -monitor stdio to QEMU command line) + device_add <dev>,id=<id>,bus=<pcie.0/PCI Express Root Port Id/PCI-PCI bridge Id/pxb-pcie Id> + + +6. Device assignment +==================== +Host devices are mostly PCI Express and should be plugged only into +PCI Express Root Ports or PCI Express Downstream Ports. +PCI-PCI bridge slots can be used for legacy PCI host devices. + +6.1 How to detect if a device is PCI Express: + > lspci -s 03:00.0 -v (as root) +
Quoted 8 lines
Quoted 8 lines
+ 03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83) + Subsystem: Intel Corporation Dual Band Wireless-AC 7260 + Flags: bus master, fast devsel, latency 0, IRQ 50
+ Memory atf0400000(64-bit, non-prefetchable) [size=8K] + Capabilities: [c8] Power Management version 3
+ Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ + Capabilities: [40] Express Endpoint, MSI 00
+
I'd skip this empty line...
Quoted 2 lines
Quoted 2 lines
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
... and this one too.
Quoted 4 lines
Quoted 4 lines
+ Capabilities: [100] Advanced Error Reporting
+ Capabilities: [140] Device Serial Number 7c-7a-91-ff-ff-90-db-20 + Capabilities: [14c] Latency Tolerance Reporting
+ Capabilities: [154] Vendor Specific Information: ID=cafe Rev=1 Len=014
I'd also add a small note along the lines of
If you can see the "Express Endpoint" capability in the output, then the device is indeed PCI Express.
Quoted 13 lines
Quoted 13 lines
+7. Virtio devices
+=================docs/pcie.txt new file +11
-0+Virtio devices plugged into the PCI hierarchy or as Integrated Devices +will remain PCI and have transitional behaviour as default. +Transitional virtio devices work in both IO and MMIO modes depending on +the guest support. + +Virtio devices plugged into PCI Express ports are PCI Express devices and +have "1.0" behavior by default without IO support. +In both case disable-* properties can be used to override the behaviour. + +Note that setting disable-legacy=off will enable legacy mode (enabling +legacy behavior) for PCI Express virtio devices causing them to
Quoted 8 lines
docs/pcie.txt line 272
Quoted 8 lines
docs/pcie.txt new file +8
-0+require IO space, which, given our PCI Express hierarchy, may quickly +lead to resource exhaustion, and is therefore strongly discouraged. + + +8. Conclusion +============== +The proposal offers a usage model that is easy to understand and follow +and in the same time overcomes the PCI Express architecture limitations.
s/in the same/at the same/
Overall I think the contents we care about are pretty much there and are exposed and organized in a very clear fashion; pretty much all of my comments are meant to improve the few areas where I believe we could make things even easier to grasp for the reader, remove potential ambiguity, or be more consistent.
Thanks for working on this! Looking forward to v3 ;)
--
Andrea Bolognani / Red Hat / Virtualization
Quoted 35 lines · Andrea Bolognani
Quoted 21 lines · Marcel Apfelbaum
Quoted 21 lines
docs/pcie.txt new file +21
-0+PCI EXPRESS GUIDELINES +====================== + +1. Introduction +================ +The doc proposes best practices on how to use PCI Express/PCI device +in PCI Express based machines and explains the reasoning behind them. + + +2. Device placement strategy +============================ +QEMU does not have a clear socket-device matching mechanism +and allows any PCI/PCI Express device to be plugged into any PCI/PCI Express slot. +Plugging a PCI device into a PCI Express slot might not always work and +is weird anyway since it cannot be done for "bare metal". +Plugging a PCI Express device into a PCI slot will hide the Extended +Configuration Space thus is also not recommended. + +The recommendation is to separate the PCI Express and PCI hierarchies. +PCI Express devices should be plugged only into PCI Express Root Ports and +PCI Express Downstream ports.Quoted 8 lines
docs/pcie.txt line 29
Quoted 8 lines
docs/pcie.txt new file +8
-0+ +2.1 Root Bus (pcie.0) +===================== +Place only the following kinds of devices directly on the Root Complex: + (1) Devices with dedicated, specific functionality (network card, + graphics card, IDE controller, etc); place only legacy PCI devices on + the Root Complex. These will be considered Integrated Endpoints. + Note: Integrated devices are not hot-pluggable.s/Integrated devices/Integrated Endpoints/ (which I assume is a Spec-Originated Term) in the last sentence, to be consistent with the one right before it.
Quoted 3 lines
I'm also not sure what you mean by devices with "dedicated, specific functionality", and unfortunately the examples don't seem to be helping me.
That language is from me (I suggested it earlier). It means devices that you want to use for some actual task, rather than just to build your PCI (Express) hierarchy with them. "Leaf nodes" or whatever. "Everything non-bridge".
Thanks
Laszlo
Quoted 15 lines · Laszlo Ersek
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+2.1 Root Bus (pcie.0)
+=====================
+Place only the following kinds of devices directly on the Root Complex:
+ (1) Devices with dedicated, specific functionality (network card, + graphics card, IDE controller, etc); place only legacy PCI devices on + the Root Complex. These will be considered Integrated Endpoints. + Note: Integrated devices are not hot-pluggable.Quoted 8 lines
s/Integrated devices/Integrated Endpoints/ (which I assume is a Spec-Originated Term) in the last sentence, to be consistent with the one right before it.
I'm also not sure what you mean by devices with "dedicated, specific functionality", and unfortunately the examples don't seem to be helping me.
Quoted 5 lines
That language is from me (I suggested it earlier). It means devices that you want to use for some actual task, rather than just to build your PCI (Express) hierarchy with them. "Leaf nodes" or whatever. "Everything non-bridge".
Isn't that basically the definition of Endpoint? It certainly is what I convinced myself "Endpoint" means :)
Either way, I think we should spend a few more words there, for clarity's sake. Rewording the phrase to put more emphasis on the "legacy PCI devices only" part would probably be warranted as well.
--
Andrea Bolognani / Red Hat / Virtualization
Quoted 22 lines · Andrea Bolognani
Quoted 21 lines · Marcel Apfelbaum
Quoted 21 lines
docs/pcie.txt new file +21
-0+PCI EXPRESS GUIDELINES +====================== + +1. Introduction +================ +The doc proposes best practices on how to use PCI Express/PCI device +in PCI Express based machines and explains the reasoning behind them. + + +2. Device placement strategy +============================ +QEMU does not have a clear socket-device matching mechanism +and allows any PCI/PCI Express device to be plugged into any PCI/PCI Express slot. +Plugging a PCI device into a PCI Express slot might not always work and +is weird anyway since it cannot be done for "bare metal". +Plugging a PCI Express device into a PCI slot will hide the Extended +Configuration Space thus is also not recommended. + +The recommendation is to separate the PCI Express and PCI hierarchies. +PCI Express devices should be plugged only into PCI Express Root Ports and +PCI Express Downstream ports.
Quoted 9 lines
Quoted 8 lines
docs/pcie.txt line 29
Quoted 8 lines
docs/pcie.txt new file +8
-0+ +2.1 Root Bus (pcie.0) +===================== +Place only the following kinds of devices directly on the Root Complex: + (1) Devices with dedicated, specific functionality (network card, + graphics card, IDE controller, etc); place only legacy PCI devices on + the Root Complex. These will be considered Integrated Endpoints. + Note: Integrated devices are not hot-pluggable.
Hi Andrea,
Thanks for the review.
Quoted 4 lines
s/Integrated devices/Integrated Endpoints/ (which I assume is a Spec-Originated Term) in the last sentence, to be consistent with the one right before it.
OK
Quoted 3 lines
I'm also not sure what you mean by devices with "dedicated, specific functionality", and unfortunately the examples don't seem to be helping me.
I'll try to re-phrase a little, the PCI Express spec doesn't say anything specific about what Endpoints can be (as far as I know) and what is happening is that on-board devices remain *usually* PCI and not PCI express.They may be NICs, Sound cards..
Sounds better?
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
docs/pcie.txt new file +14
-0+ Although the PCI Express spec does not forbid PCI Express devices as + Integrated Endpoints, existing hardware mostly integrates legacy PCI + devices with the Root Complex. Guest OSes are suspected to behave + strangely when PCI Express devices are integrated with the Root Complex. + + (2) PCI Express Root Ports (ioh3420), for starting exclusively PCI Express + hierarchies. + + (3) DMI-PCI bridges (i82801b11-bridge), for starting legacy PCI hierarchies. + + (4) Extra Root Complexes (pxb-pcie), if multiple PCIe Root Buses are needed. + + pcie.0 bus + -----------------------------------------------------------------------------
Quoted 9 lines
Quoted 6 lines
docs/pcie.txt line 50
Quoted 6 lines
docs/pcie.txt new file +6
-0+ | | | | + ----------- ------------------ ------------------ -------------- + | PCI Dev | | PCIe Root Port | | DMI-PCI bridge | | pxb-pcie | + ----------- ------------------ ------------------ -------------- + +2.1.1 To plug a device into a pcie.0 as Root Complex Integrated Device use:s/Root Complex Integrated Device/Integrated Endpoint/ ?
sure
Quoted 9 lines
I don't know how much any of these terms can be used interchangeably, but it would be good IMHO if we could choose a single term and stick to it throughout the document.
Quoted 1 line
Quoted 1 line
+ -device <dev>[,bus=pcie.0]
Is the bus=pcie.0 bit really optional? Will QEMU just assign devices to pcie.0 automatically unless you provide an explicit bus= option telling it otherwise?
yes, that is if you dont have a pxb-pcie devices that exposes a new PCI Root Bus.
If you have only one PCI Root Bus is OK.
Quoted 10 lines
Quoted 6 lines
docs/pcie.txt line 56
Quoted 6 lines
+2.1.2 To expose a new PCI Express Root Bus use:
docs/pcie.txt new file +4
-0+ -device pxb-pcie,id=pcie.1,bus_nr=x,[numa_node=y],[addr=z] + Only PCI Express Root Ports and DMI-PCI bridges can be connected to the pcie.1 bus: + -device ioh3420,id=root_port1[,bus=pcie.1][,chassis=x][,slot=y][,addr=z] \ + -device i82801b11-bridge,id=dmi_pci_bridge1,bus=pcie.1Here I really can't see how the bus= option would be optional for ioh3420 but mandatory for i82801b11-bridge.
As explained above, is not related to the DMI-PCI bridge, but to the fact we have 2 PCI root buses, so we have to specify which one we need.
Quoted 2 lines
Neither for <dev> above nor for i82801b11-bridge you show that the slot= option exists.
Because we don't have this option.
Of course these are merely
Quoted 5 lines
usage examples and are not intended to replace the full
documentation: since this is the case, I think we should make that very explicit and possibly avoid listing options we don't use at all, eg.
I will mention that the document does not list all the options, only the ones needed for the examples.
Quoted 7 lines
-device e1000,bus=pcie.0
This will plug a e1000 Ethernet adapter into pcie.0 as an Integrated Endpoint.
and so on.
Right, but the bus is optional if you don't have multiple PCI root buses (pxb/pxb-pcie).
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+2.2 PCI Express only hierarchy
+==============================(quoted diff) +2
-0+Always use PCI Express Root Ports to start PCI Express hierarchies. +
Quoted 9 lines
Quoted 6 lines
docs/pcie.txt line 68
Quoted 6 lines
docs/pcie.txt new file +6
-0+A PCI Express Root bus supports up to 32 devices. Since each +PCI Express Root Port is a function and a multi-function +device may support up to 8 functions, the maximum possible +PCI Express Root Ports per PCI Express Root Bus is 256. + +Prefer coupling PCI Express Root Ports into multi-function devicess/coupling/grouping/
OK
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
docs/pcie.txt new file +25
-0+to keep a simple flat hierarchy that is enough for most scenarios. +Only use PCI Express Switches (x3130-upstream, xio3130-downstream) +if there is no more room for PCI Express Root Ports. +Please see section 4. for further justifications. + +Plug only PCI Express devices into PCI Express Ports. + + + pcie.0 bus + ---------------------------------------------------------------------------------- + | | | + ------------- ------------- ------------- + | Root Port | | Root Port | | Root Port | + ------------ ------------- ------------- + | -------------------------|------------------------ + ------------ | ----------------- | + | PCIe Dev | | PCI Express | Upstream Port | | + ------------ | Switch ----------------- | + | | | | + | ------------------- ------------------- | + | | Downstream Port | | Downstream Port | | + | ------------------- ------------------- | + -------------|-----------------------|------------ + ------------ + | PCIe Dev |
Quoted 9 lines
Quoted 6 lines
docs/pcie.txt line 99
Quoted 6 lines
docs/pcie.txt new file +6
-0+ ------------ + +2.2.1 Plugging a PCI Express device into a PCI Express Root Port: + -device ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \ + -device <dev>,bus=root_port1 + Note that chassis parameter is compulsory, and must be uniques/compulsory/mandatory/
OK
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
docs/pcie.txt new file +7
-0+ for each PCI Express Root Port. +2.2.2 Using multi-function PCI Express Root Ports: + -device ioh3420,id=root_port1,multifunction=on,chassis=x[,bus=pcie.0][,slot=y][,addr=z.0] \ + -device ioh3420,id=root_port2,,chassis=x1[,bus=pcie.0][,slot=y1][,addr=z.1] \ + -device ioh3420,id=root_port3,,chassis=x2[,bus=pcie.0][,slot=y2][,addr=z.2] \ +2.2.2 Plugging a PCI Express device into a Switch: + -device ioh3420,id=root_port1,chassis=x[,bus=pcie.0][,slot=y][,addr=z] \Quoted 8 lines
docs/pcie.txt line 114
Quoted 8 lines
docs/pcie.txt new file +8
-0+ -device x3130-upstream,id=upstream_port1,bus=root_port1[,addr=x] \ + -device xio3130-downstream,id=downstream_port1,bus=upstream_port1,chassis=x1[,slot=y1][,addr=z1]] \ + -device <dev>,bus=downstream_port1 + + +2.3 PCI only hierarchy +====================== +Legacy PCI devices can be plugged into pcie.0 as Integrated Devices.Maybe we could add something like
Quoted 4 lines
but, as mentioned above, doing so means the legacy PCI device in question will be incapable of hot-unplugging.
just to stress the fact.
good idea.
Quoted 6 lines
Aside: "device" or "endpoint"? My understanding is that endpoints are things like Ethernet adapters, and devices are endpoints *or* controller, but I might be way off base here ;)
You are right, I will stick with "endpoints" and make the distinction. I actually used "Integrated devices" as it is clearer than "endpoints" for the reader, but if is not clear enough I'll do it "right".
Quoted 59 lines
Quoted 47 lines
Quoted 47 lines
docs/pcie.txt new file +47
-0+Besides that use DMI-PCI bridges (i82801b11-bridge) to start PCI hierarchies. + +Prefer flat hierarchies. For most scenarios a single DMI-PCI bridge (having 32 slots) +and several PCI-PCI bridges attached to it (each supporting also 32 slots) will support +hundreds of legacy devices. The recommendation is to populate one PCI-PCI bridge +under the DMI-PCI bridge until is full and then plug a new PCI-PCI bridge... + + pcie.0 bus + ---------------------------------------------- + | | + ----------- ------------------ + | PCI Dev | | DMI-PCI BRIDGE | + ---------- ------------------ + | | + ----------- ------------------ + | PCI Dev | | PCI-PCI Bridge | + ----------- ------------------ + | | + ----------- ----------- + | PCI Dev | | PCI Dev | + ----------- ----------- + +2.3.1 To plug a PCI device into a pcie.0 as Integrated Device use: + -device <dev>[,bus=pcie.0] +2.3.2 Plugging a PCI device into a DMI-PCI bridge: + -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device <dev>,bus=dmi_pci_bridge1[,addr=x] +2.3.3 Plugging a PCI device into a PCI-PCI bridge: + -device i82801b11-bridge,id=dmi_pci_bridge1,[,bus=pcie.0] \ + -device pci-bridge,id=pci_bridge1,bus=dmi_pci_bridge1[,chassis_nr=x][,addr=y] \ + -device <dev>,bus=pci_bridge1[,addr=x] + + +3. IO space issues +=================== +The PCI Express Root Ports and PCI Express Downstream ports are seen by +Firmware/Guest OS as PCI-PCI bridges and, as required by PCI spec, +should reserve a 4K IO range for each even if only one (multifunction) +device can be plugged into them, resulting in poor IO space utilization. + +The firmware used by QEMU (SeaBIOS/OVMF) may try further optimizations +by not allocating IO space if possible: + (1) - For empty PCI Express Root Ports/PCI Express Downstream ports. + (2) - If the device behind the PCI Express Root Ports/PCI Express + Downstream has no IO BARs. + +The IO space is very limited, 65536 byte-wide IO ports, but it's fragmentedQuoted 8 lines
docs/pcie.txt line 169
Quoted 8 lines
docs/pcie.txt new file +8
-0+resulting in ~10 PCI Express Root Ports (or PCI Express Downstream/Upstream ports) +ports per system if devices with IO BARs are used in the PCI Express hierarchy. + +Using the proposed device placing strategy solves this issue +by using only PCI Express devices within PCI Express hierarchy. + +The PCI Express spec requires the PCI Express devices to work without using IO. +The PCI hierarchy has no such limitations.After reading this section and piecing all bits together, my understanding is that
Quoted 3 lines
a) the spec requires firmware and OS to allocate 4K of IO space for each PCI Express Root Port or PCI Express Switch Downstream Port
at least
Quoted 4 lines
b) that's necessary because legacy PCI Devices require IO space to operate
right
Quoted 2 lines
c) however, IO space is a very limited resource
right again
Quoted 3 lines
d) the spec also requires PCI Express Devices (or rather Endpoints?) to work without using any IO space
PCI Express Devices, not Endpoints.
Quoted 6 lines
e) if we stick to the plan outlined in this document, there will never be legacy PCI Devices plugged into PCI Express Root Ports or PCI Express Switch Downstream Ports (only PCI Express Endpoints or PCI Express Switch Upstream Ports)
Yes, this is the idea.
Quoted 5 lines
f) thanks to d) and e), the firmware (and OS? IIRC Linux currently doesn't do this) can ignore a) and allocate no IO space for PCI Express Root Ports and PCI Express Switch Downstream Ports
Right, and even if the firmware/OS would try to allocate IO and fail, a device not requiring IO should still be able to function properly.
Quoted 2 lines
g) thus effectively making c) irrelevant
Yes.
Quoted 6 lines
If my reading is correct, I think we should put more emphasis on the fact that our device placement strategy is effective in avoiding IO space exaustion because we stick to PCI Express Devices only which, unlike legacy PCI Devices, require no IO space to operate.
Well, this is what the "3." point is about.
But since the device placement "theory" proposed by this document is not aimed only for the IO limitation, we have several points, each of them explaining another reason to do so.
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
+4. Bus numbers issues
+======================docs/pcie.txt new file +5
-0+Each PCI domain can have up to only 256 buses and the QEMU PCI Express +machines do not support multiple PCI domains even if extra Root +Complexes (pxb-pcie) are used. + +Each element of the PCI Express hierarchy (Root Complexes,Quoted 8 lines
docs/pcie.txt line 186
Quoted 8 lines
docs/pcie.txt new file +8
-0+PCI Express Root Ports, PCI Express Downstream/Upstream ports) +takes up bus numbers. Since only one (multifunction) device +can be attached to a PCI Express Root Port or PCI Express Downstream +Port it is advised to plan in advance for the expected number of +devices to prevent bus numbers starvation. + + +5. Hot PlugHot Plug, hot-plug or hotplug?
Quoted 2 lines
Pick one and stick with it :)
You got me here :) I'll pick one.
Quoted 31 lines
Quoted 20 lines
Quoted 20 lines
+============
docs/pcie.txt new file +19
-0+The PCI Express root buses (pcie.0 and the buses exposed by pxb-pcie devices) +do not support hot-plug, so any devices plugged into Root Complexes +cannot be hot-plugged/hot-unplugged: + (1) PCI Express Integrated Devices + (2) PCI Express Root Ports + (3) DMI-PCI bridges + (4) pxb-pcie + +PCI devices can be hot-plugged into PCI-PCI bridges, however cannot +be hot-plugged into DMI-PCI bridges. +The PCI hotplug is ACPI based and can work side by side with the +PCI Express native hotplug. + +PCI Express devices can be natively hot-plugged/hot-unplugged into/from +PCI Express Root Ports (and PCI Express Downstream Ports). + +5.1 Planning for hotplug: + (1) PCI hierarchy + Leave enough PCI-PCI bridge slots empty or add oneQuoted 8 lines
docs/pcie.txt line 214
Quoted 8 lines
docs/pcie.txt new file +8
-0+ or more empty PCI-PCI bridges to the DMI-PCI bridge. + + For each such bridge the Guest Firmware is expected to reserve 4K IO + space and 2M MMIO range to be used for all devices behind it. + + Because of the hard IO limit of around 10 PCI bridges (~ 40K space) per system + don't use more than 9 bridges, leaving 4K for the Integrated devices + and none for the PCI Express Hierarchy.I would rewrite the last line as
Quoted 3 lines
(the PCI Express hierarchy needs no IO space).
or something like that. Unless I misunderstood :)
maybe "...the PCI Express hierarchy that needs no IO space"
Quoted 5 lines
Quoted 4 lines
docs/pcie.txt line 218
Quoted 4 lines
docs/pcie.txt new file +3
-0+ (2) PCI Express hierarchy: + Leave enough PCI Express Root Ports empty. Use multifunction + PCI Express Root Ports to prevent going out of PCI bus numbers.
Quoted 8 lines
When you say "multifunction PCI Express Root Ports", are you suggesting the user should take advantage of all 8 functions in a PCI Express Root Port, eg. by plugging 4 Ethernet adapters into the same PCI Express Root Port instead of using a single PCI Express Root Port for each one of them, or that multiple PCI Express Root Ports should be plugged into functions of the same pcie.0 slot?
The later, please see the example 2.2.2
Quoted 5 lines
Either way, I don't see how doing so would prevent you from running out of PCI bus numbers - if anything, not doing the latter will make it so you'll run out of ports way before you come anywhere close to 256 PCI buses.
You are right, the reason is to not run out of ports. (the context is hot-plug here)
Quoted 9 lines
Point is, being less terse here could be very helpful.
Quoted 2 lines
docs/pcie.txt line 220
Quoted 2 lines
docs/pcie.txt new file +2
-0+ Don't use PCI Express Switches if you don't have too, they use + an extra PCI bus that may handy to plug another device id it comes to it.s/too/to/
s/may handy/may come handy/
s/id it comes/if it comes/
thanks again
Quoted 35 lines
Quoted 14 lines
Quoted 14 lines
+5.3 Hot plug example:
docs/pcie.txt new file +13
-0+Using HMP: (add -monitor stdio to QEMU command line) + device_add <dev>,id=<id>,bus=<pcie.0/PCI Express Root Port Id/PCI-PCI bridge Id/pxb-pcie Id> + + +6. Device assignment +==================== +Host devices are mostly PCI Express and should be plugged only into +PCI Express Root Ports or PCI Express Downstream Ports. +PCI-PCI bridge slots can be used for legacy PCI host devices. + +6.1 How to detect if a device is PCI Express: + > lspci -s 03:00.0 -v (as root) +Quoted 8 lines
docs/pcie.txt line 243
Quoted 8 lines
docs/pcie.txt new file +8
-0+ 03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83) + Subsystem: Intel Corporation Dual Band Wireless-AC 7260 + Flags: bus master, fast devsel, latency 0, IRQ 50 + Memory at f0400000 (64-bit, non-prefetchable) [size=8K] + Capabilities: [c8] Power Management version 3 + Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+ + Capabilities: [40] Express Endpoint, MSI 00 +I'd skip this empty line...
Quoted 2 lines
docs/pcie.txt line 245
Quoted 2 lines
docs/pcie.txt new file +2
-0+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... and this one too.
Quoted 4 lines
docs/pcie.txt line 249
Quoted 4 lines
docs/pcie.txt new file +4
-0+ Capabilities: [100] Advanced Error Reporting + Capabilities: [140] Device Serial Number 7c-7a-91-ff-ff-90-db-20 + Capabilities: [14c] Latency Tolerance Reporting + Capabilities: [154] Vendor Specific Information: ID=cafe Rev=1 Len=014
Quoted 5 lines
I'd also add a small note along the lines of
If you can see the "Express Endpoint" capability in the output, then the device is indeed PCI Express.
OK
Quoted 25 lines
Quoted 13 lines
Quoted 13 lines
+7. Virtio devices
+=================docs/pcie.txt new file +11
-0+Virtio devices plugged into the PCI hierarchy or as Integrated Devices +will remain PCI and have transitional behaviour as default. +Transitional virtio devices work in both IO and MMIO modes depending on +the guest support. + +Virtio devices plugged into PCI Express ports are PCI Express devices and +have "1.0" behavior by default without IO support. +In both case disable-* properties can be used to override the behaviour. + +Note that setting disable-legacy=off will enable legacy mode (enabling +legacy behavior) for PCI Express virtio devices causing them toQuoted 8 lines
docs/pcie.txt line 272
Quoted 8 lines
docs/pcie.txt new file +8
-0+require IO space, which, given our PCI Express hierarchy, may quickly +lead to resource exhaustion, and is therefore strongly discouraged. + + +8. Conclusion +============== +The proposal offers a usage model that is easy to understand and follow +and in the same time overcomes the PCI Express architecture limitations.s/in the same/at the same/
Quoted 9 lines
Overall I think the contents we care about are pretty much there and are exposed and organized in a very clear fashion; pretty much all of my comments are meant to improve the few areas where I believe we could make things even easier to grasp for the reader, remove potential ambiguity, or be more consistent.
Thanks for working on this! Looking forward to v3 ;)
Thanks a lot, the review is valuable and much appreciated! Marcel
Quoted 3 lines
--
Andrea Bolognani / Red Hat / Virtualization