Skip to contentSkip to conversation

ipv6: replace rwlock with rcu and spinlock in fib6 table

PATCH In review Wei Wang 6 participants 26 messages Oct 6, 2017 – Oct 9, 2017

Subsystems (3)
lore
Share & tools
lore

Wei Wang

author
#0 lore raw

cover ipv6: replace rwlock with rcu and spinlock in fib6 table

From: Wei Wang <[email protected]>

Currently, fib6 table is protected by rwlock. During route lookup, reader lock is taken and during route insertion, deletion or modification, writer lock is taken. This is a very inefficient implementation because the fastpath always has to do the operation to grab the reader lock.
According to my latest syn flood test on an iota ivybridage machine with 2 10G mlx nics bonded together, each with 8 rx queues on 2 NUMA nodes, and with the upstream net-next kernel:
ipv4 stack can handle around 4.2Mpps
ipv6 stack can handle around 1.3Mpps

In order to close the gap of the performance number between ipv4 and ipv6 stack, this patch series tries to get rid of the usage of the rwlock and replace it with rcu and spinlock protection. This will greatly speed up the fastpath performance as it only needs to hold rcu which is much less expensive than grabbing the reader lock. It also makes ipv6 fib implementation more consistent with ipv4.

In order to be able to replace the current rwlock with rcu and spinlock, some preparation work is needed:
Patch 1-8 introduces a per-route hash table (protected by rcu and a different spinlock) to store all cached routes created by pmtu and ip redirect under its main route. This makes the main fib6 tree only contain static routes.
Patch 9-14 prepares all the reader path to be ready to tolerate concurrent writer.
Patch 15 finally does the rwlock to rcu and spinlock conversion. Patch 16 takes care of rt6_stats.

After this patch series, in the same syn flood test,
ipv6 stack can now handle around 3.5Mpps compared to previous 1.3Mpps in my test setup.

After this patch series, there are still some improvements that should be done in ipv6 stack:
1. During route lookup, dst_use() is called everytime on the selected route to update dst->__use and dst->lastuse. This dirties the cacheline and causes extra cacheline miss and should be avoided.
2. when no route is found in the current table, net->ip6.ipv6_null_entry is used and refcnt is taken on it. As there is no pcpu cache for this specific route, frequent change on the refcnt for this route causes quite some cacheline misses.
And to make things worse, if CONFIG_IPV6_MULTIPLE_TABLES is defined, output path route lookup always starts with local table first and guarantees to hit net->ipv6.ip6_null_entry before continuing to do lookup in the main table.
These operations on net->ipv6.ip6_null_entry could potentially be avoided.
3. ipv6 input path route lookup grabs refcnt on dst. This is different from ipv4. We could potentially change this behavior to let ipv6 input path route lookup not to grab refcnt on dst. However, it does not give us much performance boost as we currently have pcpu route cache for input path as well in ipv6. But this work probably is still worth doing to unify ipv6 and ipv4 route lookup behavior.

The above issues will be addressed separately after this patch series has been accepted.

This is a joint work with Martin KaFai Lau and Eric Dumazet. And many many thanks to them for their inspiring ideas and big big code review efforts.

Wei Wang (16):
ipv6: introduce a new function fib6_update_sernum()
ipv6: introduce a hash table to store dst cache
ipv6: prepare fib6_remove_prefsrc() for exception table
ipv6: prepare rt6_mtu_change() for exception table
ipv6: prepare rt6_clean_tohost() for exception table
ipv6: prepare fib6_age() for exception table
ipv6: prepare fib6_locate() for exception table
ipv6: hook up exception table to store dst cache
ipv6: grab rt->rt6i_ref before allocating pcpu rt
ipv6: don't release rt->rt6i_pcpu memory during rt6_release()
ipv6: replace dst_hold() with dst_hold_safe() in routing code
ipv6: update fn_sernum after route is inserted to tree
ipv6: check fn->leaf before it is used
ipv6: add key length check into rt6_select()
ipv6: replace rwlock with rcu and spinlock in fib6_table
ipv6: take care of rt6_stats

 include/net/dst.h       |   2 +-
 include/net/ip6_fib.h   |  79 ++++-
 include/net/ip6_route.h |   5 +
 net/ipv6/addrconf.c     |  17 +-
 net/ipv6/ip6_fib.c      | 645 ++++++++++++++++++----------------
 net/ipv6/route.c        | 901 ++++++++++++++++++++++++++++++++++++++++--------
 6 files changed, 1179 insertions(+), 470 deletions(-)
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#1 lore raw

PATCH 1/16 ipv6: introduce a new function fib6_update_sernum()

From: Wei Wang <[email protected]>

This function takes a route as input and tries to update the sernum in the fib6_node this route is associated with. It will be used in later commit when adding a cached route into the exception table under that route.

---
 include/net/ip6_fib.h |  2 ++
 net/ipv6/ip6_fib.c    | 14 ++++++++++++++
 2 files changed, 16 insertions(+)
include/net/ip6_fib.h +2 -0
index d060d711a624..152b7b14a5a5 100644
@@ -358,6 +358,8 @@ void __net_exit fib6_notifier_exit(struct net *net);
 unsigned int fib6_tables_seq_read(struct net *net);
 int fib6_tables_dump(struct net *net, struct notifier_block *nb);
 
+void fib6_update_sernum(struct rt6_info *rt);
+
 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
 int fib6_rules_init(void);
 void fib6_rules_cleanup(void);
net/ipv6/ip6_fib.c +14 -0
index e5308d7cbd75..0ba4fbb2f855 100644
@@ -110,6 +110,20 @@ enum {
 	FIB6_NO_SERNUM_CHANGE = 0,
 };
 
+void fib6_update_sernum(struct rt6_info *rt)
+{
+	struct fib6_table *table = rt->rt6i_table;
+	struct net *net = dev_net(rt->dst.dev);
+	struct fib6_node *fn;
+
+	write_lock_bh(&table->tb6_lock);
+	fn = rcu_dereference_protected(rt->rt6i_node,
+			lockdep_is_held(&table->tb6_lock));
+	if (fn)
+		fn->fn_sernum = fib6_new_sernum(net);
+	write_unlock_bh(&table->tb6_lock);
+}
+
 /*
  *	Auxiliary address test functions for the radix tree.
  *
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#2 lore raw

PATCH 2/16 ipv6: introduce a hash table to store dst cache

From: Wei Wang <[email protected]>

Add a hash table into struct rt6_info in order to store dst caches created by pmtu discovery and ip redirect in ipv6 routing code. APIs to add dst cache, delete dst cache, find dst cache and update dst cache in the hash table are implemented and will be used in later commits.
This is a preparation work to move all cache routes into the exception table instead of getting inserted into the fib6 tree.

---
 include/net/ip6_fib.h   |  19 +++
 include/net/ip6_route.h |   3 +
 net/ipv6/route.c        | 341 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 363 insertions(+)
include/net/ip6_fib.h +19 -0
index 152b7b14a5a5..c4864c1e8f13 100644
@@ -98,6 +98,22 @@ struct rt6key {
 
 struct fib6_table;
 
+struct rt6_exception_bucket {
+	struct hlist_head	chain;
+	int			depth;
+};
+
+struct rt6_exception {
+	struct hlist_node	hlist;
+	struct rt6_info		*rt6i;
+	unsigned long		stamp;
+	struct rcu_head		rcu;
+};
+
+#define FIB6_EXCEPTION_BUCKET_SIZE_SHIFT 10
+#define FIB6_EXCEPTION_BUCKET_SIZE (1 << FIB6_EXCEPTION_BUCKET_SIZE_SHIFT)
+#define FIB6_MAX_DEPTH 5
+
 struct rt6_info {
 	struct dst_entry		dst;
 
@@ -134,12 +150,15 @@ struct rt6_info {
 
 	struct inet6_dev		*rt6i_idev;
 	struct rt6_info * __percpu	*rt6i_pcpu;
+	struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
 
 	u32				rt6i_metric;
 	u32				rt6i_pmtu;
 	/* more non-fragment space at head required */
 	unsigned short			rt6i_nfheader_len;
 	u8				rt6i_protocol;
+	u8				exception_bucket_flushed:1,
+					unused:7;
 };
 
 static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
include/net/ip6_route.h +3 -0
index ee96f402cb75..3315605f34c9 100644
@@ -95,6 +95,9 @@ int ip6_route_add(struct fib6_config *cfg, struct netlink_ext_ack *extack);
 int ip6_ins_rt(struct rt6_info *);
 int ip6_del_rt(struct rt6_info *);
 
+void rt6_flush_exceptions(struct rt6_info *rt);
+int rt6_remove_exception_rt(struct rt6_info *rt);
+
 static inline int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
 				      const struct in6_addr *daddr,
 				      unsigned int prefs,
net/ipv6/route.c +341 -0

371 lines not on this page · raw message

Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#3 lore raw

PATCH 3/16 ipv6: prepare fib6_remove_prefsrc() for exception table

From: Wei Wang <[email protected]>

After we move cached dst entries into the exception table under its parent route, current fib6_remove_prefsrc() no longer can access them. This commit makes fib6_remove_prefsrc() also go through all routes in the exception table to remove the pref src.
This is a preparation patch in order to move all cached dst into the exception table.

---
 net/ipv6/route.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
net/ipv6/route.c +29 -0
index dc5e70975966..f52ac57dcc99 100644
@@ -1264,6 +1264,12 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 	if (ort->rt6i_src.plen)
 		src_key = &nrt->rt6i_src.addr;
 #endif
+
+	/* Update rt6i_prefsrc as it could be changed
+	 * in rt6_remove_prefsrc()
+	 */
+	nrt->rt6i_prefsrc = ort->rt6i_prefsrc;
+
 	rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr,
 					       src_key);
 	if (rt6_ex)
@@ -1432,6 +1438,25 @@ static void rt6_update_exception_stamp_rt(struct rt6_info *rt)
 	rcu_read_unlock();
 }
 
+static void rt6_exceptions_remove_prefsrc(struct rt6_info *rt)
+{
+	struct rt6_exception_bucket *bucket;
+	struct rt6_exception *rt6_ex;
+	int i;
+
+	bucket = rcu_dereference_protected(rt->rt6i_exception_bucket,
+					lockdep_is_held(&rt6_exception_lock));
+
+	if (bucket) {
+		for (i = 0; i < FIB6_EXCEPTION_BUCKET_SIZE; i++) {
+			hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) {
+				rt6_ex->rt6i->rt6i_prefsrc.plen = 0;
+			}
+			bucket++;
+		}
+	}
+}
+
 struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 			       int oif, struct flowi6 *fl6, int flags)
 {
@@ -3159,8 +3184,12 @@ static int fib6_remove_prefsrc(struct rt6_info *rt, void *arg)
 	if (((void *)rt->dst.dev == dev || !dev) &&
 	    rt != net->ipv6.ip6_null_entry &&
 	    ipv6_addr_equal(addr, &rt->rt6i_prefsrc.addr)) {
+		spin_lock_bh(&rt6_exception_lock);
 		/* remove prefsrc entry */
 		rt->rt6i_prefsrc.plen = 0;
+		/* need to update cache as well */
+		rt6_exceptions_remove_prefsrc(rt);
+		spin_unlock_bh(&rt6_exception_lock);
 	}
 	return 0;
 }
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#4 lore raw

PATCH 4/16 ipv6: prepare rt6_mtu_change() for exception table

From: Wei Wang <[email protected]>

If we move all cached dst into the exception table under the main route, current rt6_mtu_change() will no longer be able to access them. This commit makes rt6_mtu_change_route() function to also go through all cached routes in the exception table under the main route and do proper updates on the mtu.
This is a preparation in order to move all cached routes into the exception table.

---
 net/ipv6/route.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
net/ipv6/route.c +40 -0
index f52ac57dcc99..d9805a857809 100644
@@ -1269,6 +1269,14 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 	 * in rt6_remove_prefsrc()
 	 */
 	nrt->rt6i_prefsrc = ort->rt6i_prefsrc;
