Bug 1666559 - Can not hotplug i6300esb watchdog device to q35 guest without assigning the pci address
Summary: Can not hotplug i6300esb watchdog device to q35 guest without assigning the p...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: 8.0
Hardware: Unspecified
OS: Unspecified
medium
high
Target Milestone: rc
: 8.0
Assignee: Laine Stump
QA Contact: Lili Zhu
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-01-16 03:19 UTC by Lili Zhu
Modified: 2021-12-17 17:15 UTC (History)
14 users (show)

Fixed In Version: libvirt-5.0.0-5.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-05-29 16:05:29 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-2019:1293 0 None None None 2019-05-29 16:05:53 UTC

Description Lili Zhu 2019-01-16 03:19:20 UTC
Description of problem:


Version-Release number of selected component (if applicable):
bvirt-daemon-4.5.0-17.module+el8+2603+0a5231c4.x86_64
qemu-kvm-2.12.0-57.module+el8+2608+a17c4bfe.x86_64


How reproducible:
100%

Steps to Reproduce:
1. prepare a q35 guest
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 16    avocado-vt-vm2                 running

# virsh dumpxml avocado-vt-vm2 |grep "<os>" -A3
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.6.0'>hvm</type>
    <boot dev='hd'/>
  </os>

2. prepare a i6300esb watchdog device xml snippet
# cat watchdog.xml
<watchdog model='i6300esb'/>

3. attach the watchdog device to the guest
# virsh attach-device avocado-vt-vm2 watchdog.xml
error: Failed to attach device from watchdog.xml
error: internal error: unable to execute QEMU command 'device_add': Bus 'pcie.0' does not support hotplugging

Actual results:
libvirt tried to attach the watchdog device to pcie-root controller

Expected results:
Attaching i6300esb wathdog device should be successful

Additional info:
Trying to attach the watchdog device to pcie-root-port controller would be successful
# cat watchdog.xml
<watchdog model='i6300esb'>
    <address type='pci' domain='0x0000' bus='0x09' slot='0x01' function='0x0'/>
 </watchdog>

# virsh attach-device avocado-vt-vm2 watchdog.xml
Device attached successfully

Comment 1 Laine Stump 2019-01-16 22:58:54 UTC
The problem is that the i6300esb is a conventional PCI device, and by default there are no hotpluggable conventional PCI slots(and actually, no conventional PCI slots at all) on a Q35 machine.

