Bug 2040548

Summary: 'unassigned' address type changed after hotplug
Product: Red Hat Enterprise Linux 9 Reporter: Yanqiu Zhang <yanqzhan>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
libvirt sub component: Networking QA Contact: Yanqiu Zhang <yanqzhan>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: crobinso, jdenemar, jtomko, laine, lvivier, mprivozn, virt-maint, xuzhang, yafu, yalzhang, yanqzhan
Version: 9.0Keywords: Triaged, Upstream
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-8.1.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-15 10:03:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version: 8.1.0
Embargoed:

Description Yanqiu Zhang 2022-01-14 03:03:14 UTC
Description of problem:
If start guest with hostdev, <address type='unassigned'/> will not change in live xml. But if hotplug a hostdev with 'unassigned' address, it will changed to normal pci address.

Version-Release number of selected component (if applicable):
libvirt-8.0.0-0rc1.1.el9.x86_64
Qemu-kvm-6.2.0-3.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1.start with
# virsh dumpxml r8|grep hostdev -B8
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x3b' slot='0x0a' function='0x0'/>
      </source>
      <rom enabled='no'/>
      <address type='unassigned'/>
    </hostdev>

# virsh start r8
Domain 'r8' started

# virsh dumpxml r8|grep hostdev -B8
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x3b' slot='0x0a' function='0x0'/>
      </source>
      <alias name='hostdev0'/>
      <rom enabled='no'/>
      <address type='unassigned'/>
    </hostdev>

2.hotplug
# virsh dumpxml r8|grep /hostdev -B8
(no output)
# cat hostdev-romno-unassigned.xml 
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x3b' slot='0x0a' function='0x0'/>
      </source>
      <alias name='hostdev0'/>
      <rom enabled='no'/>
      <address type='unassigned'/>
    </hostdev>

# virsh attach-device r8 hostdev-romno-unassigned.xml
Device attached successfully

# virsh dumpxml r8|grep /hostdev -B8
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x3b' slot='0x0a' function='0x0'/>
      </source>
      <alias name='hostdev0'/>
      <rom enabled='no'/>
      <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
    </hostdev>


Actual results:


Expected results:
1. Hotplug should not assign pci address for 'unassigned' type.
2. Or block hotplug for 'unassigned' address type hostdev since the scenario may be meaningless.

Additional info:
1.After checking codes, we found that hotplug uses qemuDomainEnsurePCIAddress, will not call qemuDomainAssignDevicePCISlots(which includes  /* do not reserve address for info->type='unassigned' */). Only start and reconnect will go to qemuDomainAssignDevicePCISlots.
2. Not produces on coldplug, it keeps 'unassigned'.

Comment 1 Cole Robinson 2022-01-17 15:41:58 UTC
Yes this seems like a bug. type='unassigned' are treated like PCI devices for vfio purposes, but are not passed to the qemu command line. they shouldn't require a virtual PCI address to be allocated, and the address type shouldn't change on hotplug.

Comment 2 Michal Privoznik 2022-01-25 12:09:11 UTC
FYI it's not just hotplug that suffers the same problem. A <hostdev/> with unassigned address can't be hotunpluged either.

Comment 3 Michal Privoznik 2022-01-25 12:17:35 UTC
Patches posted on the list:

https://listman.redhat.com/archives/libvir-list/2022-January/msg01111.html

Comment 5 Michal Privoznik 2022-01-27 13:03:45 UTC
Merged upstream as:

7251307199 qemuDomainDetachDeviceLive: Handle hostevs with unassigned type of address
f5de3af7f4 qemuDomainAttachHostPCIDevice: Handle hostevs with unassigned type of address
89f9346791 domain_validate: Refuse VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED

v8.0.0-206-g7251307199

Comment 6 Yanqiu Zhang 2022-03-31 10:33:18 UTC
Tested with:
libvirt-8.1.0-1.el9.x86_64
qemu-kvm-6.2.0-12.el9.x86_64

1. # cat hostdev-unassigned.xml 
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x3b' slot='0x02' function='0x0'/>
      </source>
      <address type='unassigned'/>
    </hostdev>

# virsh dumpxml r9|grep hostdev
(nothing)

# virsh attach-device r9 hostdev-unassigned.xml 
Device attached successfully

# virsh dumpxml r9|grep /hostdev -B8
    </video>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x3b' slot='0x02' function='0x0'/>
      </source>
      <alias name='hostdev0'/>
      <address type='unassigned'/>
    </hostdev>

# virsh detach-device r9 hostdev-unassigned.xml 
Device detached successfully

# virsh dumpxml r9|grep /hostdev -B8
(nothing)

2. # cat iface-hostdev.xml 
<interface type='hostdev' managed='yes'>
      <source>
        <address type='pci' domain='0x0000' bus='0x3b' slot='0x02' function='0x0'/>
      </source>
      <address type='unassigned'/>
    </interface>

# virsh attach-device r9 iface-hostdev.xml 
error: Failed to attach device from iface-hostdev.xml
error: unsupported configuration: address of type 'unassigned' is supported only for hostdevs

# virsh edit r9
error: unsupported configuration: address of type 'unassigned' is supported only for hostdevs
Failed. Try again? [y,n,i,f,?]: 

# virsh define r9.xml-hostdeviface 
error: Failed to define domain from r9.xml-hostdeviface
error: unsupported configuration: address of type 'unassigned' is supported only for hostdevs


Hi Michal,
Could you help confirm whether result of step2 is expected please? The hostdev interface can not use 'unassigned' address type anymore.
Thank you!

Comment 8 Yanqiu Zhang 2022-04-01 01:46:41 UTC
Thanks Michal.

Comment 11 Yanqiu Zhang 2022-04-14 04:43:16 UTC
Verified with:
libvirt-8.2.0-1.el9.x86_64
qemu-kvm-6.2.0-12.el9.x86_64

Same steps and results as comment6.

And same behaviors for coldplug/unplug.

Comment 13 errata-xmlrpc 2022-11-15 10:03:03 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 (Low: libvirt security, bug fix, and enhancement update), 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-2022:8003