+	/* rt6_mtu_change() might lower mtu on ort.
+	 * Only insert this exception route if its mtu
+	 * is less than ort's mtu value.
+	 */
+	if (nrt->rt6i_pmtu >= dst_mtu(&ort->dst)) {
+		err = -EINVAL;
+		goto out;
+	}
 
 	rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr,
 					       src_key);
@@ -1457,6 +1465,32 @@ static void rt6_exceptions_remove_prefsrc(struct rt6_info *rt)
 	}
 }
 
+static void rt6_exceptions_update_pmtu(struct rt6_info *rt, int mtu)
+{
+	struct rt6_exception_bucket *bucket;
+	struct rt6_exception *rt6_ex;
+	int i;
+
+	bucket = rcu_dereference_protected(rt->rt6i_exception_bucket,
+					lockdep_is_held(&rt6_exception_lock));
+
+	if (bucket) {
+		for (i = 0; i < FIB6_EXCEPTION_BUCKET_SIZE; i++) {
+			hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) {
+				struct rt6_info *entry = rt6_ex->rt6i;
+				/* For RTF_CACHE with rt6i_pmtu == 0
+				 * (i.e. a redirected route),
+				 * the metrics of its rt->dst.from has already
+				 * been updated.
+				 */
+				if (entry->rt6i_pmtu && entry->rt6i_pmtu > mtu)
+					entry->rt6i_pmtu = mtu;
+			}
+			bucket++;
+		}
+	}
+}
+
 struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 			       int oif, struct flowi6 *fl6, int flags)
 {
@@ -3296,6 +3330,10 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
 	if (rt->dst.dev == arg->dev &&
 	    dst_metric_raw(&rt->dst, RTAX_MTU) &&
 	    !dst_metric_locked(&rt->dst, RTAX_MTU)) {
+		spin_lock_bh(&rt6_exception_lock);
+		/* This case will be removed once the exception table
+		 * is hooked up.
+		 */
 		if (rt->rt6i_flags & RTF_CACHE) {
 			/* For RTF_CACHE with rt6i_pmtu == 0
 			 * (i.e. a redirected route),
@@ -3309,6 +3347,8 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
 			    dst_mtu(&rt->dst) == idev->cnf.mtu6)) {
 			dst_metric_set(&rt->dst, RTAX_MTU, arg->mtu);
 		}
+		rt6_exceptions_update_pmtu(rt, arg->mtu);
+		spin_unlock_bh(&rt6_exception_lock);
 	}
 	return 0;
 }
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#5 lore raw

PATCH 5/16 ipv6: prepare rt6_clean_tohost() for exception table

From: Wei Wang <[email protected]>

If we move all cached dst into the exception table under the main route, current rt6_clean_tohost() will no longer be able to access them. This commit makes fib6_clean_tohost() to also go through all cached routes in exception table and removes cached gateway routes to the passed in gateway.
This is a preparation in order to move all cached routes into the exception table.

---
 net/ipv6/route.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)
net/ipv6/route.c +47 -1
index d9805a857809..e8e901589564 100644
@@ -1491,6 +1491,43 @@ static void rt6_exceptions_update_pmtu(struct rt6_info *rt, int mtu)
 	}
 }
 
+#define RTF_CACHE_GATEWAY	(RTF_GATEWAY | RTF_CACHE)
+
+static void rt6_exceptions_clean_tohost(struct rt6_info *rt,
+					struct in6_addr *gateway)
+{
+	struct rt6_exception_bucket *bucket;
+	struct rt6_exception *rt6_ex;
+	struct hlist_node *tmp;
+	int i;
+
+	if (!rcu_access_pointer(rt->rt6i_exception_bucket))
+		return;
+
+	spin_lock_bh(&rt6_exception_lock);
+	bucket = rcu_dereference_protected(rt->rt6i_exception_bucket,
+				     lockdep_is_held(&rt6_exception_lock));
+
+	if (bucket) {
+		for (i = 0; i < FIB6_EXCEPTION_BUCKET_SIZE; i++) {
+			hlist_for_each_entry_safe(rt6_ex, tmp,
+						  &bucket->chain, hlist) {
+				struct rt6_info *entry = rt6_ex->rt6i;
+
+				if ((entry->rt6i_flags & RTF_CACHE_GATEWAY) ==
+				    RTF_CACHE_GATEWAY &&
+				    ipv6_addr_equal(gateway,
+						    &entry->rt6i_gateway)) {
+					rt6_remove_exception(bucket, rt6_ex);
+				}
+			}
+			bucket++;
+		}
+	}
+
+	spin_unlock_bh(&rt6_exception_lock);
+}
+
 struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 			       int oif, struct flowi6 *fl6, int flags)
 {
@@ -3240,18 +3277,27 @@ void rt6_remove_prefsrc(struct inet6_ifaddr *ifp)
 }
 
 #define RTF_RA_ROUTER		(RTF_ADDRCONF | RTF_DEFAULT | RTF_GATEWAY)
-#define RTF_CACHE_GATEWAY	(RTF_GATEWAY | RTF_CACHE)
 
 /* Remove routers and update dst entries when gateway turn into host. */
 static int fib6_clean_tohost(struct rt6_info *rt, void *arg)
 {
 	struct in6_addr *gateway = (struct in6_addr *)arg;
 
+	/* RTF_CACHE_GATEWAY case will be removed once the exception
+	 * table is hooked up to store all cached routes.
+	 */
 	if ((((rt->rt6i_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) ||
 	     ((rt->rt6i_flags & RTF_CACHE_GATEWAY) == RTF_CACHE_GATEWAY)) &&
 	     ipv6_addr_equal(gateway, &rt->rt6i_gateway)) {
 		return -1;
 	}
+
+	/* Further clean up cached routes in exception table.
+	 * This is needed because cached route may have a different
+	 * gateway than its 'parent' in the case of an ip redirect.
+	 */
+	rt6_exceptions_clean_tohost(rt, gateway);
+
 	return 0;
 }
 
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#6 lore raw

PATCH 6/16 ipv6: prepare fib6_age() for exception table

From: Wei Wang <[email protected]>

If all dst cache entries are stored in the exception table under the main route, we have to go through them during fib6_age() when doing garbage collecting.
Introduce a new function rt6_age_exception() which goes through all dst entries in the exception table and remove those entries that are expired. This function is called in fib6_age() so that all dst caches are also garbage collected.

---
 include/net/ip6_fib.h   | 13 +++++++++++
 include/net/ip6_route.h |  2 ++
 net/ipv6/ip6_fib.c      | 26 ++++++++-------------
 net/ipv6/route.c        | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 17 deletions(-)
include/net/ip6_fib.h +13 -0
index c4864c1e8f13..11a79ef87a28 100644
@@ -29,6 +29,14 @@
 #define FIB6_TABLE_HASHSZ 1
 #endif
 
+#define RT6_DEBUG 2
+
+#if RT6_DEBUG >= 3
+#define RT6_TRACE(x...) pr_debug(x)
+#else
+#define RT6_TRACE(x...) do { ; } while (0)
+#endif
+
 struct rt6_info;
 
 struct fib6_config {
@@ -75,6 +83,11 @@ struct fib6_node {
 	struct rcu_head		rcu;
 };
 
+struct fib6_gc_args {
+	int			timeout;
+	int			more;
+};
+
 #ifndef CONFIG_IPV6_SUBTREES
 #define FIB6_SUBTREE(fn)	NULL
 #else
include/net/ip6_route.h +2 -0
index 3315605f34c9..a0087fb9864b 100644
@@ -97,6 +97,8 @@ int ip6_del_rt(struct rt6_info *);
 
 void rt6_flush_exceptions(struct rt6_info *rt);
 int rt6_remove_exception_rt(struct rt6_info *rt);
+void rt6_age_exceptions(struct rt6_info *rt, struct fib6_gc_args *gc_args,
+			unsigned long now);
 
 static inline int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
 				      const struct in6_addr *daddr,
net/ipv6/ip6_fib.c +9 -17
index 0ba4fbb2f855..3afbe50f2779 100644
@@ -38,14 +38,6 @@
 #include <net/ip6_fib.h>
 #include <net/ip6_route.h>
 
-#define RT6_DEBUG 2
-
-#if RT6_DEBUG >= 3
-#define RT6_TRACE(x...) pr_debug(x)
-#else
-#define RT6_TRACE(x...) do { ; } while (0)
-#endif
-
 static struct kmem_cache *fib6_node_kmem __read_mostly;
 
 struct fib6_cleaner {
@@ -1890,12 +1882,6 @@ static void fib6_flush_trees(struct net *net)
  *	Garbage collection
  */
 
-struct fib6_gc_args
-{
-	int			timeout;
-	int			more;
-};
-
 static int fib6_age(struct rt6_info *rt, void *arg)
 {
 	struct fib6_gc_args *gc_args = arg;
@@ -1904,9 +1890,6 @@ static int fib6_age(struct rt6_info *rt, void *arg)
 	/*
 	 *	check addrconf expiration here.
 	 *	Routes are expired even if they are in use.
-	 *
-	 *	Also age clones. Note, that clones are aged out
-	 *	only if they are not in use now.
 	 */
 
 	if (rt->rt6i_flags & RTF_EXPIRES && rt->dst.expires) {
@@ -1915,6 +1898,9 @@ static int fib6_age(struct rt6_info *rt, void *arg)
 			return -1;
 		}
 		gc_args->more++;
+	/* The following part will soon be removed when the exception
+	 * table is hooked up to store all cached routes.
+	 */
 	} else if (rt->rt6i_flags & RTF_CACHE) {
 		if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout))
 			rt->dst.obsolete = DST_OBSOLETE_KILL;
@@ -1940,6 +1926,12 @@ static int fib6_age(struct rt6_info *rt, void *arg)
 		gc_args->more++;
 	}
 
+	/*	Also age clones in the exception table.
+	 *	Note, that clones are aged out
+	 *	only if they are not in use now.
+	 */
+	rt6_age_exceptions(rt, gc_args, now);
+
 	return 0;
 }
 
net/ipv6/route.c +60 -0

66 lines not on this page · raw message

Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#7 lore raw

PATCH 7/16 ipv6: prepare fib6_locate() for exception table

From: Wei Wang <[email protected]>

fib6_locate() is used to find the fib6_node according to the passed in prefix address key. It currently tries to find the fib6_node with the exact match of the passed in key. However, when we move cached routes into the exception table, fib6_locate() will fail to find the fib6_node for it as the cached routes will be stored in the exception table under the fib6_node with the longest prefix match of the cache's dst addr key. This commit adds a new parameter to let the caller specify if it needs exact match or longest prefix match.
Right now, all callers still does exact match when calling fib6_locate(). It will be changed in later commit where exception table is hooked up to store cached routes.

---
 include/net/ip6_fib.h |  3 ++-
 net/ipv6/addrconf.c   |  2 +-
 net/ipv6/ip6_fib.c    | 30 +++++++++++++++++++++++-------
 net/ipv6/route.c      |  5 +++--
 4 files changed, 29 insertions(+), 11 deletions(-)
include/net/ip6_fib.h +2 -1
index 11a79ef87a28..4497a1eb4d41 100644
@@ -357,7 +357,8 @@ struct fib6_node *fib6_lookup(struct fib6_node *root,
 
 struct fib6_node *fib6_locate(struct fib6_node *root,
 			      const struct in6_addr *daddr, int dst_len,
-			      const struct in6_addr *saddr, int src_len);
+			      const struct in6_addr *saddr, int src_len,
+			      bool exact_match);
 
 void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
 		    void *arg);
net/ipv6/addrconf.c +1 -1
index 837418ff2d4b..3ccaf52824c9 100644
@@ -2322,7 +2322,7 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
 		return NULL;
 
 	read_lock_bh(&table->tb6_lock);
-	fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0);
+	fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0, true);
 	if (!fn)
 		goto out;
 
