Page MenuHomeFreeBSD

D46155.diff
No OneTemporary

D46155.diff

diff --git a/sys/sys/buf_ring.h b/sys/sys/buf_ring.h
--- a/sys/sys/buf_ring.h
+++ b/sys/sys/buf_ring.h
@@ -89,7 +89,17 @@
#endif
critical_enter();
do {
- prod_head = br->br_prod_head;
+ /*
+ * br->br_prod_head needs to be read before br->br_cons_tail.
+ * If not then we could perform the dequeue and enqueue
+ * between reading br_cons_tail and reading br_prod_head. This
+ * could give us values where br_cons_head == br_prod_tail
+ * (after masking).
+ *
+ * To work around this us a load acquire. This is just to
+ * ensure ordering within this thread.
+ */
+ prod_head = atomic_load_acq_32(&br->br_prod_head);
prod_next = prod_head + 1;
cons_tail = atomic_load_acq_32(&br->br_cons_tail);
@@ -137,7 +147,12 @@
critical_enter();
mask = br->br_cons_mask;
do {
- cons_head = br->br_cons_head;
+ /*
+ * As with buf_ring_enqueue ensure we read the head before
+ * the tail. If we read them in the wrong order we may
+ * think the bug_ring is full when it is empty.
+ */
+ cons_head = atomic_load_acq_32(&br->br_cons_head);
cons_next = cons_head + 1;
prod_tail = atomic_load_acq_32(&br->br_prod_tail);

File Metadata

Mime Type
text/plain
Expires
Fri, Jan 17, 2:53 AM (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15832359
Default Alt Text
D46155.diff (1 KB)

Event Timeline