Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F172379845
D59779.id187018.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D59779.id187018.diff
View Options
diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c
--- a/usr.sbin/bhyve/pci_xhci.c
+++ b/usr.sbin/bhyve/pci_xhci.c
@@ -265,6 +265,15 @@
struct pci_devinst *xsc_pi;
pthread_mutex_t mtx;
+ pthread_mutex_t event_mtx; /* serialises er_enq_idx / er_events_cnt
+ * updates in insert_event (libusb thread)
+ * against the recalculation in the ERDP
+ * high-word write handler (MMIO thread).
+ * Must NOT be held across pci_generate_msi
+ * to avoid stalling the vCPU's ERDP write,
+ * which also needs this lock (under sc->mtx).
+ * Lock order: sc->mtx -> [xfer_lock ->]
+ * event_mtx */
uint32_t caplength; /* caplen & hciversion */
uint32_t hcsparams1; /* structural parameters 1 */
@@ -767,6 +776,8 @@
err = XHCI_TRB_ERROR_SUCCESS;
+ pthread_mutex_lock(&sc->event_mtx);
+
rts = &sc->rtsregs;
erdp = rts->intrreg.erdp & ~0xF;
@@ -789,7 +800,7 @@
DPRINTF(("pci_xhci[%d] cannot insert event; ring full",
__LINE__));
err = XHCI_TRB_ERROR_EV_RING_FULL;
- goto done;
+ goto done_locked;
}
if (rts->er_events_cnt == rts->erstba_p->dwEvrsTableSize - 1) {
@@ -814,7 +825,7 @@
err = XHCI_TRB_ERROR_EV_RING_FULL;
do_intr = 1;
- goto done;
+ goto done_locked;
}
} else {
rts->er_events_cnt++;
@@ -830,7 +841,9 @@
if (rts->er_enq_idx == 0)
rts->event_pcs ^= 1;
-done:
+done_locked:
+ pthread_mutex_unlock(&sc->event_mtx);
+
if (do_intr)
pci_xhci_assert_interrupt(sc);
@@ -2166,7 +2179,7 @@
break;
case 0x18:
- /* ERDP low bits */
+ /* ERDP low bits — does not touch er_events_cnt/er_enq_idx */
rts->intrreg.erdp =
MASK_64_HI(sc->rtsregs.intrreg.erdp) |
(rts->intrreg.erdp & XHCI_ERDP_LO_BUSY) |
@@ -2182,6 +2195,7 @@
case 0x1C:
/* ERDP high bits */
+ pthread_mutex_lock(&sc->event_mtx);
rts->intrreg.erdp = (value << 32) |
MASK_64_LO(sc->rtsregs.intrreg.erdp);
@@ -2203,6 +2217,7 @@
DPRINTF(("pci_xhci: erdp 0x%lx, events cnt %u",
erdp, rts->er_events_cnt));
}
+ pthread_mutex_unlock(&sc->event_mtx);
break;
@@ -2965,6 +2980,9 @@
pi->pi_arg = sc;
sc->xsc_pi = pi;
+ pthread_mutex_init(&sc->mtx, NULL);
+ pthread_mutex_init(&sc->event_mtx, NULL);
+
sc->usb2_port_start = (XHCI_MAX_DEVS/2) + 1;
sc->usb3_port_start = 1;
@@ -3033,10 +3051,10 @@
pci_lintr_request(pi);
- pthread_mutex_init(&sc->mtx, NULL);
-
done:
if (error) {
+ pthread_mutex_destroy(&sc->event_mtx);
+ pthread_mutex_destroy(&sc->mtx);
free(sc);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Sep 19, 2:19 AM (10 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39189017
Default Alt Text
D59779.id187018.diff (2 KB)
Attached To
Mode
D59779: bhyve: usb: add a finer-grained mutex for the event thread
Attached
Detach File
Event Timeline
Log In to Comment