Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 1491434 - KVM leaks file descriptors when attaching and detaching virtio-scsi block devices
KVM leaks file descriptors when attaching and detaching virtio-scsi block dev...
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: qemu-kvm (Show other bugs)
7.3
x86_64 Linux
high Severity high
: rc
: ---
Assigned To: Fam Zheng
Xueqiang Wei
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-09-13 15:44 EDT by bugzilla
Modified: 2018-04-10 10:35 EDT (History)
16 users (show)

See Also:
Fixed In Version: qemu-kvm-1.5.3-149.el7
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2018-04-10 10:35:07 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2018:0816 normal SHIPPED_LIVE Low: qemu-kvm security, bug fix, and enhancement update 2018-04-10 08:47:03 EDT

  None (edit)
Description bugzilla 2017-09-13 15:44:33 EDT
Description of problem:

KVM leaks file descriptors when attaching and detaching virtio-scsi block devices. The AIO file descriptor is not freed on detach.

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

qemu-kvm-1.5.3-126.el7_3.10.x86_64

How reproducible:

Very

Steps to Reproduce:
1. Use this XML:
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>
      <source dev='/dev/loop0'/>
      <target dev='sdzz' bus='scsi'/>
	  <address type='drive' controller='0' bus='0' target='0' unit='39'/>
    </disk>


2. Attach device and count AIO file descriptors:
~]# virsh attach-device vm1 disk.xml --live --config && lsof -p 12463 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz --config --live && lsof -p 12463 |grep '\[aio\]' |wc -l
Device attached successfully

27
Disk detached successfully

27


3. Note that before and after detach there are the same number of file descriptors.

4. Run it many more times and notice the file descriptors creeping skyward:

~]# virsh attach-device vm1 disk.xml --live --config && lsof -p 12463 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz --config --live && lsof -p 12463 |grep '\[aio\]' |wc -l
Device attached successfully

28
Disk detached successfully

28
~]# virsh attach-device vm1 disk.xml --live --config && lsof -p 12463 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz --config --live && lsof -p 12463 |grep '\[aio\]' |wc -l
Device attached successfully

29
Disk detached successfully

29



Actual results:

File descriptors leak. After awhile, we hit 8192 and fail to detach devices. I could increase the FD limits, but that seems like a work around.

Expected results:

File descriptors should not leak.
Comment 2 bugzilla 2017-09-13 15:47:30 EDT
We have not tested to see if this affects non-virtio disks. Presumably, any AIO-backed disk source causes this leak.

This is our XML for the domain:

<domain type='kvm' id='32'>
  <name>vm1</name>
  <uuid>f5e388b4-7abb-4e7f-a949-fbbe4887d92a</uuid>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>
      <source dev='/dev/loop0'/>
      <backingStore/>
      <target dev='sda' bus='scsi'/>
      <alias name='scsi0-0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>
      <source dev='/dev/loop1'/>
      <backingStore/>
      <target dev='sde' bus='scsi'/>
      <serial>drive-scsi0-0-0-4</serial>
      <encryption format='luks'>
      </encryption>
      <alias name='scsi0-0-0-4'/>
      <address type='drive' controller='0' bus='0' target='0' unit='4'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='scsi' index='0' model='virtio-scsi'>
      <alias name='scsi0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </controller>
    <controller type='ide' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='usb' index='0'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:17:c7:f4'/>
      <source bridge='vlanbr23'/>
      <target dev='vnet19'/>
      <model type='virtio'/>
      <driver name='vhost' queues='4'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <source path='/dev/pts/3'/>
      <target type='isa-serial' port='0'/>
      <alias name='serial0'/>
    </serial>
    <console type='pty' tty='/dev/pts/3'>
      <source path='/dev/pts/3'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    </console>
    <input type='mouse' bus='ps2'>
      <alias name='input0'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input1'/>
    </input>
    <graphics type='vnc' port='5901' autoport='yes' listen='127.0.0.1'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='none'>
      <alias name='balloon0'/>
    </memballoon>
  </devices>
  <seclabel type='dynamic' model='selinux' relabel='yes'>
    <label>system_u:system_r:svirt_t:s0:c47,c608</label>
    <imagelabel>system_u:object_r:svirt_image_t:s0:c47,c608</imagelabel>
  </seclabel>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+107:+107</label>
    <imagelabel>+107:+107</imagelabel>
  </seclabel>
