Bug 2108483

Summary: Add alias support for virtio-iommu
Product: Red Hat Enterprise Linux 9 Reporter: Han Han <hhan>
Component: libvirtAssignee: Andrea Bolognani <abologna>
libvirt sub component: General QA Contact: yalzhang <yalzhang>
Status: CLOSED ERRATA Docs Contact:
Severity: low    
Priority: low CC: abologna, dzheng, hzhao, jdenemar, jinl, lmen, ly2850002, pkrempa, virt-maint, xuzhang, yalzhang, yicui
Version: 9.1Keywords: Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-8.7.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 07:26:34 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.6.0
Embargoed:

Description Han Han 2022-07-19 07:47:24 UTC
Description of problem:
virtio-iommu device cannot generate alias element and customized alias will not work for virtio-iommu

Version-Release number of selected component (if applicable):
libvirt-8.5.0-2.el9.x86_64
qemu-kvm-7.0.0-9.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
Test1: Check the auto-assigned alias for virtio-iommu:
1. Start a q35 VM with virtio-iommu:
...
    <iommu model="virtio"/>
...

2. Check the live XML and qemu command line of iommu:
➜  ~ virsh dumpxml rhel --xpath //iommu
<iommu model="virtio">
  <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0"/>
</iommu>


➜  ~ ps aux|grep iommu
... -device {"driver":"virtio-iommu","bus":"pcie.0","addr":"0x3"}

No <alias/> in live XML. No id in the properties of virtio-iommu.


Test2: Set customized alias for virtio-iommu:
1. Start a q35 VM with customized alias for virtio-iommu
...
<iommu model="virtio">
  <alias name="ua-xx"/>
</iommu>
...

2. Check the live XML and qemu command line of iommu. Validate the live XML
➜  ~ virsh dumpxml rhel --xpath //iommu
<iommu model="virtio">
  <alias name="ua-xx"/>
  <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0"/>
</iommu>

➜  ~ ps aux|grep iommu
... -device {"driver":"virtio-iommu","bus":"pcie.0","addr":"0x3"}

No id property for virtio-iommu.

➜  ~ virsh dumpxml rhel|virt-xml-validate -
Relax-NG validity error : Extra element devices in interleave
-:64: element devices: Relax-NG validity error : Element domain failed to validate content
- fails to validate

Validation failed.


Actual results:
As above

Expected results:
If no customized alias, libvirt will generate one for iommu and works for live XML and qemu command line. And customized alias of iommu will works. The XML validation will pass for virtio-iommu with alias.

Additional info:

Comment 1 jinl 2022-07-19 08:37:05 UTC
try with intel_iommu can also hit this issue

steps to reproduce: same with the above Description
just change the model from "virtio" to "intel" 
<iommu model="intel">

get the same error message:
Extra element devices in interleave
Element domain failed to validate content

Comment 2 Andrea Bolognani 2022-07-21 09:33:41 UTC
Patches posted upstream.

https://listman.redhat.com/archives/libvir-list/2022-July/233042.html

Comment 3 Andrea Bolognani 2022-07-22 15:53:14 UTC
Patches merged upstream.

  commit 510540961417288a24d0870f0226f8255420c463
  Author: Andrea Bolognani <abologna>
  Date:   Thu Jul 21 11:14:21 2022 +0200

    qemu: Add IOMMU device alias to command line
    
    Note that we can only do this for intel-iommu and virtio-iommu,
    which are configured using -device; smmuv3 is configured using
    a machine type property, so there's no room on the command line
    for an alias in that case.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=2108483
    
    Signed-off-by: Andrea Bolognani <abologna>
    Reviewed-by: Michal Privoznik <mprivozn>

  v8.5.0-172-g5105409614

Comment 4 yalzhang@redhat.com 2022-09-16 01:51:26 UTC
Test on libvirt-8.7.0-1.el9.x86_64, the result is as expected, intel iommu also works fine.

1. start vm with a virtio iommu device

2. # virsh dumpxml rhel --xpath //iommu
<iommu model="virtio">
  <alias name="iommu0"/>
  <address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"/>
</iommu>

3. # virsh dumpxml rhel|virt-xml-validate -
- validates

4. Try with customized alias:
# virsh dumpxml rhel --xpath //iommu
<iommu model="virtio">
  <alias name="ua-b52d2352-5650-4546-9a22-9d685cf6ce23"/>
  <address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"/>
</iommu>

# virsh start rhel 
Domain 'rhel' started

# virsh dumpxml rhel|virt-xml-validate -
- validates

Comment 8 errata-xmlrpc 2023-05-09 07:26:34 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 (libvirt 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/RHBA-2023:2171