Skip to content

Commit f40b6ae

Browse files
dsaherndavem330
authored andcommitted
ipv6: Move pcpu cached routes to fib6_nh
rt6_info are specific instances of a fib entry and are tied to a device and gateway - ie., a nexthop. Before nexthop objects, IPv6 fib entries have separate fib6_info for each nexthop in a multipath route, so the location of the pcpu cache in the fib6_info struct worked. However, with nexthop objects a fib6_info can point to a set of nexthops (yet another alignment of ipv6 with ipv4). Accordingly, the pcpu cache needs to be moved to the fib6_nh struct so the cached entries are local to the nexthop specification used to create the rt6_info. Initialization and free of the pcpu entries moved to fib6_nh_init and fib6_nh_release. Change in location only, from fib6_info down to fib6_nh; no other functional change intended. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent daeceb2 commit f40b6ae

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

include/net/ip6_fib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ struct fib6_nh {
131131
#ifdef CONFIG_IPV6_ROUTER_PREF
132132
unsigned long last_probe;
133133
#endif
134+
135+
struct rt6_info * __percpu *rt6i_pcpu;
134136
};
135137

136138
struct fib6_info {
@@ -156,7 +158,6 @@ struct fib6_info {
156158
struct rt6key fib6_src;
157159
struct rt6key fib6_prefsrc;
158160

159-
struct rt6_info * __percpu *rt6i_pcpu;
160161
struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
161162

162163
u32 fib6_metric;

net/ipv6/addrconf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6341,16 +6341,16 @@ void addrconf_disable_policy_idev(struct inet6_dev *idev, int val)
63416341
list_for_each_entry(ifa, &idev->addr_list, if_list) {
63426342
spin_lock(&ifa->lock);
63436343
if (ifa->rt) {
6344-
struct fib6_info *rt = ifa->rt;
6344+
struct fib6_nh *nh = &ifa->rt->fib6_nh;
63456345
int cpu;
63466346

63476347
rcu_read_lock();
63486348
ifa->rt->dst_nopolicy = val ? true : false;
6349-
if (rt->rt6i_pcpu) {
6349+
if (nh->rt6i_pcpu) {
63506350
for_each_possible_cpu(cpu) {
63516351
struct rt6_info **rtp;
63526352

6353-
rtp = per_cpu_ptr(rt->rt6i_pcpu, cpu);
6353+
rtp = per_cpu_ptr(nh->rt6i_pcpu, cpu);
63546354
addrconf_set_nopolicy(*rtp, val);
63556355
}
63566356
}

net/ipv6/ip6_fib.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags)
155155
if (!f6i)
156156
return NULL;
157157

158-
f6i->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags);
159-
if (!f6i->rt6i_pcpu) {
160-
kfree(f6i);
161-
return NULL;
162-
}
163-
164158
INIT_LIST_HEAD(&f6i->fib6_siblings);
165159
refcount_set(&f6i->fib6_ref, 1);
166160

@@ -177,25 +171,6 @@ void fib6_info_destroy_rcu(struct rcu_head *head)
177171
bucket = rcu_dereference_protected(f6i->rt6i_exception_bucket, 1);
178172
kfree(bucket);
179173

180-
if (f6i->rt6i_pcpu) {
181-
int cpu;
182-
183-
for_each_possible_cpu(cpu) {
184-
struct rt6_info **ppcpu_rt;
185-
struct rt6_info *pcpu_rt;
186-
187-
ppcpu_rt = per_cpu_ptr(f6i->rt6i_pcpu, cpu);
188-
pcpu_rt = *ppcpu_rt;
189-
if (pcpu_rt) {
190-
dst_dev_put(&pcpu_rt->dst);
191-
dst_release(&pcpu_rt->dst);
192-
*ppcpu_rt = NULL;
193-
}
194-
}
195-
196-
free_percpu(f6i->rt6i_pcpu);
197-
}
198-
199174
fib6_nh_release(&f6i->fib6_nh);
200175

201176
ip_fib_metrics_put(f6i->fib6_metrics);
@@ -902,8 +877,12 @@ static struct fib6_node *fib6_add_1(struct net *net,
902877
static void fib6_drop_pcpu_from(struct fib6_info *f6i,
903878
const struct fib6_table *table)
904879
{
880+
struct fib6_nh *fib6_nh = &f6i->fib6_nh;
905881
int cpu;
906882

883+
if (!fib6_nh->rt6i_pcpu)
884+
return;
885+
907886
/* Make sure rt6_make_pcpu_route() wont add other percpu routes
908887
* while we are cleaning them here.
909888
*/
@@ -917,7 +896,7 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i,
917896
struct rt6_info **ppcpu_rt;
918897
struct rt6_info *pcpu_rt;
919898

920-
ppcpu_rt = per_cpu_ptr(f6i->rt6i_pcpu, cpu);
899+
ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu);
921900
pcpu_rt = *ppcpu_rt;
922901
if (pcpu_rt) {
923902
struct fib6_info *from;
@@ -933,8 +912,7 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
933912
{
934913
struct fib6_table *table = rt->fib6_table;
935914

936-
if (rt->rt6i_pcpu)
937-
fib6_drop_pcpu_from(rt, table);
915+
fib6_drop_pcpu_from(rt, table);
938916

939917
if (refcount_read(&rt->fib6_ref) != 1) {
940918
/* This route is used as dummy address holder in some split

net/ipv6/route.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res)
12701270
{
12711271
struct rt6_info *pcpu_rt, **p;
12721272

1273-
p = this_cpu_ptr(res->f6i->rt6i_pcpu);
1273+
p = this_cpu_ptr(res->nh->rt6i_pcpu);
12741274
pcpu_rt = *p;
12751275

12761276
if (pcpu_rt)
@@ -1291,7 +1291,7 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,
12911291
}
12921292

12931293
dst_hold(&pcpu_rt->dst);
1294-
p = this_cpu_ptr(res->f6i->rt6i_pcpu);
1294+
p = this_cpu_ptr(res->nh->rt6i_pcpu);
12951295
prev = cmpxchg(p, NULL, pcpu_rt);
12961296
BUG_ON(prev);
12971297

@@ -3068,6 +3068,12 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
30683068
!netif_carrier_ok(dev))
30693069
fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
30703070

3071+
fib6_nh->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags);
3072+
if (!fib6_nh->rt6i_pcpu) {
3073+
err = -ENOMEM;
3074+
goto out;
3075+
}
3076+
30713077
err = fib_nh_common_init(&fib6_nh->nh_common, cfg->fc_encap,
30723078
cfg->fc_encap_type, cfg, gfp_flags, extack);
30733079
if (err)
@@ -3092,6 +3098,25 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
30923098

30933099
void fib6_nh_release(struct fib6_nh *fib6_nh)
30943100
{
3101+
if (fib6_nh->rt6i_pcpu) {
3102+
int cpu;
3103+
3104+
for_each_possible_cpu(cpu) {
3105+
struct rt6_info **ppcpu_rt;
3106+
struct rt6_info *pcpu_rt;
3107+
3108+
ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu);
3109+
pcpu_rt = *ppcpu_rt;
3110+
if (pcpu_rt) {
3111+
dst_dev_put(&pcpu_rt->dst);
3112+
dst_release(&pcpu_rt->dst);
3113+
*ppcpu_rt = NULL;
3114+
}
3115+
}
3116+
3117+
free_percpu(fib6_nh->rt6i_pcpu);
3118+
}
3119+
30953120
fib_nh_common_release(&fib6_nh->nh_common);
30963121
}
30973122

0 commit comments

Comments
 (0)