Skip to contentSkip to conversation

fix xenfb_update_screen bogus rect

PATCH In review Akio Takebe 3 participants 14 messages Jan 27, 2009 – Feb 2, 2009 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix xenfb_update_screen bogus rect

Hi,

When I tested pvfb, I got the following warnings.
It seems to be caused by checking/setting info->dirty without dirty_lock. We need to check/set info->dirty safely.

xenfb_update_screen bogus rect 2147483647 0 2147483647 0

 BUG: warning at /root/linux-2.6.18-xen.hg/drivers/xen/fbfront/xenfb.c:240/xenfb_update_screen()

 Call Trace:
  [<ffffffff8036920e>] xenfb_thread+0x19b/0x2be
  [<ffffffff8022730a>] try_to_wake_up+0x33b/0x34c
  [<ffffffff80225c3d>] __wake_up_common+0x3e/0x68
  [<ffffffff80241e20>] autoremove_wake_function+0x0/0x2e
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff80369073>] xenfb_thread+0x0/0x2be
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff80241ceb>] kthread+0xd4/0x109
  [<ffffffff8020afe0>] child_rip+0xa/0x12
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff8021477f>] xen_send_IPI_mask+0x0/0xf5
  [<ffffffff80241c17>] kthread+0x0/0x109
  [<ffffffff8020afd6>] child_rip+0x0/0x12

FYI, when I tested it, I used the following shell scripts on PV guest. The above warnings occurred in /var/log/messages.
=======================
#!/bin/bash

while true
do
date
done
=======================

The attached patch fixed this warnings.
How about it?

Best Regards,

Akio Takebe

drivers/xen/fbfront/xenfb.c +19 -2
diff -r 83b71f4b5cb2 drivers/xen/fbfront/xenfb.c
@@ -255,19 +255,36 @@
 	}
 	spin_unlock_irqrestore(&info->resize_lock, flags);
 }
+static int check_is_dirty(struct xenfb_info *info)
+{
+	int is_dirty;
+	unsigned long flags;
+	spin_lock_irqsave(&info->dirty_lock, flags);
+	is_dirty = info->dirty;
+	spin_unlock_irqrestore(&info->dirty_lock, flags);
+
+	return is_dirty;
+}
 
 static int xenfb_thread(void *data)
 {
 	struct xenfb_info *info = data;
+	unsigned long flags;
+	int is_dirty;
 
 	while (!kthread_should_stop()) {
 		xenfb_handle_resize_dpy(info);
-		if (info->dirty) {
+		spin_lock_irqsave(&info->dirty_lock, flags);
+		is_dirty = info->dirty;
+		if (is_dirty) {
 			info->dirty = 0;
+			spin_unlock_irqrestore(&info->dirty_lock, flags);
 			xenfb_update_screen(info);
+		} else {
+			spin_unlock_irqrestore(&info->dirty_lock, flags);
 		}
 		wait_event_interruptible(info->wq,
-			kthread_should_stop() || info->dirty);
+			kthread_should_stop() || check_is_dirty(info));
 		try_to_freeze();
 	}
 	return 0;

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

#1 lore raw

This looks bogus to me. check_is_dirty() definitely isn't needed - if at all, a memory read barrier may need to be added, but since kthread_should_stop() is a function call even that ought to be unnecessary.

I also think the other change is more involved than it needs to be - it'd be much simpler to let xenfb_update_screen() check-and-clear the dirty flag along with reading the other fields, and bail if the flag was clear.

Jan

Quoted 1 line
Quoted 1 line
Quoted 1 line

Akio Takebe <[email protected]> 27.01.09 03:58 >>>

Hi,

When I tested pvfb, I got the following warnings.
It seems to be caused by checking/setting info->dirty without dirty_lock. We need to check/set info->dirty safely.

xenfb_update_screen bogus rect 2147483647 0 2147483647 0

 BUG: warning at /root/linux-2.6.18-xen.hg/drivers/xen/fbfront/xenfb.c:240/xenfb_update_screen()

 Call Trace:
  [<ffffffff8036920e>] xenfb_thread+0x19b/0x2be
  [<ffffffff8022730a>] try_to_wake_up+0x33b/0x34c
  [<ffffffff80225c3d>] __wake_up_common+0x3e/0x68
  [<ffffffff80241e20>] autoremove_wake_function+0x0/0x2e
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff80369073>] xenfb_thread+0x0/0x2be
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff80241ceb>] kthread+0xd4/0x109
  [<ffffffff8020afe0>] child_rip+0xa/0x12
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff8021477f>] xen_send_IPI_mask+0x0/0xf5
  [<ffffffff80241c17>] kthread+0x0/0x109
  [<ffffffff8020afd6>] child_rip+0x0/0x12

