From: ebiederm@xmission.com (Eric W. Biederman)
To: Francesco Ruggeri <fruggeri@aristanetworks.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>, Jiri Pirko <jiri@resnulli.us>,
Alexander Duyck <alexander.h.duyck@intel.com>,
Cong Wang <amwang@redhat.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH 1/1] net: race condition when removing virtual net_device
Date: Thu, 12 Sep 2013 22:50:06 -0700 [thread overview]
Message-ID: <871u4t1d9t.fsf@xmission.com> (raw)
In-Reply-To: <CA+HUmGgyCsc-er6iB_mqg9whMyaquGWinkHOQEuEHbFCYVrXBw@mail.gmail.com> (Francesco Ruggeri's message of "Thu, 12 Sep 2013 14:48:19 -0700")
Francesco Ruggeri <fruggeri@aristanetworks.com> writes:
> That would be great. There would still be one scenario to take care of though:
>
> - veth interfaces v0 and v1 are in namespaces ns0 and ns1.
> - process p0 unregisters v0, which also causes v1 to be unregistered.
> When p0 enters netdev_run_todo both v0 and v1 are in net_todo_list and
> have been unlisted from their namespaces.
> - then in p0's netdev_run_todo:
So I looked at this a little more and this problem appears largely
specific to veth. In the normal case the caller of dellink has to hold
a reference to the network namespace to find the device to delete.
So I think the solution is just to warp the interface of the second
device into the network namespace of the device we are actually
deleting.
I will buy that similar situations can happen with other virtual devices
that have one foot in two network namespaces, and I expect the same
solution will apply.
So the patch below looks like the solution. If there is more than one
device that needs this treatment perhaps the code should be moved
into a helper function rather than expanded inline.
Does this look like it will fix your issue?
Eric
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index da86652..5922066 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -423,6 +423,19 @@ static void veth_dellink(struct net_device *dev, struct list_head *head)
unregister_netdevice_queue(dev, head);
if (peer) {
+ struct net *net = dev_net(dev);
+ if (dev_net(peer) != net) {
+ /* Move the peer to the same net to avoid teardown races */
+ char peer_name[IFNAMSIZ];
+ int err;
+ snprintf(fb_name, IFNAMSIZ, "dev%d", peer->ifindex);
+ err = dev_change_net_namespace(peer, net, peer_name);
+ if (err) {
+ pr_emerg("%s: failed to move %s to peers net: %d\n",
+ __func__, peer->name, err);
+ BUG();
+ }
+ }
priv = netdev_priv(peer);
RCU_INIT_POINTER(priv->peer, NULL);
unregister_netdevice_queue(peer, head);
next prev parent reply other threads:[~2013-09-13 5:50 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1379008796-2121-1-git-send-email-fruggeri@aristanetworks.com>
2013-09-12 20:06 ` [PATCH 1/1] net: race condition when removing virtual net_device Eric W. Biederman
2013-09-12 21:48 ` Francesco Ruggeri
2013-09-12 22:02 ` Francesco Ruggeri
2013-09-13 5:50 ` Eric W. Biederman [this message]
2013-09-13 17:54 ` Francesco Ruggeri
2013-09-14 1:46 ` Eric W. Biederman
2013-09-16 2:54 ` Francesco Ruggeri
2013-09-16 10:45 ` Eric W. Biederman
2013-09-16 20:30 ` Francesco Ruggeri
2013-09-16 23:52 ` [PATCH net-next] net loopback: Set loopback_dev to NULL when freed Eric W. Biederman
2013-09-17 0:50 ` Eric Dumazet
2013-09-17 1:34 ` David Miller
2013-09-17 1:41 ` Eric Dumazet
2013-09-17 1:52 ` Eric W. Biederman
2013-09-17 23:05 ` David Miller
2013-09-17 0:25 ` [PATCH 1/1] net: race condition when removing virtual net_device Eric W. Biederman
2013-09-17 5:12 ` Francesco Ruggeri
2013-09-17 3:49 ` [CFT][PATCH] net: Delay default_device_exit_batch until no devices are unregistering Eric W. Biederman
2013-09-17 6:54 ` Francesco Ruggeri
2013-09-17 9:38 ` Eric W. Biederman
2013-09-17 17:14 ` Francesco Ruggeri
2013-09-17 23:21 ` David Miller
2013-09-17 23:41 ` Eric W. Biederman
2013-09-18 0:15 ` David Miller
2013-09-18 3:50 ` Francesco Ruggeri
2013-09-18 3:52 ` David Miller
2013-09-18 8:19 ` Eric W. Biederman
2013-09-20 16:34 ` Francesco Ruggeri
2013-09-24 4:19 ` [PATCH] net: Delay default_device_exit_batch until no devices are unregistering v2 Eric W. Biederman
2013-09-24 17:54 ` Francesco Ruggeri
2013-09-28 22:14 ` David Miller
2013-09-14 0:16 ` [PATCH 1/1] net: race condition when removing virtual net_device David Miller
2013-09-14 1:32 ` Eric W. Biederman
2013-09-09 23:15 Francesco Ruggeri
2013-09-10 0:57 ` Stephen Hemminger
2013-09-10 2:03 ` Francesco Ruggeri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871u4t1d9t.fsf@xmission.com \
--to=ebiederm@xmission.com \
--cc=alexander.h.duyck@intel.com \
--cc=amwang@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fruggeri@aristanetworks.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.