Bug 680058

Summary: can't hotplug second vf successful with message "Too many open files"
Product: Red Hat Enterprise Linux 6 Reporter: Chao Yang <chayang>
Component: qemu-kvmAssignee: Alex Williamson <alex.williamson>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.1CC: alex.williamson, gcosta, juzhang, michen, mkenneth, tburke, virt-maint
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: qemu-kvm-0.12.1.2-2.149.el6 Doc Type: Bug Fix
Doc Text:
Cause: On device removal, the device assignment code was only removing resources that had been mapped into the guest address space. Consequence: The qemu process may leak open file handles if an assigned device is removed before the guest maps the device resources. If this is repeated, the qemu process may eventually reach it's limit of open file handles. Fix: Close all file handles for assigned devices when the device is removed. Result: Qemu no longer leaks file handles, regardless of how quickly devices are add and removed from the VM.
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-05-19 11:28:15 UTC Type: ---
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: 580953    
Attachments:
Description Flags
device message generated by hot plug/unplug
none
listing of /proc/<pid of qemu>/fd none

Description Chao Yang 2011-02-24 09:17:09 UTC
Created attachment 480692 [details]
device message generated by hot plug/unplug

Description of problem:
when doing hot plug/unplug two vfs about 300 times, qemu reports " get_real_device: /sys/bus/pci/devices/0000:04:10.3/resource: Too many open files"

Version-Release number of selected component (if applicable):
# rpm -qa|grep qemu
gpxe-roms-qemu-0.9.7-6.4.el6.noarch
qemu-kvm-0.12.1.2-2.147.el6.x86_64
qemu-img-0.12.1.2-2.147.el6.x86_64

# uname -r
2.6.32-117.el6.x86_64

# lspci|grep 82576
04:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
04:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)


How reproducible:
2/2

Steps to Reproduce:
1.boot a guest
# /usr/libexec/qemu-kvm -M rhel6.1.0 -enable-kvm -m 4096 -smp 4 -cpu qemu64,+sse2,+x2apic -name win2008r2 -uuid b044ca52-c418-461e-bf1e-4075b3e613e4 -rtc base=localtime -boot c -drive file=/root/images/windows2008r2-copy-2.qcow2,if=none,id=drive-ide2-0-0,media=disk,format=qcow2,cache=none -device ide-drive,drive=drive-ide2-0-0,id=ide2-0-0 -netdev tap,id=hostnet2 -device e1000,netdev=hostnet2,id=net2,mac=52:54:87:91:87:93 -usb -device usb-tablet -vnc :2 -monitor stdio -balloon none -qmp tcp:0:4445,server,nowait

2.execute a python script to issue hot plug/unplug vf
for i in range(num):
        t = i + 1
        print("Try %s times" % t)
        cmd = "device_add driver=pci-assign host=04:10.1 id=vf1"
        qmp_socket.send(cmd)
	time.sleep(3)
        cmd = "device_add driver=pci-assign host=04:10.3 id=vf3"
        qmp_socket.send(cmd)
        time.sleep(3)
        cmd = "device_del id=vf1"
        qmp_socket.send(cmd)
	time.sleep(3)
        cmd = "device_del id=vf3"
        qmp_socket.send(cmd)
        time.sleep(3)

3.
  
Actual results:

300 times around, qemu failed to hot plug 2nd vf and monitor starts reporting "get_real_device: /sys/bus/pci/devices/0000:04:10.3/resource: Too many open files" when hotplug the second vf every time. At this time, if hot unplug the first vf, then hot plug the second one, qemu won't report such info, and then hot plug the first vf, qemu reports "get_real_device: /sys/bus/pci/devices/0000:04:10.1/resource: Too many open files
pci-assign: Error: Couldn't get real device (vf1)!
Device 'pci-assign' could not be initialized"


Expected results:
qemu could hot plug 2nd vf successfully.

Additional info:

Comment 2 Alex Williamson 2011-02-24 15:38:36 UTC
When this occurs, can you please find the qemu process id (note there may be more than one), and add the listing (ls -l) of /proc/<pid>/fd to the bz.  You should use the pid that has entries for anon_inode:kvm-vcpu in the same directory.  In my testing, all device assignment related file handles are successfully closed when the device is removed.

