From 312ea0b3746e529ab056c22e43f276f265e81f8e Mon Sep 17 00:00:00 2001 From: Long Liu Date: Tue, 21 Jul 2020 05:35:09 +0000 Subject: [PATCH] DM: xHCI: Release all device resource when received HCRST. There has one bug that the pci_xhci_dev_emu objects recorded in xdev->devices haven't destroy when OVMF transfer to guest OS. This will cause the the fds of usbfs can't be freed in libusb. The OVMF xHCI driver needs to disable all enabled slots during graceful existing flow, but it doesn't. The USBCMD.HCRST bit is used for xHC reset that will be triggered in xHCI driver initialization. We can use this chance to clear all pci_xhci_dev_emu objects Tracked-On: #4897 Signed-off-by: Long Liu Acked-by: Yu Wang --- devicemodel/hw/pci/xhci.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c index b79c74b56..40da4ec3b 100644 --- a/devicemodel/hw/pci/xhci.c +++ b/devicemodel/hw/pci/xhci.c @@ -1192,9 +1192,26 @@ pci_xhci_reset(struct pci_xhci_vdev *xdev) xdev->rtsregs.er_enq_idx = 0; xdev->rtsregs.er_enq_seg = 0; xdev->rtsregs.event_pcs = 1; + struct pci_xhci_dev_emu *dev; + + for (i = 1; i <= XHCI_MAX_DEVS; i++) + { + dev = xdev->devices[i]; + if (dev) { + xdev->devices[i] = NULL; + pci_xhci_dev_destroy(dev); + /* FIXME: The ndevices hasn't + * aligned between ++ and -- + * */ + xdev->ndevices--; + } + } for (i = 1; i <= XHCI_MAX_SLOTS; i++) - pci_xhci_reset_slot(xdev, i); + { + xdev->slots[i] = NULL; + xdev->slot_allocated[i] = false; + } } static uint32_t