[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+HUmGjg9jE1fjSMgkfVtiWVRD3d2DuwfbPU3Owrk_cTCe0FQA@mail.gmail.com>
Date: Mon, 16 Sep 2013 23:54:41 -0700
From: Francesco Ruggeri <fruggeri@...stanetworks.com>
To: "Eric W. Biederman" <ebiederm@...ssion.com>
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jiri Pirko <jiri@...nulli.us>,
Alexander Duyck <alexander.h.duyck@...el.com>,
Cong Wang <amwang@...hat.com>, netdev@...r.kernel.org
Subject: Re: [CFT][PATCH] net: Delay default_device_exit_batch until no
devices are unregistering
On Mon, Sep 16, 2013 at 8:49 PM, Eric W. Biederman
<ebiederm@...ssion.com> wrote:
>
> The implementation is a little rough but the logic should be right.
>
> Device registration and unregistration is serialized with the rtnl_lock.
> The final pieces of device unregistration do not happen under the
> rtnl_lock resulting in the possibility that while we wait for the
> refcount of a device to drop to zero the network namespace is
> unregistered while no locks are held.
>
> Prevent that by keeping a count of the network devices that are being
> unregistered and before we make the final pass through a network
> namespace to flush out all of the network devices, wait for the count of
> network devices being unregistered to drop to zero.
>
> Reported-by: Francesco Ruggeri <fruggeri@...stanetworks.com>
> Signed-off-by: "Eric W. Biederman" <ebiederm@...ssion.com>
> ---
>
> Francesco could you take a look at this. I am about 99% certain this is
> right but I am starting to fade. So it is entirely possible I missed
> something.
Same here ...
The logic looks right to me and I think it should address the original
issue I ran into.
Would it make sense to have netdev_unregistering and
netdev_unregistering_wait be per-namespace, and have
default_device_exit_batch only wait for the namespaces in net_list? It
would require some extra loops and locking, but it may help avoid
unnecessary waits.
Francesco
>
> net/core/dev.c | 12 ++++++++++++
> 1 files changed, 12 insertions(+), 0 deletions(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 5d702fe..c25e6f3 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -5002,10 +5002,13 @@ static int dev_new_index(struct net *net)
>
> /* Delayed registration/unregisteration */
> static LIST_HEAD(net_todo_list);
> +static atomic_t netdev_unregistering = ATOMIC_INIT(0);
> +static DECLARE_WAIT_QUEUE_HEAD(netdev_unregistering_wait);
>
> static void net_set_todo(struct net_device *dev)
> {
> list_add_tail(&dev->todo_list, &net_todo_list);
> + atomic_inc(&netdev_unregistering);
> }
>
> static void rollback_registered_many(struct list_head *head)
> @@ -5673,6 +5676,9 @@ void netdev_run_todo(void)
> if (dev->destructor)
> dev->destructor(dev);
>
> + if (atomic_dec_and_test(&netdev_unregistering))
> + wake_up(&netdev_unregistering_wait);
> +
> /* Free network device */
> kobject_put(&dev->dev.kobj);
> }
> @@ -6369,7 +6375,13 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list)
> struct net *net;
> LIST_HEAD(dev_kill_list);
>
> +retry:
> + wait_event(netdev_unregistering_wait, (atomic_read(&netdev_unregistering) == 0));
> rtnl_lock();
> + if (atomic_read(&netdev_unregistering) != 0) {
> + __rtnl_unlock();
> + goto retry;
> + }
> list_for_each_entry(net, net_list, exit_list) {
> for_each_netdev_reverse(net, dev) {
> if (dev->rtnl_link_ops)
> --
> 1.7.5.4
>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists