Skip to content

Commit 169fd62

Browse files
q2venPaolo Abeni
authored andcommitted
ipv6: Get rid of RTNL for SIOCADDRT and RTM_NEWROUTE.
Now we are ready to remove RTNL from SIOCADDRT and RTM_NEWROUTE. The remaining things to do are 1. pass false to lwtunnel_valid_encap_type_attr() 2. use rcu_dereference_rtnl() in fib6_check_nexthop() 3. place rcu_read_lock() before ip6_route_info_create_nh(). Let's complete the RTNL-free conversion. When each CPU-X adds 100000 routes on table-X in a batch concurrently on c7a.metal-48xl EC2 instance with 192 CPUs, without this series: $ sudo ./route_test.sh ... added 19200000 routes (100000 routes * 192 tables). time elapsed: 191577 milliseconds. with this series: $ sudo ./route_test.sh ... added 19200000 routes (100000 routes * 192 tables). time elapsed: 62854 milliseconds. I changed the number of routes in each table (1000 ~ 100000) and consistently saw it finish 3x faster with this series. Note that now every caller of lwtunnel_valid_encap_type() passes false as the last argument, and this can be removed later. Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 081efd1 commit 169fd62

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

net/ipv4/nexthop.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,12 +1556,12 @@ int fib6_check_nexthop(struct nexthop *nh, struct fib6_config *cfg,
15561556
if (nh->is_group) {
15571557
struct nh_group *nhg;
15581558

1559-
nhg = rtnl_dereference(nh->nh_grp);
1559+
nhg = rcu_dereference_rtnl(nh->nh_grp);
15601560
if (nhg->has_v4)
15611561
goto no_v4_nh;
15621562
is_fdb_nh = nhg->fdb_nh;
15631563
} else {
1564-
nhi = rtnl_dereference(nh->nh_info);
1564+
nhi = rcu_dereference_rtnl(nh->nh_info);
15651565
if (nhi->family == AF_INET)
15661566
goto no_v4_nh;
15671567
is_fdb_nh = nhi->fdb_nh;

net/ipv6/route.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,12 +3903,16 @@ int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,
39033903
if (IS_ERR(rt))
39043904
return PTR_ERR(rt);
39053905

3906+
rcu_read_lock();
3907+
39063908
err = ip6_route_info_create_nh(rt, cfg, extack);
39073909
if (err)
3908-
return err;
3910+
goto unlock;
39093911

39103912
err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, extack);
39113913
fib6_info_release(rt);
3914+
unlock:
3915+
rcu_read_unlock();
39123916

39133917
return err;
39143918
}
@@ -4529,12 +4533,10 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, struct in6_rtmsg *rtmsg)
45294533

45304534
switch (cmd) {
45314535
case SIOCADDRT:
4532-
rtnl_lock();
45334536
/* Only do the default setting of fc_metric in route adding */
45344537
if (cfg.fc_metric == 0)
45354538
cfg.fc_metric = IP6_RT_PRIO_USER;
45364539
err = ip6_route_add(&cfg, GFP_KERNEL, NULL);
4537-
rtnl_unlock();
45384540
break;
45394541
case SIOCDELRT:
45404542
err = ip6_route_del(&cfg, NULL);
@@ -5113,7 +5115,7 @@ static int rtm_to_fib6_multipath_config(struct fib6_config *cfg,
51135115
} while (rtnh_ok(rtnh, remaining));
51145116

51155117
return lwtunnel_valid_encap_type_attr(cfg->fc_mp, cfg->fc_mp_len,
5116-
extack, newroute);
5118+
extack, false);
51175119
}
51185120

51195121
static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -5251,7 +5253,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
52515253
cfg->fc_encap_type = nla_get_u16(tb[RTA_ENCAP_TYPE]);
52525254

52535255
err = lwtunnel_valid_encap_type(cfg->fc_encap_type,
5254-
extack, newroute);
5256+
extack, false);
52555257
if (err < 0)
52565258
goto errout;
52575259
}
@@ -5518,6 +5520,8 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
55185520
if (err)
55195521
return err;
55205522

5523+
rcu_read_lock();
5524+
55215525
err = ip6_route_mpath_info_create_nh(&rt6_nh_list, extack);
55225526
if (err)
55235527
goto cleanup;
@@ -5609,6 +5613,8 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
56095613
}
56105614

56115615
cleanup:
5616+
rcu_read_unlock();
5617+
56125618
list_for_each_entry_safe(nh, nh_safe, &rt6_nh_list, list) {
56135619
fib6_info_release(nh->fib6_info);
56145620
list_del(&nh->list);
@@ -6891,7 +6897,7 @@ static void bpf_iter_unregister(void)
68916897

68926898
static const struct rtnl_msg_handler ip6_route_rtnl_msg_handlers[] __initconst_or_module = {
68936899
{.owner = THIS_MODULE, .protocol = PF_INET6, .msgtype = RTM_NEWROUTE,
6894-
.doit = inet6_rtm_newroute},
6900+
.doit = inet6_rtm_newroute, .flags = RTNL_FLAG_DOIT_UNLOCKED},
68956901
{.owner = THIS_MODULE, .protocol = PF_INET6, .msgtype = RTM_DELROUTE,
68966902
.doit = inet6_rtm_delroute, .flags = RTNL_FLAG_DOIT_UNLOCKED},
68976903
{.owner = THIS_MODULE, .protocol = PF_INET6, .msgtype = RTM_GETROUTE,

0 commit comments

Comments
 (0)