* [PATCH] Fix tun: wake up waitqueues after IFF_UP is set
@ 2019-06-17 7:33 Fei Li
2019-06-17 8:10 ` Jason Wang
0 siblings, 1 reply; 5+ messages in thread
From: Fei Li @ 2019-06-17 7:33 UTC (permalink / raw)
To: davem, jasowang, netdev, linux-kernel; +Cc: zhengfeiran, duanxiongchun, Fei Li
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>
---
drivers/net/tun.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index c452d6d831dd..a3c9cab5a4d0 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1015,17 +1015,9 @@ static void tun_net_uninit(struct net_device *dev)
static int tun_net_open(struct net_device *dev)
{
struct tun_struct *tun = netdev_priv(dev);
- int i;
netif_tx_start_all_queues(dev);
- for (i = 0; i < tun->numqueues; i++) {
- struct tun_file *tfile;
-
- tfile = rtnl_dereference(tun->tfiles[i]);
- tfile->socket.sk->sk_write_space(tfile->socket.sk);
- }
-
return 0;
}
@@ -3634,6 +3626,7 @@ static int tun_device_event(struct notifier_block *unused,
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
struct tun_struct *tun = netdev_priv(dev);
+ int i;
if (dev->rtnl_link_ops != &tun_link_ops)
return NOTIFY_DONE;
@@ -3643,6 +3636,14 @@ static int tun_device_event(struct notifier_block *unused,
if (tun_queue_resize(tun))
return NOTIFY_BAD;
break;
+ case NETDEV_UP:
+ for (i = 0; i < tun->numqueues; i++) {
+ struct tun_file *tfile;
+
+ tfile = rtnl_dereference(tun->tfiles[i]);
+ tfile->socket.sk->sk_write_space(tfile->socket.sk);
+ }
+ break;
default:
break;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix tun: wake up waitqueues after IFF_UP is set
2019-06-17 7:33 [PATCH] Fix tun: wake up waitqueues after IFF_UP is set Fei Li
@ 2019-06-17 8:10 ` Jason Wang
2019-06-17 8:16 ` Jason Wang
0 siblings, 1 reply; 5+ messages in thread
From: Jason Wang @ 2019-06-17 8:10 UTC (permalink / raw)
To: Fei Li, davem, netdev, linux-kernel; +Cc: zhengfeiran, duanxiongchun
On 2019/6/17 下午3:33, Fei Li wrote:
> 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>
> ---
> drivers/net/tun.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index c452d6d831dd..a3c9cab5a4d0 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1015,17 +1015,9 @@ static void tun_net_uninit(struct net_device *dev)
> static int tun_net_open(struct net_device *dev)
> {
> struct tun_struct *tun = netdev_priv(dev);
> - int i;
>
> netif_tx_start_all_queues(dev);
>
> - for (i = 0; i < tun->numqueues; i++) {
> - struct tun_file *tfile;
> -
> - tfile = rtnl_dereference(tun->tfiles[i]);
> - tfile->socket.sk->sk_write_space(tfile->socket.sk);
> - }
> -
> return 0;
> }
>
> @@ -3634,6 +3626,7 @@ static int tun_device_event(struct notifier_block *unused,
> {
> struct net_device *dev = netdev_notifier_info_to_dev(ptr);
> struct tun_struct *tun = netdev_priv(dev);
> + int i;
>
> if (dev->rtnl_link_ops != &tun_link_ops)
> return NOTIFY_DONE;
> @@ -3643,6 +3636,14 @@ static int tun_device_event(struct notifier_block *unused,
> if (tun_queue_resize(tun))
> return NOTIFY_BAD;
> break;
> + case NETDEV_UP:
> + for (i = 0; i < tun->numqueues; i++) {
> + struct tun_file *tfile;
> +
> + tfile = rtnl_dereference(tun->tfiles[i]);
> + tfile->socket.sk->sk_write_space(tfile->socket.sk);
> + }
> + break;
> default:
> break;
> }
Acked-by: Jason Wang <jasowang@redhat.com)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix tun: wake up waitqueues after IFF_UP is set
2019-06-17 8:10 ` Jason Wang
@ 2019-06-17 8:16 ` Jason Wang
2019-06-17 9:58 ` [External Email] " 李菲
[not found] ` <CA+=e4K6_EGK+r4RXWpK2wZ5OW9JNQS9NfGpZtG3grjhApAFCEw@mail.gmail.com>
0 siblings, 2 replies; 5+ messages in thread
From: Jason Wang @ 2019-06-17 8:16 UTC (permalink / raw)
To: Fei Li, davem, netdev, linux-kernel; +Cc: zhengfeiran, duanxiongchun
On 2019/6/17 下午4:10, Jason Wang wrote:
>
> On 2019/6/17 下午3:33, Fei Li wrote:
>> 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.
Btw, the title needs some tweak. E.g you need use "net" as prefix since
it's a fix for net.git and "Fix" could be removed like:
[PATCH net] tun: wake up waitqueues after IFF_UP is set.
Thanks
>>
>> Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
>> ---
>> drivers/net/tun.c | 17 +++++++++--------
>> 1 file changed, 9 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
>> index c452d6d831dd..a3c9cab5a4d0 100644
>> --- a/drivers/net/tun.c
>> +++ b/drivers/net/tun.c
>> @@ -1015,17 +1015,9 @@ static void tun_net_uninit(struct net_device
>> *dev)
>> static int tun_net_open(struct net_device *dev)
>> {
>> struct tun_struct *tun = netdev_priv(dev);
>> - int i;
>> netif_tx_start_all_queues(dev);
>> - for (i = 0; i < tun->numqueues; i++) {
>> - struct tun_file *tfile;
>> -
>> - tfile = rtnl_dereference(tun->tfiles[i]);
>> - tfile->socket.sk->sk_write_space(tfile->socket.sk);
>> - }
>> -
>> return 0;
>> }
>> @@ -3634,6 +3626,7 @@ static int tun_device_event(struct
>> notifier_block *unused,
>> {
>> struct net_device *dev = netdev_notifier_info_to_dev(ptr);
>> struct tun_struct *tun = netdev_priv(dev);
>> + int i;
>> if (dev->rtnl_link_ops != &tun_link_ops)
>> return NOTIFY_DONE;
>> @@ -3643,6 +3636,14 @@ static int tun_device_event(struct
>> notifier_block *unused,
>> if (tun_queue_resize(tun))
>> return NOTIFY_BAD;
>> break;
>> + case NETDEV_UP:
>> + for (i = 0; i < tun->numqueues; i++) {
>> + struct tun_file *tfile;
>> +
>> + tfile = rtnl_dereference(tun->tfiles[i]);
>> + tfile->socket.sk->sk_write_space(tfile->socket.sk);
>> + }
>> + break;
>> default:
>> break;
>> }
>
>
> Acked-by: Jason Wang <jasowang@redhat.com)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [External Email] Re: [PATCH] Fix tun: wake up waitqueues after IFF_UP is set
2019-06-17 8:16 ` Jason Wang
@ 2019-06-17 9:58 ` 李菲
[not found] ` <CA+=e4K6_EGK+r4RXWpK2wZ5OW9JNQS9NfGpZtG3grjhApAFCEw@mail.gmail.com>
1 sibling, 0 replies; 5+ messages in thread
From: 李菲 @ 2019-06-17 9:58 UTC (permalink / raw)
Cc: netdev, linux-kernel
Ok, thanks for the detail suggestion! :)
On Mon, Jun 17, 2019 at 4:16 PM Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 2019/6/17 下午4:10, Jason Wang wrote:
> >
> > On 2019/6/17 下午3:33, Fei Li wrote:
> >> 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.
>
>
> Btw, the title needs some tweak. E.g you need use "net" as prefix since
> it's a fix for net.git and "Fix" could be removed like:
>
> [PATCH net] tun: wake up waitqueues after IFF_UP is set.
>
> Thanks
>
>
> >>
> >> Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
> >> ---
> >> drivers/net/tun.c | 17 +++++++++--------
> >> 1 file changed, 9 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> >> index c452d6d831dd..a3c9cab5a4d0 100644
> >> --- a/drivers/net/tun.c
> >> +++ b/drivers/net/tun.c
> >> @@ -1015,17 +1015,9 @@ static void tun_net_uninit(struct net_device
> >> *dev)
> >> static int tun_net_open(struct net_device *dev)
> >> {
> >> struct tun_struct *tun = netdev_priv(dev);
> >> - int i;
> >> netif_tx_start_all_queues(dev);
> >> - for (i = 0; i < tun->numqueues; i++) {
> >> - struct tun_file *tfile;
> >> -
> >> - tfile = rtnl_dereference(tun->tfiles[i]);
> >> - tfile->socket.sk->sk_write_space(tfile->socket.sk);
> >> - }
> >> -
> >> return 0;
> >> }
> >> @@ -3634,6 +3626,7 @@ static int tun_device_event(struct
> >> notifier_block *unused,
> >> {
> >> struct net_device *dev = netdev_notifier_info_to_dev(ptr);
> >> struct tun_struct *tun = netdev_priv(dev);
> >> + int i;
> >> if (dev->rtnl_link_ops != &tun_link_ops)
> >> return NOTIFY_DONE;
> >> @@ -3643,6 +3636,14 @@ static int tun_device_event(struct
> >> notifier_block *unused,
> >> if (tun_queue_resize(tun))
> >> return NOTIFY_BAD;
> >> break;
> >> + case NETDEV_UP:
> >> + for (i = 0; i < tun->numqueues; i++) {
> >> + struct tun_file *tfile;
> >> +
> >> + tfile = rtnl_dereference(tun->tfiles[i]);
> >> + tfile->socket.sk->sk_write_space(tfile->socket.sk);
> >> + }
> >> + break;
> >> default:
> >> break;
> >> }
> >
> >
> > Acked-by: Jason Wang <jasowang@redhat.com)
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [External Email] Re: [PATCH] Fix tun: wake up waitqueues after IFF_UP is set
[not found] ` <CA+=e4K6_EGK+r4RXWpK2wZ5OW9JNQS9NfGpZtG3grjhApAFCEw@mail.gmail.com>
@ 2019-06-17 10:40 ` 李菲
0 siblings, 0 replies; 5+ messages in thread
From: 李菲 @ 2019-06-17 10:40 UTC (permalink / raw)
To: Jason Wang, davem, netdev, linux-kernel; +Cc: zhengfeiran, duanxiongchun
Hi all,
On Mon, Jun 17, 2019 at 5:32 PM 李菲 <lifei.shirley@bytedance.com> wrote:
>
> Ok, thanks for detail suggestion! :)
>
> On Mon, Jun 17, 2019 at 4:16 PM Jason Wang <jasowang@redhat.com> wrote:
>>
>>
>> On 2019/6/17 下午4:10, Jason Wang wrote:
>> >
>> > On 2019/6/17 下午3:33, Fei Li wrote:
>> >> 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.
>>
>>
>> Btw, the title needs some tweak. E.g you need use "net" as prefix since
>> it's a fix for net.git and "Fix" could be removed like:
>>
>> [PATCH net] tun: wake up waitqueues after IFF_UP is set.
>>
>> Thanks
>>
>>
>> >>
>> >> Signed-off-by: Fei Li <lifei.shirley@bytedance.com>
>> >> ---
>> >> drivers/net/tun.c | 17 +++++++++--------
>> >> 1 file changed, 9 insertions(+), 8 deletions(-)
>> >>
>> >> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
>> >> index c452d6d831dd..a3c9cab5a4d0 100644
>> >> --- a/drivers/net/tun.c
>> >> +++ b/drivers/net/tun.c
>> >> @@ -1015,17 +1015,9 @@ static void tun_net_uninit(struct net_device
>> >> *dev)
>> >> static int tun_net_open(struct net_device *dev)
>> >> {
>> >> struct tun_struct *tun = netdev_priv(dev);
Will remove the above unused struct in next version.
Sorry for the negligence!
Have a nice day, thanks
Fei
>> >> - int i;
>> >> netif_tx_start_all_queues(dev);
>> >> - for (i = 0; i < tun->numqueues; i++) {
>> >> - struct tun_file *tfile;
>> >> -
>> >> - tfile = rtnl_dereference(tun->tfiles[i]);
>> >> - tfile->socket.sk->sk_write_space(tfile->socket.sk);
>> >> - }
>> >> -
>> >> return 0;
>> >> }
>> >> @@ -3634,6 +3626,7 @@ static int tun_device_event(struct
>> >> notifier_block *unused,
>> >> {
>> >> struct net_device *dev = netdev_notifier_info_to_dev(ptr);
>> >> struct tun_struct *tun = netdev_priv(dev);
>> >> + int i;
>> >> if (dev->rtnl_link_ops != &tun_link_ops)
>> >> return NOTIFY_DONE;
>> >> @@ -3643,6 +3636,14 @@ static int tun_device_event(struct
>> >> notifier_block *unused,
>> >> if (tun_queue_resize(tun))
>> >> return NOTIFY_BAD;
>> >> break;
>> >> + case NETDEV_UP:
>> >> + for (i = 0; i < tun->numqueues; i++) {
>> >> + struct tun_file *tfile;
>> >> +
>> >> + tfile = rtnl_dereference(tun->tfiles[i]);
>> >> + tfile->socket.sk->sk_write_space(tfile->socket.sk);
>> >> + }
>> >> + break;
>> >> default:
>> >> break;
>> >> }
>> >
>> >
>> > Acked-by: Jason Wang <jasowang@redhat.com)
>> >
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-06-17 10:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-17 7:33 [PATCH] Fix tun: wake up waitqueues after IFF_UP is set Fei Li
2019-06-17 8:10 ` Jason Wang
2019-06-17 8:16 ` Jason Wang
2019-06-17 9:58 ` [External Email] " 李菲
[not found] ` <CA+=e4K6_EGK+r4RXWpK2wZ5OW9JNQS9NfGpZtG3grjhApAFCEw@mail.gmail.com>
2019-06-17 10:40 ` 李菲
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).