Bug 1751580 - The connection of hostdev network do not decrease after detach interface
Summary: The connection of hostdev network do not decrease after detach interface
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: 8.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: 8.0
Assignee: Daniel Berrangé
QA Contact: jiyan
URL:
Whiteboard:
Depends On:
Blocks: 1585087
TreeView+ depends on / blocked
 
Reported: 2019-09-12 08:09 UTC by yalzhang@redhat.com
Modified: 2020-05-05 09:50 UTC (History)
4 users (show)

Fixed In Version: libvirt-5.9.0-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-05-05 09:49:41 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2020:2017 0 None None None 2020-05-05 09:50:27 UTC

Description yalzhang@redhat.com 2019-09-12 08:09:37 UTC
Description of problem:
The connection of hostdev network do not decrease after detach interface

Version-Release number of selected component (if applicable):
libvirt-5.6.0-4.module+el8.1.0+4160+b50057dc.x86_64

How reproducible:
100%

Steps to Reproduce:
1. On sriov system, prepare a hostdev type network interface pool,  and a vm with 3 interfaces connected to this network:
# virsh net-dumpxml passthrough1
<network>
  <name>passthrough1</name>
  <uuid>7a5ff548-75f6-45bd-8564-d944a00d1321</uuid>
  <forward mode='hostdev' managed='yes'>
    <driver name='vfio'/>
    <address type='pci' domain='0x0000' bus='0x03' slot='0x10' function='0x1'/>
    <address type='pci' domain='0x0000' bus='0x03' slot='0x10' function='0x3'/>
    <address type='pci' domain='0x0000' bus='0x03' slot='0x10' function='0x5'/>
    <address type='pci' domain='0x0000' bus='0x03' slot='0x10' function='0x7'/>
  </forward>
</network>

# virsh dumpxml rhel | grep /interface -B5
    <interface type='network'>
      <mac address='52:54:00:a0:5a:a0'/>
      <source network='passthrough1'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x0b' slot='0x01' function='0x0'/>
    </interface>
    <interface type='network'>
      <mac address='52:54:00:ee:db:4b'/>
      <source network='passthrough1'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x0b' slot='0x02' function='0x0'/>
    </interface>

# virsh domiflist rhel 
 Interface   Type      Source         Model     MAC
-------------------------------------------------------------------
 -           network   passthrough1   rtl8139   52:54:00:a0:5a:a0
 -           network   passthrough1   rtl8139   52:54:00:ee:db:4b

2. Start the vm, then check the network connection count, it is expected:
# virsh start rhel
Domain rhel started

# virsh domiflist rhel 
 Interface   Type      Source   Model     MAC
-------------------------------------------------------------
 -           hostdev   -        rtl8139   52:54:00:a0:5a:a0
 -           hostdev   -        rtl8139   52:54:00:ee:db:4b

# virsh net-dumpxml passthrough1 | grep connections
<network connections='2'>

3. Detach the interface from the vm, check the connection count, it do not decrease:
# virsh detach-interface rhel hostdev 52:54:00:a0:5a:a0
Interface detached successfully

# virsh domiflist rhel 
 Interface   Type      Source   Model     MAC
-------------------------------------------------------------
 -           hostdev   -        rtl8139   52:54:00:ee:db:4b

# virsh net-dumpxml passthrough1 | grep connections 
<network connections='2'>
 
4. Destroy the vm, and check the connection again:
# virsh destroy rhel
Domain rhel destroyed

# virsh net-dumpxml passthrough1 | grep connections 
<network connections='1'>

Actual results:
In step 3, after detach the interface, the connection count do not decrease to "1"
In step 4, after vm is destroyed, the connection count do not recover to "0"

Expected results:
In step 3, after detach the interface, the connection count should decrease to "1"
In step 4, after vm is destroyed, the connection count should recover to "0"

Additional info:
1. No such issue on  libvirt-5.0.0-12.module+el8.0.1+3755+6782b0ed.x86_64
2. No such issue for other type of networks, including nat, direct interface pool, shared host bridge type network.

