Skip to contentSkip to conversation

ring/macro: Add a new macro to detect whether there is an overflow in requests and response.

PATCH Superseded Konrad Rzeszutek Wilk 2 participants 2 messages Jan 25, 2013 – Jan 28, 2013

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ring/macro: Add a new macro to detect whether there is an overflow in requests and response.

We want to be able to exit if the difference between the request produced (what the frontend tells us) and the requests consumed (what we have so far processed) is greater than the ring size.

If so, we should terminate the loop as the request produced is not trusted and it means it is bogus.

---
 xen/include/public/io/ring.h | 6 ++++++
 1 file changed, 6 insertions(+)
xen/include/public/io/ring.h +6 -0
index 38b7051..219ab63 100644
@@ -234,6 +234,12 @@ typedef struct __name##_back_ring __name##_back_ring_t
 #define RING_REQUEST_CONS_OVERFLOW(_r, _cons)                           \
     (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
 
+/* Loop termination condition: Is the difference between request produced
+ * and request consumed greater than the ring size. If so, terminate the
+ * loop. */
+#define RING_REQUEST_PROD_OVERFLOW(_r, _cons, _prod)                     \
+    (((_prod) - (_prod)) > RING_SIZE(_r))
+
 #define RING_PUSH_REQUESTS(_r) do {                                     \
     xen_wmb(); /* back sees requests /before/ updated producer index */ \
     (_r)->sring->req_prod = (_r)->req_prod_pvt;                         \
Signature · 1 line
1.8.0.2
#1 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk

We want to be able to exit if the difference between the request produced (what the frontend tells us) and the requests consumed (what we have so far processed) is greater than the ring size.

If so, we should terminate the loop as the request produced is not trusted and it means it is bogus.

---
 xen/include/public/io/ring.h | 6 ++++++
 1 file changed, 6 insertions(+)
xen/include/public/io/ring.h +0 -0
index 38b7051..219ab63 100644

xen/include/public/io/ring.h typedef struct __name##_back_ring __name##_back_ring_t · line 241

Quoted 8 lines
xen/include/public/io/ring.h +5 -0
@@ -234,6 +234,12 @@ typedef struct __name##_back_ring __name##_back_ring_t
 #define RING_REQUEST_CONS_OVERFLOW(_r, _cons)                           \
     (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
 
+/* Loop termination condition: Is the difference between request produced
+ * and request consumed greater than the ring size. If so, terminate the
+ * loop. */
+#define RING_REQUEST_PROD_OVERFLOW(_r, _cons, _prod)                     \
+    (((_prod) - (_prod)) > RING_SIZE(_r))

Clearly one of the two _prod-s ought to be _cons?

Jan

Quoted 12 lines
xen/include/public/io/ring.h +1 -0
+
 #define RING_PUSH_REQUESTS(_r) do {                                     \
     xen_wmb(); /* back sees requests /before/ updated producer index */ \
     (_r)->sring->req_prod = (_r)->req_prod_pvt;                         \
Signature · 7 lines
1.8.0.2


_______________________________________________
Xen-devel mailing list
[email protected] 
http://lists.xen.org/xen-devel