Skip to content

Commit

Permalink
Add memory barrier to r281764.
Browse files Browse the repository at this point in the history
While race at this point may cause only a single packet delay and so was
not really reproduced, it is better to not have it at all.

MFC after:	1 week
  • Loading branch information
amotin committed May 6, 2015
1 parent e941445 commit eb1da25
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions usr.sbin/bhyve/pci_virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
#include <sys/select.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <machine/atomic.h>
#include <net/ethernet.h>

#include <errno.h>
Expand Down Expand Up @@ -453,7 +454,7 @@ pci_vtnet_tx_thread(void *param)
{
struct pci_vtnet_softc *sc = param;
struct vqueue_info *vq;
int have_work, error;
int error;

vq = &sc->vsc_queues[VTNET_TXQ];

Expand All @@ -467,20 +468,16 @@ pci_vtnet_tx_thread(void *param)

for (;;) {
/* note - tx mutex is locked here */
do {
while (sc->resetting || !vq_has_descs(vq)) {
vq->vq_used->vu_flags &= ~VRING_USED_F_NO_NOTIFY;
if (sc->resetting)
have_work = 0;
else
have_work = vq_has_descs(vq);

if (!have_work) {
sc->tx_in_progress = 0;
error = pthread_cond_wait(&sc->tx_cond,
&sc->tx_mtx);
assert(error == 0);
}
} while (!have_work);
mb();
if (!sc->resetting && vq_has_descs(vq))
break;

sc->tx_in_progress = 0;
error = pthread_cond_wait(&sc->tx_cond, &sc->tx_mtx);
assert(error == 0);
}
vq->vq_used->vu_flags |= VRING_USED_F_NO_NOTIFY;
sc->tx_in_progress = 1;
pthread_mutex_unlock(&sc->tx_mtx);
Expand Down

0 comments on commit eb1da25

Please sign in to comment.