8000 ipv6: Add rt6_make_pcpu_route() · bsd-unix/linux@a73e419 · GitHub
[go: up one dir, main page]

Skip to content

Commit a73e419

Browse files
iamkafaidavem330
authored andcommitted
ipv6: Add rt6_make_pcpu_route()
It is a prep work for fixing a potential deadlock when creating a pcpu rt. The current rt6_get_pcpu_route() will also create a pcpu rt if one does not exist. This patch moves the pcpu rt creation logic into another function, rt6_make_pcpu_route(). Signed-off-by: Martin KaFai Lau <kafai@fb.com> CC: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ad70686 commit a73e419

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

net/ipv6/route.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,13 +993,21 @@ static struct rt6_info *ip6_rt_pcpu_alloc(struct rt6_info *rt)
993993
/* It should be called with read_lock_bh(&tb6_lock) acquired */
994994
static struct rt6_info *rt6_get_pcpu_route(struct rt6_info *rt)
995995
{
996-
struct rt6_info *pcpu_rt, *prev, **p;
996+
struct rt6_info *pcpu_rt, **p;
997997

998998
p = this_cpu_ptr(rt->rt6i_pcpu);
999999
pcpu_rt = *p;
10001000

1001-
if (pcpu_rt)
1002-
goto done;
1001+
if (pcpu_rt) {
1002+
dst_hold(&pcpu_rt->dst);
1003+
rt6_dst_from_metrics_check(pcpu_rt);
1004+
}
1005+
return pcpu_rt;
1006+
}
1007+
1008+
static struct rt6_info *rt6_make_pcpu_route(struct rt6_info *rt)
1009+
{
1010+
struct rt6_info *pcpu_rt, *prev, **p;
10031011

10041012
pcpu_rt = ip6_rt_pcpu_alloc(rt);
10051013
if (!pcpu_rt) {
@@ -1009,6 +1017,7 @@ static struct rt6_info *rt6_get_pcpu_route(struct rt6_info *rt)
10091017
goto done;
10101018
}
10111019

1020+
p = this_cpu_ptr(rt->rt6i_pcpu);
10121021
prev = cmpxchg(p, NULL, pcpu_rt);
10131022
if (prev) {
10141023
/* If someone did it before us, return prev instead */
@@ -1093,8 +1102,11 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
10931102
rt->dst.lastuse = jiffies;
10941103
rt->dst.__use++;
10951104
pcpu_rt = rt6_get_pcpu_route(rt);
1096-
read_unlock_bh(&table->tb6_lock);
10971105

1106+
if (!pcpu_rt)
1107+
pcpu_rt = rt6_make_pcpu_route(rt);
1108+
1109+
read_unlock_bh(&table->tb6_lock);
10981110
return pcpu_rt;
10991111
}
11001112
}

0 commit comments

Comments
 (0)
0