netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ipv6: clean up anycast when an interface is destroyed
@ 2014-09-10 10:27 Sabrina Dubroca
  2014-09-10 17:15 ` Cong Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Sabrina Dubroca @ 2014-09-10 10:27 UTC (permalink / raw)
  To: netdev; +Cc: Hannes Frederic Sowa, David Miller

If we try to rmmod the driver for an interface while sockets with
setsockopt(JOIN_ANYCAST) are alive, some refcounts aren't cleaned up
and we get stuck on:

  unregister_netdevice: waiting for ens3 to become free. Usage count = 1

If we LEAVE_ANYCAST/close everything before rmmod'ing, there is no
problem.

We need to perform a cleanup similar to the one for multicast in
addrconf_ifdown(how == 1).

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
The problem is also present on a 3.2 and 3.16 kernel, and most likely
everything in between.

 include/net/addrconf.h |  1 +
 net/ipv6/addrconf.c    |  8 +++++---
 net/ipv6/anycast.c     | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index f679877bb601..ec51e673b4b6 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -204,6 +204,7 @@ void ipv6_sock_ac_close(struct sock *sk);
 
 int ipv6_dev_ac_inc(struct net_device *dev, const struct in6_addr *addr);
 int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr);
+void ipv6_ac_destroy_dev(struct inet6_dev *idev);
 bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
 			 const struct in6_addr *addr);
 bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index fc1fac2a0528..3342ee64f2e3 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3094,11 +3094,13 @@ static int addrconf_ifdown(struct net_device *dev, int how)
 
 	write_unlock_bh(&idev->lock);
 
-	/* Step 5: Discard multicast list */
-	if (how)
+	/* Step 5: Discard anycast and multicast list */
+	if (how) {
+		ipv6_ac_destroy_dev(idev);
 		ipv6_mc_destroy_dev(idev);
-	else
+	} else {
 		ipv6_mc_down(idev);
+	}
 
 	idev->tstamp = jiffies;
 
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index ff2de7d9d8e6..a1bf80574bfe 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -351,6 +351,28 @@ static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr *addr)
 	return __ipv6_dev_ac_dec(idev, addr);
 }
 
+/* Device is being destroyed: clean up */
+void ipv6_ac_destroy_dev(struct inet6_dev *idev)
+{
+	struct ifacaddr6 *aca;
+
+	write_lock_bh(&idev->lock);
+	while ((aca = idev->ac_list) != NULL) {
+		idev->ac_list = aca->aca_next;
+		write_unlock_bh(&idev->lock);
+
+		addrconf_leave_solict(idev, &aca->aca_addr);
+
+		dst_hold(&aca->aca_rt->dst);
+		ip6_del_rt(aca->aca_rt);
+
+		aca_put(aca);
+
+		write_lock_bh(&idev->lock);
+	}
+	write_unlock_bh(&idev->lock);
+}
+
 /*
  *	check if the interface has this anycast address
  *	called with rcu_read_lock()
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net] ipv6: clean up anycast when an interface is destroyed
  2014-09-10 10:27 [PATCH net] ipv6: clean up anycast when an interface is destroyed Sabrina Dubroca
@ 2014-09-10 17:15 ` Cong Wang
  2014-09-10 20:58   ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Cong Wang @ 2014-09-10 17:15 UTC (permalink / raw)
  To: Sabrina Dubroca; +Cc: netdev, Hannes Frederic Sowa, David Miller

On Wed, Sep 10, 2014 at 3:27 AM, Sabrina Dubroca <sd@queasysnail.net> wrote:
> diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
> index ff2de7d9d8e6..a1bf80574bfe 100644
> --- a/net/ipv6/anycast.c
> +++ b/net/ipv6/anycast.c
> @@ -351,6 +351,28 @@ static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr *addr)
>         return __ipv6_dev_ac_dec(idev, addr);
>  }
>
> +/* Device is being destroyed: clean up */

This comment is useless.

> +void ipv6_ac_destroy_dev(struct inet6_dev *idev)
> +{
> +       struct ifacaddr6 *aca;
> +
> +       write_lock_bh(&idev->lock);
> +       while ((aca = idev->ac_list) != NULL) {
> +               idev->ac_list = aca->aca_next;
> +               write_unlock_bh(&idev->lock);
> +
> +               addrconf_leave_solict(idev, &aca->aca_addr);
> +
> +               dst_hold(&aca->aca_rt->dst);
> +               ip6_del_rt(aca->aca_rt);
> +
> +               aca_put(aca);
> +
> +               write_lock_bh(&idev->lock);
> +       }
> +       write_unlock_bh(&idev->lock);
> +}
> +