net/ipv6/ip6_fib.c +23 -7
index 3afbe50f2779..b3e4cf0962f8 100644
@@ -1343,14 +1343,21 @@ struct fib6_node *fib6_lookup(struct fib6_node *root, const struct in6_addr *dad
 /*
  *	Get node with specified destination prefix (and source prefix,
  *	if subtrees are used)
+ *	exact_match == true means we try to find fn with exact match of
+ *	the passed in prefix addr
+ *	exact_match == false means we try to find fn with longest prefix
+ *	match of the passed in prefix addr. This is useful for finding fn
+ *	for cached route as it will be stored in the exception table under
+ *	the node with longest prefix length.
  */
 
 
 static struct fib6_node *fib6_locate_1(struct fib6_node *root,
 				       const struct in6_addr *addr,
-				       int plen, int offset)
+				       int plen, int offset,
+				       bool exact_match)
 {
-	struct fib6_node *fn;
+	struct fib6_node *fn, *prev = NULL;
 
 	for (fn = root; fn ; ) {
 		struct rt6key *key = (struct rt6key *)((u8 *)fn->leaf + offset);
@@ -1360,11 +1367,13 @@ static struct fib6_node *fib6_locate_1(struct fib6_node *root,
 		 */
 		if (plen < fn->fn_bit ||
 		    !ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
-			return NULL;
+			goto out;
 
 		if (plen == fn->fn_bit)
 			return fn;
 
+		prev = fn;
+
 		/*
 		 *	We have more bits to go
 		 */
@@ -1373,24 +1382,31 @@ static struct fib6_node *fib6_locate_1(struct fib6_node *root,
 		else
 			fn = fn->left;
 	}
-	return NULL;
+out:
+	if (exact_match)
+		return NULL;
+	else
+		return prev;
 }
 
 struct fib6_node *fib6_locate(struct fib6_node *root,
 			      const struct in6_addr *daddr, int dst_len,
-			      const struct in6_addr *saddr, int src_len)
+			      const struct in6_addr *saddr, int src_len,
+			      bool exact_match)
 {
 	struct fib6_node *fn;
 
 	fn = fib6_locate_1(root, daddr, dst_len,
-			   offsetof(struct rt6_info, rt6i_dst));
+			   offsetof(struct rt6_info, rt6i_dst),
+			   exact_match);
 
 #ifdef CONFIG_IPV6_SUBTREES
 	if (src_len) {
 		WARN_ON(saddr == NULL);
 		if (fn && fn->subtree)
 			fn = fib6_locate_1(fn->subtree, saddr, src_len,
-					   offsetof(struct rt6_info, rt6i_src));
+					   offsetof(struct rt6_info, rt6i_src),
+					   exact_match);
 	}
 #endif
 
net/ipv6/route.c +3 -2
index d2dd55f58b5d..855b4ceec349 100644
@@ -2800,7 +2800,8 @@ static int ip6_route_del(struct fib6_config *cfg,
 
 	fn = fib6_locate(&table->tb6_root,
 			 &cfg->fc_dst, cfg->fc_dst_len,
-			 &cfg->fc_src, cfg->fc_src_len);
+			 &cfg->fc_src, cfg->fc_src_len,
+			 true);
 
 	if (fn) {
 		for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
@@ -3009,7 +3010,7 @@ static struct rt6_info *rt6_get_route_info(struct net *net,
 		return NULL;
 
 	read_lock_bh(&table->tb6_lock);
-	fn = fib6_locate(&table->tb6_root, prefix, prefixlen, NULL, 0);
+	fn = fib6_locate(&table->tb6_root, prefix, prefixlen, NULL, 0, true);
 	if (!fn)
 		goto out;
 
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#8 lore raw

PATCH 8/16 ipv6: hook up exception table to store dst cache

From: Wei Wang <[email protected]>

This commit makes use of the exception hash table implementation to store dst caches created by pmtu discovery and ip redirect into the hash table under the rt_info and no longer inserts these routes into fib6 tree.
This makes the fib6 tree only contain static configured routes and could now be protected by rcu instead of a rw lock.
With this change, in the route lookup related functions, after finding the rt6_info with the longest prefix, we also need to search for the exception table before doing backtracking.
In the route delete function, if the route being deleted is not a dst cache, deletion of this route also need to flush the whole hash table under it. If it is a dst cache, then only delete the cached dst in the hash table.

Note: for fib6_walk_continue() function, w->root now is always pointing to a root node considering that fib6_prune_clones() is removed from the code. So we add a WARN_ON() msg to make sure w->root always points to a root node and also removed the update of w->root in fib6_repair_tree(). This is a prerequisite for later patch because we don't need to make w->root as rcu protected when replacing rwlock with RCU. Also, we remove all prune related variables as it is no longer used.

---
 include/net/ip6_fib.h |   1 -
 net/ipv6/addrconf.c   |   1 -
 net/ipv6/ip6_fib.c    |  95 ++++++++------------------------------------
 net/ipv6/route.c      | 108 +++++++++++++++++++++++++-------------------------
 4 files changed, 72 insertions(+), 133 deletions(-)
include/net/ip6_fib.h +0 -1
index 4497a1eb4d41..d0b7283073e3 100644
@@ -280,7 +280,6 @@ struct fib6_walker {
 	struct fib6_node *root, *node;
 	struct rt6_info *leaf;
 	enum fib6_walk_state state;
-	bool prune;
 	unsigned int skip;
 	unsigned int count;
 	int (*func)(struct fib6_walker *);
net/ipv6/addrconf.c +0 -1
index 3ccaf52824c9..873afafddfc4 100644
@@ -2326,7 +2326,6 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
 	if (!fn)
 		goto out;
 
-	noflags |= RTF_CACHE;
 	for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
 		if (rt->dst.dev->ifindex != dev->ifindex)
 			continue;
net/ipv6/ip6_fib.c +17 -78

187 lines not on this page · raw message

net/ipv6/route.c +55 -53

199 lines not on this page · raw message

Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#9 lore raw

PATCH 9/16 ipv6: grab rt->rt6i_ref before allocating pcpu rt

From: Wei Wang <[email protected]>

After rwlock is replaced with rcu and spinlock, ip6_pol_route() will be called with only rcu held. That means rt6 route deletion could happen simultaneously with rt6_make_pcpu_rt(). This could potentially cause memory leak if rt6_release() is called right before rt6_make_pcpu_rt() on the same route.

This patch grabs rt->rt6i_ref safely before calling rt6_make_pcpu_rt() to make sure rt6_release() will not get triggered while rt6_make_pcpu_rt() is in progress. And rt6_release() is called after rt6_make_pcpu_rt() is finished.

Note: As we are incrementing rt->rt6i_ref in ip6_pol_route(), there is a very slim chance that fib6_purge_rt() will be triggered unnecessarily when deleting a route if ip6_pol_route() running on another thread picks this route as well and tries to make pcpu cache for it.

---
 net/ipv6/route.c | 58 ++++++++++++++++++++++++++++----------------------------
 1 file changed, 29 insertions(+), 29 deletions(-)
net/ipv6/route.c +29 -29
index 65130dde276a..941c062389d2 100644
@@ -1070,7 +1070,6 @@ static struct rt6_info *rt6_get_pcpu_route(struct rt6_info *rt)
 
 static struct rt6_info *rt6_make_pcpu_route(struct rt6_info *rt)
 {
-	struct fib6_table *table = rt->rt6i_table;
 	struct rt6_info *pcpu_rt, *prev, **p;
 
 	pcpu_rt = ip6_rt_pcpu_alloc(rt);
@@ -1081,28 +1080,20 @@ static struct rt6_info *rt6_make_pcpu_route(struct rt6_info *rt)
 		return net->ipv6.ip6_null_entry;
 	}
 
-	read_lock_bh(&table->tb6_lock);
-	if (rt->rt6i_pcpu) {
-		p = this_cpu_ptr(rt->rt6i_pcpu);
-		prev = cmpxchg(p, NULL, pcpu_rt);
-		if (prev) {
-			/* If someone did it before us, return prev instead */
-			dst_release_immediate(&pcpu_rt->dst);
-			pcpu_rt = prev;
-		}
-	} else {
-		/* rt has been removed from the fib6 tree
-		 * before we have a chance to acquire the read_lock.
-		 * In this case, don't brother to create a pcpu rt
-		 * since rt is going away anyway.  The next
-		 * dst_check() will trigger a re-lookup.
-		 */
+	dst_hold(&pcpu_rt->dst);
+	p = this_cpu_ptr(rt->rt6i_pcpu);
+	prev = cmpxchg(p, NULL, pcpu_rt);
+	if (prev) {
+		/* If someone did it before us, return prev instead */
+		/* release refcnt taken by ip6_rt_pcpu_alloc() */
+		dst_release_immediate(&pcpu_rt->dst);
+		/* release refcnt taken by above dst_hold() */
 		dst_release_immediate(&pcpu_rt->dst);
-		pcpu_rt = rt;
+		dst_hold(&prev->dst);
+		pcpu_rt = prev;
 	}
-	dst_hold(&pcpu_rt->dst);
+
 	rt6_dst_from_metrics_check(pcpu_rt);
-	read_unlock_bh(&table->tb6_lock);
 	return pcpu_rt;
 }
 
@@ -1683,19 +1674,28 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 		if (pcpu_rt) {
 			read_unlock_bh(&table->tb6_lock);
 		} else {
-			/* We have to do the read_unlock first
-			 * because rt6_make_pcpu_route() may trigger
-			 * ip6_dst_gc() which will take the write_lock.
-			 */
-			dst_hold(&rt->dst);
-			read_unlock_bh(&table->tb6_lock);
-			pcpu_rt = rt6_make_pcpu_route(rt);
-			dst_release(&rt->dst);
+			/* atomic_inc_not_zero() is needed when using rcu */
+			if (atomic_inc_not_zero(&rt->rt6i_ref)) {
+				/* We have to do the read_unlock first
+				 * because rt6_make_pcpu_route() may trigger
+				 * ip6_dst_gc() which will take the write_lock.
+				 *
+				 * No dst_hold() on rt is needed because grabbing
+				 * rt->rt6i_ref makes sure rt can't be released.
+				 */
+				read_unlock_bh(&table->tb6_lock);
+				pcpu_rt = rt6_make_pcpu_route(rt);
+				rt6_release(rt);
+			} else {
+				/* rt is already removed from tree */
+				read_unlock_bh(&table->tb6_lock);
+				pcpu_rt = net->ipv6.ip6_null_entry;
+				dst_hold(&pcpu_rt->dst);
+			}
 		}
 
 		trace_fib6_table_lookup(net, pcpu_rt, table->tb6_id, fl6);
 		return pcpu_rt;
-
 	}
 }
 EXPORT_SYMBOL_GPL(ip6_pol_route);
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#10 lore raw

PATCH 10/16 ipv6: don't release rt->rt6i_pcpu memory during rt6_release()

From: Wei Wang <[email protected]>

After rwlock is replaced with rcu and spinlock, route lookup can happen simultanously with route deletion.
This patch removes the call to free_percpu(rt->rt6i_pcpu) from rt6_release() to avoid the race condition between rt6_release() and rt6_get_pcpu_route(). And as free_percpu(rt->rt6i_pcpu) is already called in ip6_dst_destroy() after the rcu grace period, it is safe to do this change.

---
 net/ipv6/ip6_fib.c | 3 ---
 1 file changed, 3 deletions(-)
net/ipv6/ip6_fib.c +0 -3
index 9c8e704e6af7..eee392f7b1f6 100644
@@ -190,9 +190,6 @@ void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
 			*ppcpu_rt = NULL;
 		}
 	}
-
-	free_percpu(non_pcpu_rt->rt6i_pcpu);
-	non_pcpu_rt->rt6i_pcpu = NULL;
 }
 EXPORT_SYMBOL_GPL(rt6_free_pcpu);
 
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#11 lore raw

PATCH 11/16 ipv6: replace dst_hold() with dst_hold_safe() in routing code

