Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-154214

virsh attach-device cmd hangs when hot-plugging the vfio pci device in same iommu group second time

Linking RHIVOS CVEs to...Migration: Automation ...Sync from "Extern...XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Undefined Undefined
    • None
    • rhel-10.2
    • libvirt / General
    • None
    • None
    • None
    • rhel-virt-core-libvirt-1
    • None
    • False
    • False
    • Hide

      None

      Show
      None
    • None
    • None
    • None
    • None
    • Unspecified
    • Unspecified
    • Unspecified
    • x86_64
    • None

      What were you trying to do that didn't work?

      There a 2 pic device in same iommu group. Hotplug one device with manage='yes' and iommufd backend to guest then get a expect error. But when hotplug the other device with manage='yes' and iommufd backend to guest, the virsh attach-device cmd hangs without return.

      Please provide the package NVR for which the bug is seen:

      # rpm -q libvirt qemu-kvm
      libvirt-11.10.0-10.el10.x86_64
      qemu-kvm-10.1.0-13.el10.x86_64

      How reproducible is this bug?:100%

      Steps to reproduce

      1. There are 2 pci device within same iommu group on host:

       

      #  ls -l /sys/bus/pci/devices/0000\:01\:00.1/driver
      lrwxrwxrwx. 1 root root 0 Mar  9 03:16 /sys/bus/pci/devices/0000:01:00.1/driver -> ../../../../bus/pci/drivers/tg3
      #  ls -l /sys/bus/pci/devices/0000\:01\:00.0/driver
      lrwxrwxrwx. 1 root root 0 Mar  9 03:18 /sys/bus/pci/devices/0000:01:00.0/driver -> ../../../../bus/pci/drivers/tg3
      
      # ls -ld /sys/bus/pci/devices/0000:01:00.0/iommu_group
      lrwxrwxrwx. 1 root root 0 Mar  5 06:51 /sys/bus/pci/devices/0000:01:00.0/iommu_group -> ../../../../kernel/iommu_groups/28
      # ls -ld /sys/bus/pci/devices/0000:01:00.1/iommu_group
      lrwxrwxrwx. 1 root root 0 Mar  5 06:51 /sys/bus/pci/devices/0000:01:00.1/iommu_group -> ../../../../kernel/iommu_groups/28
      

       

      2. Start a guest

      3. Hoplug one pci device to the guest, then get the error:

      # cat pci-0.xml
      <hostdev mode='subsystem' type='pci' managed='yes'>
            <driver iommufd='yes'/>
            <source>
              <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
            </source>
          </hostdev>
      # virsh attach-device vm2 pci-0.xml 
      error: Failed to attach device from pci-0.xml
      error: internal error: unable to execute QEMU command 'device_add': vfio hostdev0: error bind device fd=108 to iommufd=107: Operation not permitted

      4. Check the driver of pci devices:

      #  ls -l /sys/bus/pci/devices/0000\:01\:00.1/driver
      lrwxrwxrwx. 1 root root 0 Mar  9 03:16 /sys/bus/pci/devices/0000:01:00.1/driver -> ../../../../bus/pci/drivers/tg3
      #  ls -l /sys/bus/pci/devices/0000\:01\:00.0/driver
      lrwxrwxrwx. 1 root root 0 Mar  9 03:26 /sys/bus/pci/devices/0000:01:00.0/driver -> ../../../../bus/pci/drivers/tg3

      5. Hoplug the other pci device to the guest, found the virsh cmd hangs there:

      # cat pci-1.xml
      <hostdev mode='subsystem' type='pci' managed='yes'>
            <driver iommufd='yes'/>
            <source>
              <address domain='0x0000' bus='0x01' slot='0x00' function='0x1'/>
            </source>
          </hostdev>
      
      # virsh attach-device vm2 pci-1.xml

      6. Then check the  driver of pci devices:

      1.  ls -l /sys/bus/pci/devices/0000\:01\:00.0/driver
        lrwxrwxrwx. 1 root root 0 Mar  9 03:26 /sys/bus/pci/devices/0000:01:00.0/driver -> ../../../../bus/pci/drivers/tg3
      2.  ls -l /sys/bus/pci/devices/0000\:01\:00.1/driver
        lrwxrwxrwx. 1 root root 0 Mar  9 03:27 /sys/bus/pci/devices/0000:01:00.1/driver -> ../../../../bus/pci/drivers/vfio-pci

        Expected results

      The virsh attach-device cmd should give error as the first time.

      Actual results

      The virsh attach-device cmd hangs.

      Additional info: 

      The same behavior when exchanging the hotplug sequence of the pci devices.

        1. vm2.log
          11 kB
          Liang Cong
        2. libvirtd.log
          1.12 MB
          Liang Cong

              virt-maint virt-maint
              lcong@redhat.com Liang Cong
              virt-maint virt-maint
              virt-bugs virt-bugs
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated: