]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
ipvs: avoid rcu_barrier during netns cleanup
authorJulian Anastasov <ja@ssi.bg>
Wed, 9 Oct 2013 06:24:27 +0000 (09:24 +0300)
committerSimon Horman <horms@verge.net.au>
Tue, 15 Oct 2013 01:36:01 +0000 (10:36 +0900)
commit 578bc3ef1e473a ("ipvs: reorganize dest trash") added
rcu_barrier() on cleanup to wait dest users and schedulers
like LBLC and LBLCR to put their last dest reference.
Using rcu_barrier with many namespaces is problematic.

Trying to fix it by freeing dest with kfree_rcu is not
a solution, RCU callbacks can run in parallel and execution
order is random.

Fix it by creating new function ip_vs_dest_put_and_free()
which is heavier than ip_vs_dest_put(). We will use it just
for schedulers like LBLC, LBLCR that can delay their dest
release.

By default, dests reference is above 0 if they are present in
service and it is 0 when deleted but still in trash list.
Change the dest trash code to use ip_vs_dest_put_and_free(),
so that refcnt -1 can be used for freeing. As result,
such checks remain in slow path and the rcu_barrier() from
netns cleanup can be removed.

Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
include/net/ip_vs.h
net/netfilter/ipvs/ip_vs_ctl.c
net/netfilter/ipvs/ip_vs_lblc.c
net/netfilter/ipvs/ip_vs_lblcr.c

index 1c2e1b9f6b8603aecdf14452a6b424b227cd504b..cd7275f9c463b49c7f86f0eb5508a7aa07048144 100644 (file)
@@ -1442,6 +1442,12 @@ static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
        atomic_dec(&dest->refcnt);
 }
 
+static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
+{
+       if (atomic_dec_return(&dest->refcnt) < 0)
+               kfree(dest);
+}
+
 /*
  *      IPVS sync daemon data and function prototypes
  *      (from ip_vs_sync.c)
index a3df9bddc4f76251a8722792d8e9f15478546ac1..62786a495cea481a3fd18d063b7174cdb36052ad 100644 (file)
@@ -704,7 +704,7 @@ static void ip_vs_dest_free(struct ip_vs_dest *dest)
        __ip_vs_dst_cache_reset(dest);
        __ip_vs_svc_put(svc, false);
        free_percpu(dest->stats.cpustats);
-       kfree(dest);
+       ip_vs_dest_put_and_free(dest);
 }
 
 /*
@@ -3820,10 +3820,6 @@ void __net_exit ip_vs_control_net_cleanup(struct net *net)
 {
        struct netns_ipvs *ipvs = net_ipvs(net);
 
-       /* Some dest can be in grace period even before cleanup, we have to
-        * defer ip_vs_trash_cleanup until ip_vs_dest_wait_readers is called.
-        */
-       rcu_barrier();
        ip_vs_trash_cleanup(net);
        ip_vs_stop_estimator(net, &ipvs->tot_stats);
        ip_vs_control_net_cleanup_sysctl(net);
index eff13c94498e068173c66b6a481a6264d038ffea..ca056a331e60b23f1b6e542fd640b2b996878335 100644 (file)
@@ -136,7 +136,7 @@ static void ip_vs_lblc_rcu_free(struct rcu_head *head)
                                                   struct ip_vs_lblc_entry,
                                                   rcu_head);
 
-       ip_vs_dest_put(en->dest);
+       ip_vs_dest_put_and_free(en->dest);
        kfree(en);
 }
 
index 0b8550089a2e580e7feba0723117f1c849048a39..3f21a2f47de1ffc6be71bcc93b6c35be98f8ae3a 100644 (file)
@@ -130,7 +130,7 @@ static void ip_vs_lblcr_elem_rcu_free(struct rcu_head *head)
        struct ip_vs_dest_set_elem *e;
 
        e = container_of(head, struct ip_vs_dest_set_elem, rcu_head);
-       ip_vs_dest_put(e->dest);
+       ip_vs_dest_put_and_free(e->dest);
        kfree(e);
 }