From df1767b784fd3100f288460bf8a8d61e08d0a3cb Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Wed, 6 Apr 2022 13:51:10 +0200 Subject: [PATCH] vbox6: tidy up devxhci poweroff The issue came apparent with Windows Guests and USB passthrough of smart-card readers. If the VM is powered off, PDMR3Term cleans up all devices incl. (first) acpi and (later) devxhci. The latter used a dangling reference to ACPI structs in a indirect call to apicIsLogicalDest() from xhciR3Destruct(). VMMR3_INT_DECL(int) PDMR3Term(PVM pVM) virtualbox6/src/VBox/VMM/VMMR3/PDM.cpp:817 "apic" (pDevIns->pReg->szName) static void apicR3TermState(PVM pVM) virtualbox6/src/VBox/VMM/VMMR3/APIC.cpp:1235 "qemu-xhci" (pDevIns->pReg->szName) static DECLCALLBACK(int) xhciR3Destruct(PPDMDEVINS pDevIns) repos/ports/src/virtualbox6/devxhci.cc:431 void usb_detach(USBPort *port) /src/lib/qemu/hw/usb/core.c:70 static void xhci_port_notify(XHCIPort *port, uint32_t bits) /src/lib/qemu/hw/usb/hcd-xhci.c:2592 static DECLCALLBACK(void) pciSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc) virtualbox6/src/VBox/Devices/Bus/DevPCI.cpp:398 static bool apicIsLogicalDest(PVMCPUCC pVCpu, uint32_t fDest) virtualbox6/src/VBox/VMM/VMMAll/APICAll.cpp:797 The fix removes our Qemu library reset from xhciR3Destruct() and registers xhciR3Reset() as PowerOff hook. Thanks to Raphael for the thorough investigation. --- repos/ports/src/virtualbox6/devxhci.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/repos/ports/src/virtualbox6/devxhci.cc b/repos/ports/src/virtualbox6/devxhci.cc index 2891be405c..48ba6c46f4 100644 --- a/repos/ports/src/virtualbox6/devxhci.cc +++ b/repos/ports/src/virtualbox6/devxhci.cc @@ -423,12 +423,20 @@ static DECLCALLBACK(void) xhciR3Reset(PPDMDEVINS pDevIns) } +/** + * @interface_method_impl{PDMDEVREG,pfnPowerOff} + */ +static DECLCALLBACK(void) xhciR3PowerOff(PPDMDEVINS pDevIns) +{ + Qemu::usb_reset(); +} + + /** * @nterface_method_impl{PDMDEVREG,pfnDestruct} */ static DECLCALLBACK(int) xhciR3Destruct(PPDMDEVINS pDevIns) { - Qemu::usb_reset(); return 0; } @@ -554,7 +562,7 @@ const PDMDEVREG g_DeviceXHCI = /* .pfnDetach = */ NULL, /* .pfnQueryInterface = */ NULL, /* .pfnInitComplete = */ NULL, - /* .pfnPowerOff = */ NULL, + /* .pfnPowerOff = */ xhciR3PowerOff, /* .pfnSoftReset = */ NULL, /* .pfnReserved0 = */ NULL, /* .pfnReserved1 = */ NULL,