Skip to contentSkip to conversation

vhost: Avoid that vhost_work_flush() locks up

PATCH In review Bart Van Assche 2 participants 3 messages Jul 5, 2013 – Jul 7, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: Avoid that vhost_work_flush() locks up

Wake up work->done waiters even if the TIF_NEED_RESCHED task flag has been set. This patch fixes a regression introduced in commit d550dda (kernel v3.4).

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=60505
Cc: Michael S. Tsirkin <[email protected]>
Cc: Asias He <[email protected]>
Cc: Nadav Har'El <[email protected]>
Cc: Abel Gordon <[email protected]>
Cc: <[email protected]> # v3.4+

---
 drivers/vhost/vhost.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/vhost/vhost.c +9 -1
index 60aa5ad..cd544ae 100644
@@ -227,8 +227,16 @@ static int vhost_worker(void *data)
 		if (work) {
 			__set_current_state(TASK_RUNNING);
 			work->fn(work);
-			if (need_resched())
+			if (need_resched()) {
+				spin_lock_irq(&dev->work_lock);
+				work->done_seq = seq;
+				if (work->flushing)
+					wake_up_all(&work->done);
+				spin_unlock_irq(&dev->work_lock);
+
+				work = NULL;
 				schedule();
+			}
 		} else
 			schedule();
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · Bart Van Assche

Wake up work->done waiters even if the TIF_NEED_RESCHED task flag has been set. This patch fixes a regression introduced in commit d550dda (kernel v3.4).

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=60505

(replying to my own e-mail)

Please ignore this patch. Although it might help to wake up vhost_work_flush() earlier, the patch description does not match the patch itself and the patch does not fix the vhost_work_flush() lockup.

Bart.

#2 lore raw
In reply to Bart Van Assche
Quoted 11 lines · Bart Van Assche

Wake up work->done waiters even if the TIF_NEED_RESCHED task flag has been set. This patch fixes a regression introduced in commit d550dda (kernel v3.4).

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=60505
Cc: Michael S. Tsirkin <[email protected]>
Cc: Asias He <[email protected]>
Cc: Nadav Har'El <[email protected]>
Cc: Abel Gordon <[email protected]>
Cc: <[email protected]> # v3.4+

I just posted a patch fixing a bug in this function. [PATCHv3] vhost-net: fix use-after-free in vhost_net_flush could you please try with this patch applied?

Quoted 28 lines
---
 drivers/vhost/vhost.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/vhost/vhost.c +9 -1
index 60aa5ad..cd544ae 100644
@@ -227,8 +227,16 @@ static int vhost_worker(void *data)
 		if (work) {
 			__set_current_state(TASK_RUNNING);
 			work->fn(work);
-			if (need_resched())
+			if (need_resched()) {
+				spin_lock_irq(&dev->work_lock);
+				work->done_seq = seq;
+				if (work->flushing)
+					wake_up_all(&work->done);
+				spin_unlock_irq(&dev->work_lock);
+
+				work = NULL;
 				schedule();
+			}
 		} else
 			schedule();
 
Signature · 1 line
1.7.10.4