From: Wei Wang <[email protected]>

With rwlock, it is safe to call dst_hold() in the read thread because read thread is guaranteed to be separated from write thread. However, after we replace rwlock with rcu, it is no longer safe to use dst_hold(). A dst might already have been deleted but is waiting for the rcu grace period to pass before freeing the memory when a read thread is trying to do dst_hold(). This could potentially cause double free issue.

So this commit replaces all dst_hold() with dst_hold_safe() in all read thread to avoid this double free issue.
And in order to make the code more compact, a new function ip6_hold_safe() is introduced. It calls dst_hold_safe() first, and if that fails, it will either fall back to hold and return net->ipv6.ip6_null_entry or set rt to NULL according to the caller's need.

---
 net/ipv6/addrconf.c |  3 ++-
 net/ipv6/route.c    | 71 +++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 54 insertions(+), 20 deletions(-)
net/ipv6/addrconf.c +2 -1
index 873afafddfc4..f86e931d555e 100644
@@ -2333,7 +2333,8 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
 			continue;
 		if ((rt->rt6i_flags & noflags) != 0)
 			continue;
-		dst_hold(&rt->dst);
+		if (!dst_hold_safe(&rt->dst))
+			rt = NULL;
 		break;
 	}
 out:
net/ipv6/route.c +52 -19

145 lines not on this page · raw message

Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#12 lore raw

PATCH 12/16 ipv6: update fn_sernum after route is inserted to tree

From: Wei Wang <[email protected]>

fib6_add() logic currently calls fib6_add_1() to figure out what node should be used for the newly added route and then call fib6_add_rt2node() to insert the route to the node.
And during the call of fib6_add_1(), fn_sernum is updated for all nodes that share the same prefix as the new route.
This does not have issue in the current code because reader thread will not be able to access the tree while writer thread is inserting new route to it. However, it is not the case once we transition to use RCU. Reader thread could potentially see the new fn_sernum before the new route is inserted. As a result, reader thread's route lookup will return a stale route with the new fn_sernum.

In order to solve this issue, we remove all the update of fn_sernum in fib6_add_1(), and instead, introduce a new function that updates fn_sernum for all related nodes and call this functions once the route is successfully inserted to the tree.
Also, smp_wmb() is used after a route is successfully inserted into the fib tree and right before the updated of fn->sernum. And smp_rmb() is used right after fn->sernum is accessed in rt6_get_cookie_safe(). This is to guarantee that when the reader thread sees the new fn->sernum, the new route is already inserted in the tree in memory.

---
 include/net/ip6_fib.h |  2 ++
 net/ipv6/ip6_fib.c    | 39 +++++++++++++++++++++------------------
 2 files changed, 23 insertions(+), 18 deletions(-)
include/net/ip6_fib.h +2 -0
index d0b7283073e3..6bf929b50951 100644
@@ -220,6 +220,8 @@ static inline bool rt6_get_cookie_safe(const struct rt6_info *rt,
 
 	if (fn) {
 		*cookie = fn->fn_sernum;
+		/* pairs with smp_wmb() in fib6_update_sernum_upto_root() */
+		smp_rmb();
 		status = true;
 	}
 
net/ipv6/ip6_fib.c +21 -18
index eee392f7b1f6..f604b311cc3e 100644
@@ -585,7 +585,7 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
 static struct fib6_node *fib6_add_1(struct fib6_node *root,
 				     struct in6_addr *addr, int plen,
 				     int offset, int allow_create,
-				     int replace_required, int sernum,
+				     int replace_required,
 				     struct netlink_ext_ack *extack)
 {
 	struct fib6_node *fn, *in, *ln;
@@ -631,8 +631,6 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
 				fn->leaf = NULL;
 			}
 
-			fn->fn_sernum = sernum;
-
 			return fn;
 		}
 
@@ -641,7 +639,6 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
 		 */
 
 		/* Try to walk down on tree. */
-		fn->fn_sernum = sernum;
 		dir = addr_bit_set(addr, fn->fn_bit);
 		pn = fn;
 		fn = dir ? fn->right : fn->left;
@@ -677,7 +674,6 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
 	ln->fn_bit = plen;
 
 	ln->parent = pn;
-	ln->fn_sernum = sernum;
 
 	if (dir)
 		pn->right = ln;
@@ -737,8 +733,6 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
 		in->leaf = fn->leaf;
 		atomic_inc(&in->leaf->rt6i_ref);
 
-		in->fn_sernum = sernum;
-
 		/* update parent pointer */
 		if (dir)
 			pn->right = in;
@@ -750,8 +744,6 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
 		ln->parent = in;
 		fn->parent = in;
 
-		ln->fn_sernum = sernum;
-
 		if (addr_bit_set(addr, bit)) {
 			in->right = ln;
 			in->left  = fn;
@@ -776,8 +768,6 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
 
 		ln->parent = pn;
 
-		ln->fn_sernum = sernum;
-
 		if (dir)
 			pn->right = ln;
 		else
@@ -1079,6 +1069,20 @@ void fib6_force_start_gc(struct net *net)
 			  jiffies + net->ipv6.sysctl.ip6_rt_gc_interval);
 }
 
