aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFei Li <lifei.shirley@bytedance.com>2019-06-17 09:26:36 -0400
committerDavid S. Miller <davem@davemloft.net>2019-06-18 13:46:52 -0400
commit72b319dc08b4924a29f5e2560ef6d966fa54c429 (patch)
tree5b903ccecff7da043c98ae8242c2e7f86374cdc2
parentd0bae4a0e3d8c5690a885204d7eb2341a5b4884d (diff)
tun: wake up waitqueues after IFF_UP is set
Currently after setting tap0 link up, the tun code wakes tx/rx waited queues up in tun_net_open() when .ndo_open() is called, however the IFF_UP flag has not been set yet. If there's already a wait queue, it would fail to transmit when checking the IFF_UP flag in tun_sendmsg(). Then the saving vhost_poll_start() will add the wq into wqh until it is waken up again. Although this works when IFF_UP flag has been set when tun_chr_poll detects; this is not true if IFF_UP flag has not been set at that time. Sadly the latter case is a fatal error, as the wq will never be waken up in future unless later manually setting link up on purpose. Fix this by moving the wakeup process into the NETDEV_UP event notifying process, this makes sure IFF_UP has been set before all waited queues been waken up. Signed-off-by: Fei Li <lifei.shirley@bytedance.com> Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/tun.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index c452d6d831dd..d7c55e0fa8f4 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1014,18 +1014,8 @@ static void tun_net_uninit(struct net_device *dev)
1014/* Net device open. */ 1014/* Net device open. */
1015static int tun_net_open(struct net_device *dev) 1015static int tun_net_open(struct net_device *dev)
1016{ 1016{
1017 struct tun_struct *tun = netdev_priv(dev);
1018 int i;
1019
1020 netif_tx_start_all_queues(dev); 1017 netif_tx_start_all_queues(dev);
1021 1018
1022 for (i = 0; i < tun->numqueues; i++) {
1023 struct tun_file *tfile;
1024
1025 tfile = rtnl_dereference(tun->tfiles[i]);
1026 tfile->socket.sk->sk_write_space(tfile->socket.sk);
1027 }
1028
1029 return 0; 1019 return 0;
1030} 1020}
1031 1021
@@ -3634,6 +3624,7 @@ static int tun_device_event(struct notifier_block *unused,
3634{ 3624{
3635 struct net_device *dev = netdev_notifier_info_to_dev(ptr); 3625 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
3636 struct tun_struct *tun = netdev_priv(dev); 3626 struct tun_struct *tun = netdev_priv(dev);
3627 int i;
3637 3628
3638 if (dev->rtnl_link_ops != &tun_link_ops) 3629 if (dev->rtnl_link_ops != &tun_link_ops)
3639 return NOTIFY_DONE; 3630 return NOTIFY_DONE;
@@ -3643,6 +3634,14 @@ static int tun_device_event(struct notifier_block *unused,
3643 if (tun_queue_resize(tun)) 3634 if (tun_queue_resize(tun))
3644 return NOTIFY_BAD; 3635 return NOTIFY_BAD;
3645 break; 3636 break;
3637 case NETDEV_UP:
3638 for (i = 0; i < tun->numqueues; i++) {
3639 struct tun_file *tfile;
3640
3641 tfile = rtnl_dereference(tun->tfiles[i]);
3642 tfile->socket.sk->sk_write_space(tfile->socket.sk);
3643 }
3644 break;
3646 default: 3645 default:
3647 break; 3646 break;
3648 } 3647 }