Comment 1 Daniel Berrangé 2019-09-13 11:04:36 UTC
I've bisected this issue back to the following commit:

commit bbe2aa627f621e6749af374b22856184d1f351dc (refs/bisect/bad)
Author: Daniel P. Berrangé <berrange>
Date:   Thu Jul 26 17:24:30 2018 +0100

    conf: simplify link from hostdev back to network device
    
    hostdevs have a link back to the original network device. This is fairly
    generic accepting any type of device, however, we don't intend to make
    use of this approach in future. It can thus be specialized to network
    devices.
    
    Reviewed-by: Cole Robinson <crobinso>
    Signed-off-by: Daniel P. Berrangé <berrange>


which is rather annoying as AFAICT this commit has no functional change, but clearly it does break the counting somehow.

Comment 2 Daniel Berrangé 2019-09-13 14:22:20 UTC
Patch proposed upstream

https://www.redhat.com/archives/libvir-list/2019-September/msg00523.html

Comment 3 Daniel Berrangé 2019-09-13 14:23:00 UTC
Fix merged upstream

commit b9ed82c9fba30666428f482b4830a26ffb0a4f52
Author: Daniel P. Berrangé <berrange>
Date:   Fri Sep 13 13:41:29 2019 +0100

    qemu: fix detach of hostdev based network interface
    
    This fixes bug in
    
      commit bbe2aa627f621e6749af374b22856184d1f351dc
      Author: Daniel P. Berrangé <berrange>
      Date:   Thu Jul 26 17:24:30 2018 +0100
    
        conf: simplify link from hostdev back to network device
    
        hostdevs have a link back to the original network device. This is fairly
        generic accepting any type of device, however, we don't intend to make
        use of this approach in future. It can thus be specialized to network
        devices.
    
        Reviewed-by: Cole Robinson <crobinso>
        Signed-off-by: Daniel P. Berrangé <berrange>
    
    which mistakenly deleted the assignment to the 'net' variable,
    which meant we never invoked the network driver release callback
    
    Reviewed-by: Michal Privoznik <mprivozn>
    Signed-off-by: Daniel P. Berrangé <berrange>

Comment 5 jiyan 2020-01-20 05:21:18 UTC
Reproduce this issue with libvirt-5.9.0-1.module+el8.2.0+4682+acceb91e.x86_64.

Version:
libvirt-5.9.0-1.module+el8.2.0+4682+acceb91e.x86_64
qemu-kvm-4.1.0-14.module+el8.2.0+4673+ff4b3b61.x86_64
kernel-4.18.0-171.el8.x86_64

Steps:
1. Set up the vfs and create virtual network using the vfs
# echo 5 > /sys/devices/pci0000:80/0000:80:02.0/0000:82:00.1/sriov_numvfs

# virsh nodedev-dumpxml pci_0000_82_00_1 
<device>
  <name>pci_0000_82_00_1</name>
  <path>/sys/devices/pci0000:80/0000:80:02.0/0000:82:00.1</path>
  <parent>pci_0000_80_02_0</parent>
  <driver>
    <name>ixgbe</name>
  </driver>
  <capability type='pci'>
    <class>0x020000</class>
    <domain>0</domain>
    <bus>130</bus>
    <slot>0</slot>
    <function>1</function>
    <product id='0x10fb'>82599ES 10-Gigabit SFI/SFP+ Network Connection</product>
    <vendor id='0x8086'>Intel Corporation</vendor>
    <capability type='virt_functions' maxCount='63'>
      <address domain='0x0000' bus='0x82' slot='0x10' function='0x1'/>
      <address domain='0x0000' bus='0x82' slot='0x10' function='0x3'/>
      <address domain='0x0000' bus='0x82' slot='0x10' function='0x5'/>
      <address domain='0x0000' bus='0x82' slot='0x10' function='0x7'/>
      <address domain='0x0000' bus='0x82' slot='0x11' function='0x1'/>
    </capability>
    <iommuGroup number='42'>
      <address domain='0x0000' bus='0x82' slot='0x00' function='0x1'/>
    </iommuGroup>
    <numa node='1'/>
    <pci-express>
      <link validity='cap' port='0' speed='5' width='8'/>
      <link validity='sta' speed='5' width='8'/>
    </pci-express>
  </capability>
