Skip to content

Commit a80886e

Browse files
committed
Merge branch 'ipv6-Move-exceptions-to-fib6_nh-and-make-it-optional-in-a-fib6_info'
David Ahern says: ==================== ipv6: Move exceptions to fib6_nh and make it optional in a fib6_info Patches 1 and 4 move pcpu and exception caches from fib6_info to fib6_nh. With respect to the current FIB entries this is only a movement from one struct to another contained within the first. Patch 2 refactors the core logic of fib6_drop_pcpu_from into a helper that is invoked per fib6_nh. Patch 3 refactors exception handling in a similar way - creating a bunch of helpers that can be invoked per fib6_nh with the goal of making patch 4 easier to review as well as creating the code needed for nexthop objects. Patch 5 makes a fib6_nh at the end of a fib6_info an array similar to IPv4 and its fib_info. For the current fib entry model, all fib6_info will have a fib6_nh allocated for it. Patch 6 refactors ip6_route_del moving the code for deleting an exception entry into a new function. Patch 7 adds tests for redirect route exceptions. The new test was written against 5.1 (before any of the nexthop refactoring). It and the pmtu.sh selftest exercise the exception code paths - from creating exceptions to cleaning them up on device delete. All tests pass without any rcu locking or memleak warnings. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents daeceb2 + ec81053 commit a80886e

8 files changed

Lines changed: 820 additions & 244 deletions

File tree

‎drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,7 +2886,7 @@ mlxsw_sp_nexthop6_group_cmp(const struct mlxsw_sp_nexthop_group *nh_grp,
28862886
return false;
28872887

28882888
list_for_each_entry(mlxsw_sp_rt6, &fib6_entry->rt6_list, list) {
2889-
struct fib6_nh *fib6_nh = &mlxsw_sp_rt6->rt->fib6_nh;
2889+
struct fib6_nh *fib6_nh = mlxsw_sp_rt6->rt->fib6_nh;
28902890
struct in6_addr *gw;
28912891
int ifindex, weight;
28922892

@@ -2958,7 +2958,7 @@ mlxsw_sp_nexthop6_group_hash(struct mlxsw_sp_fib6_entry *fib6_entry, u32 seed)
29582958
struct net_device *dev;
29592959

29602960
list_for_each_entry(mlxsw_sp_rt6, &fib6_entry->rt6_list, list) {
2961-
dev = mlxsw_sp_rt6->rt->fib6_nh.fib_nh_dev;
2961+
dev = mlxsw_sp_rt6->rt->fib6_nh->fib_nh_dev;
29622962
val ^= dev->ifindex;
29632963
}
29642964

@@ -3960,9 +3960,9 @@ mlxsw_sp_rt6_nexthop(struct mlxsw_sp_nexthop_group *nh_grp,
39603960
struct mlxsw_sp_nexthop *nh = &nh_grp->nexthops[i];
39613961
struct fib6_info *rt = mlxsw_sp_rt6->rt;
39623962

3963-
if (nh->rif && nh->rif->dev == rt->fib6_nh.fib_nh_dev &&
3963+
if (nh->rif && nh->rif->dev == rt->fib6_nh->fib_nh_dev &&
39643964
ipv6_addr_equal((const struct in6_addr *) &nh->gw_addr,
3965-
&rt->fib6_nh.fib_nh_gw6))
3965+
&rt->fib6_nh->fib_nh_gw6))
39663966
return nh;
39673967
continue;
39683968
}
@@ -4022,13 +4022,13 @@ mlxsw_sp_fib6_entry_offload_set(struct mlxsw_sp_fib_entry *fib_entry)
40224022
if (fib_entry->type == MLXSW_SP_FIB_ENTRY_TYPE_LOCAL ||
40234023
fib_entry->type == MLXSW_SP_FIB_ENTRY_TYPE_BLACKHOLE) {
40244024
list_first_entry(&fib6_entry->rt6_list, struct mlxsw_sp_rt6,
4025-
list)->rt->fib6_nh.fib_nh_flags |= RTNH_F_OFFLOAD;
4025+
list)->rt->fib6_nh->fib_nh_flags |= RTNH_F_OFFLOAD;
40264026
return;
40274027
}
40284028

