From e1ed1fbdea19659120d372dcdc7c13060c823e2b Mon Sep 17 00:00:00 2001 From: Vincenzo Maffione Date: Sat, 22 Dec 2018 15:15:45 +0000 Subject: netmap: fix bug in netmap_poll() optimization The bug was introduced by r339639, although it is present in the upstream netmap code since 2015. It is due to resetting the want_rx variable to POLLIN, rather than resetting it to POLLIN|POLLRDNORM. It only affects select(), which uses POLLRDNORM. poll() is not affected, because it uses POLLIN. Also, it only affects FreeBSD, because Linux skips the optimization implemented by the piece of code where the bug occurs. MFC after: 3 days Sponsored by: Sunny Valley Networks --- sys/dev/netmap/netmap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'sys/dev/netmap') diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c index a6af3d3eebdcc..b51c0300493d0 100644 --- a/sys/dev/netmap/netmap.c +++ b/sys/dev/netmap/netmap.c @@ -3304,16 +3304,19 @@ netmap_poll(struct netmap_priv_d *priv, int events, NM_SELRECORD_T *sr) } if (want_rx) { enum txrx t = NR_RX; - want_rx = 0; /* look for a reason to run the handlers */ + int rxsync_needed = 0; + + /* look for a reason to run the handlers */ for (i = priv->np_qfirst[t]; i < priv->np_qlast[t]; i++) { kring = NMR(na, t)[i]; if (kring->ring->cur == kring->ring->tail /* try fetch new buffers */ || kring->rhead != kring->ring->head /* release buffers */) { - want_rx = 1; + rxsync_needed = 1; + break; } } - if (!want_rx) - revents |= events & (POLLIN | POLLRDNORM); /* we have data */ + if (!rxsync_needed) + revents |= want_rx; /* we have data */ } #endif -- cgit v1.3