Skip to contentSkip to conversation

xenfb bug fix and clean up

PATCH Superseded Wei Liu 3 participants 9 messages Apr 12, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover xenfb bug fix and clean up

Wei Liu (2):
xenfb: use the correct condition to avoid excessive looping
xenfb: remove out_cons in xenfb_handle_events

 hw/display/xenfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH 1/2 xenfb: use the correct condition to avoid excessive looping

In commit ac0487e1 ("xenfb.c: avoid expensive loops when prod <= out_cons"), ">=" was used. In fact, a full ring is a legit state. Correct the test to use ">".

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

Backport candidate to our own tree.

---
 hw/display/xenfb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/xenfb.c +1 -1
index 40b096a..9866dfd 100644
@@ -775,7 +775,7 @@ static void xenfb_handle_events(struct XenFB *xenfb)
 
     prod = page->out_prod;
     out_cons = page->out_cons;
-    if (prod - out_cons >= XENFB_OUT_RING_LEN) {
+    if (prod - out_cons > XENFB_OUT_RING_LEN) {
         return;
     }
     xen_rmb();		/* ensure we see ring contents up to prod */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#2 lore raw

PATCH 1/2 xenfb: use the correct condition to avoid excessive looping

In reply to Wei Liu

In commit ac0487e1 ("xenfb.c: avoid expensive loops when prod <= out_cons"), ">=" was used. In fact, a full ring is a legit state. Correct the test to use ">".

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

Backport candidate to our own tree.

---
 hw/display/xenfb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/xenfb.c +1 -1
index 40b096a..9866dfd 100644
@@ -775,7 +775,7 @@ static void xenfb_handle_events(struct XenFB *xenfb)
 
     prod = page->out_prod;
     out_cons = page->out_cons;
-    if (prod - out_cons >= XENFB_OUT_RING_LEN) {
+    if (prod - out_cons > XENFB_OUT_RING_LEN) {
         return;
     }
     xen_rmb();		/* ensure we see ring contents up to prod */
Signature · 1 line
2.1.4
Acked-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] xenfb: use the correct condition to avoid excessive looping

Quoted 7 lines · Wei Liu

In commit ac0487e1 ("xenfb.c: avoid expensive loops when prod <= out_cons"), ">=" was used. In fact, a full ring is a legit state. Correct the test to use ">".

Quoted 25 lines

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

Backport candidate to our own tree.

---
 hw/display/xenfb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/xenfb.c +1 -1
index 40b096a..9866dfd 100644
@@ -775,7 +775,7 @@ static void xenfb_handle_events(struct XenFB *xenfb)
 
     prod = page->out_prod;
     out_cons = page->out_cons;
-    if (prod - out_cons >= XENFB_OUT_RING_LEN) {
+    if (prod - out_cons > XENFB_OUT_RING_LEN) {
         return;
     }
     xen_rmb();		/* ensure we see ring contents up to prod */
Signature · 1 line
2.1.4
Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v1 1/2
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] xenfb: use the correct condition to avoid excessive looping

In reply to Wei Liu
Quoted 7 lines · Wei Liu

In commit ac0487e1 ("xenfb.c: avoid expensive loops when prod <= out_cons"), ">=" was used. In fact, a full ring is a legit state. Correct the test to use ">".

Quoted 25 lines

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

Backport candidate to our own tree.

---
 hw/display/xenfb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/xenfb.c +1 -1
index 40b096a..9866dfd 100644
@@ -775,7 +775,7 @@ static void xenfb_handle_events(struct XenFB *xenfb)
 
     prod = page->out_prod;
     out_cons = page->out_cons;
-    if (prod - out_cons >= XENFB_OUT_RING_LEN) {
+    if (prod - out_cons > XENFB_OUT_RING_LEN) {
         return;
     }
     xen_rmb();		/* ensure we see ring contents up to prod */
Signature · 1 line
2.1.4
Signature · 1 line
Anthony PERARD
author
#5 lore raw

PATCH 2/2 xenfb: remove out_cons in xenfb_handle_events

In reply to Wei Liu

The variable out_cons was only used to temporarily hold the consumer index. Use cons directly to simplify code a bit.

No functional change introduced.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

---
 hw/display/xenfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/display/xenfb.c +4 -4
index 9866dfd..78a8dcd 100644
@@ -770,16 +770,16 @@ static void xenfb_invalidate(void *opaque)
 
 static void xenfb_handle_events(struct XenFB *xenfb)
 {
-    uint32_t prod, cons, out_cons;
+    uint32_t prod, cons;
     struct xenfb_page *page = xenfb->c.page;
 
     prod = page->out_prod;
-    out_cons = page->out_cons;
-    if (prod - out_cons > XENFB_OUT_RING_LEN) {
+    cons = page->out_cons;
+    if (prod - cons > XENFB_OUT_RING_LEN) {
         return;
     }
     xen_rmb();		/* ensure we see ring contents up to prod */
-    for (cons = out_cons; cons != prod; cons++) {
+    for ( ; cons != prod; cons++) {
 	union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons);
         uint8_t type = event->type;
 	int x, y, w, h;
Signature · 1 line
2.1.4
#6 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH 2/2] xenfb: remove out_cons in xenfb_handle_events

Quoted 19 lines · Wei Liu

The variable out_cons was only used to temporarily hold the consumer index. Use cons directly to simplify code a bit.

No functional change introduced.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

---
 hw/display/xenfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/display/xenfb.c +0 -0
index 9866dfd..78a8dcd 100644
@@ -770,16 +770,16 @@ static void xenfb_invalidate(void *opaque)
 

hw/display/xenfb.c static void xenfb_invalidate(void *opaque) · line 777

Quoted 10 lines
hw/display/xenfb.c +2 -3
 static void xenfb_handle_events(struct XenFB *xenfb)
 {
-    uint32_t prod, cons, out_cons;
+    uint32_t prod, cons;
     struct xenfb_page *page = xenfb->c.page;
 
     prod = page->out_prod;
-    out_cons = page->out_cons;
-    if (prod - out_cons > XENFB_OUT_RING_LEN) {
+    cons = page->out_cons;

You need the xen_rmb() before the first use of prod or cons.

~Andrew

hw/display/xenfb.c static void xenfb_invalidate(void *opaque) · line 785

Quoted 9 lines
hw/display/xenfb.c +2 -1
+    if (prod - cons > XENFB_OUT_RING_LEN) {
         return;
     }
     xen_rmb();		/* ensure we see ring contents up to prod */
-    for (cons = out_cons; cons != prod; cons++) {
+    for ( ; cons != prod; cons++) {
 	union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons);
         uint8_t type = event->type;
 	int x, y, w, h;

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

author
#7 lore raw

Re: [PATCH 2/2] xenfb: remove out_cons in xenfb_handle_events

Quoted 26 lines · Andrew Cooper
Quoted 25 lines · Wei Liu

The variable out_cons was only used to temporarily hold the consumer index. Use cons directly to simplify code a bit.

No functional change introduced.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

---
 hw/display/xenfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/display/xenfb.c +1 -1
index 9866dfd..78a8dcd 100644
@@ -770,16 +770,16 @@ static void xenfb_invalidate(void *opaque)
 
 static void xenfb_handle_events(struct XenFB *xenfb)
 {
-    uint32_t prod, cons, out_cons;
+    uint32_t prod, cons;
     struct xenfb_page *page = xenfb->c.page;
 
Quoted 7 lines

hw/display/xenfb.c static void xenfb_invalidate(void *opaque) · line 777

Quoted 4 lines
hw/display/xenfb.c +1 -2
     prod = page->out_prod;
-    out_cons = page->out_cons;
-    if (prod - out_cons > XENFB_OUT_RING_LEN) {
+    cons = page->out_cons;

You need the xen_rmb() before the first use of prod or cons.

Good point. I overlooked that.

The change should belong to either previous patch or a new patch though.

Wei.

Quoted 12 lines

~Andrew

Quoted 9 lines
hw/display/xenfb.c +2 -1
+    if (prod - cons > XENFB_OUT_RING_LEN) {
         return;
     }
     xen_rmb();		/* ensure we see ring contents up to prod */
-    for (cons = out_cons; cons != prod; cons++) {
+    for ( ; cons != prod; cons++) {
 	union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons);
         uint8_t type = event->type;
 	int x, y, w, h;

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

author
#8 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH 2/2] xenfb: remove out_cons in xenfb_handle_events

In reply to Andrew Cooper
Quoted 26 lines · Andrew Cooper
Quoted 25 lines · Wei Liu

The variable out_cons was only used to temporarily hold the consumer index. Use cons directly to simplify code a bit.

No functional change introduced.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

---
 hw/display/xenfb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/display/xenfb.c +1 -1
index 9866dfd..78a8dcd 100644
@@ -770,16 +770,16 @@ static void xenfb_invalidate(void *opaque)
 
 static void xenfb_handle_events(struct XenFB *xenfb)
 {
-    uint32_t prod, cons, out_cons;
+    uint32_t prod, cons;
     struct xenfb_page *page = xenfb->c.page;
 
Quoted 7 lines

hw/display/xenfb.c static void xenfb_invalidate(void *opaque) · line 777

Quoted 4 lines
hw/display/xenfb.c +1 -2
     prod = page->out_prod;
-    out_cons = page->out_cons;
-    if (prod - out_cons > XENFB_OUT_RING_LEN) {
+    cons = page->out_cons;

You need the xen_rmb() before the first use of prod or cons.

Good point. I overlooked that.

The change should belong to either previous patch or a new patch though.

Wei.

Quoted 12 lines

~Andrew

Quoted 9 lines
hw/display/xenfb.c +2 -1
+    if (prod - cons > XENFB_OUT_RING_LEN) {
         return;
     }
     xen_rmb();		/* ensure we see ring contents up to prod */
-    for (cons = out_cons; cons != prod; cons++) {
+    for ( ; cons != prod; cons++) {
 	union xenfb_out_event *event = &XENFB_OUT_RING_REF(page, cons);
         uint8_t type = event->type;
 	int x, y, w, h;