Skip to content

Commit

Permalink
tuntap: attach queue 0 before registering netdevice
Browse files Browse the repository at this point in the history
We attach queue 0 after registering netdevice currently. This leads to call
netif_set_real_num_{tx|rx}_queues() after registering the netdevice. Since we
allow tun/tap has a maximum of 1024 queues, this may lead a huge number of
uevents to be injected to userspace since we create 2048 kobjects and then
remove 2046. Solve this problem by attaching queue 0 and set the real number of
queues before registering netdevice.

Reported-by: Jiri Slaby <jslaby@suse.cz>
Tested-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
jasowang authored and davem330 committed Dec 3, 2012
1 parent 092a5fc commit eb0fb36
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,6 @@ static int tun_attach(struct tun_struct *tun, struct file *file)

tun_set_real_num_queues(tun);

if (tun->numqueues == 1)
netif_carrier_on(tun->dev);

/* device is allowed to go away first, so no need to hold extra
* refcnt.
*/
Expand Down Expand Up @@ -1612,6 +1609,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
TUN_USER_FEATURES;
dev->features = dev->hw_features;

err = tun_attach(tun, file);
if (err < 0)
goto err_free_dev;

err = register_netdevice(tun->dev);
if (err < 0)
goto err_free_dev;
Expand All @@ -1621,9 +1622,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
device_create_file(&tun->dev->dev, &dev_attr_group))
pr_err("Failed to create tun sysfs files\n");

err = tun_attach(tun, file);
if (err < 0)
goto err_free_dev;
netif_carrier_on(tun->dev);
}

tun_debug(KERN_INFO, tun, "tun_set_iff\n");
Expand Down

0 comments on commit eb0fb36

Please sign in to comment.