40294029
list_for_each_entry(mlxsw_sp_rt6, &fib6_entry->rt6_list, list) {
40304030
struct mlxsw_sp_nexthop_group *nh_grp = fib_entry->nh_group;
4031-
struct fib6_nh *fib6_nh = &mlxsw_sp_rt6->rt->fib6_nh;
4031+
struct fib6_nh *fib6_nh = mlxsw_sp_rt6->rt->fib6_nh;
40324032
struct mlxsw_sp_nexthop *nh;
40334033

40344034
nh = mlxsw_sp_rt6_nexthop(nh_grp, mlxsw_sp_rt6);
@@ -4050,7 +4050,7 @@ mlxsw_sp_fib6_entry_offload_unset(struct mlxsw_sp_fib_entry *fib_entry)
40504050
list_for_each_entry(mlxsw_sp_rt6, &fib6_entry->rt6_list, list) {
40514051
struct fib6_info *rt = mlxsw_sp_rt6->rt;
40524052

4053-
rt->fib6_nh.fib_nh_flags &= ~RTNH_F_OFFLOAD;
4053+
rt->fib6_nh->fib_nh_flags &= ~RTNH_F_OFFLOAD;
40544054
}
40554055
}
40564056

@@ -4928,7 +4928,8 @@ static void mlxsw_sp_rt6_destroy(struct mlxsw_sp_rt6 *mlxsw_sp_rt6)
49284928
static bool mlxsw_sp_fib6_rt_can_mp(const struct fib6_info *rt)
49294929
{
49304930
/* RTF_CACHE routes are ignored */
4931-
return !(rt->fib6_flags & RTF_ADDRCONF) && rt->fib6_nh.fib_nh_gw_family;
4931+
return !(rt->fib6_flags & RTF_ADDRCONF) &&
4932+
rt->fib6_nh->fib_nh_gw_family;
49324933
}
49334934

49344935
static struct fib6_info *
@@ -4987,8 +4988,8 @@ static bool mlxsw_sp_nexthop6_ipip_type(const struct mlxsw_sp *mlxsw_sp,
49874988
const struct fib6_info *rt,
49884989
enum mlxsw_sp_ipip_type *ret)
49894990
{
4990-
return rt->fib6_nh.fib_nh_dev &&
4991-
mlxsw_sp_netdev_ipip_type(mlxsw_sp, rt->fib6_nh.fib_nh_dev, ret);
4991+
return rt->fib6_nh->fib_nh_dev &&
4992+
mlxsw_sp_netdev_ipip_type(mlxsw_sp, rt->fib6_nh->fib_nh_dev, ret);
49924993
}
49934994

