summaryrefslogtreecommitdiff
path: root/sys/dev/pv/hyperv.c
diff options
context:
space:
mode:
authorMike Belopuhov <mikeb@cvs.openbsd.org>2017-01-05 11:47:03 +0000
committerMike Belopuhov <mikeb@cvs.openbsd.org>2017-01-05 11:47:03 +0000
commit004d74ddb0a738c454c384dbf32e51fa3fa4f386 (patch)
tree1a069d4af8a11640de119f75ac1e65807aa8d9a3 /sys/dev/pv/hyperv.c
parent1197886a3ec36e59181c881b0b35834155919d8f (diff)
Don't let producer index become equal with the consumer when writing
A nod to the re.c commit by dlg@, perhaps pure paranoia, but works nevertheless. While here replace a more expensive modulo operation with a subtraction.
Diffstat (limited to 'sys/dev/pv/hyperv.c')
-rw-r--r--sys/dev/pv/hyperv.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/sys/dev/pv/hyperv.c b/sys/dev/pv/hyperv.c
index 985b5949d14..d77fa7ecb6d 100644
--- a/sys/dev/pv/hyperv.c
+++ b/sys/dev/pv/hyperv.c
@@ -1242,7 +1242,8 @@ hv_ring_put(struct hv_ring_data *wrd, uint8_t *data, uint32_t datalen)
memcpy(&wrd->rd_ring->br_data[wrd->rd_prod], data, left);
memcpy(&wrd->rd_ring->br_data[0], data + left, datalen - left);
wrd->rd_prod += datalen;
- wrd->rd_prod %= wrd->rd_dsize;
+ if (wrd->rd_prod >= wrd->rd_dsize)
+ wrd->rd_prod -= wrd->rd_dsize;
}
static inline void
@@ -1255,7 +1256,8 @@ hv_ring_get(struct hv_ring_data *rrd, uint8_t *data, uint32_t datalen,
memcpy(data + left, &rrd->rd_ring->br_data[0], datalen - left);
if (!peek) {
rrd->rd_cons += datalen;
- rrd->rd_cons %= rrd->rd_dsize;
+ if (rrd->rd_cons >= rrd->rd_dsize)
+ rrd->rd_cons -= rrd->rd_dsize;
}
}
@@ -1291,7 +1293,7 @@ hv_ring_write(struct hv_ring_data *wrd, struct iovec *iov, int iov_cnt,
KASSERT(datalen <= wrd->rd_dsize);
hv_ring_avail(wrd, &avail, NULL);
- if (avail < datalen) {
+ if (avail <= datalen) {
DPRINTF("%s: avail %u datalen %u\n", __func__, avail, datalen);
return (EAGAIN);
}
@@ -1432,7 +1434,8 @@ hv_ring_read(struct hv_ring_data *rrd, void *data, uint32_t datalen,
if (offset) {
rrd->rd_cons += offset;
- rrd->rd_cons %= rrd->rd_dsize;
+ if (rrd->rd_cons >= rrd->rd_dsize)
+ rrd->rd_cons -= rrd->rd_dsize;
}
hv_ring_get(rrd, (uint8_t *)data, datalen, 0);