I think you can probably refactor the code out of __ipv6_dev_ac_dec()
so that you don't have to kinda duplicate the code?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] ipv6: clean up anycast when an interface is destroyed
  2014-09-10 17:15 ` Cong Wang
@ 2014-09-10 20:58   ` David Miller
  2014-09-10 21:23     ` [PATCH v2 " Sabrina Dubroca
  0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2014-09-10 20:58 UTC (permalink / raw)
  To: cwang; +Cc: sd, netdev, hannes

From: Cong Wang <cwang@twopensource.com>
Date: Wed, 10 Sep 2014 10:15:01 -0700

> On Wed, Sep 10, 2014 at 3:27 AM, Sabrina Dubroca <sd@queasysnail.net> wrote:
>> diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
>> index ff2de7d9d8e6..a1bf80574bfe 100644
>> --- a/net/ipv6/anycast.c
>> +++ b/net/ipv6/anycast.c
>> @@ -351,6 +351,28 @@ static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr *addr)
>>         return __ipv6_dev_ac_dec(idev, addr);
>>  }
>>
>> +/* Device is being destroyed: clean up */
> 
> This comment is useless.

Agreed, please remove this and respin that patch.

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 net] ipv6: clean up anycast when an interface is destroyed
  2014-09-10 20:58   ` David Miller
