Bug 1408808

Summary: PCIe: Add Generic PCIe Root Ports
Product: Red Hat Enterprise Linux 7 Reporter: Marcel Apfelbaum <marcel>
Component: libvirtAssignee: Andrea Bolognani <abologna>
Status: CLOSED ERRATA QA Contact: Han Han <hhan>
Severity: low Docs Contact: Yehuda Zimmerman <yzimmerm>
Priority: medium    
Version: 7.4CC: abologna, ailan, chayang, drjones, dyuan, ehabkost, jinzhao, juzhang, laine, lersek, lmen, mavital, michen, mtessun, rbalakri, virt-maint, vyerys, xuzhang
Target Milestone: rcKeywords: FutureFeature
Target Release: 7.4   
Hardware: All   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-3.2.0-1.el7 Doc Type: Enhancement
Doc Text:
_libvirt_ now uses generic PCIe root ports in QEMU In previous releases, _libvirt_ used PCIe root ports based on Intel hardware (ioh3420 device). This had some limitations, like needing IO space. With this release, _libvirt_ now uses generic PCIe root ports (pcie-root-port device) in QEMU, if available. This provides support for removing the aforementioned limitations in the future.
Story Points: ---
Clone Of: 1390316
: 1410437 1410441 (view as bug list) Environment:
Last Closed: 2017-08-01 17:21:45 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1390316    
Bug Blocks: 1173755, 1395265, 1410437, 1410441, 1412322, 1422967    

Description Marcel Apfelbaum 2016-12-27 12:08:26 UTC
+++ This bug was initially created as a clone of Bug #1390316 +++

Two reasons:
1. Can be used by both x86 and ARM VMs
2. Add a vendor-specific pci capability to these ports,
   with recommended window sizes (io/mem/prefmem) for the firmware
   for more efficient resource allocation.


Add libvirt support for the new controller.

Comment 2 Andrea Bolognani 2017-03-14 16:59:38 UTC
Patches submitted upstream.

  https://www.redhat.com/archives/libvir-list/2017-March/msg00590.html

Comment 3 Andrea Bolognani 2017-03-16 17:18:45 UTC
v2 patches submitted upstream.

  https://www.redhat.com/archives/libvir-list/2017-March/msg00788.html

Comment 4 Andrea Bolognani 2017-03-17 13:30:31 UTC
Fix committed upstream.

commit befd1c674bba4ddfd1735d6a80656142b2a8804c
Author: Andrea Bolognani <abologna>
Date:   Tue Mar 14 14:42:51 2017 +0100

    qemu: Use generic PCIe Root Ports by default when available
    
    ioh3420 is emulated Intel hardware, so it always looked
    quite out of place in aarch64/virt guests. Even for x86/q35
    guests, the recently-introduced pcie-root-port is a better
    choice because, unlike ioh3420, it doesn't require IO space
    (a fairly constrained resource) to work.
    
    If pcie-root-port is available in QEMU, use it; ioh3420 is
    still used as fallback for when pcie-root-port is not
    available.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1408808

v3.1.0-173-gbefd1c6

Comment 6 Han Han 2017-04-26 10:44:15 UTC
Verify it on libvirt-3.2.0-3.virtcov.el7.x86_64 qemu-kvm-rhev-2.9.0-1.el7.x86_64

First of all, if qemu-kvm support 'Generic PCIe Root Ports'. Libvirt will set it as default type of pcie-root-port
# cat /tmp/pcie-root-port.xml
<controller type='pci' index='9' model='pcie-root-port'/>
# virsh attach-device Q /tmp/pcie-root-port.xml --config
Device attached successfully
# virsh dumpxml Q
```
<controller type='pci' index='9' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='9' port='0x16'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
    </controller>
```

Second, check the controller in qemu cmdline and in VM; test it with hot-plug
1. Start a q35 machine with xml like following:
     <controller type='pci' index='6' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='6' port='0x13'/>
      <alias name='pci.6'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
    </controller>