FYI, when I tested it, I used the following shell scripts on PV guest. The above warnings occurred in /var/log/messages.
=======================
#!/bin/bash

while true
do
date
done
=======================

The attached patch fixed this warnings.
How about it?

Best Regards,

Akio Takebe

#2 lore raw

Hi, Jan

Thank you for your review.
I remade it simpler.
But Just moving check-and-clear dirty flag to xenfb_update_screen(), a guest with vcpu=1 could not boot.
It is caused by info->update_wanted = 0.
So I moved kthread_run() into XenbusStateConnected handling. How about it?

Best Regards,

Akio Takebe

Quoted 47 lines · Jan Beulich

This looks bogus to me. check_is_dirty() definitely isn't needed - if at all, a memory read barrier may need to be added, but since kthread_should_stop() is a function call even that ought to be unnecessary.

I also think the other change is more involved than it needs to be - it'd be much simpler to let xenfb_update_screen() check-and-clear the dirty flag along with reading the other fields, and bail if the flag was clear.

Jan

Quoted 1 line
Quoted 1 line
Quoted 1 line

Akio Takebe <[email protected]> 27.01.09 03:58 >>>

Hi,

When I tested pvfb, I got the following warnings.
It seems to be caused by checking/setting info->dirty without dirty_lock. We need to check/set info->dirty safely.

xenfb_update_screen bogus rect 2147483647 0 2147483647 0

 BUG: warning at /root/linux-2.6.18-xen.hg/drivers/xen/fbfront/xenfb.c:240/xenfb_update_screen()

 Call Trace:
  [<ffffffff8036920e>] xenfb_thread+0x19b/0x2be
  [<ffffffff8022730a>] try_to_wake_up+0x33b/0x34c
  [<ffffffff80225c3d>] __wake_up_common+0x3e/0x68
  [<ffffffff80241e20>] autoremove_wake_function+0x0/0x2e
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff80369073>] xenfb_thread+0x0/0x2be
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff80241ceb>] kthread+0xd4/0x109
  [<ffffffff8020afe0>] child_rip+0xa/0x12
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff8021477f>] xen_send_IPI_mask+0x0/0xf5
  [<ffffffff80241c17>] kthread+0x0/0x109
  [<ffffffff8020afd6>] child_rip+0x0/0x12

FYI, when I tested it, I used the following shell scripts on PV guest. The above warnings occurred in /var/log/messages.
=======================
#!/bin/bash

while true
do
date
done
=======================

Quoted 10 lines

The attached patch fixed this warnings.
How about it?

Best Regards,

Akio Takebe

drivers/xen/fbfront/xenfb.c +22 -21
diff -r 83b71f4b5cb2 drivers/xen/fbfront/xenfb.c
@@ -213,17 +213,23 @@
 	if (xenfb_queue_full(info))
 		return;
 
-	mutex_lock(&info->mm_lock);
-
 	spin_lock_irqsave(&info->dirty_lock, flags);
-	y1 = info->y1;
-	y2 = info->y2;
-	x1 = info->x1;
-	x2 = info->x2;
-	info->x1 = info->y1 = INT_MAX;
-	info->x2 = info->y2 = 0;
+	if (info->dirty){
+		info->dirty = 0;
+		y1 = info->y1;
+		y2 = info->y2;
+		x1 = info->x1;
+		x2 = info->x2;
+		info->x1 = info->y1 = INT_MAX;
+		info->x2 = info->y2 = 0;
+	} else {
+		spin_unlock_irqrestore(&info->dirty_lock, flags);
+		return;
+	}
 	spin_unlock_irqrestore(&info->dirty_lock, flags);
 