49944995
static int mlxsw_sp_nexthop6_type_init(struct mlxsw_sp *mlxsw_sp,
@@ -4998,7 +4999,7 @@ static int mlxsw_sp_nexthop6_type_init(struct mlxsw_sp *mlxsw_sp,
49984999
{
49995000
const struct mlxsw_sp_ipip_ops *ipip_ops;
50005001
struct mlxsw_sp_ipip_entry *ipip_entry;
5001-
struct net_device *dev = rt->fib6_nh.fib_nh_dev;
5002+
struct net_device *dev = rt->fib6_nh->fib_nh_dev;
50025003
struct mlxsw_sp_rif *rif;
50035004
int err;
50045005

@@ -5041,11 +5042,11 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp,
50415042
struct mlxsw_sp_nexthop *nh,
50425043
const struct fib6_info *rt)
50435044
{
5044-
struct net_device *dev = rt->fib6_nh.fib_nh_dev;
5045+
struct net_device *dev = rt->fib6_nh->fib_nh_dev;
50455046

50465047
nh->nh_grp = nh_grp;
5047-
nh->nh_weight = rt->fib6_nh.fib_nh_weight;
5048-
memcpy(&nh->gw_addr, &rt->fib6_nh.fib_nh_gw6, sizeof(nh->gw_addr));
5048+
nh->nh_weight = rt->fib6_nh->fib_nh_weight;
5049+
memcpy(&nh->gw_addr, &rt->fib6_nh->fib_nh_gw6, sizeof(nh->gw_addr));
50495050
mlxsw_sp_nexthop_counter_alloc(mlxsw_sp, nh);
50505051

50515052
list_add_tail(&nh->router_list_node, &mlxsw_sp->router->nexthop_list);
@@ -5068,7 +5069,7 @@ static void mlxsw_sp_nexthop6_fini(struct mlxsw_sp *mlxsw_sp,
50685069
static bool mlxsw_sp_rt6_is_gateway(const struct mlxsw_sp *mlxsw_sp,
50695070
const struct fib6_info *rt)
50705071
{
5071-
return rt->fib6_nh.fib_nh_gw_family ||
5072+
return rt->fib6_nh->fib_nh_gw_family ||
50725073
mlxsw_sp_nexthop6_ipip_type(mlxsw_sp, rt, NULL);
50735074
}
50745075

‎include/net/ip6_fib.h‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ struct fib6_nh {
131131
#ifdef CONFIG_IPV6_ROUTER_PREF
132132
unsigned long last_probe;
133133
#endif
134+
135+
struct rt6_info * __percpu *rt6i_pcpu;
136+
struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
134137
};
135138

136139
struct fib6_info {
@@ -156,22 +159,18 @@ struct fib6_info {
156159
struct rt6key fib6_src;
157160
struct rt6key fib6_prefsrc;
158161

159-
struct rt6_info * __percpu *rt6i_pcpu;
160-
struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
161-
162162
u32 fib6_metric;
163163
u8 fib6_protocol;
164164
u8 fib6_type;
165-
u8 exception_bucket_flushed:1,
166-
should_flush:1,
165+
u8 should_flush:1,
167166
dst_nocount:1,
168167
dst_nopolicy:1,
169168
dst_host:1,
170169
fib6_destroying:1,
171-
unused:2;
170+
unused:3;
172171

173-
struct fib6_nh fib6_nh;
174172
struct rcu_head rcu;
173+
struct fib6_nh fib6_nh[0];
175174
};
176175

177176
struct rt6_info {
@@ -281,7 +280,7 @@ static inline void ip6_rt_put(struct rt6_info *rt)
281280
dst_release(&rt->dst);
282281
}
283282

284-
struct fib6_info *fib6_info_alloc(gfp_t gfp_flags);
283+
struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh);
285284
void fib6_info_destroy_rcu(struct rcu_head *head);
286285

287286
static inline void fib6_info_hold(struct fib6_info *f6i)
@@ -444,7 +443,7 @@ void rt6_get_prefsrc(const struct rt6_info *rt, struct in6_addr *addr)
444443

445444
static inline struct net_device *fib6_info_nh_dev(const struct fib6_info *f6i)
446445
{
447-
return f6i->fib6_nh.fib_nh_dev;
446+
return f6i->fib6_nh->fib_nh_dev;
448447
}
449448

450449
int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,

‎include/net/ip6_route.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static inline bool rt6_qualify_for_ecmp(const struct fib6_info *f6i)
7070
{
7171
/* the RTF_ADDRCONF flag filters out RA's */
7272
return !(f6i->fib6_flags & RTF_ADDRCONF) &&
73-
f6i->fib6_nh.fib_nh_gw_family;
73+
f6i->fib6_nh->fib_nh_gw_family;
7474
}
7575

7676
void ip6_route_input(struct sk_buff *skb);
@@ -275,7 +275,7 @@ static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt,
275275

276276
static inline bool rt6_duplicate_nexthop(struct fib6_info *a, struct fib6_info *b)
277277
{
278-
struct fib6_nh *nha = &a->fib6_nh, *nhb = &b->fib6_nh;
278+
struct fib6_nh *nha = a->fib6_nh, *nhb = b->fib6_nh;
279279

280280
return nha->fib_nh_dev == nhb->fib_nh_dev &&
281281
ipv6_addr_equal(&nha->fib_nh_gw6, &nhb->fib_nh_gw6) &&

‎net/ipv6/addrconf.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,9 +2421,9 @@ static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
24212421
goto out;
24222422

24232423
for_each_fib6_node_rt_rcu(fn) {
2424-
if (rt->fib6_nh.fib_nh_dev->ifindex != dev->ifindex)
2424+
if (rt->fib6_nh->fib_nh_dev->ifindex != dev->ifindex)
24252425
continue;
2426-
if (no_gw && rt->fib6_nh.fib_nh_gw_family)
2426+
if (no_gw && rt->fib6_nh->fib_nh_gw_family)
24272427
continue;
24282428
if ((rt->fib6_flags & flags) != flags)
24292429
continue;
@@ -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: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,18 @@ static __be32 addr_bit_set(const void *token, int fn_bit)
147147
addr[fn_bit >> 5];
148148
}
149149

150-
struct fib6_info *fib6_info_alloc(gfp_t gfp_flags)
150+
struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh)
151151
{
152152
struct fib6_info *f6i;
153+
size_t sz = sizeof(*f6i);
153154

154-
f6i = kzalloc(sizeof(*f6i), gfp_flags);
155+
if (with_fib6_nh)
156+
sz += sizeof(struct fib6_nh);
157+
158+
f6i = kzalloc(sz, gfp_flags);
155159
if (!f6i)
156160
return NULL;
157161

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-
164162
INIT_LIST_HEAD(&f6i->fib6_siblings);
165163
refcount_set(&f6i->fib6_ref, 1);
166164

@@ -170,36 +168,11 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags)
170168
void fib6_info_destroy_rcu(struct rcu_head *head)
171169
{
172170
struct fib6_info *f6i = container_of(head, struct fib6_info, rcu);
173-
struct rt6_exception_bucket *bucket;
174171

175172
WARN_ON(f6i->fib6_node);
176173

177-
bucket = rcu_dereference_protected(f6i->rt6i_exception_bucket, 1);
178-
kfree(bucket);
179-
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-
199-
fib6_nh_release(&f6i->fib6_nh);
200-
174+
fib6_nh_release(f6i->fib6_nh);
201175
ip_fib_metrics_put(f6i->fib6_metrics);
202-
203176
kfree(f6i);
204177
}
205178
EXPORT_SYMBOL_GPL(fib6_info_destroy_rcu);
@@ -899,16 +872,14 @@ static struct fib6_node *fib6_add_1(struct net *net,
899872
return ln;
900873
}
901874

902-
static void fib6_drop_pcpu_from(struct fib6_info *f6i,
903-
const struct fib6_table *table)
875+
static void __fib6_drop_pcpu_from(struct fib6_nh *fib6_nh,
876+
const struct fib6_info *match,
877+
const struct fib6_table *table)
904878
{
905879
int cpu;
906880

907-
/* Make sure rt6_make_pcpu_route() wont add other percpu routes
908-
* while we are cleaning them here.
909-
*/
910-
f6i->fib6_destroying = 1;
911-
mb(); /* paired with the cmpxchg() in rt6_make_pcpu_route() */
881+
if (!fib6_nh->rt6i_pcpu)
882+
return;
912883

913884
/* release the reference to this fib entry from
914885
* all of its cached pcpu routes
@@ -917,9 +888,15 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i,
917888
struct rt6_info **ppcpu_rt;
918889
struct rt6_info *pcpu_rt;
919890

920-
ppcpu_rt = per_cpu_ptr(f6i->rt6i_pcpu, cpu);
891+
ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu);
921892
pcpu_rt = *ppcpu_rt;
922-
if (pcpu_rt) {
893+
894+
/* only dropping the 'from' reference if the cached route
895+
* is using 'match'. The cached pcpu_rt->from only changes
896+
* from a fib6_info to NULL (ip6_dst_destroy); it can never
897+
* change from one fib6_info reference to another
898+
*/
899+
if (pcpu_rt && rcu_access_pointer(pcpu_rt->from) == match) {
923900
struct fib6_info *from;
924901

925902
from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL);
@@ -928,13 +905,27 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i,
928905
}
929906
}
930907

908+
static void fib6_drop_pcpu_from(struct fib6_info *f6i,
909+
const struct fib6_table *table)
910+
{
911+
struct fib6_nh *fib6_nh;
912+
913+
/* Make sure rt6_make_pcpu_route() wont add other percpu routes
914+
* while we are cleaning them here.
915+
*/
916+
f6i->fib6_destroying = 1;
917+
mb(); /* paired with the cmpxchg() in rt6_make_pcpu_route() */
918+
919+
fib6_nh = f6i->fib6_nh;
920+
__fib6_drop_pcpu_from(fib6_nh, f6i, table);
921+
}
922+
931923
static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
932924
struct net *net)
933925
{
934926
struct fib6_table *table = rt->fib6_table;
935927

936-
if (rt->rt6i_pcpu)
937-
fib6_drop_pcpu_from(rt, table);
928+
fib6_drop_pcpu_from(rt, table);
938929

939930
if (refcount_read(&rt->fib6_ref) != 1) {
940931
/* This route is used as dummy address holder in some split
@@ -2314,14 +2305,14 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v)
23142305
#else
23152306
seq_puts(seq, "00000000000000000000000000000000 00 ");
23162307
#endif
2317-
if (rt->fib6_nh.fib_nh_gw_family) {
2308+
if (rt->fib6_nh->fib_nh_gw_family) {
23182309
flags |= RTF_GATEWAY;
2319-
seq_printf(seq, "%pi6", &rt->fib6_nh.fib_nh_gw6);
2310+
seq_printf(seq, "%pi6", &rt->fib6_nh->fib_nh_gw6);
23202311
} else {
23212312
seq_puts(seq, "00000000000000000000000000000000");
23222313
}
23232314

2324-
dev = rt->fib6_nh.fib_nh_dev;
2315+
dev = rt->fib6_nh->fib_nh_dev;
23252316
seq_printf(seq, " %08x %08x %08x %08x %8s\n",
23262317
rt->fib6_metric, refcount_read(&rt->fib6_ref), 0,
23272318
flags, dev ? dev->name : "");

‎net/ipv6/ndisc.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,8 @@ static void ndisc_router_discovery(struct sk_buff *skb)
12931293
rt = rt6_get_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev);
12941294

12951295
if (rt) {
1296-
neigh = ip6_neigh_lookup(&rt->fib6_nh.fib_nh_gw6,
1297-
rt->fib6_nh.fib_nh_dev, NULL,
1296+
neigh = ip6_neigh_lookup(&rt->fib6_nh->fib_nh_gw6,
1297+
rt->fib6_nh->fib_nh_dev, NULL,
12981298
&ipv6_hdr(skb)->saddr);
12991299
if (!neigh) {
13001300
ND_PRINTK(0, err,
@@ -1323,8 +1323,8 @@ static void ndisc_router_discovery(struct sk_buff *skb)
13231323
return;
13241324
}
13251325

1326-
neigh = ip6_neigh_lookup(&rt->fib6_nh.fib_nh_gw6,
1327-
rt->fib6_nh.fib_nh_dev, NULL,
1326+
neigh = ip6_neigh_lookup(&rt->fib6_nh->fib_nh_gw6,
1327+
rt->fib6_nh->fib_nh_dev, NULL,
13281328
&ipv6_hdr(skb)->saddr);
13291329
if (!neigh) {
13301330
ND_PRINTK(0, err,

0 commit comments

Comments
 (0)