</domain>
Comment 4 Xueqiang Wei 2017-09-14 02:37:15 EDT
Run on latest qemu-kvm-rhev, not hit this issue. The details as below:

Host kernel: 3.10.0-693.el7.x86_64
Guest kernel: 3.10.0-648.el7.x86_64
qemu-kvm-rhev-2.9.0-16.el7_4.6

Run once:
# virsh attach-device vm1 disk.xml && lsof -p 11147 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz  && lsof -p 11147 |grep '\[aio\]' |wc -l

The output:
Device attached successfully
1
Disk detached successfully
1

 
Run it 1000 times, the file descriptors is not increase:
shell cmd line:

#!/bin/bash
let i=0
while [ $i -lt 1000 ] 
do
virsh attach-device vm1 disk.xml && lsof -p 11147 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz  && lsof -p 11147 |grep '\[aio\]' |wc -l
let i=$i+1
done

The output:
Device attached successfully
1
Disk detached successfully
1
Device attached successfully
1
Disk detached successfully
1
......
Comment 5 Xueqiang Wei 2017-09-14 03:18:44 EDT
Run on latest qemu-kvm, hit this issue. The details as below:

Host kernel: 3.10.0-693.el7.x86_64
Guest kernel: 3.10.0-648.el7.x86_64
qemu-kvm-1.5.3-126.el7_3.11

Run once:
# virsh attach-device vm1 disk.xml && lsof -p 32235 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz  && lsof -p 32235 |grep '\[aio\]' |wc -l

The output:
Device attached successfully
3
Disk detached successfully
3

 
Run it 1000 times, the file descriptors creeping skyward:
shell cmd line:

#!/bin/bash
let i=0
while [ $i -lt 1000 ] 
do
virsh attach-device vm1 disk.xml && lsof -p 32235 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz  && lsof -p 32235 |grep '\[aio\]' |wc -l
let i=$i+1
done

The output:
Device attached successfully
3
Disk detached successfully
3
Device attached successfully
4
Disk detached successfully
4
Device attached successfully
5
Disk detached successfully
5
......
......
Device attached successfully
1005
Disk detached successfully
1005
Comment 6 Ademar Reis 2017-09-18 19:17:54 EDT
Thanks for taking the time to enter a bug report with us. We use reports like yours to keep improving the quality of our products and releases. That said, we're not able to guarantee the timeliness or suitability of a resolution for issues entered here because this is not a mechanism for requesting support.

If this issue is critical or in any way time sensitive, please raise a ticket through your regular Red Hat support channels to make certain it receives the proper attention and prioritization that will result in a timely resolution.

For information on how to contact the Red Hat production support team, please visit: https://www.redhat.com/support/process/production/#howto
Comment 7 Fam Zheng 2017-11-20 11:15:45 EST
Identified two fixes from upstream that could fix this.
Comment 11 Miroslav Rezanina 2017-11-29 01:06:55 EST
Fix included in qemu-kvm-1.5.3-149.el7
Comment 13 Xueqiang Wei 2017-11-30 07:36:02 EST
Run on qemu-kvm-1.5.3-149.el7, not hit this issue. The details as below:

Host kernel: 3.10.0-796.el7.x86_64
Guest kernel: 3.10.0-798.el7.x86_64
qemu-kvm-1.5.3-149.el7

Run once:
# virsh attach-device vm1 disk.xml && lsof -p 13626 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz  && lsof -p 13626 |grep '\[aio\]' |wc -l

The output:
Device attached successfully
3
Disk detached successfully
2

 
Run it 1000 times, the file descriptors is not increase:
shell cmd line:

#!/bin/bash
let i=0
while [ $i -lt 1000 ] 
do
virsh attach-device vm1 disk.xml && lsof -p 13626 |grep '\[aio\]' |wc -l && virsh detach-disk vm1 sdzz  && lsof -p 13626 |grep '\[aio\]' |wc -l
let i=$i+1
done

The output:
Device attached successfully
3
Disk detached successfully
2
Device attached successfully
3
Disk detached successfully
2
Device attached successfully
3
Disk detached successfully
2
......
......
Device attached successfully
3
Disk detached successfully
2
Comment 18 errata-xmlrpc 2018-04-10 10:35:07 EDT
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/RHSA-2018:0816

Note You need to log in before you can comment on or make changes to this bug.