Bug 1265587

Summary: unbind PF will cause VF0 disappear in host, but it still exist in guest.
Product: Red Hat Enterprise Linux 7 Reporter: Yanan Fu <yfu>
Component: qemu-kvm-rhevAssignee: Alex Williamson <alex.williamson>
Status: CLOSED NOTABUG QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.2CC: chayang, juzhang, knoel, virt-maint, yfu
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-09-25 02:19:47 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 Yanan Fu 2015-09-23 09:54:11 UTC
Description of problem:
bring up VFs,unbind VF and assign to guest with "x-req=off" :

"-device vfio-pci,host=47:06.0,id=vf-06-0,x-req=off "
boot the guest, and unbound PF: 
"echo 0000:47:00.1 > /sys/bus/pci/devices/0000\:47\:00.1/driver/unbind"
the echo operation will be blocked until user unplug the VFs, this is normal.
then in the guest and qemu monitor, can show all the vfs, but in the host,vf0 will disappear, other vfs are normal.

Version-Release number of selected component (if applicable):
host:kernel:3.10.0-316.el7.x86_64
     qemu-kvm:qemu-kvm-rhev-2.3.0-24.el7.x86_64
guest:kernel:kernel:3.10.0-316.el7.x86_64


How reproducible:
100%

Steps to Reproduce:
1.bring up vfs
2.unbind VFs and assign to guest:
-device vfio-pci,host=47:06.0,id=vf-06-0,x-req=off 
-device vfio-pci,host=47:06.1,id=vf-06-1,x-req=off
3.boot the guest, then unbound the PF in host
"echo 0000:47:00.1 > /sys/bus/pci/devices/0000\:47\:00.1/driver/unbind"
4.echo operation will be blocked as "x-req=off"
5.in the guest, "lspci" and "ifconfig" , and in qemu "info pci" can see all the VFs, but in the host "ls /sys/bus/pci/drivers/vfio-pci/" have no VF0(ex:47:06.0)

if bring only one vf, the result is same. 

Actual results:
VF0 will disappear in the host.

Expected results:
VF0 exist in the host.

Additional info:
CLI:
/usr/libexec/qemu-kvm -name rhel7 -machine pc,accel=kvm,usb=off -realtime mlock=off -cpu Opteron_G5,enforce -sandbox off -m 4G -smp 8,cores=8,threads=1,sockets=1 -object memory-backend-file,prealloc=yes,size=1024M,id=ram-node0,host-nodes=0,policy=bind,mem-path=/mnt/hugetlbfs -numa node,nodeid=0,cpus=0,cpus=1,memdev=ram-node0 -object memory-backend-file,prealloc=yes,size=1024M,id=ram-node1,host-nodes=1,policy=bind,mem-path=/mnt/hugetlbfs -numa node,nodeid=1,cpus=2,cpus=3,memdev=ram-node1 -object memory-backend-file,prealloc=yes,size=1024M,id=ram-node2,host-nodes=2,policy=bind,mem-path=/mnt/hugetlbfs -numa node,nodeid=2,cpus=4,cpus=5,memdev=ram-node2 -object memory-backend-file,prealloc=yes,size=1024M,id=ram-node3,host-nodes=3,policy=bind,mem-path=/mnt/hugetlbfs -numa node,nodeid=3,cpus=6,cpus=7,memdev=ram-node3 -boot order=c,menu=on,splash-time=3000,strict=on -device ich9-usb-ehci1,id=usb0,bus=pci.0,addr=0x5.0x7 -device ich9-usb-uhci1,masterbus=usb0.0,firstport=0,bus=pci.0,multifunction=on,addr=0x5 -device ich9-usb-uhci2,masterbus=usb0.0,firstport=2,bus=pci.0,addr=0x5.0x1 -device ich9-usb-uhci3,masterbus=usb0.0,firstport=4,bus=pci.0,addr=0x5.0x2 -device virtio-scsi-pci,id=scsi0,cmd_per_lun=234,bus=pci.0,addr=0x8 -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x7 -drive file=/root/rhel-7.2.qcow2,if=none,id=drive-virtio-disk0,format=qcow2,cache=none,discard=unmap,werror=stop,rerror=stop,aio=threads -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x9,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -device usb-tablet,id=usb-tablet1 -monitor stdio -qmp tcp:0:4444,server,nowait -serial unix:/tmp/ttym,server,nowait -spice port=5901,addr=0.0.0.0,seamless-migration=on,disable-ticketing -k en-us -device qxl-vga,id=video0,ram_size=134217728,vram_size=67108864,vgamem_mb=16,bus=pci.0,addr=0x2 -device pci-bridge,bus=pci.0,id=bridge1,chassis_nr=1,addr=0xc -netdev tap,id=hostnet0,vhost=on,id=hostnet0,script=/etc/qemu-ifup -device virtio-net-pci,netdev=hostnet0,id=virtio-net-pci0,mac=b6:af:42:b8:46:18,bus=bridge1,addr=0x14 -rtc base=utc,clock=host,driftfix=slew -device vfio-pci,host=47:06.0,id=vf-06-0

