Bug 1329090

Summary: Provide proper error when setting pcie-switch-upstream-port controller's index >=257
Product: Red Hat Enterprise Linux 7 Reporter: Yang Yang <yanyang>
Component: libvirtAssignee: Laine Stump <laine>
Status: CLOSED ERRATA QA Contact: Han Han <hhan>
Severity: low Docs Contact:
Priority: low    
Version: 7.3CC: dyuan, mzhan, rbalakri, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-3.2.0-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 17:09:12 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:

Description Yang Yang 2016-04-21 07:59:18 UTC
Description of problem:
When setting pcie-switch-upstream-port index>=257, libvirt report
long unclear error message like this
# virsh create vm1-q35.xml
error: Failed to create domain from vm1-q35.xml
error: internal error: early end of file from monitor, possible problem: 247,bus=pci.9,addr=0x1c -device pci-bridge,chassis_nr=248,id=pci.248,bus=pci.9,addr=0x1d -device pci-bridge,chassis_nr=249,id=pci.249,bus=pci.9,addr=0x1e -device pci-bridge,chassis_nr=250,id=pci.250,bus=pci.9,addr=0x1f -device pci-bridge,chassis_nr=251,id=pci.251,bus=pci.10,addr=0x1 -device pci-bridge,chassis_nr=252,id=pci.252,bus=pci.10,addr=0x2 -device pci-bridge,chassis_nr=253,id=pci.253,bus=pci.10,addr=0x3 -device pci-bridge,chassis_nr=254,id=pci.254,bus=pci.10,addr=0x4 -device pci-bridge,chassis_nr=255,id=pci.255,bus=pci.10,addr=0x5 -device pci-bridge,chassis_nr=256,id=pci.256,bus=pci.10,addr=0x6 -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 vir!
 tio-scsi-pci,id=scsi0,bus=pci.10,addr=0xa -device virtio

Version-Release number of selected component (if applicable):
100%

How reproducible:
libvirt-1.3.3-2.el7.x86_64

Steps to Reproduce:
1. prepare a xml and set pcie-switch-upstream-port controller's index=257
<controller type='pci' index='3' model='pcie-root-port'/>
<controller type='pci' index='257' model='pcie-switch-upstream-port'/>

2. create vm
# virsh create vm1-q35.xml
error: Failed to create domain from vm1-q35.xml
error: internal error: early end of file from monitor, possible problem: 247,bus=pci.9,addr=0x1c -device pci-bridge,chassis_nr=248,id=pci.248,bus=pci.9,addr=0x1d -device pci-bridge,chassis_nr=249,id=pci.249,bus=pci.9,addr=0x1e -device pci-bridge,chassis_nr=250,id=pci.250,bus=pci.9,addr=0x1f -device pci-bridge,chassis_nr=251,id=pci.251,bus=pci.10,addr=0x1 -device pci-bridge,chassis_nr=252,id=pci.252,bus=pci.10,addr=0x2 -device pci-bridge,chassis_nr=253,id=pci.253,bus=pci.10,addr=0x3 -device pci-bridge,chassis_nr=254,id=pci.254,bus=pci.10,addr=0x4 -device pci-bridge,chassis_nr=255,id=pci.255,bus=pci.10,addr=0x5 -device pci-bridge,chassis_nr=256,id=pci.256,bus=pci.10,addr=0x6 -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 vir!
 tio-scsi-pci,id=scsi0,bus=pci.10,addr=0xa -device virtio

Actual results
Error messages are not friendly

Expected results
Actually creating vm failed due to chassis_nr out of range. So libvirt should provide proper error like this
# virsh create vm1-q35.xml
error: Failed to create domain from vm1-q35.xml
error: Parameter 'chassis_nr' out of range - must be 0-255

Additional info:

Comment 2 Laine Stump 2016-06-27 22:08:18 UTC
We do check the boundaries of chassis_nr, but that happens when parsing user input. We haven't been bounds-checking chassis_nr when the number is auto-generated.

A side note: on one hand, we apparently want to support > 256 downstream ports, but on the other hand each downstream port requires a chassis_nr, and we want chassis_nr (which is limited to 1-256) to be unique (see Bug 1349227). So which do we try to satisfy?

Comment 4 Laine Stump 2017-03-27 00:50:50 UTC
Actually we should just limit the max for PCI controller index to 256, since index is a proxy for the controller's bus number, and that is an 8 bit value.

Patch posted upstream:

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

Comment 5 Laine Stump 2017-03-27 16:41:15 UTC
Fixed upstream:

commit 272f18563179d7372ce0a11b4425a0497cf70e93
Author: Laine Stump <laine>
Date:   Sun Mar 26 20:47:17 2017 -0400

    conf: validate that PCI controller index is < 256

Comment 7 Han Han 2017-05-02 01:09:07 UTC
Verified on libvirt-3.2.0-3.el7.x86_64.
1. Cold plug pcie-switch-upstream-port controllers to VM, index up to 256.
# cat /tmp/upstream.xml      
<controller type='pci' index='INDEX' model='pcie-switch-upstream-port'/>
# for i in $(seq 6 2 256);do 
    sed "s/INDEX/$i/g" /tmp/upstream.xml > /tmp/xx.xml
    sudo virsh attach-device q35-upstream /tmp/xx.xml --config
done

You will get a error when the index reaches 256:
error: unsupported configuration: PCI controller index 256 too high, maximum is 255
Failed. Try again? [y,n,i,f,?]: 

Or you can use 'virsh edit' to add the index to 256:
# virsh edit q35-upstream
error: unsupported configuration: PCI controller index 256 too high, maximum is 255
Failed. Try again? [y,n,i,f,?]:

Comment 8 errata-xmlrpc 2017-08-01 17:09:12 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-01 23:51:16 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