@ 2014-09-10 21:23     ` Sabrina Dubroca
  2014-09-12 19:45       ` Hannes Frederic Sowa
  2014-09-12 21:33       ` David Miller
  0 siblings, 2 replies; 6+ messages in thread
From: Sabrina Dubroca @ 2014-09-10 21:23 UTC (permalink / raw)
  To: David Miller; +Cc: cwang, netdev, hannes

If we try to rmmod the driver for an interface while sockets with
setsockopt(JOIN_ANYCAST) are alive, some refcounts aren't cleaned up
and we get stuck on:

  unregister_netdevice: waiting for ens3 to become free. Usage count = 1

If we LEAVE_ANYCAST/close everything before rmmod'ing, there is no
problem.

We need to perform a cleanup similar to the one for multicast in
addrconf_ifdown(how == 1).

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
v2: remove comment

 include/net/addrconf.h |  1 +
 net/ipv6/addrconf.c    |  8 +++++---
 net/ipv6/anycast.c     | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index f679877bb601..ec51e673b4b6 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -204,6 +204,7 @@ void ipv6_sock_ac_close(struct sock *sk);
 
 int ipv6_dev_ac_inc(struct net_device *dev, const struct in6_addr *addr);
 int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr);
+void ipv6_ac_destroy_dev(struct inet6_dev *idev);
 bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
 			 const struct in6_addr *addr);
 bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index fc1fac2a0528..3342ee64f2e3 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3094,11 +3094,13 @@ static int addrconf_ifdown(struct net_device *dev, int how)
 
 	write_unlock_bh(&idev->lock);
 
-	/* Step 5: Discard multicast list */
-	if (how)
+	/* Step 5: Discard anycast and multicast list */
+	if (how) {
+		ipv6_ac_destroy_dev(idev);
 		ipv6_mc_destroy_dev(idev);
-	else
+	} else {
 		ipv6_mc_down(idev);
+	}
 
 	idev->tstamp = jiffies;
 
diff --git a/net/ipv6/anycast.c b/net/ipv6/anycast.c
index ff2de7d9d8e6..9a386842fd62 100644
--- a/net/ipv6/anycast.c
+++ b/net/ipv6/anycast.c
@@ -351,6 +351,27 @@ static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr *addr)
 	return __ipv6_dev_ac_dec(idev, addr);
 }
 
+void ipv6_ac_destroy_dev(struct inet6_dev *idev)
+{
+	struct ifacaddr6 *aca;
+
+	write_lock_bh(&idev->lock);
+	while ((aca = idev->ac_list) != NULL) {
+		idev->ac_list = aca->aca_next;
+		write_unlock_bh(&idev->lock);
+
+		addrconf_leave_solict(idev, &aca->aca_addr);
+
+		dst_hold(&aca->aca_rt->dst);
+		ip6_del_rt(aca->aca_rt);
+
+		aca_put(aca);
+
+		write_lock_bh(&idev->lock);
+	}
+	write_unlock_bh(&idev->lock);
+}
+
 /*
  *	check if the interface has this anycast address
  *	called with rcu_read_lock()
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 net] ipv6: clean up anycast when an interface is destroyed
  2014-09-10 21:23     ` [PATCH v2 " Sabrina Dubroca
@ 2014-09-12 19:45       ` Hannes Frederic Sowa
  2014-09-12 21:33       ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: Hannes Frederic Sowa @ 2014-09-12 19:45 UTC (permalink / raw)
  To: Sabrina Dubroca; +Cc: David Miller, cwang, netdev

On Mi, 2014-09-10 at 23:23 +0200, Sabrina Dubroca wrote:
> If we try to rmmod the driver for an interface while sockets with
> setsockopt(JOIN_ANYCAST) are alive, some refcounts aren't cleaned up
> and we get stuck on:
> 
>   unregister_netdevice: waiting for ens3 to become free. Usage count = 1
> 
> If we LEAVE_ANYCAST/close everything before rmmod'ing, there is no
> problem.
> 
> We need to perform a cleanup similar to the one for multicast in
> addrconf_ifdown(how == 1).
> 
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>

This is the correct fix for the bug:

Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>

more comments inline:

> ---
> v2: remove comment
> 
>  include/net/addrconf.h |  1 +
>  net/ipv6/addrconf.c    |  8 +++++---
>  net/ipv6/anycast.c     | 21 +++++++++++++++++++++
>  3 files changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/include/net/addrconf.h b/include/net/addrconf.h
> index f679877bb601..ec51e673b4b6 100644
> --- a/include/net/addrconf.h
> +++ b/include/net/addrconf.h
> @@ -204,6 +204,7 @@ void ipv6_sock_ac_close(struct sock *sk);
>  
>  int ipv6_dev_ac_inc(struct net_device *dev, const struct in6_addr *addr);
>  int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr);
> +void ipv6_ac_destroy_dev(struct inet6_dev *idev);
>  bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev,
>  			 const struct in6_addr *addr);
>  bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev,
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index fc1fac2a0528..3342ee64f2e3 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -3094,11 +3094,13 @@ static int addrconf_ifdown(struct net_device *dev, int how)
>  
>  	write_unlock_bh(&idev->lock);
>  
> -	/* Step 5: Discard multicast list */
> -	if (how)
> +	/* Step 5: Discard anycast and multicast list */
> +	if (how) {
> +		ipv6_ac_destroy_dev(idev);
>  		ipv6_mc_destroy_dev(idev);
> -	else
> +	} else {
>  		ipv6_mc_down(idev);
> +	}

Do we also need to provide a ipv6_ac_down function to unload all anycast
sources when we ifdown an interface (we need to keep the entries in
aca_list around and activate them when we initialize the interface
again)?
 
Thanks,
Hannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 net] ipv6: clean up anycast when an interface is destroyed
  2014-09-10 21:23     ` [PATCH v2 " Sabrina Dubroca
  2014-09-12 19:45       ` Hannes Frederic Sowa
@ 2014-09-12 21:33       ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2014-09-12 21:33 UTC (permalink / raw)
  To: sd; +Cc: cwang, netdev, hannes

From: Sabrina Dubroca <sd@queasysnail.net>
Date: Wed, 10 Sep 2014 23:23:02 +0200

> If we try to rmmod the driver for an interface while sockets with
> setsockopt(JOIN_ANYCAST) are alive, some refcounts aren't cleaned up
> and we get stuck on:
> 
>   unregister_netdevice: waiting for ens3 to become free. Usage count = 1
> 
> If we LEAVE_ANYCAST/close everything before rmmod'ing, there is no
> problem.
> 
> We need to perform a cleanup similar to the one for multicast in
> addrconf_ifdown(how == 1).
> 
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
> ---
> v2: remove comment

Applied, thank you.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-12 21:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-10 10:27 [PATCH net] ipv6: clean up anycast when an interface is destroyed Sabrina Dubroca
2014-09-10 17:15 ` Cong Wang
2014-09-10 20:58   ` David Miller
2014-09-10 21:23     ` [PATCH v2 " Sabrina Dubroca
2014-09-12 19:45       ` Hannes Frederic Sowa
2014-09-12 21:33       ` David Miller

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).