diff options
author | Eric Dumazet <edumazet@google.com> | 2014-01-16 19:41:19 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-17 21:36:39 -0500 |
commit | 6c7e7610ff6888ea15a901fbcb30c5d461816b34 (patch) | |
tree | 15e55648f844c0338783711c523008301486c637 /net/ipv4 | |
parent | db893473d313a4ad9455e89d1bd5e136a57f411e (diff) |
ipv4: fix a dst leak in tunnels
This patch :
1) Remove a dst leak if DST_NOCACHE was set on dst
Fix this by holding a reference only if dst really cached.
2) Remove a lockdep warning in __tunnel_dst_set()
This was reported by Cong Wang.
3) Remove usage of a spinlock where xchg() is enough
4) Remove some spurious inline keywords.
Let compiler decide for us.
Fixes: 7d442fab0a67 ("ipv4: Cache dst in tunnels")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Cong Wang <cwang@twopensource.com>
Cc: Tom Herbert <therbert@google.com>
Cc: Maciej Żenczykowski <maze@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/ip_tunnel.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index d3929a69f008..432c28ab3197 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c | |||
@@ -68,27 +68,27 @@ static unsigned int ip_tunnel_hash(struct ip_tunnel_net *itn, | |||
68 | IP_TNL_HASH_BITS); | 68 | IP_TNL_HASH_BITS); |
69 | } | 69 | } |
70 | 70 | ||
71 | static inline void __tunnel_dst_set(struct ip_tunnel_dst *idst, | 71 | static void __tunnel_dst_set(struct ip_tunnel_dst *idst, |
72 | struct dst_entry *dst) | 72 | struct dst_entry *dst) |
73 | { | 73 | { |
74 | struct dst_entry *old_dst; | 74 | struct dst_entry *old_dst; |
75 | 75 | ||
76 | if (dst && (dst->flags & DST_NOCACHE)) | 76 | if (dst) { |
77 | dst = NULL; | 77 | if (dst->flags & DST_NOCACHE) |
78 | 78 | dst = NULL; | |
79 | spin_lock_bh(&idst->lock); | 79 | else |
80 | old_dst = rcu_dereference(idst->dst); | 80 | dst_clone(dst); |
81 | rcu_assign_pointer(idst->dst, dst); | 81 | } |
82 | old_dst = xchg((__force struct dst_entry **)&idst->dst, dst); | ||
82 | dst_release(old_dst); | 83 | dst_release(old_dst); |
83 | spin_unlock_bh(&idst->lock); | ||
84 | } | 84 | } |
85 | 85 | ||
86 | static inline void tunnel_dst_set(struct ip_tunnel *t, struct dst_entry *dst) | 86 | static void tunnel_dst_set(struct ip_tunnel *t, struct dst_entry *dst) |
87 | { | 87 | { |
88 | __tunnel_dst_set(this_cpu_ptr(t->dst_cache), dst); | 88 | __tunnel_dst_set(this_cpu_ptr(t->dst_cache), dst); |
89 | } | 89 | } |
90 | 90 | ||
91 | static inline void tunnel_dst_reset(struct ip_tunnel *t) | 91 | static void tunnel_dst_reset(struct ip_tunnel *t) |
92 | { | 92 | { |
93 | tunnel_dst_set(t, NULL); | 93 | tunnel_dst_set(t, NULL); |
94 | } | 94 | } |
@@ -101,7 +101,7 @@ static void tunnel_dst_reset_all(struct ip_tunnel *t) | |||
101 | __tunnel_dst_set(per_cpu_ptr(t->dst_cache, i), NULL); | 101 | __tunnel_dst_set(per_cpu_ptr(t->dst_cache, i), NULL); |
102 | } | 102 | } |
103 | 103 | ||
104 | static inline struct dst_entry *tunnel_dst_get(struct ip_tunnel *t) | 104 | static struct dst_entry *tunnel_dst_get(struct ip_tunnel *t) |
105 | { | 105 | { |
106 | struct dst_entry *dst; | 106 | struct dst_entry *dst; |
107 | 107 | ||
@@ -413,7 +413,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev) | |||
413 | 413 | ||
414 | if (!IS_ERR(rt)) { | 414 | if (!IS_ERR(rt)) { |
415 | tdev = rt->dst.dev; | 415 | tdev = rt->dst.dev; |
416 | tunnel_dst_set(tunnel, dst_clone(&rt->dst)); | 416 | tunnel_dst_set(tunnel, &rt->dst); |
417 | ip_rt_put(rt); | 417 | ip_rt_put(rt); |
418 | } | 418 | } |
419 | if (dev->type != ARPHRD_ETHER) | 419 | if (dev->type != ARPHRD_ETHER) |
@@ -668,7 +668,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, | |||
668 | goto tx_error; | 668 | goto tx_error; |
669 | } | 669 | } |
670 | if (connected) | 670 | if (connected) |
671 | tunnel_dst_set(tunnel, dst_clone(&rt->dst)); | 671 | tunnel_dst_set(tunnel, &rt->dst); |
672 | } | 672 | } |
673 | 673 | ||
674 | if (rt->dst.dev == dev) { | 674 | if (rt->dst.dev == dev) { |
@@ -1066,12 +1066,6 @@ int ip_tunnel_init(struct net_device *dev) | |||
1066 | return -ENOMEM; | 1066 | return -ENOMEM; |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | for_each_possible_cpu(i) { | ||
1070 | struct ip_tunnel_dst *idst = per_cpu_ptr(tunnel->dst_cache, i); | ||
1071 | idst-> dst = NULL; | ||
1072 | spin_lock_init(&idst->lock); | ||
1073 | } | ||
1074 | |||
1075 | err = gro_cells_init(&tunnel->gro_cells, dev); | 1069 | err = gro_cells_init(&tunnel->gro_cells, dev); |
1076 | if (err) { | 1070 | if (err) { |
1077 | free_percpu(tunnel->dst_cache); | 1071 | free_percpu(tunnel->dst_cache); |