<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<p class="msipheadera4477989" align="Left" style="margin:0"><span style="font-size:10.0pt;font-family:Arial;color:#0000FF">[AMD Official Use Only]</span></p>
<br>
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal">I am using Fedora 33, with the following KVM, qemu and libvirt versions:<o:p></o:p></p>
<p class="MsoNormal">QEMU 5.1.0<o:p></o:p></p>
<p class="MsoNormal">libvirt 6.6.0<o:p></o:p></p>
<p class="MsoNormal">KVM 5.14.18<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">We have done pass-through of a PCIe NVMe device to the guest running on FC33<o:p></o:p></p>
<p class="MsoNormal">using either virt-manager or virsh and then we do the hot-unplug of the device<o:p></o:p></p>
<p class="MsoNormal">while it is attached to the guest.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The device is no longer seen on the guest hardware device list on virt-manager<o:p></o:p></p>
<p class="MsoNormal">and then we hotplug the device again and we are able to use it on the Host,<o:p></o:p></p>
<p class="MsoNormal">but when we try to re-attach it to the guest, we get the following error message:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Requested operation is not valid, PCI device 0000:c4::00.0 is in use by driver QEMU,<o:p></o:p></p>
<p class="MsoNormal">Domain fedora 33. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So somehow libvirt still thinks the hot-unplugged device is attached.<o:p></o:p></p>
<p class="MsoNormal">               <o:p></o:p></p>
<p class="MsoNormal">Tracing the flow of hot un-plug event from guest to host :<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">->Guest pcie hotplug support detected the NVMe driver unplug (from guest kernel logs):
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">pciehp: Slot (0-6): Attention button pressed<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">pciehp: Slot (0-6): Powering off due to to button press.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-> Also looks like the guest notified Host/KVM (from host kernel logs):<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">pcieport: 0000:c4:0000.0: pciehp: Slot (208): Card not present<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-> Correspondingly, vfio-pci module notified Qemu :<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">vfio-pci: 0000:c4:0000.0: Relaying device request to user (#0)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-> Then the un-plugged device reset is done.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">vfio-pci: vfio_bar_restore: reset recovery - restoring BARs<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">pci 0000:c4:00.0: Removing from iommu group 105.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-> Next tried to verify if libvirt detected the DELETED_DRIVE event from qemu.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Running SystemTap script to capture events between qemu and libvirt :<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">stap examples/systemtap/qemu-monitor.stp<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">When the NVMe drive is attached to VM the following log output is seen from SystemTap:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">execute "device-add", driver: "vfio-pci", host: "0000:c4:00.0", id: "hostdev0", bus: "pci.7", addr: "0".<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">When we hot-unplug the NVMe drive, the following log output is seen from SystemTap:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">event: DEVICE_DELETED, device: "hostdev0", path: "/machine/peripheral/hostdev0".<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">So it looks like that qemu sent the "DEVICE_DELTED" event to libvirt, but libvirt has still not removed the attached<o:p></o:p></p>
<p class="MsoNormal">device from its bookeeping list.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I understand there is already a thread from 20202, discussing a similar issue :<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:black;background:white"><a href="https://www.spinics.net/linux/fedora/libvirt-users/msg12590.html">https://www.spinics.net/linux/fedora/libvirt-users/msg12590.html</a></span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But I am not sure if there is any fix/support added for this recently.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Looking for any feedback related to above and PCI device passthrough and hotplug support.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Ashish<o:p></o:p></p>
</div>
</body>
</html>