Bug 1610215

Summary: [Q35] hotplug failed when using pcie-root-port multifunction
Product: Red Hat Enterprise Linux 7 Reporter: Yiqian Wei <yiwei>
Component: qemu-kvm-rhevAssignee: Michael S. Tsirkin <mst>
Status: CLOSED NOTABUG QA Contact: jingzhao <jinzhao>
Severity: low Docs Contact:
Priority: unspecified    
Version: 7.6CC: ailan, chayang, fjin, jinzhao, juzhang, laine, meili, michen, virt-maint, yafu, yiwei
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1610587 (view as bug list) Environment:
Last Closed: 2018-09-05 20:39:22 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:    
Bug Blocks: 1610587    

Description Yiqian Wei 2018-07-31 08:50:26 UTC
Description of problem:
hotplug failed when using pcie-root-port multifunction

Version-Release number of selected component (if applicable):
host version:
qemu-kvm-rhev-2.12.0-8.el7.x86_64
kernel-3.10.0-928.el7.x86_64
seabios-1.11.0-2.el7.x86_64
guest:rhel7.6

How reproducible:
2/2

Steps to Reproduce:
1.boot a guest with [1]
2.hot plug a virtio-net-pci device with "addr=0x0.1" to guest by:
In hmp:
(qemu)netdev_add tap,id=hostnet1,vhost=on
(qemu)device_add virtio-net-pci,netdev=hostnet1,mac=9a:6a:6b:6c:6d:69,id=net1,iommu_platform=on,ats=on,bus=root1,addr=0x0.1

Actual results:
After step2,
(qemu) device_add virtio-net-pci,netdev=hostnet1,mac=9a:6a:6b:6c:6d:69,id=net1,iommu_platform=on,ats=on,bus=root1,addr=0x0.1
PCI: slot 0 function 0 already ocuppied by virtio-net-pci, new func virtio-net-pci cannot be exposed to guest.

Expected results:
Hotplug device success.

Additional info:
[1]
/usr/libexec/qemu-kvm \
-M q35,kernel-irqchip=split \
-device intel-iommu,intremap=on,caching-mode=on,device-iotlb=on \
-name vm \
-cpu Haswell-noTSX,enforce \
-nodefaults -rtc base=utc \
-m 4G \
-smp 4,sockets=4,cores=1,threads=1,maxcpus=4 \
-enable-kvm \
-k en-us \
-vga qxl \
-boot menu=on \
-qmp tcp:0:6667,server,nowait \
-device pcie-root-port,bus=pcie.0,id=root0,multifunction=on,chassis=1,addr=0xa.0 \
-drive file=/mnt/rhel7.6.qcow2,if=none,id=drive-virtio-disk0,format=qcow2,cache=none,werror=stop,rerror=stop \
-device virtio-blk-pci,drive=drive-virtio-disk0,id=virtio-disk0,bus=root0,bootindex=1,iommu_platform=on   \
-device pcie-root-port,bus=pcie.0,id=root1,chassis=11,addr=0xa.1 \
-device virtio-net-pci,netdev=hostnet0,mac=9a:6a:6b:6c:6d:68,bus=root1,id=net0,iommu_platform=on,ats=on,multifunction=on,addr=0x0.0   \
-netdev tap,id=hostnet0,vhost=on   \
-monitor stdio \
-spice port=5901,disable-ticketing  \

2.with "qemu-kvm-rhev-2.10.0-21.el7_5.4.x86_64" version,hit the same issue.

Comment 2 Amnon Ilan 2018-08-06 17:55:52 UTC
Is this a valid hotplug config? i.e. when hotpluging via libvirt does it 
use this config?

Comment 3 Yiqian Wei 2018-08-07 08:39:43 UTC
(In reply to Amnon Ilan from comment #2)
> Is this a valid hotplug config? i.e. when hotpluging via libvirt does it 
> use this config?

I retest this bug with libvirt,as follows:
1.boot a rhel7.6 guest with virt-manager
2.edit vm XML file [1]
virsh # edit vm 
Domain vm XML configuration edited.
3.hotplug NIC to guest by:
#virsh attach-device vm /home/bz/nic1.xml

test results:
after step3,
# virsh attach-device vm /home/bz/nic1.xml
error: Failed to attach device from /home/bz/nic1.xml
error: internal error: Only PCI device addresses with function=0 are supported

additional info:
[1].Modified part in vm XML file
<interface type='bridge'>
      <mac address='52:54:00:23:ba:95'/>
      <source bridge='switch'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0' multifunction='on'/>
</interface>

2.cat nic1.xml
<interface type='bridge'>
   <mac address='52:54:00:23:ba:93'/>
   <source bridge='switch'/>
   <model type='virtio'/>
   <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x1'/>
</interface>

Comment 4 Michael S. Tsirkin 2018-08-13 13:57:45 UTC
to comment 0, it looks like you supply the same function in both cases.

Comment 6 Laine Stump 2018-09-05 20:39:22 UTC
You can only hotplug an entire slot at once. The PCI standard doesn't allow hotplugging something into an unused function of a slot that already has a device in it. IOW, what you're trying to do is explicitly illegal.