+	mutex_lock(&info->mm_lock);
+	
 	list_for_each_entry(map, &info->mappings, link) {
 		if (!map->faults)
 			continue;
@@ -262,10 +268,7 @@
 
 	while (!kthread_should_stop()) {
 		xenfb_handle_resize_dpy(info);
-		if (info->dirty) {
-			info->dirty = 0;
-			xenfb_update_screen(info);
-		}
+		xenfb_update_screen(info);
 		wait_event_interruptible(info->wq,
 			kthread_should_stop() || info->dirty);
 		try_to_freeze();
@@ -666,15 +669,6 @@
 	if (ret < 0)
 		goto error;
 
-	/* FIXME should this be delayed until backend XenbusStateConnected? */
-	info->kthread = kthread_run(xenfb_thread, info, "xenfb thread");
-	if (IS_ERR(info->kthread)) {
-		ret = PTR_ERR(info->kthread);
-		info->kthread = NULL;
-		xenbus_dev_fatal(dev, ret, "register_framebuffer");
-		goto error;
-	}
-
 	return 0;
 
  error_nomem:
@@ -839,6 +833,13 @@
 					"feature-resize", "%d", &val) < 0)
 			val = 0;
 		info->feature_resize = val;
+
+		info->kthread = kthread_run(xenfb_thread, info, "xenfb thread");
+		if (IS_ERR(info->kthread)) {
+			info->kthread = NULL;
+			xenbus_dev_fatal(dev, PTR_ERR(info->kthread),
+					"register_framebuffer");
+		}
 		break;
 
 	case XenbusStateClosing:

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

#3 lore raw

Generally this looks okay (assuming it works), but couldn't the update_wanted field then go away altogether?

Jan

Quoted 1 line
Quoted 1 line
Quoted 1 line

Akio Takebe <[email protected]> 28.01.09 08:31 >>>

Hi, Jan

Thank you for your review.
I remade it simpler.
But Just moving check-and-clear dirty flag to xenfb_update_screen(), a guest with vcpu=1 could not boot.
It is caused by info->update_wanted = 0.
So I moved kthread_run() into XenbusStateConnected handling. How about it?

Best Regards,

Akio Takebe

Quoted 57 lines · Jan Beulich

This looks bogus to me. check_is_dirty() definitely isn't needed - if at all, a memory read barrier may need to be added, but since kthread_should_stop() is a function call even that ought to be unnecessary.

I also think the other change is more involved than it needs to be - it'd be much simpler to let xenfb_update_screen() check-and-clear the dirty flag along with reading the other fields, and bail if the flag was clear.

Jan

Quoted 1 line
Quoted 1 line
Quoted 1 line

Akio Takebe <[email protected]> 27.01.09 03:58 >>>

Hi,

When I tested pvfb, I got the following warnings.
It seems to be caused by checking/setting info->dirty without dirty_lock. We need to check/set info->dirty safely.

xenfb_update_screen bogus rect 2147483647 0 2147483647 0

 BUG: warning at /root/linux-2.6.18-xen.hg/drivers/xen/fbfront/xenfb.c:240/xenfb_update_screen()

 Call Trace:
  [<ffffffff8036920e>] xenfb_thread+0x19b/0x2be
  [<ffffffff8022730a>] try_to_wake_up+0x33b/0x34c
  [<ffffffff80225c3d>] __wake_up_common+0x3e/0x68
  [<ffffffff80241e20>] autoremove_wake_function+0x0/0x2e
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff80369073>] xenfb_thread+0x0/0x2be
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff80241ceb>] kthread+0xd4/0x109
  [<ffffffff8020afe0>] child_rip+0xa/0x12
  [<ffffffff80241a75>] keventd_create_kthread+0x0/0x61
  [<ffffffff8021477f>] xen_send_IPI_mask+0x0/0xf5
  [<ffffffff80241c17>] kthread+0x0/0x109
  [<ffffffff8020afd6>] child_rip+0x0/0x12

FYI, when I tested it, I used the following shell scripts on PV guest. The above warnings occurred in /var/log/messages.
=======================
#!/bin/bash

while true
do
date
done
=======================

The attached patch fixed this warnings.
How about it?

Best Regards,

Akio Takebe

#7 lore raw
In reply to Akio Takebe
Quoted 7 lines · Akio Takebe

Hi, Jan

Thank you for your review.
I remade it simpler.
But Just moving check-and-clear dirty flag to xenfb_update_screen(), a guest with vcpu=1 could not boot.
It is caused by info->update_wanted = 0.