On a 440fx machine, all slots are conventional PCI, and all can accept hotplugged devices. On a Q35 machine, there are only root bus slots (which are kind of like conventional PCI slots, since they don't support extended PCI config space, but are also different because they don't accept hotplugged devices), and pcie-root-ports (which accept hotplugged devices, but we only allow hotplugging PCI Express devices into them, because that's how real hardware behaves). And at that, the default behavior of libvirt when creating the initial config is to add enough pcie-root-ports for the initially configured devices, plus one extra pcie-root-port in case a user wants to hotplug a single PCI Express device.

Beyond that, if you want to hotplug a 2nd PCIe device, or if you want to hotplug any conventional PCI devices, you need to plan ahead and add extra pcie-root-ports (for PCI Express devices) or a pcie-pci-bridge (for conventional PCI devices).

So, the solution to your problem is to add this to the config of the guest before you start it:

    <controller type='pci' model='pcie-to-pci-bridge'/>

This adds a conventional PCI bus with 32 hotpluggable conventional PCI slots. You'll then be able to hotplug the i6300esb watchdog device (assuming it was hotpluggable on a 440fx machine).

Note that you can add conventional PCI devices to a guest that is shutdown without manually adding the pcie-to-pci-bridge - libvirt will determine the need for it and add it (it can't do this while the guest is running, because PCI controllers cannot themselves be hotplugged).

Comment 2 Lili Zhu 2019-01-17 03:08:50 UTC
Hi, Laine
I have tried with pcie-to-pci-bridge controller, still failed
1. check the guest info
# virsh dumpxml avocado-vt-vm1
...
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.6.0'>hvm</type>
    <boot dev='hd'/>
  </os>
...
    <controller type='pci' index='7' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='7' port='0x16'/>
      <alias name='pci.7'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
    </controller>
    <controller type='pci' index='8' model='pcie-to-pci-bridge'>
      <model name='pcie-pci-bridge'/>
      <alias name='pci.8'/>
      <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
    </controller>
...

2. prepare a watchdog device xml snippet
# cat watchdog.xml 
<watchdog model='i6300esb'/>

3.# virsh attach-device avocado-vt-vm1 watchdog.xml 
error: Failed to attach device from watchdog.xml
error: internal error: unable to execute QEMU command 'device_add': Bus 'pcie.0' does not support hotplugging

Comment 3 Laine Stump 2019-01-17 21:43:48 UTC
Aha! It turns out there has been a bug in the watchdog hotplug code since it was first introduced in commit 361c8dc17 (libvirt-3.9.0). The device_add command string for watchdog devices was being generated before assigning a PCI address, so the command had no PCI address, leaving qemu to decide on an address itself (which libvirt should never let happen), and qemu then assigns a slot that is on pcie.0 (the root bus), then realizes that pcie.0 doesn't support hotplug, so it fails and returns an error.

I just posted a patch upstream that fixes the problem:

 https://www.redhat.com/archives/libvir-list/2019-January/msg00625.html

This should be backported to RHEL7 as well.

Comment 4 Karen Noel 2019-01-18 03:21:22 UTC
Martin, What is the priority of this bug? Should it be an exception for 8.0.0? Or, move it to 8.0.1? Or, just move it to fast train? Thanks.

Comment 5 Laine Stump 2019-01-18 19:15:24 UTC
Fix pushed upstream:

commit 40136bd3168a09c2524440d3b734015f0b618a05
Author: Laine Stump <laine>
Date:   Thu Jan 17 15:05:54 2019 -0500

    qemu: fix i6300esb watchdog hotplug on Q35

Comment 6 Martin Tessun 2019-02-01 16:16:24 UTC
(In reply to Karen Noel from comment #4)
> Martin, What is the priority of this bug? Should it be an exception for
> 8.0.0? Or, move it to 8.0.1? Or, just move it to fast train? Thanks.

I would move it to RHEL-AV. I don't think we need this fixed before RHEL 8.1.
Anyways as we already have the fix, we can add it to 8.0.0.

Comment 9 Lili Zhu 2019-03-04 03:18:20 UTC
Verify this bug with:
libvirt-daemon-5.0.0-5.module+el8+2850+33063f9c.x86_64
libvirt-daemon-5.0.0-5.module+el8+2850+33063f9c.x86_64

Verification steps:
1. prepare a q35 guest with pcie-to-pci-bridge controller
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 16    avocado-vt-vm1                 running

# virsh dumpxml avocado-vt-vm1
...
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.6.0'>hvm</type>
    <boot dev='hd'/>
  </os>
...
    <controller type='pci' index='7' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='7' port='0x16'/>
      <alias name='pci.7'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
    </controller>
    <controller type='pci' index='8' model='pcie-to-pci-bridge'>
      <model name='pcie-pci-bridge'/>
      <alias name='pci.8'/>
      <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
    </controller>
...

2. prepare a i6300esb watchdog device xml snippet
# cat watchdog.xml
<watchdog model='i6300esb'/>

3. attach the watchdog device to the guest
# virsh attach-device avocado-vt-vm2 watchdog.xml
Device attached successfully

4. dumpxml the guest xml after hotplugging
# virsh dumpxml avocado-vt-vm1 |grep '<watchdog' -A3
    <watchdog model='i6300esb' action='reset'>
      <alias name='watchdog0'/>
      <address type='pci' domain='0x0000' bus='0x08' slot='0x01' function='0x0'/>
    </watchdog>

5. login the guest, check the watchdog device
# virsh console avocado-vt-vm1 
Connected to domain avocado-vt-vm1
Escape character is ^]

Red Hat Enterprise Linux 8.0 Beta (Ootpa)
Kernel 4.18.0-67.el8.x86_64 on an x86_64

localhost login: root
Password: 
Last login: Fri Mar  1 17:00:19 on ttyS0
[root@localhost ~]# lsmod |grep 6300
i6300esb               16384  0

5. hotunplug the watchdog device
# virsh detach-device avocado-vt-vm1 watchdog1.xml 
Device detached successfully

# virsh dumpxml avocado-vt-vm1 |grep '<watchdog' -A3

As the result match with expected result, mark the bug as verified

Comment 12 errata-xmlrpc 2019-05-29 16:05:29 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-2019:1293


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