Comment 3 Chao Yang 2011-02-25 07:26:20 UTC
Created attachment 480945 [details]
listing of /proc/<pid of qemu>/fd

Hi Alex,
Hit again with windows guest, for detail please check the attachment, and I tested with rhel6.1 guest twice, seems the issue can't reproduce on rhel6.1 guest. 

# ps -aux|grep qemu
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      4021 43.0  0.9 4764716 4245716 pts/0 Sl+  14:25   2:07 /usr/libexec/qemu-kvm -M rhel6.1.0 -enable-kvm -m 4096 -smp 4 -cpu qemu64,+sse2,+x2apic -name win2008r2 -uuid b51bc5eb-098b-470c-ab40-fca98dae921c -rtc base=localtime -boot c -drive file=/root/images/windows2008r2-copy-2.qcow2,if=none,id=drive-ide2-0-0,media=disk,format=qcow2,cache=none -device ide-drive,drive=drive-ide2-0-0,id=ide2-0-0 -netdev tap,id=hostnet2 -device e1000,netdev=hostnet2,id=net2,mac=52:54:87:91:87:93 -usb -device usb-tablet -vnc :2 -monitor stdio -balloon none -qmp tcp:0:4445,server,nowait


# ls -l /proc/4021/fd >> fd.txt

Comment 4 Alex Williamson 2011-02-25 20:10:21 UTC
Please test to see if this brew build fixes the problem, I believe I found the error you're hitting:

https://brewweb.devel.redhat.com/taskinfo?taskID=3143074

Comment 5 Chao Yang 2011-02-28 11:11:37 UTC
(In reply to comment #4)
> Please test to see if this brew build fixes the problem, I believe I found the
> error you're hitting:
> 
> https://brewweb.devel.redhat.com/taskinfo?taskID=3143074

Alex,
I am testing your brew build, will get result tmr.

Comment 6 Chao Yang 2011-03-01 04:30:09 UTC
(In reply to comment #4)
> Please test to see if this brew build fixes the problem, I believe I found the
> error you're hitting:
> 
> https://brewweb.devel.redhat.com/taskinfo?taskID=3143074

Alex,
 I test for 3 times, I think this brew build you offer has fixed the error.

Comment 12 Chao Yang 2011-03-18 01:53:23 UTC
Verified with package qemu-kvm-0.12.1.2-2.150.el6.x86_64, have hot plug/unplug for 5000 times on windows 2k8 r2 guest, this issue doesn't exist any more.

/usr/libexec/qemu-kvm -M rhel6.1.0 -enable-kvm -m 4096 -smp 4 -name win2008r2 -uuid 918f1abd-b769-452b-8672-795acd07c9d4 -rtc base=localtime,clock=vm,driftfix=slew -no-kvm-pit-reinjection -boot c -drive file=/root/win2008r2.raw,if=none,id=drive-ide0-0-0,media=disk,format=raw,cache=none -device ide-drive,drive=drive-ide0-0-0,id=ide0-0-0 -netdev tap,id=hostnet2 -device e1000,netdev=hostnet2,id=net2,mac=52:54:87:91:87:93 -usb -device usb-tablet -vnc :2 -monitor stdio -balloon none -qmp tcp:0:4445,server,nowait

Comment 13 Alex Williamson 2011-05-05 16:20:52 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Cause:
On device removal, the device assignment code was only removing resources that had been mapped into the guest address space.
Consequence:
The qemu process may leak open file handles if an assigned device is removed before the guest maps the device resources.  If this is repeated, the qemu process may eventually reach it's limit of open file handles.
Fix:
Close all file handles for assigned devices when the device is removed.
Result:
Qemu no longer leaks file handles, regardless of how quickly devices are add and removed from the VM.

Comment 14 errata-xmlrpc 2011-05-19 11:28:15 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2011-0534.html

Comment 15 errata-xmlrpc 2011-05-19 13:01:50 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2011-0534.html