Thanks for debugging this!

Quoted 8 lines

So I moved kthread_run() into XenbusStateConnected handling. How about it?

Best Regards,

Akio Takebe

[...]

drivers/xen/fbfront/xenfb.c

Quoted 4 lines

diff -r 83b71f4b5cb2 drivers/xen/fbfront/xenfb.c

drivers/xen/fbfront/xenfb.c +0 -0
@@ -213,17 +213,23 @@

Please use -p with diff.

Quoted 21 lines
drivers/xen/fbfront/xenfb.c +9 -8
 	if (xenfb_queue_full(info))
 		return;
 
-	mutex_lock(&info->mm_lock);
-
 	spin_lock_irqsave(&info->dirty_lock, flags);
-	y1 = info->y1;
-	y2 = info->y2;
-	x1 = info->x1;
-	x2 = info->x2;
-	info->x1 = info->y1 = INT_MAX;
-	info->x2 = info->y2 = 0;
+	if (info->dirty){
+		info->dirty = 0;
+		y1 = info->y1;
+		y2 = info->y2;
+		x1 = info->x1;
+		x2 = info->x2;
+		info->x1 = info->y1 = INT_MAX;
+		info->x2 = info->y2 = 0;
+	} else {

drivers/xen/fbfront/xenfb.c line 235

Quoted 10 lines
drivers/xen/fbfront/xenfb.c +5 -0
+		spin_unlock_irqrestore(&info->dirty_lock, flags);
+		return;
+	}
 	spin_unlock_irqrestore(&info->dirty_lock, flags);
 
+	mutex_lock(&info->mm_lock);
+	
 	list_for_each_entry(map, &info->mappings, link) {
 		if (!map->faults)
 			continue;

Careful, locking is rather delicate here. Please read the big comment "There are three locks:", then explain why moving the locking of mm_lock is safe.

[...]

#4 lore raw
In reply to Jan Beulich
Quoted 4 lines · Jan Beulich

Generally this looks okay (assuming it works), but couldn't the update_wanted field then go away altogether?

Jan

I think so, yes. Start the kthread only when request-update.

#5 lore raw

Hi, Markus and Jan

Quoted 9 lines · Markus Armbruster
Quoted 4 lines · Jan Beulich

Generally this looks okay (assuming it works), but couldn't the update_wanted field then go away altogether?

Jan

I think so, yes. Start the kthread only when request-update.

Thank you for your review.
The patch was commited already.
So I made an additional patch which eliminate the update_wanted field.

Best Regards,

Akio Takebe

drivers/xen/fbfront/xenfb.c +12 -13
diff -r 51decc39e5e7 drivers/xen/fbfront/xenfb.c
@@ -61,7 +61,6 @@ struct xenfb_info
 	int			irq;
 	struct xenfb_page	*page;
 	unsigned long 		*mfns;
-	int			update_wanted; /* XENFB_TYPE_UPDATE wanted */
 	int			feature_resize; /* Backend has resize feature */
 	struct xenfb_resize	resize;
 	int			resize_dpy;
@@ -208,8 +207,6 @@ static void xenfb_update_screen(struct x
 	int y1, y2, x1, x2;
 	struct xenfb_mapping *map;
 
-	if (!info->update_wanted)
-		return;
 	if (xenfb_queue_full(info))
 		return;
 
@@ -823,22 +820,24 @@ static void xenfb_backend_changed(struct
 		if (dev->state != XenbusStateConnected)
 			goto InitWait; /* no InitWait seen yet, fudge it */
 
-		if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-				 "request-update", "%d", &val) < 0)
-			val = 0;
-		if (val)
-			info->update_wanted = 1;
 
 		if (xenbus_scanf(XBT_NIL, dev->otherend,
 					"feature-resize", "%d", &val) < 0)
 			val = 0;
 		info->feature_resize = val;
 
-		info->kthread = kthread_run(xenfb_thread, info, "xenfb thread");
-		if (IS_ERR(info->kthread)) {
-			info->kthread = NULL;
-			xenbus_dev_fatal(dev, PTR_ERR(info->kthread),
-					"register_framebuffer");
+		if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+				 "request-update", "%d", &val) < 0)
+			val = 0;
+
+		if (val){
+			info->kthread = kthread_run(xenfb_thread, info,
+						    "xenfb thread");
+			if (IS_ERR(info->kthread)) {
+				info->kthread = NULL;
+				xenbus_dev_fatal(dev, PTR_ERR(info->kthread),
+						"register_framebuffer");
+			}
 		}
 		break;
 

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

