From patchwork Fri Jan 17 00:41:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 311902 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D30282C0082 for ; Fri, 17 Jan 2014 11:41:46 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751379AbaAQAlY (ORCPT ); Thu, 16 Jan 2014 19:41:24 -0500 Received: from mail-yh0-f50.google.com ([209.85.213.50]:61297 "EHLO mail-yh0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750937AbaAQAlX (ORCPT ); Thu, 16 Jan 2014 19:41:23 -0500 Received: by mail-yh0-f50.google.com with SMTP id f10so1198975yha.23 for ; Thu, 16 Jan 2014 16:41:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:content-type :content-transfer-encoding:mime-version; bh=vVGwsohuuY+QI6oJZpWR8wf7d1lM/47X9XgxXyWy/9k=; b=A89ZvpoivA+LPLuHMVeW4SampP096AN6Wn6CTvyhfvTkrVYEcoHSnFELqMB2SJl6pn 3v+tQ5DfJjBa9pZNRgdbCW6+Dl1vXrW9bBZbFl34wwyH/HSkh96VxWmuuV0QGOjsDPVe ScjYDatwMW7sBFoDcC+h4iwrK8le5g/Nr4+NyIBJfLrRbx9tyinTgayNx1zvbqwVraO7 jYnyffslXR7giNeUdgyAJaC9/MXkajP955GFd2Vj4U/w9J4+s/rAMvNqVkhMv79+Ddu3 q8uLo1XCFe1+Wz3Qq9efp82/jNHFpR1qP0J1N9jIGvtll54Nf4GAdEcd4K8x2HeVylbE C+Vg== X-Received: by 10.236.118.201 with SMTP id l49mr13283811yhh.78.1389919282211; Thu, 16 Jan 2014 16:41:22 -0800 (PST) Received: from ?IPv6:2620:0:1000:3e02:14ec:532:4e5:75e1? ([2620:0:1000:3e02:14ec:532:4e5:75e1]) by mx.google.com with ESMTPSA id w45sm14940374yhk.4.2014.01.16.16.41.20 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Thu, 16 Jan 2014 16:41:21 -0800 (PST) Message-ID: <1389919279.31367.439.camel@edumazet-glaptop2.roam.corp.google.com> Subject: [PATCH net-next] ipv4: fix a dst leak in tunnels From: Eric Dumazet To: David Miller Cc: netdev , Tom Herbert , Maciej =?UTF-8?Q?=C5=BBenczykowski?= , Cong Wang Date: Thu, 16 Jan 2014 16:41:19 -0800 X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet 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 Cc: Cong Wang Cc: Tom Herbert Cc: Maciej Żenczykowski --- include/net/ip_tunnels.h | 1 - net/ipv4/ip_tunnel.c | 34 ++++++++++++++-------------------- 2 files changed, 14 insertions(+), 21 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index cd729becbb07..48ed75c21260 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -40,7 +40,6 @@ struct ip_tunnel_prl_entry { struct ip_tunnel_dst { struct dst_entry __rcu *dst; - spinlock_t lock; }; struct ip_tunnel { 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, IP_TNL_HASH_BITS); } -static inline void __tunnel_dst_set(struct ip_tunnel_dst *idst, - struct dst_entry *dst) +static void __tunnel_dst_set(struct ip_tunnel_dst *idst, + struct dst_entry *dst) { struct dst_entry *old_dst; - if (dst && (dst->flags & DST_NOCACHE)) - dst = NULL; - - spin_lock_bh(&idst->lock); - old_dst = rcu_dereference(idst->dst); - rcu_assign_pointer(idst->dst, dst); + if (dst) { + if (dst->flags & DST_NOCACHE) + dst = NULL; + else + dst_clone(dst); + } + old_dst = xchg((__force struct dst_entry **)&idst->dst, dst); dst_release(old_dst); - spin_unlock_bh(&idst->lock); } -static inline void tunnel_dst_set(struct ip_tunnel *t, struct dst_entry *dst) +static void tunnel_dst_set(struct ip_tunnel *t, struct dst_entry *dst) { __tunnel_dst_set(this_cpu_ptr(t->dst_cache), dst); } -static inline void tunnel_dst_reset(struct ip_tunnel *t) +static void tunnel_dst_reset(struct ip_tunnel *t) { tunnel_dst_set(t, NULL); } @@ -101,7 +101,7 @@ static void tunnel_dst_reset_all(struct ip_tunnel *t) __tunnel_dst_set(per_cpu_ptr(t->dst_cache, i), NULL); } -static inline struct dst_entry *tunnel_dst_get(struct ip_tunnel *t) +static struct dst_entry *tunnel_dst_get(struct ip_tunnel *t) { struct dst_entry *dst; @@ -413,7 +413,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev) if (!IS_ERR(rt)) { tdev = rt->dst.dev; - tunnel_dst_set(tunnel, dst_clone(&rt->dst)); + tunnel_dst_set(tunnel, &rt->dst); ip_rt_put(rt); } if (dev->type != ARPHRD_ETHER) @@ -668,7 +668,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, goto tx_error; } if (connected) - tunnel_dst_set(tunnel, dst_clone(&rt->dst)); + tunnel_dst_set(tunnel, &rt->dst); } if (rt->dst.dev == dev) { @@ -1066,12 +1066,6 @@ int ip_tunnel_init(struct net_device *dev) return -ENOMEM; } - for_each_possible_cpu(i) { - struct ip_tunnel_dst *idst = per_cpu_ptr(tunnel->dst_cache, i); - idst-> dst = NULL; - spin_lock_init(&idst->lock); - } - err = gro_cells_init(&tunnel->gro_cells, dev); if (err) { free_percpu(tunnel->dst_cache);