</device>

# cat network.xml 
<network>
  <name>pt2</name>
  <forward mode='hostdev'>
    <driver name='vfio' managed="yes"/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x1'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x3'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x5'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x7'/>
  </forward>
</network>

# virsh net-dumpxml pt2 
<network>
  <name>pt2</name>
  <uuid>6ee6f4f6-c89f-4dd8-9f0f-5ade13fd4c47</uuid>
  <forward mode='hostdev' managed='yes'>
    <driver name='vfio'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x1'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x3'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x5'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x7'/>
  </forward>
</network>

2. Cold-plug interface to VM using the virtual network above 
# virsh domstate test82 
shut off

# virsh attach-interface test82 --type network --source pt2 --config
Interface attached successfully

# virsh attach-interface test82 --type network --source pt2 --config
Interface attached successfully

# virsh dumpxml test82 --inactive |grep "<interface" -A7
    <interface type='network'>
      <mac address='52:54:00:f7:73:1c'/>
      <source network='pt2'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x0b' slot='0x01' function='0x0'/>
    </interface>
    <interface type='network'>
      <mac address='52:54:00:84:41:a4'/>
      <source network='pt2'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x0b' slot='0x02' function='0x0'/>
    </interface>

3. Start the VM and check the "domiflist" and "net-dumpxml"
# virsh start test82 
Domain test82 started

# virsh domiflist test82 
 Interface   Type      Source   Model     MAC
-------------------------------------------------------------
 vnet0       bridge    virbr0   virtio    52:54:00:23:b7:cd
 -           hostdev   -        rtl8139   52:54:00:f7:73:1c
 -           hostdev   -        rtl8139   52:54:00:84:41:a4

# virsh net-dumpxml pt2 
<network connections='2'>
  <name>pt2</name>
  <uuid>6ee6f4f6-c89f-4dd8-9f0f-5ade13fd4c47</uuid>
  <forward mode='hostdev' managed='yes'>
    <driver name='vfio'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x1'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x3'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x5'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x7'/>
  </forward>
</network>

4. Detach a interface from the VM and check the "domiflist" and "net-dumpxml" again
# virsh detach-interface test82 --mac 52:54:00:84:41:a4 --type hostdev
Interface detached successfully

# virsh domiflist test82 
 Interface   Type      Source   Model     MAC
-------------------------------------------------------------
 vnet0       bridge    virbr0   virtio    52:54:00:23:b7:cd
 -           hostdev   -        rtl8139   52:54:00:f7:73:1c

# virsh net-dumpxml pt2 
<network connections='1'>
  <name>pt2</name>
  <uuid>6ee6f4f6-c89f-4dd8-9f0f-5ade13fd4c47</uuid>
  <forward mode='hostdev' managed='yes'>
    <driver name='vfio'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x1'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x3'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x5'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x7'/>
  </forward>
</network>

5. Destroy the VM and check the "net-dumpxml" again
# virsh destroy test82 
Domain test82 destroyed

# virsh net-dumpxml pt2 
<network>
  <name>pt2</name>
  <uuid>6ee6f4f6-c89f-4dd8-9f0f-5ade13fd4c47</uuid>
  <forward mode='hostdev' managed='yes'>
    <driver name='vfio'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x1'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x3'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x5'/>
    <address type='pci' domain='0x0000' bus='0x82' slot='0x10' function='0x7'/>
  </forward>
</network>

All the results are as expected, move this bug to be verified.

Comment 6 jiyan 2020-01-20 05:39:31 UTC
Update the typo in last comment, Verified this bug with libvirt-5.9.0-1.module+el8.2.0+4682+acceb91e.x86_64.

Comment 8 errata-xmlrpc 2020-05-05 09:49:41 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/RHBA-2020:2017


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