Bug 667188

Summary: device-assignment leaks option ROM memory
Product: Red Hat Enterprise Linux 6 Reporter: Alex Williamson <alex.williamson>
Component: qemu-kvmAssignee: Alex Williamson <alex.williamson>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 6.1CC: juzhang, lihuang, mkenneth, virt-maint
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-0.12.1.2-2.132.el6 Doc Type: Bug Fix
Doc Text:
Cause: Device assignment code failed to release memory used for storing device PCI option ROM contents. Consequence: Hot-unplugging assigned devices with an option ROM from a VM did not free the associated ROM memory. Repeatedly adding and removing such devices results in the qemu process size growing. Fix: Fix management of memory used for PCI option ROM of assigned devices. Result: Removal of assigned devices removes all resources consumed by that device in the qemu process.
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-05-19 11:30:51 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: 580954    

Description Alex Williamson 2011-01-04 18:57:22 UTC
Description of problem:
When a PCI device with an option ROM is repeatedly added and removed from a guest, the option ROM memory is leaked, causing the guest processes size to grow and eventually be OOM killed.

Version-Release number of selected component (if applicable):
qemu-kvm-0.12.1.2-2.128.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Launch guest via libvirt
2. Create xml file to assign device, ex:

<hostdev mode='subsystem' type='pci' managed='yes'>
  <source>
    <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
  </source>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</hostdev>

In this case the device is an 82576 PF device w/ 4MB option ROM (leaks even though ROM is invalid).

3. Loop adding and removing the device:

i=1; while virsh attach-device <guest> <xml>; do echo $i; i=$[i+1]; sleep 1; virsh detach-device <guest> <xml>; sleep 1; done
  
Actual results:
top in the host shows the guest process size increasing on each iteration

Expected results:
stable guest process size

Additional info:
Fixed by backporting the following patches:
4b785d9624c1127b358d71933bb5ec476a39db25
576af1b5f5524ca0d6587ae43e395313c14059bb
plus additional patch to chmod the rom file

Comment 5 juzhang 2011-02-11 05:14:27 UTC
Reproduced on qemu-kvm-0.12.1.2-2.129.el6.

step
1.boot guest.
2.run script
while true; do ps --format 'vsz' `pidof qemu-kvm`; sleep 10; done
3.repeat hotplug and hotunplug PF and observe qemu-kvm process VSZ

Results
shows the guest process size increasing
 while true; do ps --format 'vsz' `pidof qemu-kvm`; sleep 10; done
   VSZ
2521376
   VSZ
2521376
   VSZ
2525476 after hotplug
   VSZ
2525476
   VSZ
2525472 after hotunplug
   VSZ
2525472
   VSZ

Verified on qemu-kvm-0.12.1.2-2.144.el6 using the same steps.
Results
stable guest process size
while true; do ps --format 'vsz' `pidof qemu-kvm`; sleep 10; done
   VSZ
2522228
   VSZ
2522228 
   VSZ
2522232 after hotpulg
   VSZ
2522232
   VSZ
2522228 after hotunplug
   VSZ
2522228
   VSZ
2522232 after hotplug
   VSZ
2522232
   VSZ
2522228 after hotunplug
   VSZ
2522228

This issue has been fixed.

Comment 7 Alex Williamson 2011-05-05 16:31:06 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:
Device assignment code failed to release memory used for storing device PCI option ROM contents.
Consequence:
Hot-unplugging assigned devices with an option ROM from a VM did not free the associated ROM memory.  Repeatedly adding and removing such devices results in the qemu process size growing.
Fix:
Fix management of memory used for PCI option ROM of assigned devices.
Result:
Removal of assigned devices removes all resources consumed by that device in the qemu process.

Comment 8 errata-xmlrpc 2011-05-19 11:30:51 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 9 errata-xmlrpc 2011-05-19 13:00:48 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