2. Check qemu cmdline after start. Make sure the device in qemu is pcie-root-port.
# ps aux|grep qemu
qemu     30983 41.0  4.5 2008108 349396 ?      Rl   18:30   0:15 /usr/libexec/qemu-kvm -name guest=Q,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-3-Q/master-key.aes -machine pc-q35-rhel7.4.0,accel=kvm,usb=off,vmport=off,dump-guest-core=off -cpu Broadwell,+rtm,+hle -m 1024 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid 0fc904df-299a-4abd-8d18-08fed1247b3c -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-3-Q/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=delay -no-hpet -no-shutdown -global ICH9-LPC.disable_s3=1 -global ICH9-LPC.disable_s4=1 -boot strict=on -device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e -device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 -device pcie-root-port,port=0x10,chassis=3,id=pci.3,bus=pcie.0,multifunction=on,addr=0x2 -device pcie-root-port,port=0x11,chassis=4,id=pci.4,bus=pcie.0,addr=0x2.0x1 -device pcie-root-port,port=0x12,chassis=5,id=pci.5,bus=pcie.0,addr=0x2.0x2 -device pcie-root-port,port=0x13,chassis=6,id=pci.6,bus=pcie.0,addr=0x2.0x3 -device ich9-usb-ehci1,id=usb,bus=pcie.0,addr=0x1d.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pcie.0,multifunction=on,addr=0x1d -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pcie.0,addr=0x1d.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pcie.0,addr=0x1d.0x2 -device virtio-serial-pci,id=virtio-serial0,bus=pci.3,addr=0x0 -drive file=/var/lib/libvirt/images/Q.qcow2,format=qcow2,if=none,id=drive-sata0-0-0 -device ide-hd,bus=ide.0,drive=drive-sata0-0-0,id=sata0-0-0,bootindex=1 -netdev tap,fd=29,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:80:c6:a6,bus=pci.2,addr=0x1 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -chardev spicevmc,id=charchannel0,name=vdagent -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.spice.0 -spice port=5900,addr=127.0.0.1,disable-ticketing,image-compression=off,seamless-migration=on -device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pcie.0,addr=0x1 -device intel-hda,id=sound0,bus=pci.2,addr=0x2 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -chardev spicevmc,id=charredir0,name=usbredir -device usb-redir,chardev=charredir0,id=redir0,bus=usb.0,port=1 -chardev spicevmc,id=charredir1,name=usbredir -device usb-redir,chardev=charredir1,id=redir1,bus=usb.0,port=2 -device virtio-balloon-pci,id=balloon0,bus=pci.4,addr=0x0 -msg timestamp=on

3. Check the pcie-root-port in VM
In VM:
# lspci -v
00:02.3 PCI bridge: Red Hat, Inc. Device 000c (prog-if 00 [Normal decode])
        Flags: bus master, fast devsel, latency 0, IRQ 22
        Memory at fca15000 (32-bit, non-prefetchable) [size=4K]
        Bus: primary=00, secondary=04, subordinate=04, sec-latency=0
        I/O behind bridge: 00004000-00004fff
        Memory behind bridge: fc200000-fc3fffff
        Prefetchable memory behind bridge: 00000000fe400000-00000000fe5fffff
        Capabilities: [54] Express Root Port (Slot+), MSI 00
        Capabilities: [48] MSI-X: Enable+ Count=1 Masked-
        Capabilities: [40] Subsystem: Red Hat, Inc. Device 0000
        Capabilities: [100] Advanced Error Reporting
        Kernel driver in use: pcieport
        Kernel modules: shpchp

4. Attach a disk to the pcie-root-port
# qemu-img create /tmp/xx 100M
Formatting '/tmp/xx', fmt=raw size=104857600
# virsh attach-disk Q /tmp/xx vdb --address pci:0000.06.00.0
Disk attached successfully

In VM:
# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   10G  0 disk
├─sda1          8:1    0    1G  0 part /boot
└─sda2          8:2    0    9G  0 part
  ├─rhel-root 253:0    0    8G  0 lvm  /
  └─rhel-swap 253:1    0    1G  0 lvm  [SWAP]
vda           252:0    0  100M  0 disk

Bug fixed.

Comment 8 errata-xmlrpc 2017-08-01 17:21:45 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1846

Comment 9 errata-xmlrpc 2017-08-02 00:01:15 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1846