Skip to content

Commit d27b9c4

Browse files
q2venPaolo Abeni
authored andcommitted
ipv6: Preallocate nhc_pcpu_rth_output in ip6_route_info_create().
ip6_route_info_create_nh() will be called under RCU. It calls fib_nh_common_init() and allocates nhc->nhc_pcpu_rth_output. As with the reason for rt->fib6_nh->rt6i_pcpu, we want to avoid GFP_ATOMIC allocation for nhc->nhc_pcpu_rth_output under RCU. Let's preallocate it in ip6_route_info_create(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 5720a32 commit d27b9c4

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

net/ipv4/fib_semantics.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,12 @@ int fib_nh_common_init(struct net *net, struct fib_nh_common *nhc,
617617
{
618618
int err;
619619

620-
nhc->nhc_pcpu_rth_output = alloc_percpu_gfp(struct rtable __rcu *,
621-
gfp_flags);
622-
if (!nhc->nhc_pcpu_rth_output)
623-
return -ENOMEM;
620+
if (!nhc->nhc_pcpu_rth_output) {
621+
nhc->nhc_pcpu_rth_output = alloc_percpu_gfp(struct rtable __rcu *,
622+
gfp_flags);
623+
if (!nhc->nhc_pcpu_rth_output)
624+
return -ENOMEM;
625+
}
624626

625627
if (encap) {
626628
struct lwtunnel_state *lwtstate;

net/ipv6/route.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,10 +3732,19 @@ void fib6_nh_release_dsts(struct fib6_nh *fib6_nh)
37323732

37333733
static int fib6_nh_prealloc_percpu(struct fib6_nh *fib6_nh, gfp_t gfp_flags)
37343734
{
3735+
struct fib_nh_common *nhc = &fib6_nh->nh_common;
3736+
37353737
fib6_nh->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags);
37363738
if (!fib6_nh->rt6i_pcpu)
37373739
return -ENOMEM;
37383740

3741+
nhc->nhc_pcpu_rth_output = alloc_percpu_gfp(struct rtable __rcu *,
3742+
gfp_flags);
3743+
if (!nhc->nhc_pcpu_rth_output) {
3744+
free_percpu(fib6_nh->rt6i_pcpu);
3745+
return -ENOMEM;
3746+
}
3747+
37393748
return 0;
37403749
}
37413750

0 commit comments

Comments
 (0)