Skip to contentSkip to conversation

tun: fix blocking read

PATCH In review Timur Celik 3 participants 8 messages Feb 23, 2019 – Feb 25, 2019

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

PATCH 1/1 tun: fix blocking read

This patch moves setting of the current state into the loop. Otherwise the task may end up in a busy wait loop if none of the break conditions are met.

---
 drivers/net/tun.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/tun.c +2 -2
index fed298c0cb39..d291762b9e9d 100644
@@ -2167,9 +2167,9 @@ static void *tun_ring_recv(struct tun_file *tfile, int noblock, int *err)
 	}
 
 	add_wait_queue(&tfile->wq.wait, &wait);
-	current->state = TASK_INTERRUPTIBLE;
 
 	while (1) {
+		set_current_state(TASK_INTERRUPTIBLE);
 		ptr = ptr_ring_consume(&tfile->tx_ring);
 		if (ptr)
 			break;
@@ -2185,7 +2185,7 @@ static void *tun_ring_recv(struct tun_file *tfile, int noblock, int *err)
 		schedule();
 	}
 
-	current->state = TASK_RUNNING;
+	set_current_state(TASK_RUNNING);
 	remove_wait_queue(&tfile->wq.wait, &wait);
 
 out:
Signature · 1 line
2.20.1
maintainer
#1 lore raw

From: Timur Celik <[email protected]>
Date: Sat, 23 Feb 2019 12:53:13 +0100

Quoted 5 lines

This patch moves setting of the current state into the loop. Otherwise the task may end up in a busy wait loop if none of the break conditions are met.

Applied and queued up for -stable, thanks.

#2 lore raw
Quoted 11 lines · David Miller

From: Timur Celik <[email protected]>
Date: Sat, 23 Feb 2019 12:53:13 +0100

Quoted 5 lines

This patch moves setting of the current state into the loop. Otherwise the task may end up in a busy wait loop if none of the break conditions are met.

Applied and queued up for -stable, thanks.

First part of the patch was matching the changelog, however the second change was not really needed, or should have used

__set_current_state(TASK_RUNNING);

maintainer
#3 lore raw

From: Eric Dumazet <[email protected]>
Date: Mon, 25 Feb 2019 07:53:08 -0800

Quoted 12 lines · David Miller
Quoted 9 lines

From: Timur Celik <[email protected]>
Date: Sat, 23 Feb 2019 12:53:13 +0100

Quoted 5 lines

This patch moves setting of the current state into the loop. Otherwise the task may end up in a busy wait loop if none of the break conditions are met.

Quoted 7 lines
Quoted 2 lines

Applied and queued up for -stable, thanks.

First part of the patch was matching the changelog, however the second change was not really needed, or should have used

__set_current_state(TASK_RUNNING);

Timur, please followup.

#4 lore raw
Quoted 18 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Mon, 25 Feb 2019 07:53:08 -0800

Quoted 15 lines · David Miller
Quoted 11 lines

From: Timur Celik <[email protected]>
Date: Sat, 23 Feb 2019 12:53:13 +0100

Quoted 5 lines

This patch moves setting of the current state into the loop. Otherwise the task may end up in a busy wait loop if none of the break conditions are met.

Applied and queued up for -stable, thanks.

Quoted 6 lines
Quoted 4 lines

First part of the patch was matching the changelog, however the second change was not really needed, or should have used

__set_current_state(TASK_RUNNING);

Timur, please followup.

Thanks for taking a look at this. Eric is right of course.

#5 lore raw

PATCH 1/1 tun: remove unnecessary memory barrier

In reply to David Miller

Replace set_current_state with __set_current_state since no memory barrier is needed at this point.

---
 drivers/net/tun.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/tun.c +1 -1
index d291762b9e9d..53f4f37b0ffd 100644
@@ -2185,7 +2185,7 @@ static void *tun_ring_recv(struct tun_file *tfile, int noblock, int *err)
 		schedule();
 	}
 
-	set_current_state(TASK_RUNNING);
+	__set_current_state(TASK_RUNNING);
 	remove_wait_queue(&tfile->wq.wait, &wait);
 
 out:
Signature · 1 line
2.20.1