Comment 2 Yanan Fu 2015-09-23 10:11:44 UTC
If don't unbound PF, just only unbound vf0 from vfio-pci driver:

"echo 0000:47:06.0 > /sys/bus/pci/drivers/vfio-pci/unbind"

the result is same with unbound PF:vf0 disappear in host, but exist in guest.

Comment 3 Yanan Fu 2015-09-23 10:31:35 UTC
in my latest, if don't unbind PF, just unbound VFs, not only vf0 has this issue. every vfs all have this issue.
for example:
qemu:
-device vfio-pci,host=47:06.0,id=vf-06-0,x-req=off 
-device vfio-pci,host=47:06.1,id=vf-06-1,x-req=off

in host:
#echo 0000:47:06.1 > /sys/bus/pci/drivers/vfio-pci/unbind
echo operation will be blocked as "x-req=off", in the guest, "lspci" and "ifconfig" , and in qemu "info pci" can see the VF 0000:47:06.1, but in the host "ls /sys/bus/pci/drivers/vfio-pci/" can't not see it.

Comment 4 Alex Williamson 2015-09-23 13:56:38 UTC
(In reply to Yanan Fu from comment #0) 
> Actual results:
> VF0 will disappear in the host.
> 
> Expected results:
> VF0 exist in the host.

So clearly the kernel behavior does not match your expectations, but why is your expectation correct and why is the kernel behavior incorrect?  What functional difference does it make?

When a PF is unbound, SR-IOV is typically disabled and each VF is removed in sequence, serially.  Therefore it makes sense to me that VF0 disappears from the bound devices as it's removed via the PF.  The unbind is blocked though since the user hasn't released the device.  Teardown of VF1 and therefore the unbind won't start until VF0 is released and unbound.  The driver linking shows exactly this.

In the latter case, multiple VFs are being removed concurrently and the driver link in sysfs represents that.

Does the current kernel behavior actually prevent you from doing something?  Simply being different from your expectations is not a bug.

Comment 5 Yanan Fu 2015-09-25 02:09:14 UTC
(In reply to Alex Williamson from comment #4)
> (In reply to Yanan Fu from comment #0) 
> > Actual results:
> > VF0 will disappear in the host.
> > 
> > Expected results:
> > VF0 exist in the host.
> 
> So clearly the kernel behavior does not match your expectations, but why is
> your expectation correct and why is the kernel behavior incorrect?  What
> functional difference does it make?
> 
> When a PF is unbound, SR-IOV is typically disabled and each VF is removed in
> sequence, serially.  Therefore it makes sense to me that VF0 disappears from
> the bound devices as it's removed via the PF.  The unbind is blocked though
> since the user hasn't released the device.  Teardown of VF1 and therefore
> the unbind won't start until VF0 is released and unbound.  The driver
> linking shows exactly this.
> 
> In the latter case, multiple VFs are being removed concurrently and the
> driver link in sysfs represents that.
> 
> Does the current kernel behavior actually prevent you from doing something? 
> Simply being different from your expectations is not a bug.

This behavior does not prevent my test by now.and I can understand what you say: "VF is removed in sequence, serially", but i think VF should not disappear in host until it is removed in the guest manually(device_del). 
In my test, the first VF which is in using by guest will disappear in host before it is removed in guest.

Comment 6 Alex Williamson 2015-09-25 02:19:47 UTC
Sorry, I don't think there's a bug here.  In the case of the PF, you've initiated the unbind of the PF, which attempts to unbind the VF.  The device links in the driver reflect that.  In the case of the VFs, you're initiating the unbind of each VF, and the device link in the driver reflect that.