From 57b0a3aacad90d59a6fa1024225d08b1a9c35298 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Sat, 28 Nov 2020 03:54:48 +0000 Subject: [PATCH] bhyve: 'xhci,tablet' snapshot fixes Permit suspend/resume of a XHCI device model that has not been attached to by a driver in a guest OS. Submitted by: Vitaliy Gusev Differential Revision: https://reviews.freebsd.org/D26264 --- usr.sbin/bhyve/pci_xhci.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c index 7a91a2dc917..9227b934f04 100644 --- a/usr.sbin/bhyve/pci_xhci.c +++ b/usr.sbin/bhyve/pci_xhci.c @@ -2251,7 +2251,6 @@ pci_xhci_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, assert(baridx == 0); - pthread_mutex_lock(&sc->mtx); if (offset < XHCI_CAPLEN) /* read only registers */ WPRINTF(("pci_xhci: write RO-CAPs offset %ld", offset)); @@ -2981,11 +2980,11 @@ pci_xhci_snapshot(struct vm_snapshot_meta *meta) /* opregs.cr_p */ SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(sc->opregs.cr_p, - XHCI_GADDR_SIZE(sc->opregs.cr_p), false, meta, ret, done); + XHCI_GADDR_SIZE(sc->opregs.cr_p), true, meta, ret, done); /* opregs.dcbaa_p */ SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(sc->opregs.dcbaa_p, - XHCI_GADDR_SIZE(sc->opregs.dcbaa_p), false, meta, ret, done); + XHCI_GADDR_SIZE(sc->opregs.dcbaa_p), true, meta, ret, done); /* rtsregs */ SNAPSHOT_VAR_OR_LEAVE(sc->rtsregs.mfindex, meta, ret, done); @@ -3000,11 +2999,11 @@ pci_xhci_snapshot(struct vm_snapshot_meta *meta) /* rtsregs.erstba_p */ SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(sc->rtsregs.erstba_p, - XHCI_GADDR_SIZE(sc->rtsregs.erstba_p), false, meta, ret, done); + XHCI_GADDR_SIZE(sc->rtsregs.erstba_p), true, meta, ret, done); /* rtsregs.erst_p */ SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(sc->rtsregs.erst_p, - XHCI_GADDR_SIZE(sc->rtsregs.erst_p), false, meta, ret, done); + XHCI_GADDR_SIZE(sc->rtsregs.erst_p), true, meta, ret, done); SNAPSHOT_VAR_OR_LEAVE(sc->rtsregs.er_deq_seg, meta, ret, done); SNAPSHOT_VAR_OR_LEAVE(sc->rtsregs.er_enq_idx, meta, ret, done); @@ -3090,12 +3089,14 @@ pci_xhci_snapshot(struct vm_snapshot_meta *meta) continue; SNAPSHOT_GUEST2HOST_ADDR_OR_LEAVE(dev->dev_ctx, - XHCI_GADDR_SIZE(dev->dev_ctx), false, meta, ret, done); + XHCI_GADDR_SIZE(dev->dev_ctx), true, meta, ret, done); - for (j = 1; j < XHCI_MAX_ENDPOINTS; j++) { - ret = pci_xhci_snapshot_ep(sc, dev, j, meta); - if (ret != 0) - goto done; + if (dev->dev_ctx != NULL) { + for (j = 1; j < XHCI_MAX_ENDPOINTS; j++) { + ret = pci_xhci_snapshot_ep(sc, dev, j, meta); + if (ret != 0) + goto done; + } } SNAPSHOT_VAR_OR_LEAVE(dev->dev_slotstate, meta, ret, done); -- 2.45.0