#8 lore raw
In reply to Markus Armbruster

Hi, Markus

Quoted 54 lines · Markus Armbruster
Quoted 7 lines · Akio Takebe

Hi, Jan

Thank you for your review.
I remade it simpler.
But Just moving check-and-clear dirty flag to xenfb_update_screen(), a guest with vcpu=1 could not boot.
It is caused by info->update_wanted = 0.

Thanks for debugging this!

Quoted 8 lines

So I moved kthread_run() into XenbusStateConnected handling. How about it?

Best Regards,

Akio Takebe

[...]

drivers/xen/fbfront/xenfb.c

Quoted 4 lines

diff -r 83b71f4b5cb2 drivers/xen/fbfront/xenfb.c

drivers/xen/fbfront/xenfb.c +0 -0
@@ -213,17 +213,23 @@

Please use -p with diff.

Quoted 26 lines
drivers/xen/fbfront/xenfb.c +12 -8
 	if (xenfb_queue_full(info))
 		return;
 
-	mutex_lock(&info->mm_lock);
-
 	spin_lock_irqsave(&info->dirty_lock, flags);
-	y1 = info->y1;
-	y2 = info->y2;
-	x1 = info->x1;
-	x2 = info->x2;
-	info->x1 = info->y1 = INT_MAX;
-	info->x2 = info->y2 = 0;
+	if (info->dirty){
+		info->dirty = 0;
+		y1 = info->y1;
+		y2 = info->y2;
+		x1 = info->x1;
+		x2 = info->x2;
+		info->x1 = info->y1 = INT_MAX;
+		info->x2 = info->y2 = 0;
+	} else {
+		spin_unlock_irqrestore(&info->dirty_lock, flags);
+		return;
+	}
 	spin_unlock_irqrestore(&info->dirty_lock, flags);
 
Quoted 10 lines

drivers/xen/fbfront/xenfb.c line 235