+static void fib6_update_sernum_upto_root(struct rt6_info *rt,
+					 int sernum)
+{
+	struct fib6_node *fn = rcu_dereference_protected(rt->rt6i_node,
+				lockdep_is_held(&rt->rt6i_table->tb6_lock));
+
+	/* paired with smp_rmb() in rt6_get_cookie_safe() */
+	smp_wmb();
+	while (fn) {
+		fn->fn_sernum = sernum;
+		fn = fn->parent;
+	}
+}
+
 /*
  *	Add routing information to the routing tree.
  *	<destination addr>/<source addr>
@@ -1111,7 +1115,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
 
 	fn = fib6_add_1(root, &rt->rt6i_dst.addr, rt->rt6i_dst.plen,
 			offsetof(struct rt6_info, rt6i_dst), allow_create,
-			replace_required, sernum, extack);
+			replace_required, extack);
 	if (IS_ERR(fn)) {
 		err = PTR_ERR(fn);
 		fn = NULL;
@@ -1145,15 +1149,13 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
 			sfn->leaf = info->nl_net->ipv6.ip6_null_entry;
 			atomic_inc(&info->nl_net->ipv6.ip6_null_entry->rt6i_ref);
 			sfn->fn_flags = RTN_ROOT;
-			sfn->fn_sernum = sernum;
 
 			/* Now add the first leaf node to new subtree */
 
 			sn = fib6_add_1(sfn, &rt->rt6i_src.addr,
 					rt->rt6i_src.plen,
 					offsetof(struct rt6_info, rt6i_src),
-					allow_create, replace_required, sernum,
-					extack);
+					allow_create, replace_required, extack);
 
 			if (IS_ERR(sn)) {
 				/* If it is failed, discard just allocated
@@ -1172,8 +1174,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
 			sn = fib6_add_1(fn->subtree, &rt->rt6i_src.addr,
 					rt->rt6i_src.plen,
 					offsetof(struct rt6_info, rt6i_src),
-					allow_create, replace_required, sernum,
-					extack);
+					allow_create, replace_required, extack);
 
 			if (IS_ERR(sn)) {
 				err = PTR_ERR(sn);
@@ -1190,8 +1191,10 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
 #endif
 
 	err = fib6_add_rt2node(fn, rt, info, mxc);
-	if (!err)
+	if (!err) {
+		fib6_update_sernum_upto_root(rt, sernum);
 		fib6_start_gc(info->nl_net, rt);
+	}
 
 out:
 	if (err) {
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#13 lore raw

PATCH 13/16 ipv6: check fn->leaf before it is used

From: Wei Wang <[email protected]>

If rwlock is replaced with rcu and spinlock, it is possible that the reader thread will see fn->leaf as NULL in the following scenarios:
1. fib6_add() is in progress and we have already inserted a new node but not yet inserted the route.
2. fib6_del_route() is in progress and we have already set fn->leaf to NULL but not yet freed the node because of rcu grace period.

This patch makes sure all the reader threads check fn->leaf first before using it. And together with later patch to grab rcu_read_lock() and rcu_dereference() fn->leaf, it makes sure reader threads are safe when accessing fn->leaf.

---
 net/ipv6/ip6_fib.c | 23 ++++++++++++++++++-----
 net/ipv6/route.c   | 20 ++++++++++++--------
 2 files changed, 30 insertions(+), 13 deletions(-)
net/ipv6/ip6_fib.c +18 -5
index f604b311cc3e..cf6137e81408 100644
@@ -1279,10 +1279,13 @@ static struct fib6_node *fib6_lookup_1(struct fib6_node *root,
 
 	while (fn) {
 		if (FIB6_SUBTREE(fn) || fn->fn_flags & RTN_RTINFO) {
+			struct rt6_info *leaf = fn->leaf;
 			struct rt6key *key;
 
-			key = (struct rt6key *) ((u8 *) fn->leaf +
-						 args->offset);
+			if (!leaf)
+				goto backtrack;
+
+			key = (struct rt6key *) ((u8 *)leaf + args->offset);
 
 			if (ipv6_prefix_equal(&key->addr, args->addr, key->plen)) {
 #ifdef CONFIG_IPV6_SUBTREES
@@ -1299,9 +1302,7 @@ static struct fib6_node *fib6_lookup_1(struct fib6_node *root,
 					return fn;
 			}
 		}
-#ifdef CONFIG_IPV6_SUBTREES
 backtrack:
-#endif
 		if (fn->fn_flags & RTN_ROOT)
 			break;
 
@@ -1358,7 +1359,18 @@ static struct fib6_node *fib6_locate_1(struct fib6_node *root,
 	struct fib6_node *fn, *prev = NULL;
 
 	for (fn = root; fn ; ) {
-		struct rt6key *key = (struct rt6key *)((u8 *)fn->leaf + offset);
+		struct rt6_info *leaf = fn->leaf;
+		struct rt6key *key;
+
+		/* This node is being deleted */
+		if (!leaf) {
+			if (plen <= fn->fn_bit)
+				goto out;
+			else
+				goto next;
+		}
+
+		key = (struct rt6key *)((u8 *)leaf + offset);
 
 		/*
 		 *	Prefix match
@@ -1372,6 +1384,7 @@ static struct fib6_node *fib6_locate_1(struct fib6_node *root,
 
 		prev = fn;
 
+next:
 		/*
 		 *	We have more bits to go
 		 */
net/ipv6/route.c +12 -8
index aeb349aea429..05dc450af441 100644
@@ -712,6 +712,7 @@ static struct rt6_info *find_match(struct rt6_info *rt, int oif, int strict,
 }
 
 static struct rt6_info *find_rr_leaf(struct fib6_node *fn,
+				     struct rt6_info *leaf,
 				     struct rt6_info *rr_head,
 				     u32 metric, int oif, int strict,
 				     bool *do_rr)
@@ -730,7 +731,7 @@ static struct rt6_info *find_rr_leaf(struct fib6_node *fn,
 		match = find_match(rt, oif, strict, &mpri, match, do_rr);
 	}
 
-	for (rt = fn->leaf; rt && rt != rr_head; rt = rt->dst.rt6_next) {
+	for (rt = leaf; rt && rt != rr_head; rt = rt->dst.rt6_next) {
 		if (rt->rt6i_metric != metric) {
 			cont = rt;
 			break;
@@ -748,17 +749,21 @@ static struct rt6_info *find_rr_leaf(struct fib6_node *fn,
 	return match;
 }
 
-static struct rt6_info *rt6_select(struct fib6_node *fn, int oif, int strict)
+static struct rt6_info *rt6_select(struct net *net, struct fib6_node *fn,
+				   int oif, int strict)
 {
+	struct rt6_info *leaf = fn->leaf;
 	struct rt6_info *match, *rt0;
-	struct net *net;
 	bool do_rr = false;
 
+	if (!leaf)
+		return net->ipv6.ip6_null_entry;
+
 	rt0 = fn->rr_ptr;
 	if (!rt0)
-		fn->rr_ptr = rt0 = fn->leaf;
+		fn->rr_ptr = rt0 = leaf;
 
-	match = find_rr_leaf(fn, rt0, rt0->rt6i_metric, oif, strict,
+	match = find_rr_leaf(fn, leaf, rt0, rt0->rt6i_metric, oif, strict,
 			     &do_rr);
 
 	if (do_rr) {
@@ -766,13 +771,12 @@ static struct rt6_info *rt6_select(struct fib6_node *fn, int oif, int strict)
 
 		/* no entries matched; do round-robin */
 		if (!next || next->rt6i_metric != rt0->rt6i_metric)
-			next = fn->leaf;
+			next = leaf;
 
 		if (next != rt0)
 			fn->rr_ptr = next;
 	}
 
-	net = dev_net(rt0->dst.dev);
 	return match ? match : net->ipv6.ip6_null_entry;
 }
 
@@ -1623,7 +1627,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 		oif = 0;
 
 redo_rt6_select:
-	rt = rt6_select(fn, oif, strict);
+	rt = rt6_select(net, fn, oif, strict);
 	if (rt->rt6i_nsiblings)
 		rt = rt6_multipath_select(rt, fl6, oif, strict);
 	if (rt == net->ipv6.ip6_null_entry) {
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#14 lore raw

PATCH 14/16 ipv6: add key length check into rt6_select()

From: Wei Wang <[email protected]>

After rwlock is replaced with rcu and spinlock, fib6_lookup() could potentially return an intermediate node if other thread is doing fib6_del() on a route which is the only route on the node so that fib6_repair_tree() will be called on this node and potentially assigns fn->leaf to the its child's fn->leaf.

In order to detect this situation in rt6_select(), we have to check if fn->fn_bit is consistent with the key length stored in the route. And depending on if the fn is in the subtree or not, the key is either rt->rt6i_dst or rt->rt6i_src.
If any inconsistency is found, that means the node no longer holds valid routes in it. So net->ipv6.ip6_null_entry is returned.

---
 net/ipv6/route.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
net/ipv6/route.c +14 -0
index 05dc450af441..24b80f43bbfb 100644
@@ -755,6 +755,7 @@ static struct rt6_info *rt6_select(struct net *net, struct fib6_node *fn,
 	struct rt6_info *leaf = fn->leaf;
 	struct rt6_info *match, *rt0;
 	bool do_rr = false;
+	int key_plen;
 
 	if (!leaf)
 		return net->ipv6.ip6_null_entry;
@@ -763,6 +764,19 @@ static struct rt6_info *rt6_select(struct net *net, struct fib6_node *fn,
 	if (!rt0)
 		fn->rr_ptr = rt0 = leaf;
 
+	/* Double check to make sure fn is not an intermediate node
+	 * and fn->leaf does not points to its child's leaf
+	 * (This might happen if all routes under fn are deleted from
+	 * the tree and fib6_repair_tree() is called on the node.)
+	 */
+	key_plen = rt0->rt6i_dst.plen;
+#ifdef CONFIG_IPV6_SUBTREES
+	if (rt0->rt6i_src.plen)
+		key_plen = rt0->rt6i_src.plen;
+#endif
+	if (fn->fn_bit != key_plen)
+		return net->ipv6.ip6_null_entry;
+
 	match = find_rr_leaf(fn, leaf, rt0, rt0->rt6i_metric, oif, strict,
 			     &do_rr);
 
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#15 lore raw

PATCH 15/16 ipv6: replace rwlock with rcu and spinlock in fib6_table

From: Wei Wang <[email protected]>

With all the preparation work before, we are now ready to replace rwlock with rcu and spinlock in fib6_table.
That means now all fib6_node in fib6_table are protected by rcu. And when freeing fib6_node, call_rcu() is used to wait for the rcu grace period before releasing the memory.
When accessing fib6_node, corresponding rcu APIs need to be used. And all previous sessions protected by the write lock will now be protected by the spin lock per table.
All previous sessions protected by read lock will now be protected by rcu_read_lock().

A couple of things to note here:
1. As part of the work of replacing rwlock with rcu, the linked list of fn->leaf now has to be rcu protected as well. So both fn->leaf and rt->dst.rt6_next are now __rcu tagged and corresponding rcu APIs are used when manipulating them.

2. For fn->rr_ptr, first of all, it also needs to be rcu protected now and is tagged with __rcu and rcu APIs are used in corresponding places. Secondly, fn->rr_ptr is changed in rt6_select() which is a reader thread. This makes the issue a bit complicated. We think a valid solution for it is to let rt6_select() grab the tb6_lock if it decides to change it. As it is not in the normal operation and only happens when there is no valid neighbor cache for the route, we think the performance impact should be low.

3. fib6_walk_continue() has to be called with tb6_lock held even in the route dumping related functions, e.g. inet6_dump_fib(), fib6_tables_dump() and ipv6_route_seq_ops. It is because fib6_walk_continue() makes modifications to the walker structure, and so are fib6_repair_tree() and fib6_del_route(). In order to do proper syncing between them, we need to let fib6_walk_continue() hold the lock. We may be able to do further improvement on the way we do the tree walk to get rid of the need for holding the spin lock. But not for now.

4. When fib6_del_route() removes a route from the tree, we no longer mark rt->dst.rt6_next to NULL to make simultaneous reader be able to further traverse the list with rcu. However, rt->dst.rt6_next is only valid within this same rcu period. No one should access it later.

5. All the operation of atomic_inc(rt->rt6i_ref) is changed to be performed before we publish this route (either by linking it to fn->leaf or insert it in the list pointed by fn->leaf) just to be safe because as soon as we publish the route, some read thread will be able to access it.

---
 include/net/dst.h     |   2 +-
 include/net/ip6_fib.h |  24 ++-
 net/ipv6/addrconf.c   |  11 +-
 net/ipv6/ip6_fib.c    | 405 ++++++++++++++++++++++++++++++--------------------
 net/ipv6/route.c      | 121 ++++++++-------
 5 files changed, 333 insertions(+), 230 deletions(-)
include/net/dst.h +1 -1
index 06a6765da074..204c19e25456 100644
@@ -101,7 +101,7 @@ struct dst_entry {
 	union {
 		struct dst_entry	*next;
 		struct rtable __rcu	*rt_next;
-		struct rt6_info		*rt6_next;
+		struct rt6_info __rcu	*rt6_next;
 		struct dn_route __rcu	*dn_next;
 	};
 };
include/net/ip6_fib.h +16 -8
index 6bf929b50951..0b438b9bcb10 100644
@@ -68,18 +68,18 @@ struct fib6_config {
 };
 
 struct fib6_node {
-	struct fib6_node	*parent;
-	struct fib6_node	*left;
-	struct fib6_node	*right;
+	struct fib6_node __rcu	*parent;
+	struct fib6_node __rcu	*left;
+	struct fib6_node __rcu	*right;
 #ifdef CONFIG_IPV6_SUBTREES
-	struct fib6_node	*subtree;
+	struct fib6_node __rcu	*subtree;
 #endif
-	struct rt6_info		*leaf;
+	struct rt6_info __rcu	*leaf;
 
 	__u16			fn_bit;		/* bit key */
 	__u16			fn_flags;
 	int			fn_sernum;
-	struct rt6_info		*rr_ptr;
+	struct rt6_info __rcu	*rr_ptr;
 	struct rcu_head		rcu;
 };
 
@@ -91,7 +91,7 @@ struct fib6_gc_args {
 #ifndef CONFIG_IPV6_SUBTREES
 #define FIB6_SUBTREE(fn)	NULL
 #else
-#define FIB6_SUBTREE(fn)	((fn)->subtree)
+#define FIB6_SUBTREE(fn)	(rcu_dereference_protected((fn)->subtree, 1))
 #endif
 
 struct mx6_config {
@@ -174,6 +174,14 @@ struct rt6_info {
 					unused:7;
 };
 
+#define for_each_fib6_node_rt_rcu(fn)					\
+	for (rt = rcu_dereference((fn)->leaf); rt;			\
+	     rt = rcu_dereference(rt->dst.rt6_next))
+
+#define for_each_fib6_walker_rt(w)					\
+	for (rt = (w)->leaf; rt;					\
+	     rt = rcu_dereference_protected(rt->dst.rt6_next, 1))
+
 static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
 {
 	return ((struct rt6_info *)dst)->rt6i_idev;
@@ -310,7 +318,7 @@ struct rt6_statistics {
 struct fib6_table {
 	struct hlist_node	tb6_hlist;
 	u32			tb6_id;
-	rwlock_t		tb6_lock;
+	spinlock_t		tb6_lock;
 	struct fib6_node	tb6_root;
 	struct inet_peer_base	tb6_peers;
 	unsigned int		flags;
net/ipv6/addrconf.c +5 -6
index f86e931d555e..9854d93e45bb 100644
@@ -2321,12 +2321,12 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
 	if (!table)
 		return NULL;
 
-	read_lock_bh(&table->tb6_lock);
+	rcu_read_lock();
 	fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0, true);
 	if (!fn)
 		goto out;
 
-	for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
+	for_each_fib6_node_rt_rcu(fn) {
 		if (rt->dst.dev->ifindex != dev->ifindex)
 			continue;
 		if ((rt->rt6i_flags & flags) != flags)
@@ -2338,7 +2338,7 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
 		break;
 	}
 out:
-	read_unlock_bh(&table->tb6_lock);
+	rcu_read_unlock();
 	return rt;
 }
 
@@ -5898,10 +5898,9 @@ void addrconf_disable_policy_idev(struct inet6_dev *idev, int val)
 		spin_lock(&ifa->lock);
 		if (ifa->rt) {
 			struct rt6_info *rt = ifa->rt;
-			struct fib6_table *table = rt->rt6i_table;
 			int cpu;
 
-			read_lock(&table->tb6_lock);
+			rcu_read_lock();
 			addrconf_set_nopolicy(ifa->rt, val);
 			if (rt->rt6i_pcpu) {
 				for_each_possible_cpu(cpu) {
@@ -5911,7 +5910,7 @@ void addrconf_disable_policy_idev(struct inet6_dev *idev, int val)
 					addrconf_set_nopolicy(*rtp, val);
 				}
 			}
-			read_unlock(&table->tb6_lock);
+			rcu_read_unlock();
 		}
 		spin_unlock(&ifa->lock);
 	}
net/ipv6/ip6_fib.c +244 -161

941 lines not on this page · raw message

net/ipv6/route.c +67 -54

354 lines not on this page · raw message

Signature · 1 line
2.14.2.920.gcf0c67979c-goog
author
#16 lore raw

PATCH 16/16 ipv6: take care of rt6_stats

From: Wei Wang <[email protected]>

Currently, most of the rt6_stats are not hooked up correctly. As the last part of this patch series, hook up all existing rt6_stats and add one new stat fib_rt_uncache to indicate the number of routes in the uncached list.
For details of the stats, please refer to the comments added in include/net/ip6_fib.h.

Note: fib_rt_alloc and fib_rt_uncache are not guaranteed to be modified under a lock. So atomic_t is used for them.

---
 include/net/ip6_fib.h | 15 +++++++++------
 net/ipv6/ip6_fib.c    | 42 ++++++++++++++++++++++++------------------
 net/ipv6/route.c      | 16 ++++++++++++++--
 3 files changed, 47 insertions(+), 26 deletions(-)
include/net/ip6_fib.h +9 -6
index 0b438b9bcb10..10c913816032 100644
@@ -297,12 +297,15 @@ struct fib6_walker {
 };
 
 struct rt6_statistics {
-	__u32		fib_nodes;
-	__u32		fib_route_nodes;
-	__u32		fib_rt_alloc;		/* permanent routes	*/
-	__u32		fib_rt_entries;		/* rt entries in table	*/
-	__u32		fib_rt_cache;		/* cache routes		*/
-	__u32		fib_discarded_routes;
+	__u32		fib_nodes;		/* all fib6 nodes */
+	__u32		fib_route_nodes;	/* intermediate nodes */
+	__u32		fib_rt_entries;		/* rt entries in fib table */
+	__u32		fib_rt_cache;		/* cached rt entries in exception table */
+	__u32		fib_discarded_routes;	/* total number of routes delete */
+
+	/* The following stats are not protected by any lock */
+	atomic_t	fib_rt_alloc;		/* total number of routes alloced */
+	atomic_t	fib_rt_uncache;		/* rt entries in uncached list */
 };
 
 #define RTN_TL_ROOT	0x0001
net/ipv6/ip6_fib.c +24 -18

136 lines not on this page · raw message

net/ipv6/route.c +14 -2
index cf44d0994b1e..399d1bceec4a 100644
@@ -143,9 +143,11 @@ static void rt6_uncached_list_del(struct rt6_info *rt)
 {
 	if (!list_empty(&rt->rt6i_uncached)) {
 		struct uncached_list *ul = rt->rt6i_uncached_list;
+		struct net *net = dev_net(rt->dst.dev);
 
 		spin_lock_bh(&ul->lock);
 		list_del(&rt->rt6i_uncached);
+		atomic_dec(&net->ipv6.rt6_stats->fib_rt_uncache);
 		spin_unlock_bh(&ul->lock);
 	}
 }
@@ -359,8 +361,10 @@ static struct rt6_info *__ip6_dst_alloc(struct net *net,
 	struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev,
 					1, DST_OBSOLETE_FORCE_CHK, flags);
 
-	if (rt)
+	if (rt) {
 		rt6_info_init(rt);
+		atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc);
+	}
 
 	return rt;
 }
@@ -1156,6 +1160,8 @@ static DEFINE_SPINLOCK(rt6_exception_lock);
 static void rt6_remove_exception(struct rt6_exception_bucket *bucket,
 				 struct rt6_exception *rt6_ex)
 {
+	struct net *net = dev_net(rt6_ex->rt6i->dst.dev);
+
 	if (!bucket || !rt6_ex)
 		return;
 	rt6_ex->rt6i->rt6i_node = NULL;
@@ -1164,6 +1170,7 @@ static void rt6_remove_exception(struct rt6_exception_bucket *bucket,
 	kfree_rcu(rt6_ex, rcu);
 	WARN_ON_ONCE(!bucket->depth);
 	bucket->depth--;
+	net->ipv6.rt6_stats->fib_rt_cache--;
 }
 
 /* Remove oldest rt6_ex in bucket and free the memory
@@ -1270,6 +1277,7 @@ __rt6_find_exception_rcu(struct rt6_exception_bucket **bucket,
 static int rt6_insert_exception(struct rt6_info *nrt,
 				struct rt6_info *ort)
 {
+	struct net *net = dev_net(ort->dst.dev);
 	struct rt6_exception_bucket *bucket;
 	struct in6_addr *src_key = NULL;
 	struct rt6_exception *rt6_ex;
@@ -1339,6 +1347,7 @@ static int rt6_insert_exception(struct rt6_info *nrt,
 	nrt->rt6i_node = ort->rt6i_node;
 	hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain);
 	bucket->depth++;
+	net->ipv6.rt6_stats->fib_rt_cache++;
 
 	if (bucket->depth > FIB6_MAX_DEPTH)
 		rt6_exception_remove_oldest(bucket);
@@ -1714,6 +1723,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
 			 * No need for another dst_hold()
 			 */
 			rt6_uncached_list_add(uncached_rt);
+			atomic_inc(&net->ipv6.rt6_stats->fib_rt_uncache);
 		} else {
 			uncached_rt = net->ipv6.ip6_null_entry;
 			dst_hold(&uncached_rt->dst);
@@ -1894,6 +1904,7 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori
 		       DST_OBSOLETE_NONE, 0);
 	if (rt) {
 		rt6_info_init(rt);
+		atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc);
 
 		new = &rt->dst;
 		new->__use = 1;
@@ -2341,6 +2352,7 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
 	 * do proper release of the net_device
 	 */
 	rt6_uncached_list_add(rt);
+	atomic_inc(&net->ipv6.rt6_stats->fib_rt_uncache);
 
 	dst = xfrm_lookup(net, &rt->dst, flowi6_to_flowi(fl6), NULL, 0);
 
@@ -4422,7 +4434,7 @@ static int rt6_stats_seq_show(struct seq_file *seq, void *v)
 	seq_printf(seq, "%04x %04x %04x %04x %04x %04x %04x\n",
 		   net->ipv6.rt6_stats->fib_nodes,
 		   net->ipv6.rt6_stats->fib_route_nodes,
-		   net->ipv6.rt6_stats->fib_rt_alloc,
+		   atomic_read(&net->ipv6.rt6_stats->fib_rt_alloc),
 		   net->ipv6.rt6_stats->fib_rt_entries,
 		   net->ipv6.rt6_stats->fib_rt_cache,
 		   dst_entries_get_slow(&net->ipv6.ip6_dst_ops),
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
#17 lore raw

Re: [PATCH net-next 11/16] ipv6: replace dst_hold() with dst_hold_safe() in routing code

In reply to Wei Wang

Hi,

2017-10-07 4:06 GMT+09:00 Wei Wang <[email protected]>:

net/ipv6/route.c

Quoted 4 lines
net/ipv6/route.c +0 -0
index 941c062389d2..aeb349aea429 100644

:

Quoted 13 lines
net/ipv6/route.c +7 -2
@@ -1625,12 +1643,17 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
        if (rt_cache)
                rt = rt_cache;
 
-       if (rt == net->ipv6.ip6_null_entry || (rt->rt6i_flags & RTF_CACHE)) {
-               dst_use(&rt->dst, jiffies);
+       if (rt == net->ipv6.ip6_null_entry) {
+               read_unlock_bh(&table->tb6_lock);
+               dst_hold(&rt->dst);
+               trace_fib6_table_lookup(net, rt, table->tb6_id, fl6);
+               return rt;
+       } else if (rt->rt6i_flags & RTF_CACHE) {
+               if (ip6_hold_safe(net, &rt, true)) {

net/ipv6/route.c struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, · line 1659

Quoted 10 lines
net/ipv6/route.c +3 -3
+                       dst_use_noref(&rt->dst, jiffies);
+                       rt6_dst_from_metrics_check(rt);
+               }
                read_unlock_bh(&table->tb6_lock);
-
-               rt6_dst_from_metrics_check(rt);
-
                trace_fib6_table_lookup(net, rt, table->tb6_id, fl6);
                return rt;
        } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) &&

Is it intended to move rt6_dst_from_metrics_check() inside the table lock?

--yoshfuji

author
#18 lore raw

Re: [PATCH net-next 11/16] ipv6: replace dst_hold() with dst_hold_safe() in routing code

Quoted 25 lines · 吉藤英明

Hi,

2017-10-07 4:06 GMT+09:00 Wei Wang <[email protected]>:

net/ipv6/route.c

Quoted 4 lines
net/ipv6/route.c +0 -0
index 941c062389d2..aeb349aea429 100644

:

Quoted 17 lines
net/ipv6/route.c +10 -2
@@ -1625,12 +1643,17 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
        if (rt_cache)
                rt = rt_cache;
 
-       if (rt == net->ipv6.ip6_null_entry || (rt->rt6i_flags & RTF_CACHE)) {
-               dst_use(&rt->dst, jiffies);
+       if (rt == net->ipv6.ip6_null_entry) {
+               read_unlock_bh(&table->tb6_lock);
+               dst_hold(&rt->dst);
+               trace_fib6_table_lookup(net, rt, table->tb6_id, fl6);
+               return rt;
+       } else if (rt->rt6i_flags & RTF_CACHE) {
+               if (ip6_hold_safe(net, &rt, true)) {
+                       dst_use_noref(&rt->dst, jiffies);
+                       rt6_dst_from_metrics_check(rt);
+               }
                read_unlock_bh(&table->tb6_lock);
Quoted 9 lines

net/ipv6/route.c struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, · line 1659

Quoted 6 lines
net/ipv6/route.c +0 -3
-
-               rt6_dst_from_metrics_check(rt);
-
                trace_fib6_table_lookup(net, rt, table->tb6_id, fl6);
                return rt;
        } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) &&

Is it intended to move rt6_dst_from_metrics_check() inside the table lock?

I think it doesn't really matter whether rt6_dst_from_metrics_check() is inside the table lock or not. The code looks cleaner if we put it inside the if (ip6_hold_safe()) {} block because we don't want to do rt6_dst_from_metrics_check() if ip6_hold_safe() returns false.

Quoted 1 line

--yoshfuji

maintainer
#19 lore raw

Re: [PATCH net-next 11/16] ipv6: replace dst_hold() with dst_hold_safe() in routing code

In reply to 吉藤英明

From: 吉藤英明 <[email protected]>
Date: Sat, 7 Oct 2017 08:57:49 +0900

Quoted 25 lines

Hi,

2017-10-07 4:06 GMT+09:00 Wei Wang <[email protected]>:

net/ipv6/route.c

Quoted 4 lines
net/ipv6/route.c +0 -0
index 941c062389d2..aeb349aea429 100644

:

Quoted 17 lines
net/ipv6/route.c +10 -2
@@ -1625,12 +1643,17 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
        if (rt_cache)
                rt = rt_cache;
 
-       if (rt == net->ipv6.ip6_null_entry || (rt->rt6i_flags & RTF_CACHE)) {
-               dst_use(&rt->dst, jiffies);
+       if (rt == net->ipv6.ip6_null_entry) {
+               read_unlock_bh(&table->tb6_lock);
+               dst_hold(&rt->dst);
+               trace_fib6_table_lookup(net, rt, table->tb6_id, fl6);
+               return rt;
+       } else if (rt->rt6i_flags & RTF_CACHE) {
+               if (ip6_hold_safe(net, &rt, true)) {
+                       dst_use_noref(&rt->dst, jiffies);
+                       rt6_dst_from_metrics_check(rt);
+               }
                read_unlock_bh(&table->tb6_lock);
Quoted 8 lines

net/ipv6/route.c struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, · line 1659

Quoted 6 lines
net/ipv6/route.c +0 -3
-
-               rt6_dst_from_metrics_check(rt);
-
                trace_fib6_table_lookup(net, rt, table->tb6_id, fl6);
                return rt;
        } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) &&

Is it intended to move rt6_dst_from_metrics_check() inside the table lock?

That lock is replaced with rcu_read_unlock() or similar in patch #15 so I don't think it matters much in the end.

Reviewed-by on the v1 series
#20 lore raw
In reply to Wei Wang
Quoted 82 lines · Wei Wang

From: Wei Wang <[email protected]>

Currently, fib6 table is protected by rwlock. During route lookup, reader lock is taken and during route insertion, deletion or modification, writer lock is taken. This is a very inefficient implementation because the fastpath always has to do the operation to grab the reader lock.
According to my latest syn flood test on an iota ivybridage machine with 2 10G mlx nics bonded together, each with 8 rx queues on 2 NUMA nodes, and with the upstream net-next kernel:
ipv4 stack can handle around 4.2Mpps
ipv6 stack can handle around 1.3Mpps

In order to close the gap of the performance number between ipv4 and ipv6 stack, this patch series tries to get rid of the usage of the rwlock and replace it with rcu and spinlock protection. This will greatly speed up the fastpath performance as it only needs to hold rcu which is much less expensive than grabbing the reader lock. It also makes ipv6 fib implementation more consistent with ipv4.

In order to be able to replace the current rwlock with rcu and spinlock, some preparation work is needed:
Patch 1-8 introduces a per-route hash table (protected by rcu and a different spinlock) to store all cached routes created by pmtu and ip redirect under its main route. This makes the main fib6 tree only contain static routes.
Patch 9-14 prepares all the reader path to be ready to tolerate concurrent writer.
Patch 15 finally does the rwlock to rcu and spinlock conversion. Patch 16 takes care of rt6_stats.

After this patch series, in the same syn flood test,
ipv6 stack can now handle around 3.5Mpps compared to previous 1.3Mpps in my test setup.

After this patch series, there are still some improvements that should be done in ipv6 stack:
1. During route lookup, dst_use() is called everytime on the selected route to update dst->__use and dst->lastuse. This dirties the cacheline and causes extra cacheline miss and should be avoided.
2. when no route is found in the current table, net->ip6.ipv6_null_entry is used and refcnt is taken on it. As there is no pcpu cache for this specific route, frequent change on the refcnt for this route causes quite some cacheline misses.
And to make things worse, if CONFIG_IPV6_MULTIPLE_TABLES is defined, output path route lookup always starts with local table first and guarantees to hit net->ipv6.ip6_null_entry before continuing to do lookup in the main table.
These operations on net->ipv6.ip6_null_entry could potentially be avoided.
3. ipv6 input path route lookup grabs refcnt on dst. This is different from ipv4. We could potentially change this behavior to let ipv6 input path route lookup not to grab refcnt on dst. However, it does not give us much performance boost as we currently have pcpu route cache for input path as well in ipv6. But this work probably is still worth doing to unify ipv6 and ipv4 route lookup behavior.

The above issues will be addressed separately after this patch series has been accepted.

This is a joint work with Martin KaFai Lau and Eric Dumazet. And many many thanks to them for their inspiring ideas and big big code review efforts.

Wei Wang (16):
ipv6: introduce a new function fib6_update_sernum()
ipv6: introduce a hash table to store dst cache
ipv6: prepare fib6_remove_prefsrc() for exception table
ipv6: prepare rt6_mtu_change() for exception table
ipv6: prepare rt6_clean_tohost() for exception table
ipv6: prepare fib6_age() for exception table
ipv6: prepare fib6_locate() for exception table
ipv6: hook up exception table to store dst cache
ipv6: grab rt->rt6i_ref before allocating pcpu rt
ipv6: don't release rt->rt6i_pcpu memory during rt6_release()
ipv6: replace dst_hold() with dst_hold_safe() in routing code
ipv6: update fn_sernum after route is inserted to tree
ipv6: check fn->leaf before it is used
ipv6: add key length check into rt6_select()
ipv6: replace rwlock with rcu and spinlock in fib6_table
ipv6: take care of rt6_stats

Quoted 8 lines
 include/net/dst.h       |   2 +-
 include/net/ip6_fib.h   |  79 ++++-
 include/net/ip6_route.h |   5 +
 net/ipv6/addrconf.c     |  17 +-
 net/ipv6/ip6_fib.c      | 645 ++++++++++++++++++----------------
 net/ipv6/route.c        | 901 ++++++++++++++++++++++++++++++++++++++++--------
 6 files changed, 1179 insertions(+), 470 deletions(-)

Awesome work Wei.

For the whole series :

Thanks !

Reviewed-by YOSHIFUJI Hideaki
#21 lore raw

Hi,

2017-10-07 8:49 GMT+09:00 Eric Dumazet <[email protected]>:

Quoted 92 lines · Wei Wang
Quoted 82 lines

From: Wei Wang <[email protected]>

Currently, fib6 table is protected by rwlock. During route lookup, reader lock is taken and during route insertion, deletion or modification, writer lock is taken. This is a very inefficient implementation because the fastpath always has to do the operation to grab the reader lock.
According to my latest syn flood test on an iota ivybridage machine with 2 10G mlx nics bonded together, each with 8 rx queues on 2 NUMA nodes, and with the upstream net-next kernel:
ipv4 stack can handle around 4.2Mpps
ipv6 stack can handle around 1.3Mpps

In order to close the gap of the performance number between ipv4 and ipv6 stack, this patch series tries to get rid of the usage of the rwlock and replace it with rcu and spinlock protection. This will greatly speed up the fastpath performance as it only needs to hold rcu which is much less expensive than grabbing the reader lock. It also makes ipv6 fib implementation more consistent with ipv4.

In order to be able to replace the current rwlock with rcu and spinlock, some preparation work is needed:
Patch 1-8 introduces a per-route hash table (protected by rcu and a different spinlock) to store all cached routes created by pmtu and ip redirect under its main route. This makes the main fib6 tree only contain static routes.
Patch 9-14 prepares all the reader path to be ready to tolerate concurrent writer.
Patch 15 finally does the rwlock to rcu and spinlock conversion. Patch 16 takes care of rt6_stats.

After this patch series, in the same syn flood test,
ipv6 stack can now handle around 3.5Mpps compared to previous 1.3Mpps in my test setup.

After this patch series, there are still some improvements that should be done in ipv6 stack:
1. During route lookup, dst_use() is called everytime on the selected route to update dst->__use and dst->lastuse. This dirties the cacheline and causes extra cacheline miss and should be avoided.
2. when no route is found in the current table, net->ip6.ipv6_null_entry is used and refcnt is taken on it. As there is no pcpu cache for this specific route, frequent change on the refcnt for this route causes quite some cacheline misses.
And to make things worse, if CONFIG_IPV6_MULTIPLE_TABLES is defined, output path route lookup always starts with local table first and guarantees to hit net->ipv6.ip6_null_entry before continuing to do lookup in the main table.
These operations on net->ipv6.ip6_null_entry could potentially be avoided.
3. ipv6 input path route lookup grabs refcnt on dst. This is different from ipv4. We could potentially change this behavior to let ipv6 input path route lookup not to grab refcnt on dst. However, it does not give us much performance boost as we currently have pcpu route cache for input path as well in ipv6. But this work probably is still worth doing to unify ipv6 and ipv4 route lookup behavior.

The above issues will be addressed separately after this patch series has been accepted.

This is a joint work with Martin KaFai Lau and Eric Dumazet. And many many thanks to them for their inspiring ideas and big big code review efforts.

Wei Wang (16):
ipv6: introduce a new function fib6_update_sernum()
ipv6: introduce a hash table to store dst cache
ipv6: prepare fib6_remove_prefsrc() for exception table
ipv6: prepare rt6_mtu_change() for exception table
ipv6: prepare rt6_clean_tohost() for exception table
ipv6: prepare fib6_age() for exception table
ipv6: prepare fib6_locate() for exception table
ipv6: hook up exception table to store dst cache
ipv6: grab rt->rt6i_ref before allocating pcpu rt
ipv6: don't release rt->rt6i_pcpu memory during rt6_release()
ipv6: replace dst_hold() with dst_hold_safe() in routing code
ipv6: update fn_sernum after route is inserted to tree
ipv6: check fn->leaf before it is used
ipv6: add key length check into rt6_select()
ipv6: replace rwlock with rcu and spinlock in fib6_table
ipv6: take care of rt6_stats

Quoted 8 lines
 include/net/dst.h       |   2 +-
 include/net/ip6_fib.h   |  79 ++++-
 include/net/ip6_route.h |   5 +
 net/ipv6/addrconf.c     |  17 +-
 net/ipv6/ip6_fib.c      | 645 ++++++++++++++++++----------------
 net/ipv6/route.c        | 901 ++++++++++++++++++++++++++++++++++++++++--------
 6 files changed, 1179 insertions(+), 470 deletions(-)
Quoted 5 lines

Awesome work Wei.

For the whole series :

It looks ok to me.

Quoted 4 lines

Thanks !

maintainer
#22 lore raw

From: 吉藤英明 <[email protected]>
Date: Sat, 7 Oct 2017 18:25:13 +0900

Quoted 23 lines

Hi,

2017-10-07 8:49 GMT+09:00 Eric Dumazet <[email protected]>:

Quoted 20 lines · Wei Wang
Quoted 19 lines

From: Wei Wang <[email protected]>

Currently, fib6 table is protected by rwlock. During route lookup, reader lock is taken and during route insertion, deletion or modification, writer lock is taken. This is a very inefficient implementation because the fastpath always has to do the operation to grab the reader lock.
According to my latest syn flood test on an iota ivybridage machine with 2 10G mlx nics bonded together, each with 8 rx queues on 2 NUMA nodes, and with the upstream net-next kernel:
ipv4 stack can handle around 4.2Mpps
ipv6 stack can handle around 1.3Mpps

In order to close the gap of the performance number between ipv4 and ipv6 stack, this patch series tries to get rid of the usage of the rwlock and replace it with rcu and spinlock protection. This will greatly speed up the fastpath performance as it only needs to hold rcu which is much less expensive than grabbing the reader lock. It also makes ipv6 fib implementation more consistent with ipv4.

...

Quoted 8 lines
Quoted 5 lines

Awesome work Wei.

For the whole series :

It looks ok to me.

I have some reservations about these changes, fib6_info gets bigger, etc.

And even with the amazing developers that helped review and audit these changes already, I can guarantee there are some bugs in here just like there were bugs in the ipv4 routing cache removal I did :-)

But those don't block integration, for sure.

So series applied, thanks a lot for doing this!

I think there is some code that doesn't use proper RCU accessors for rt6i_exception_bucket. For example there are some assignments of it to NULL that should use RCU_ASSIGN_FOO() or similar. Please take a lok and fix those up.

Thanks!

#23 lore raw

BUG: using smp_processor_id() in preemptible [00000000]

In reply to Wei Wang

Hi!

This appeared in net-next over the weekend - looks likely related to this set...

[  164.456668] BUG: using smp_processor_id() in preemptible [00000000] code: sshd/1255
[  164.472259] caller is ip6_pol_route+0xe88/0x4a80
[  164.477571] CPU: 10 PID: 1255 Comm: sshd Not tainted 4.14.0-rc3-debug-00960-g58e545033ed7 #312
[  164.487350] Hardware name: Dell Inc. PowerEdge R730/072T6D, BIOS 2.3.4 11/08/2016
[  164.495884] Call Trace:
[  164.498771]  dump_stack+0xb3/0x140
[  164.502720]  ? _atomic_dec_and_lock+0x2b0/0x2b0
[  164.507909]  ? __lock_is_held+0xcf/0x1a0
[  164.512492]  check_preemption_disabled+0x1a0/0x1d0
[  164.517974]  ip6_pol_route+0xe88/0x4a80
[  164.522402]  ? ip6_rt_update_pmtu+0xc0/0xc0
[  164.527205]  ? unwind_get_return_address+0x5f/0xc0
[  164.532685]  ? print_usage_bug+0x5a0/0x5a0
[  164.537399]  ? lock_downgrade+0x740/0x740
[  164.542000]  ? deref_stack_reg+0x75/0x230
[  164.546605]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.553158]  ? print_usage_bug+0x5a0/0x5a0
[  164.557859]  ? bpf_prog_alloc+0x330/0x330
[  164.562467]  ? lock_downgrade+0x740/0x740
[  164.567076]  ? __mod_tree_remove+0x40/0x40
[  164.571774]  ? deref_stack_reg+0x75/0x230
[  164.576414]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.582964]  ? deref_stack_reg+0x230/0x230
[  164.587676]  ? __free_insn_slot+0x970/0x970
[  164.592507]  ? print_usage_bug+0x5a0/0x5a0
[  164.597203]  ? deref_stack_reg+0x75/0x230
[  164.601804]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.608412]  ? show_rcu_gp_kthreads+0x160/0x160
[  164.613601]  ? is_bpf_text_address+0xa4/0x130
[  164.618590]  ? bpf_prog_alloc+0x330/0x330
[  164.623194]  ? kernel_text_address+0xec/0x120
[  164.628200]  ? cyc2ns_read_end+0x20/0x20
[  164.632705]  ? __mod_tree_remove+0x40/0x40
[  164.637403]  ? deref_stack_reg+0x75/0x230
[  164.642006]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.648552]  ? deref_stack_reg+0x75/0x230
[  164.653165]  ? sched_clock_cpu+0x18/0x290
[  164.657768]  ? lock_downgrade+0x740/0x740
[  164.662383]  ? bpf_prog_alloc+0x330/0x330
[  164.666978]  ? lock_downgrade+0x740/0x740
[  164.671581]  ? debug_check_no_locks_freed+0x2f0/0x2f0
[  164.677425]  ? deref_stack_reg+0x75/0x230
[  164.677432]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.677438]  ? deref_stack_reg+0x230/0x230
[  164.677445]  ? deref_stack_reg+0x230/0x230
[  164.677458]  ? rcu_read_lock_held+0xc0/0xc0
[  164.677466]  ? __free_insn_slot+0x970/0x970
[  164.677476]  ? rcu_is_watching+0x59/0x1f0
[  164.677483]  ? show_rcu_gp_kthreads+0x160/0x160
[  164.677496]  ? is_bpf_text_address+0xa4/0x130
[  164.677504]  ? kernel_text_address+0xec/0x120
[  164.677509]  ? __kernel_text_address+0xe/0x30
[  164.677516]  ? __kernel_text_address+0xe/0x30
[  164.677523]  ? unwind_get_return_address+0x5f/0xc0
[  164.677532]  ? __save_stack_trace+0x83/0x120
[  164.677549]  ? __lock_acquire+0x1fcf/0x4440
[  164.677557]  ? save_trace+0x350/0x350
[  164.677566]  ? cyc2ns_read_end+0x20/0x20
[  164.677580]  ? debug_check_no_locks_freed+0x2f0/0x2f0
[  164.677589]  ? ip6_pol_route_input+0x90/0x90
[  164.677595]  fib6_rule_lookup+0x10a/0x750
[  164.677604]  ? fib6_rules_seq_read+0x10/0x10
[  164.677623]  ? lock_downgrade+0x740/0x740
[  164.677631]  ? ip6_route_output_flags+0x1ff/0x310
[  164.677642]  ip6_dst_lookup_tail+0x4ce/0xd50
[  164.677671]  ip6_dst_lookup_flow+0xce/0x2a0
[  164.677679]  ? ip6_dst_lookup+0x90/0x90
[  164.677684]  ? __lock_is_held+0xcf/0x1a0
[  164.677690]  ? show_rcu_gp_kthreads+0x160/0x160
[  164.677704]  ip6_datagram_dst_update+0x728/0x1b00
[  164.677711]  ? cyc2ns_read_end+0x20/0x20
[  164.677721]  ? ip6_datagram_send_ctl+0x1400/0x1400
[  164.677733]  ? print_usage_bug+0x5a0/0x5a0
[  164.677741]  ? sched_clock_cpu+0x18/0x290
[  164.677759]  ? lock_downgrade+0x740/0x740
[  164.677765]  ? get_lock_stats+0x18/0x160
[  164.677788]  ? __ip6_datagram_connect+0x51b/0x1410
[  164.677793]  __ip6_datagram_connect+0x51b/0x1410
[  164.677803]  ? ip6_datagram_release_cb+0x5f0/0x5f0
[  164.677809]  ? mark_held_locks+0xce/0x170
[  164.677817]  ? __local_bh_enable_ip+0x5f/0xa0
[  164.677830]  ip6_datagram_connect+0x27/0x40
[  164.677839]  SYSC_connect+0x1e8/0x4a0
[  164.677847]  ? SYSC_bind+0x3e0/0x3e0
[  164.677856]  ? get_unused_fd_flags+0x133/0x210
[  164.677863]  ? trace_raw_output_sys_exit+0x110/0x110
[  164.677874]  ? __close_fd+0x242/0x400
[  164.677883]  ? sock_map_fd+0x3d/0x60
[  164.677893]  ? entry_SYSCALL_64_fastpath+0x5/0xb1
[  164.677901]  ? trace_hardirqs_on_caller+0x3cb/0x680
[  164.677908]  ? trace_hardirqs_on_thunk+0x1a/0x1c
[  164.677919]  entry_SYSCALL_64_fastpath+0x1c/0xb1
[  164.677926] RIP: 0033:0x7f44264eb160
[  164.677931] RSP: 002b:00007ffe6e705f88 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
[  164.677939] RAX: ffffffffffffffda RBX: 0000000000000046 RCX: 00007f44264eb160
[  164.677943] RDX: 000000000000001c RSI: 000055de0fedc2b0 RDI: 0000000000000003
[  164.677948] RBP: 00007ffe6e7060e0 R08: 0100007fffff0000 R09: 0000000200001600
[  164.677952] R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffe6e706090
[  164.677956] R13: 00007ffe6e7060a0 R14: 0000000000000003 R15: 00007ffe6e705f40
#24 lore raw

Re: BUG: using smp_processor_id() in preemptible [00000000]

Quoted 96 lines · Jakub Kicinski

Hi!

This appeared in net-next over the weekend - looks likely related to this set...

[  164.456668] BUG: using smp_processor_id() in preemptible [00000000] code: sshd/1255
[  164.472259] caller is ip6_pol_route+0xe88/0x4a80
[  164.477571] CPU: 10 PID: 1255 Comm: sshd Not tainted 4.14.0-rc3-debug-00960-g58e545033ed7 #312
[  164.487350] Hardware name: Dell Inc. PowerEdge R730/072T6D, BIOS 2.3.4 11/08/2016
[  164.495884] Call Trace:
[  164.498771]  dump_stack+0xb3/0x140
[  164.502720]  ? _atomic_dec_and_lock+0x2b0/0x2b0
[  164.507909]  ? __lock_is_held+0xcf/0x1a0
[  164.512492]  check_preemption_disabled+0x1a0/0x1d0
[  164.517974]  ip6_pol_route+0xe88/0x4a80
[  164.522402]  ? ip6_rt_update_pmtu+0xc0/0xc0
[  164.527205]  ? unwind_get_return_address+0x5f/0xc0
[  164.532685]  ? print_usage_bug+0x5a0/0x5a0
[  164.537399]  ? lock_downgrade+0x740/0x740
[  164.542000]  ? deref_stack_reg+0x75/0x230
[  164.546605]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.553158]  ? print_usage_bug+0x5a0/0x5a0
[  164.557859]  ? bpf_prog_alloc+0x330/0x330
[  164.562467]  ? lock_downgrade+0x740/0x740
[  164.567076]  ? __mod_tree_remove+0x40/0x40
[  164.571774]  ? deref_stack_reg+0x75/0x230
[  164.576414]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.582964]  ? deref_stack_reg+0x230/0x230
[  164.587676]  ? __free_insn_slot+0x970/0x970
[  164.592507]  ? print_usage_bug+0x5a0/0x5a0
[  164.597203]  ? deref_stack_reg+0x75/0x230
[  164.601804]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.608412]  ? show_rcu_gp_kthreads+0x160/0x160
[  164.613601]  ? is_bpf_text_address+0xa4/0x130
[  164.618590]  ? bpf_prog_alloc+0x330/0x330
[  164.623194]  ? kernel_text_address+0xec/0x120
[  164.628200]  ? cyc2ns_read_end+0x20/0x20
[  164.632705]  ? __mod_tree_remove+0x40/0x40
[  164.637403]  ? deref_stack_reg+0x75/0x230
[  164.642006]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.648552]  ? deref_stack_reg+0x75/0x230
[  164.653165]  ? sched_clock_cpu+0x18/0x290
[  164.657768]  ? lock_downgrade+0x740/0x740
[  164.662383]  ? bpf_prog_alloc+0x330/0x330
[  164.666978]  ? lock_downgrade+0x740/0x740
[  164.671581]  ? debug_check_no_locks_freed+0x2f0/0x2f0
[  164.677425]  ? deref_stack_reg+0x75/0x230
[  164.677432]  ? __read_once_size_nocheck.constprop.3+0x50/0x50
[  164.677438]  ? deref_stack_reg+0x230/0x230
[  164.677445]  ? deref_stack_reg+0x230/0x230
[  164.677458]  ? rcu_read_lock_held+0xc0/0xc0
[  164.677466]  ? __free_insn_slot+0x970/0x970
[  164.677476]  ? rcu_is_watching+0x59/0x1f0
[  164.677483]  ? show_rcu_gp_kthreads+0x160/0x160
[  164.677496]  ? is_bpf_text_address+0xa4/0x130
[  164.677504]  ? kernel_text_address+0xec/0x120
[  164.677509]  ? __kernel_text_address+0xe/0x30
[  164.677516]  ? __kernel_text_address+0xe/0x30
[  164.677523]  ? unwind_get_return_address+0x5f/0xc0
[  164.677532]  ? __save_stack_trace+0x83/0x120
[  164.677549]  ? __lock_acquire+0x1fcf/0x4440
[  164.677557]  ? save_trace+0x350/0x350
[  164.677566]  ? cyc2ns_read_end+0x20/0x20
[  164.677580]  ? debug_check_no_locks_freed+0x2f0/0x2f0
[  164.677589]  ? ip6_pol_route_input+0x90/0x90
[  164.677595]  fib6_rule_lookup+0x10a/0x750
[  164.677604]  ? fib6_rules_seq_read+0x10/0x10
[  164.677623]  ? lock_downgrade+0x740/0x740
[  164.677631]  ? ip6_route_output_flags+0x1ff/0x310
[  164.677642]  ip6_dst_lookup_tail+0x4ce/0xd50
[  164.677671]  ip6_dst_lookup_flow+0xce/0x2a0
[  164.677679]  ? ip6_dst_lookup+0x90/0x90
[  164.677684]  ? __lock_is_held+0xcf/0x1a0
[  164.677690]  ? show_rcu_gp_kthreads+0x160/0x160
[  164.677704]  ip6_datagram_dst_update+0x728/0x1b00
[  164.677711]  ? cyc2ns_read_end+0x20/0x20
[  164.677721]  ? ip6_datagram_send_ctl+0x1400/0x1400
[  164.677733]  ? print_usage_bug+0x5a0/0x5a0
[  164.677741]  ? sched_clock_cpu+0x18/0x290
[  164.677759]  ? lock_downgrade+0x740/0x740
[  164.677765]  ? get_lock_stats+0x18/0x160
[  164.677788]  ? __ip6_datagram_connect+0x51b/0x1410
[  164.677793]  __ip6_datagram_connect+0x51b/0x1410
[  164.677803]  ? ip6_datagram_release_cb+0x5f0/0x5f0
[  164.677809]  ? mark_held_locks+0xce/0x170
[  164.677817]  ? __local_bh_enable_ip+0x5f/0xa0
[  164.677830]  ip6_datagram_connect+0x27/0x40
[  164.677839]  SYSC_connect+0x1e8/0x4a0
[  164.677847]  ? SYSC_bind+0x3e0/0x3e0
[  164.677856]  ? get_unused_fd_flags+0x133/0x210
[  164.677863]  ? trace_raw_output_sys_exit+0x110/0x110
[  164.677874]  ? __close_fd+0x242/0x400
[  164.677883]  ? sock_map_fd+0x3d/0x60
[  164.677893]  ? entry_SYSCALL_64_fastpath+0x5/0xb1
[  164.677901]  ? trace_hardirqs_on_caller+0x3cb/0x680
[  164.677908]  ? trace_hardirqs_on_thunk+0x1a/0x1c
Quoted 8 lines
[  164.677919]  entry_SYSCALL_64_fastpath+0x1c/0xb1
[  164.677926] RIP: 0033:0x7f44264eb160
[  164.677931] RSP: 002b:00007ffe6e705f88 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
[  164.677939] RAX: ffffffffffffffda RBX: 0000000000000046 RCX: 00007f44264eb160
[  164.677943] RDX: 000000000000001c RSI: 000055de0fedc2b0 RDI: 0000000000000003
[  164.677948] RBP: 00007ffe6e7060e0 R08: 0100007fffff0000 R09: 0000000200001600
[  164.677952] R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffe6e706090
[  164.677956] R13: 00007ffe6e7060a0 R14: 0000000000000003 R15: 00007ffe6e705f40

Hi Jakub

This was discussed/reported earlier today by Ido.

https://patchwork.ozlabs.org/patch/823011/

We will submit an official fix shortly.

Thanks.