From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C5BFC43381 for ; Sat, 30 Mar 2019 00:47:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED6372070B for ; Sat, 30 Mar 2019 00:47:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553906866; bh=jS6GKyKmJ0Q9rfVpfOKdDr/74E8+1OYltcfQE7tyn7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=f9kkDhI3huK7V1NRjXf3o+9FTYkDqvZ8zJ3xwra0W2i1qDxTxhf4Lu42bBg7MZZbq w4KKo16q5tq2kkYzOv3PjPfmhKUXfOgmRrQpTxwAIIS1Xcq/UHFzi+S7QvSBLoYmg7 X5VJdLcLg1eugtwhx8GLWubfBFeWsmtp3h6Md0wU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730439AbfC3Aro (ORCPT ); Fri, 29 Mar 2019 20:47:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:56406 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730394AbfC3Ard (ORCPT ); Fri, 29 Mar 2019 20:47:33 -0400 Received: from kenny.it.cumulusnetworks.com. (fw.cumulusnetworks.com [216.129.126.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6C166218D8; Sat, 30 Mar 2019 00:47:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553906852; bh=jS6GKyKmJ0Q9rfVpfOKdDr/74E8+1OYltcfQE7tyn7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0R2i84FVIe3D4tgCVc2uiK6T0e6OdWYtvsH2fVUrdIwjed4MWW/r2r57sz9ZpDntX Tc9Zpju7HImislXYt1Kjd5aAudPnsPGnH/kqY5Tu8KZlm8B6AD4Ak/TGHmaw3MAN6P EXr/d7/1yZ/ewR7nko/YzXvwSMVJSk/KapLOLLsU= From: David Ahern To: davem@davemloft.net, netdev@vger.kernel.org Cc: idosch@mellanox.com, David Ahern Subject: [PATCH net-next 5/8] ipv4: Switch to nhc_exceptions for exception bucket Date: Fri, 29 Mar 2019 17:47:28 -0700 Message-Id: <20190330004731.23959-6-dsahern@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190330004731.23959-1-dsahern@kernel.org> References: <20190330004731.23959-1-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: David Ahern Flip IPv4 to use nhc_exceptions for fnhe_hash_bucket and drop nh_exceptions from fib_nh. Simplify the code a bit by converting update_or_create_fnhe, find_exception and rt_cache_route to take fib_nh_common as the input over fib_nh. Signed-off-by: David Ahern --- include/net/ip_fib.h | 1 - net/ipv4/fib_semantics.c | 13 +++++--- net/ipv4/route.c | 87 +++++++++++++++++++++++------------------------- 3 files changed, 50 insertions(+), 51 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 063430ca0c6e..9849c8901033 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -109,7 +109,6 @@ struct fib_nh { #endif __be32 nh_saddr; int nh_saddr_genid; - struct fnhe_hash_bucket __rcu *nh_exceptions; #define fib_nh_family nh_common.nhc_family #define fib_nh_dev nh_common.nhc_dev #define fib_nh_oif nh_common.nhc_oif diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index e8c9208d35d2..9db4c61ebe1c 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -157,12 +157,12 @@ static void rt_fibinfo_free(struct rtable __rcu **rtp) dst_release_immediate(&rt->dst); } -static void free_nh_exceptions(struct fib_nh *nh) +static void free_nh_exceptions(struct fib_nh_common *nhc) { struct fnhe_hash_bucket *hash; int i; - hash = rcu_dereference_protected(nh->nh_exceptions, 1); + hash = rcu_dereference_protected(nhc->nhc_exceptions, 1); if (!hash) return; for (i = 0; i < FNHE_HASH_SIZE; i++) { @@ -217,12 +217,14 @@ EXPORT_SYMBOL_GPL(fib_nh_common_release); void fib_nh_release(struct net *net, struct fib_nh *fib_nh) { + struct fib_nh_common *nhc = &fib_nh->nh_common; + #ifdef CONFIG_IP_ROUTE_CLASSID if (fib_nh->nh_tclassid) net->ipv4.fib_num_tclassid_users--; #endif - fib_nh_common_release(&fib_nh->nh_common); - free_nh_exceptions(fib_nh); + fib_nh_common_release(nhc); + free_nh_exceptions(nhc); } /* Release a nexthop info record */ @@ -1505,10 +1507,11 @@ static int call_fib_nh_notifiers(struct fib_nh *nh, */ static void nh_update_mtu(struct fib_nh *nh, u32 new, u32 orig) { + struct fib_nh_common *nhc = &nh->nh_common; struct fnhe_hash_bucket *bucket; int i; - bucket = rcu_dereference_protected(nh->nh_exceptions, 1); + bucket = rcu_dereference_protected(nhc->nhc_exceptions, 1); if (!bucket) return; diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 60d525391908..75e2952c2964 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -634,10 +634,10 @@ static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnh } } -static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw, - u32 pmtu, bool lock, unsigned long expires) +static void update_or_create_fnhe(struct fib_nh_common *nhc, __be32 daddr, + __be32 gw, u32 pmtu, bool lock, + unsigned long expires) { - struct fib_nh_common *nhc = &nh->nh_common; struct fnhe_hash_bucket *hash; struct fib_nh_exception *fnhe; struct rtable *rt; @@ -645,17 +645,20 @@ static void update_or_create_fnhe(struct fib_nh *nh, __be32 daddr, __be32 gw, unsigned int i; int depth; - genid = fnhe_genid(dev_net(nh->fib_nh_dev)); + if (nhc->nhc_family != AF_INET) + return; + + genid = fnhe_genid(dev_net(nhc->nhc_dev)); hval = fnhe_hashfun(daddr); spin_lock_bh(&fnhe_lock); - hash = rcu_dereference(nh->nh_exceptions); + hash = rcu_dereference(nhc->nhc_exceptions); if (!hash) { hash = kcalloc(FNHE_HASH_SIZE, sizeof(*hash), GFP_ATOMIC); if (!hash) goto out_unlock; - rcu_assign_pointer(nh->nh_exceptions, hash); + rcu_assign_pointer(nhc->nhc_exceptions, hash); } hash += hval; @@ -778,15 +781,10 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow if (!(n->nud_state & NUD_VALID)) { neigh_event_send(n, NULL); } else { - if (fib_lookup(net, fl4, &res, 0) == 0) { - struct fib_nh_common *nhc = FIB_RES_NH(res); - struct fib_nh *nh; - - nh = container_of(nhc, struct fib_nh, nh_common); - update_or_create_fnhe(nh, fl4->daddr, new_gw, - 0, false, + if (fib_lookup(net, fl4, &res, 0) == 0) + update_or_create_fnhe(FIB_RES_NH(res), + fl4->daddr, new_gw, 0, false, jiffies + ip_rt_gc_timeout); - } if (kill_route) rt->dst.obsolete = DST_OBSOLETE_KILL; call_netevent_notifiers(NETEVENT_NEIGH_UPDATE, n); @@ -1029,14 +1027,9 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu) return; rcu_read_lock(); - if (fib_lookup(dev_net(dst->dev), fl4, &res, 0) == 0) { - struct fib_nh_common *nhc = FIB_RES_NH(res); - struct fib_nh *nh; - - nh = container_of(nhc, struct fib_nh, nh_common); - update_or_create_fnhe(nh, fl4->daddr, 0, mtu, lock, + if (fib_lookup(dev_net(dst->dev), fl4, &res, 0) == 0) + update_or_create_fnhe(FIB_RES_NH(res), fl4->daddr, 0, mtu, lock, jiffies + ip_rt_mtu_expires); - } rcu_read_unlock(); } @@ -1292,7 +1285,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst) return mtu - lwtunnel_headroom(dst->lwtstate, mtu); } -static void ip_del_fnhe(struct fib_nh *nh, __be32 daddr) +static void ip_del_fnhe(struct fib_nh_common *nhc, __be32 daddr) { struct fnhe_hash_bucket *hash; struct fib_nh_exception *fnhe, __rcu **fnhe_p; @@ -1300,7 +1293,7 @@ static void ip_del_fnhe(struct fib_nh *nh, __be32 daddr) spin_lock_bh(&fnhe_lock); - hash = rcu_dereference_protected(nh->nh_exceptions, + hash = rcu_dereference_protected(nhc->nhc_exceptions, lockdep_is_held(&fnhe_lock)); hash += hval; @@ -1326,12 +1319,17 @@ static void ip_del_fnhe(struct fib_nh *nh, __be32 daddr) spin_unlock_bh(&fnhe_lock); } -static struct fib_nh_exception *find_exception(struct fib_nh *nh, __be32 daddr) +static struct fib_nh_exception *find_exception(struct fib_nh_common *nhc, + __be32 daddr) { - struct fnhe_hash_bucket *hash = rcu_dereference(nh->nh_exceptions); + struct fnhe_hash_bucket *hash; struct fib_nh_exception *fnhe; u32 hval; + if (nhc->nhc_family != AF_INET) + return NULL; + + hash = rcu_dereference(nhc->nhc_exceptions); if (!hash) return NULL; @@ -1342,7 +1340,7 @@ static struct fib_nh_exception *find_exception(struct fib_nh *nh, __be32 daddr) if (fnhe->fnhe_daddr == daddr) { if (fnhe->fnhe_expires && time_after(jiffies, fnhe->fnhe_expires)) { - ip_del_fnhe(nh, daddr); + ip_del_fnhe(nhc, daddr); break; } return fnhe; @@ -1369,10 +1367,9 @@ u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr) mtu = fi->fib_mtu; if (likely(!mtu)) { - struct fib_nh *nh = container_of(nhc, struct fib_nh, nh_common); struct fib_nh_exception *fnhe; - fnhe = find_exception(nh, daddr); + fnhe = find_exception(nhc, daddr); if (fnhe && !time_after_eq(jiffies, fnhe->fnhe_expires)) mtu = fnhe->fnhe_pmtu; } @@ -1431,9 +1428,8 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe, return ret; } -static bool rt_cache_route(struct fib_nh *nh, struct rtable *rt) +static bool rt_cache_route(struct fib_nh_common *nhc, struct rtable *rt) { - struct fib_nh_common *nhc = &nh->nh_common; struct rtable *orig, *prev, **p; bool ret = true; @@ -1537,22 +1533,28 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr, if (fi) { struct fib_nh_common *nhc = FIB_RES_NH(*res); - struct fib_nh *nh = container_of(nhc, struct fib_nh, nh_common); - if (nh->fib_nh_gw4 && nh->fib_nh_scope == RT_SCOPE_LINK) { - rt->rt_gateway = nh->fib_nh_gw4; + if (nhc->nhc_gw.ipv4 && nhc->nhc_scope == RT_SCOPE_LINK) { + rt->rt_gateway = nhc->nhc_gw.ipv4; rt->rt_uses_gateway = 1; } ip_dst_init_metrics(&rt->dst, fi->fib_metrics); #ifdef CONFIG_IP_ROUTE_CLASSID - rt->dst.tclassid = nh->nh_tclassid; + if (nhc->nhc_family == AF_INET) { + struct fib_nh *nh; + + nh = container_of(nhc, struct fib_nh, nh_common); + rt->dst.tclassid = nh->nh_tclassid; + } #endif - rt->dst.lwtstate = lwtstate_get(nh->fib_nh_lws); + + rt->dst.lwtstate = lwtstate_get(nhc->nhc_lwtstate); if (unlikely(fnhe)) cached = rt_bind_exception(rt, fnhe, daddr, do_cache); else if (do_cache) - cached = rt_cache_route(nh, rt); + cached = rt_cache_route(nhc, rt); + if (unlikely(!cached)) { /* Routes we intend to cache in nexthop exception or * FIB nexthop have the DST_NOCACHE bit clear. @@ -1709,9 +1711,8 @@ static int __mkroute_input(struct sk_buff *skb, { struct fib_nh_common *nhc = FIB_RES_NH(*res); struct net_device *dev = nhc->nhc_dev; - struct fib_nh_exception *fnhe; + struct fib_nh_exception *fnhe = NULL; struct rtable *rth; - struct fib_nh *nh; int err; struct in_device *out_dev; bool do_cache; @@ -1758,8 +1759,7 @@ static int __mkroute_input(struct sk_buff *skb, } } - nh = container_of(nhc, struct fib_nh, nh_common); - fnhe = find_exception(nh, daddr); + fnhe = find_exception(nhc, daddr); if (do_cache) { if (fnhe) rth = rcu_dereference(fnhe->fnhe_rth_input); @@ -2091,7 +2091,6 @@ out: return err; if (do_cache) { struct fib_nh_common *nhc = FIB_RES_NH(*res); - struct fib_nh *nh; rth->dst.lwtstate = lwtstate_get(nhc->nhc_lwtstate); if (lwtunnel_input_redirect(rth->dst.lwtstate)) { @@ -2100,8 +2099,7 @@ out: return err; rth->dst.input = lwtunnel_input; } - nh = container_of(nhc, struct fib_nh, nh_common); - if (unlikely(!rt_cache_route(nh, rth))) + if (unlikely(!rt_cache_route(nhc, rth))) rt_add_uncached_list(rth); } skb_dst_set(skb, &rth->dst); @@ -2273,10 +2271,9 @@ static struct rtable *__mkroute_output(const struct fib_result *res, do_cache &= fi != NULL; if (fi) { struct fib_nh_common *nhc = FIB_RES_NH(*res); - struct fib_nh *nh = container_of(nhc, struct fib_nh, nh_common); struct rtable __rcu **prth; - fnhe = find_exception(nh, fl4->daddr); + fnhe = find_exception(nhc, fl4->daddr); if (!do_cache) goto add; if (fnhe) { -- 2.11.0