Quoted 5 lines
drivers/xen/fbfront/xenfb.c +2 -0
+	mutex_lock(&info->mm_lock);
+	
 	list_for_each_entry(map, &info->mappings, link) {
 		if (!map->faults)
 			continue;

Careful, locking is rather delicate here. Please read the big comment "There are three locks:", then explain why moving the locking of mm_lock is safe.

Thank you for your review.
First, I thought mm_lock just protected the mappings,
and the dirty rectangle was protected by the dirty_lock.
So I moved the mm_lock.
Also when I tested the patch, I didn't get any problem.
Do you mean the narrow point of between unloking dirty_lock and locking mm_lock in xenfb_update_screen() may be not safe?
Do you find any critical cases?

Best Regards,

Akio Takebe

#6 lore raw
In reply to Akio Takebe
Quoted 16 lines · Akio Takebe

Hi, Markus and Jan

Quoted 9 lines · Markus Armbruster
Quoted 4 lines · Jan Beulich

Generally this looks okay (assuming it works), but couldn't the update_wanted field then go away altogether?

Jan

I think so, yes. Start the kthread only when request-update.

Thank you for your review.
The patch was commited already.
So I made an additional patch which eliminate the update_wanted field.

Quoted 5 lines

Best Regards,

Akio Takebe

Looks good to me.

A possible reason not to take this cleanup is the fact that this version of the driver is a dead end (the living end lives in current upstream kernels). Perhaps only true fixes with minimal structural impact are desired because of that. Not my call to make.

#9 lore raw
In reply to Akio Takebe
Quoted 4 lines · Akio Takebe

Hi, Markus

Quoted 1 line · Markus Armbruster

Akio Takebe <[email protected]> writes:

[...]

Quoted 41 lines
Quoted 32 lines

drivers/xen/fbfront/xenfb.c

Quoted 4 lines

diff -r 83b71f4b5cb2 drivers/xen/fbfront/xenfb.c

drivers/xen/fbfront/xenfb.c +0 -0
@@ -213,17 +213,23 @@

Please use -p with diff.

Quoted 25 lines
drivers/xen/fbfront/xenfb.c +12 -7
 	if (xenfb_queue_full(info))
 		return;
 -	mutex_lock(&info->mm_lock);
-
 	spin_lock_irqsave(&info->dirty_lock, flags);
-	y1 = info->y1;
-	y2 = info->y2;
-	x1 = info->x1;
-	x2 = info->x2;
-	info->x1 = info->y1 = INT_MAX;
-	info->x2 = info->y2 = 0;
+	if (info->dirty){
+		info->dirty = 0;
+		y1 = info->y1;
+		y2 = info->y2;
+		x1 = info->x1;
+		x2 = info->x2;
+		info->x1 = info->y1 = INT_MAX;
+		info->x2 = info->y2 = 0;
+	} else {
+		spin_unlock_irqrestore(&info->dirty_lock, flags);
+		return;
+	}
 	spin_unlock_irqrestore(&info->dirty_lock, flags);
 +	mutex_lock(&info->mm_lock);
Quoted 9 lines

drivers/xen/fbfront/xenfb.c line 235

Quoted 4 lines
drivers/xen/fbfront/xenfb.c +1 -0
+	
 	list_for_each_entry(map, &info->mappings, link) {
 		if (!map->faults)
 			continue;

Careful, locking is rather delicate here. Please read the big comment "There are three locks:", then explain why moving the locking of mm_lock is safe.

Quoted 1 line

Thank you for your review.

My pleasure. I have to thank for your fix!

Quoted 4 lines

First, I thought mm_lock just protected the mappings, and the dirty rectangle was protected by the dirty_lock. So I moved the mm_lock.
Also when I tested the patch, I didn't get any problem.

Subtle locking bugs are notoriously hard to demonstrate by testing.

Quoted 7 lines

Do you mean the narrow point of between unloking dirty_lock and locking mm_lock in xenfb_update_screen() may be not safe?
Do you find any critical cases?

Best Regards,

Akio Takebe

Your proposed change might be fine, it might be racy, I don't know. What I do know is that it invalidates the comment I mentioned. That's a nasty trap for the unwary, and clearly a bug as far as I'm concerned.

I strongly recommend to either revert the locking change, or fix the comment to match the new code.

#10 lore raw

Hi, Markus

Quoted 65 lines · Markus Armbruster
Quoted 4 lines · Akio Takebe

Hi, Markus

Quoted 1 line · Markus Armbruster

Akio Takebe <[email protected]> writes:

[...]

Quoted 39 lines
Quoted 30 lines

drivers/xen/fbfront/xenfb.c

Quoted 4 lines

diff -r 83b71f4b5cb2 drivers/xen/fbfront/xenfb.c

drivers/xen/fbfront/xenfb.c +0 -0
@@ -213,17 +213,23 @@

Please use -p with diff.

Quoted 24 lines
drivers/xen/fbfront/xenfb.c +12 -7
 	if (xenfb_queue_full(info))
 		return;
 -	mutex_lock(&info->mm_lock);
-
 	spin_lock_irqsave(&info->dirty_lock, flags);
-	y1 = info->y1;
-	y2 = info->y2;
-	x1 = info->x1;
-	x2 = info->x2;
-	info->x1 = info->y1 = INT_MAX;
-	info->x2 = info->y2 = 0;
+	if (info->dirty){
+		info->dirty = 0;
+		y1 = info->y1;
+		y2 = info->y2;
+		x1 = info->x1;
+		x2 = info->x2;
+		info->x1 = info->y1 = INT_MAX;
+		info->x2 = info->y2 = 0;
+	} else {
+		spin_unlock_irqrestore(&info->dirty_lock, flags);
+		return;
+	}
 	spin_unlock_irqrestore(&info->dirty_lock, flags);
Quoted 9 lines

drivers/xen/fbfront/xenfb.c line 234

Quoted 5 lines
drivers/xen/fbfront/xenfb.c +1 -0
 +	mutex_lock(&info->mm_lock);
+	
 	list_for_each_entry(map, &info->mappings, link) {
 		if (!map->faults)
 			continue;

Careful, locking is rather delicate here. Please read the big comment "There are three locks:", then explain why moving the locking of mm_lock is safe.

Quoted 1 line

Thank you for your review.

My pleasure. I have to thank for your fix!

Quoted 4 lines

First, I thought mm_lock just protected the mappings, and the dirty rectangle was protected by the dirty_lock. So I moved the mm_lock.
Also when I tested the patch, I didn't get any problem.

Subtle locking bugs are notoriously hard to demonstrate by testing.

Quoted 7 lines

Do you mean the narrow point of between unloking dirty_lock and locking mm_lock in xenfb_update_screen() may be not safe?
Do you find any critical cases?

Best Regards,

Akio Takebe

Quoted 8 lines

Your proposed change might be fine, it might be racy, I don't know. What I do know is that it invalidates the comment I mentioned. That's a nasty trap for the unwary, and clearly a bug as far as I'm concerned.

I strongly recommend to either revert the locking change, or fix the comment to match the new code.

I agree with you. I revert the mm_lock changing.
In my graphic test, I didn't get any problem with this patch.

Best Regards,

Akio Takebe

drivers/xen/fbfront/xenfb.c +3 -2
diff -r f90f02049d7e drivers/xen/fbfront/xenfb.c
@@ -210,6 +210,8 @@ static void xenfb_update_screen(struct x
 	if (xenfb_queue_full(info))
 		return;
 
+	mutex_lock(&info->mm_lock);
+	
 	spin_lock_irqsave(&info->dirty_lock, flags);
 	if (info->dirty){
 		info->dirty = 0;
@@ -221,12 +223,11 @@ static void xenfb_update_screen(struct x
 		info->x2 = info->y2 = 0;
 	} else {
 		spin_unlock_irqrestore(&info->dirty_lock, flags);
+		mutex_unlock(&info->mm_lock);
 		return;
 	}
 	spin_unlock_irqrestore(&info->dirty_lock, flags);
 
-	mutex_lock(&info->mm_lock);
-	
 	list_for_each_entry(map, &info->mappings, link) {
 		if (!map->faults)
 			continue;

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

#11 lore raw
Quoted 3 lines · Akio Takebe

Hi, Markus

Markus Armbruster wrote:

[...]

Quoted 11 lines
Quoted 3 lines

I strongly recommend to either revert the locking change, or fix the comment to match the new code.

I agree with you. I revert the mm_lock changing.
In my graphic test, I didn't get any problem with this patch.

Best Regards,

Akio Takebe

Looks good to me. Thanks again!

#12 lore raw

PATCH 1/1 fbfront: Improve diagnostics when kthread_run() fails

In reply to Akio Takebe

Failure is reported with xenbus_dev_fatal(..."register_framebuffer"), which was already suboptimal before it got moved away from register_framebuffer(), and is outright misleading now.

drivers/xen/fbfront/xenfb.c +2 -2
diff -r 26ddc59c674d drivers/xen/fbfront/xenfb.c
@@ -211,7 +211,7 @@
 		return;
 
 	mutex_lock(&info->mm_lock);
-	
+
 	spin_lock_irqsave(&info->dirty_lock, flags);
 	if (info->dirty){
 		info->dirty = 0;
@@ -837,7 +837,7 @@
 			if (IS_ERR(info->kthread)) {
 				info->kthread = NULL;
 				xenbus_dev_fatal(dev, PTR_ERR(info->kthread),
-						"register_framebuffer");
+						"xenfb_thread");
 			}
 		}
 		break;
#13 lore raw

Re: [PATCH] fbfront: Improve diagnostics when kthread_run()fails

Hi, Markus

Thanks. I agree with you.

Best Regards,

Akio Takebe

Quoted 32 lines

Failure is reported with xenbus_dev_fatal(..."register_framebuffer"), which was already suboptimal before it got moved away from register_framebuffer(), and is outright misleading now.

diff -r 26ddc59c674d drivers/xen/fbfront/xenfb.c

drivers/xen/fbfront/xenfb.c +2 -2
@@ -211,7 +211,7 @@
 		return;
 
 	mutex_lock(&info->mm_lock);
-	
+
 	spin_lock_irqsave(&info->dirty_lock, flags);
 	if (info->dirty){
 		info->dirty = 0;
@@ -837,7 +837,7 @@
 			if (IS_ERR(info->kthread)) {
 				info->kthread = NULL;
 				xenbus_dev_fatal(dev, PTR_ERR(info->kthread),
-						"register_framebuffer");
+						"xenfb_thread");
 			}
 		}
 		break;

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