This change makes the e82545 emulated PCI device hotpluggable
by implementing the appropriate teardown method and adding the
appropriate device initialization routines to libbbhyve.
Details
- Reviewers
- None
- Group Reviewers
bhyve
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped - Build Status
Buildable 69804 Build 66687: arc lint + arc unit
Event Timeline
| usr.sbin/bhyve/pci_e82545.c | ||
|---|---|---|
| 2389 | The TX thread is normally cancelled inside pthread_cond_wait(). That is a cancellation point that re-acquires the mutex before the thread exits, and there is no cleanup handler, so the thread exits holding esc_mtx, which is then destroyed while locked. A stop flag is easier to reason about: pthread_mutex_lock(&sc->esc_mtx); sc->esc_tx_stop = true; pthread_cond_broadcast(&sc->esc_tx_cond); pthread_mutex_unlock(&sc->esc_mtx); pthread_join(sc->esc_tx_tid, NULL); with the wait loop in e82545_tx_thread() checking esc_tx_stop and returning. | |
| 2395 | With hotplug, tap_cleanup() runs while the VM keeps going, and it has an ordering problem: mevent_delete() only queues the EV_DELETE for the mevent thread, and tap_cleanup() then calls close(be->fd) right away. If the next hot-added NIC's tap gets the same descriptor number before the mevent thread applies the change, the late EV_DELETE removes the new NIC's registration and the new NIC never receives anything. We hit this on hardware with add/remove cycles: about 1 in 20 new NICs got no DHCP lease, together with "Error return from kevent change: Bad file descriptor" in the log. Using mevent_delete_close() (the mevent thread deletes, then closes) and not closing the fd in tap_cleanup() fixed it for us. netmap_cleanup() has the same mevent_delete() + immediate close pattern. | |
| 2396 | mevent_handle() calls the callback for every event kevent() returned, without checking whether the mevent has been deleted in the meantime, and this teardown runs on the IPC thread. So an RX (or ITR timer) callback that was already dispatched can still run after free(sc) here and lock the destroyed esc_mtx. Disabling RX under esc_mtx first narrows the window but does not close it. Waiting until the mevent thread has applied the deletes before freeing the softc (or doing the final free from the mevent thread) would. | |