From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: [PATCH net-next 4/7] net/ipv6: Move rcu locking to callers of fib6_get_cookie_safe Date: Fri, 20 Apr 2018 15:38:00 -0700 Message-ID: <20180420223803.15743-5-dsahern@gmail.com> References: <20180420223803.15743-1-dsahern@gmail.com> Cc: davem@davemloft.net, idosch@idosch.org, roopa@cumulusnetworks.com, eric.dumazet@gmail.com, weiwan@google.com, kafai@fb.com, yoshfuji@linux-ipv6.org, David Ahern To: netdev@vger.kernel.org Return-path: Received: from mail-pl0-f67.google.com ([209.85.160.67]:36063 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751169AbeDTWiR (ORCPT ); Fri, 20 Apr 2018 18:38:17 -0400 Received: by mail-pl0-f67.google.com with SMTP id m7-v6so5987424plt.3 for ; Fri, 20 Apr 2018 15:38:17 -0700 (PDT) In-Reply-To: <20180420223803.15743-1-dsahern@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: A later patch protects 'from' in rt6_info and this simplifies the locking needed by it. Signed-off-by: David Ahern --- include/net/ip6_fib.h | 6 ++++-- net/ipv6/route.c | 13 ++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index dd1481ed8bdb..dc3505fb62b3 100644 --- a/include/net/ip6_fib.h +++ b/include/net/ip6_fib.h @@ -234,7 +234,6 @@ static inline bool fib6_get_cookie_safe(const struct fib6_info *f6i, struct fib6_node *fn; bool status = false; - rcu_read_lock(); fn = rcu_dereference(f6i->fib6_node); if (fn) { @@ -244,7 +243,6 @@ static inline bool fib6_get_cookie_safe(const struct fib6_info *f6i, status = true; } - rcu_read_unlock(); return status; } @@ -252,10 +250,14 @@ static inline u32 rt6_get_cookie(const struct rt6_info *rt) { u32 cookie = 0; + rcu_read_lock(); + if (rt->rt6i_flags & RTF_PCPU || (unlikely(!list_empty(&rt->rt6i_uncached)) && rt->from)) fib6_get_cookie_safe(rt->from, &cookie); + rcu_read_unlock(); + return cookie; } diff --git a/net/ipv6/route.c b/net/ipv6/route.c index f8b22183b7fd..810a37ac043b 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2159,9 +2159,12 @@ static struct dst_entry *rt6_dst_from_check(struct rt6_info *rt, u32 cookie) static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie) { + struct dst_entry *dst_ret; struct rt6_info *rt; - rt = (struct rt6_info *) dst; + rt = container_of(dst, struct rt6_info, dst); + + rcu_read_lock(); /* All IPV6 dsts are created with ->obsolete set to the value * DST_OBSOLETE_FORCE_CHK which forces validation calls down @@ -2170,9 +2173,13 @@ static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie) if (rt->rt6i_flags & RTF_PCPU || (unlikely(!list_empty(&rt->rt6i_uncached)) && rt->from)) - return rt6_dst_from_check(rt, cookie); + dst_ret = rt6_dst_from_check(rt, cookie); else - return rt6_check(rt, cookie); + dst_ret = rt6_check(rt, cookie); + + rcu_read_unlock(); + + return dst_ret; } static struct dst_entry *ip6_negative_advice(struct dst_entry *dst) -- 2.11.0