tun: Persistent devices can get stuck in xoff state
Subsystems (3)
PATCH 1/1 tun: Persistent devices can get stuck in xoff state
The scenario goes like this. App stops reading from tun/tap. TX queue gets full and driver does netif_stop_queue(). App closes fd and TX queue gets flushed as part of the cleanup. Next time the app opens tun/tap and starts reading from it but the xoff state is not cleared. We're stuck.
Normally xoff state is cleared when netdev is brought up. But in the case of persistent devices this happens only during initial setup.
The fix is trivial. If device is already up when an app opens it we clear xoff state and that gets things moving again.
--- drivers/net/tun.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/net/tun.c +5 -0
@@ -576,6 +576,11 @@ static int tun_set_iff(struct file *file, struct ifreq *ifr) file->private_data = tun; tun->attached =1 ; +/* Make sure persistent devices do not get stuck in +* xoff state */ +if (netif_running (tun->dev)) +netif_wake_queue (tun->dev); +strcpy (ifr->ifr_name, tun->dev->name);return 0 ;
Signature · 1 line
1.5.5.1
Am Mittwoch, 9. Juli 2008 schrieb Max Krasnyansky:
Quoted 8 lines
The scenario goes like this. App stops reading from tun/tap. TX queue gets full and driver does
netif_stop_queue(). App closes fd and TX queue gets flushed as part of the cleanup. Next time the app opens tun/tap and starts reading from it but the xoff state is not cleared. We're stuck.
Normally xoff state is cleared when netdev is brought up. But in the case of persistent devices this happens only during initial setup.
Thats interesting. I believe we have seen exactly this behaviour with KVM and lots of preallocated tap devices.
[...]
Review static int tun_set_iff(struct file *file, struct ifreq
Quoted 2 lines
+++
b/drivers/net/tun.c(quoted diff) +0
-0@@ -576,6 +576,11 @@ static int tun_set_iff(struct file *file, struct ifreq
*ifr)
drivers/net/tun.c static int tun_set_iff(struct file *file, struct ifreq *ifr) · line 585
Quoted 10 lines
drivers/net/tun.c +5
-0file->private_data = tun; tun->attached =1 ; +/* Make sure persistent devices do not get stuck in +* xoff state */ +if (netif_running (tun->dev)) +netif_wake_queue (tun->dev); +strcpy (ifr->ifr_name, tun->dev->name);return 0 ;
I think that patch looks ok, but I am curious why you dont clear the xoff state on application close at the same time when the TX queue gets flushed?
Christian
Quoted 10 lines · Christian Borntraeger
Am Mittwoch, 9. Juli 2008 schrieb Max Krasnyansky:
Quoted 8 lines
The scenario goes like this. App stops reading from tun/tap. TX queue gets full and driver does
netif_stop_queue(). App closes fd and TX queue gets flushed as part of the cleanup. Next time the app opens tun/tap and starts reading from it but the xoff state is not cleared. We're stuck.
Normally xoff state is cleared when netdev is brought up. But in the case of persistent devices this happens only during initial setup.
Quoted 2 lines
Thats interesting. I believe we have seen exactly this behaviour with KVM and lots of preallocated tap devices.
Yeah, it's interesting given that it's (the bug that is) been there for at least 2-3 years now :).
Quoted 7 lines
[...]
Review static int tun_set_iff(struct file *file, struct ifreq
Quoted 2 lines
+++
b/drivers/net/tun.c(quoted diff) +0
-0@@ -576,6 +576,11 @@ static int tun_set_iff(struct file *file, struct ifreq*ifr)
Quoted 3 lines
drivers/net/tun.c +0
-0file->private_data = tun; tun->attached =1 ;
Quoted 9 lines
drivers/net/tun.c static int tun_set_iff(struct file *file, struct ifreq *ifr) · line 585
Quoted 7 lines
drivers/net/tun.c +5
-0+/* Make sure persistent devices do not get stuck in +* xoff state */ +if (netif_running (tun->dev)) +netif_wake_queue (tun->dev); +strcpy (ifr->ifr_name, tun->dev->name);return 0 ;I think that patch looks ok, but I am curious why you dont clear the xoff state on application close at the same time when the TX queue gets flushed?
Why bother. I mean the packets will be dropped anyway.
Max
Am Mittwoch, 9. Juli 2008 schrieb Max Krasnyansky:
Quoted 8 lines
The scenario goes like this. App stops reading from tun/tap. TX queue gets full and driver does
netif_stop_queue(). App closes fd and TX queue gets flushed as part of the cleanup. Next time the app opens tun/tap and starts reading from it but the xoff state is not cleared. We're stuck.
Normally xoff state is cleared when netdev is brought up. But in the case of persistent devices this happens only during initial setup.
I was able to reproduce the problem. The patch seems to fix it.
Quoted 10 lines · Christian Borntraeger
Am Mittwoch, 9. Juli 2008 schrieb Max Krasnyansky:
Quoted 8 lines
The scenario goes like this. App stops reading from tun/tap. TX queue gets full and driver does
netif_stop_queue(). App closes fd and TX queue gets flushed as part of the cleanup. Next time the app opens tun/tap and starts reading from it but the xoff state is not cleared. We're stuck.
Normally xoff state is cleared when netdev is brought up. But in the case of persistent devices this happens only during initial setup.
Quoted 3 lines
I was able to reproduce the problem. The patch seems to fix it.
Oh it definitely fixes that problem. It's very easy to reproduce by just suspending (ctrl-z) an app that is ready from the tun, waiting a bit for the queue to fill up and then killing the app. I have a simple test app that simulates this. It's just that in real life that does not happen very often. ie Applications either constantly read from tun or they close it.
Thanks a lot for testing and confirming.
Max
From: Max Krasnyansky <[email protected]>
Date: Wed, 09 Jul 2008 14:19:28 -0700
Quoted 15 lines
Quoted 10 lines · Christian Borntraeger
Am Mittwoch, 9. Juli 2008 schrieb Max Krasnyansky:
Quoted 8 lines
The scenario goes like this. App stops reading from tun/tap. TX queue gets full and driver does
netif_stop_queue(). App closes fd and TX queue gets flushed as part of the cleanup. Next time the app opens tun/tap and starts reading from it but the xoff state is not cleared. We're stuck.
Normally xoff state is cleared when netdev is brought up. But in the case of persistent devices this happens only during initial setup.Quoted 3 lines
I was able to reproduce the problem. The patch seems to fix it.
Quoted 8 lines
Oh it definitely fixes that problem. It's very easy to reproduce by just suspending (ctrl-z) an app that is ready from the tun, waiting a bit for the queue to fill up and then killing the app. I have a simple test app that simulates this. It's just that in real life that does not happen very often. ie Applications either constantly read from tun or they close it.
Thanks a lot for testing and confirming.
I've applied this, thanks.
But I had to apply it by hand. You made this against an older tree, because in the current code there is a get_net() call right before the new lines you added but in your patch context it isn't there.
Quoted 18 lines · David Miller
From: Max Krasnyansky <[email protected]>
Date: Wed, 09 Jul 2008 14:19:28 -0700Quoted 15 lines
Quoted 9 lines · Christian Borntraeger
Am Mittwoch, 9. Juli 2008 schrieb Max Krasnyansky:
Quoted 8 lines
The scenario goes like this. App stops reading from tun/tap. TX queue gets full and driver does
netif_stop_queue(). App closes fd and TX queue gets flushed as part of the cleanup. Next time the app opens tun/tap and starts reading from it but the xoff state is not cleared. We're stuck.
Normally xoff state is cleared when netdev is brought up. But in the case of persistent devices this happens only during initial setup.Quoted 3 lines
I was able to reproduce the problem. The patch seems to fix it.
Oh it definitely fixes that problem. It's very easy to reproduce by just suspending (ctrl-z) an app that is ready from the tun, waiting a bit for the queue to fill up and then killing the app. I have a simple test app that simulates this. It's just that in real life that does not happen very often. ie Applications either constantly read from tun or they close it.
Quoted 8 lines
Quoted 1 line
Thanks a lot for testing and confirming.
I've applied this, thanks.
But I had to apply it by hand. You made this against an older tree, because in the current code there is a
get_net()call right before the new lines you added but in your patch context it isn't there.
Hmm, I though I used latest git tree. Oh, turns out it was 2.6.25.4. Sorry. Thanx for fixing it.
Max