RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1491434 - KVM leaks file descriptors when attaching and detaching virtio-scsi block devices
Summary: KVM leaks file descriptors when attaching and detaching virtio-scsi block dev...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: qemu-kvm
Version: 7.3
Hardware: x86_64
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Fam Zheng
QA Contact: Xueqiang Wei
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-09-13 19:44 UTC by bugzilla
Modified: 2018-04-10 14:35 UTC (History)
16 users (show)

Fixed In Version: qemu-kvm-1.5.3-149.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-10 14:35:07 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2018:0816 0 normal SHIPPED_LIVE Low: qemu-kvm security, bug fix, and enhancement update 2018-04-10 12:47:03 UTC

Description bugzilla 2017-09-13 19:44:33 UTC
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 19:47:30 UTC
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 06:37:15 UTC
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 07:18:44 UTC
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 23:17:54 UTC
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 16:15:45 UTC
Identified two fixes from upstream that could fix this.

Comment 11 Miroslav Rezanina 2017-11-29 06:06:55 UTC
Fix included in qemu-kvm-1.5.3-149.el7

Comment 13 Xueqiang Wei 2017-11-30 12:36:02 UTC
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 14:35:07 UTC
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.