Skip to content

Commit

Permalink
ipv6: add (struct uncached_list)->quarantine list
Browse files Browse the repository at this point in the history
This is an optimization to keep the per-cpu lists as short as possible:

Whenever rt6_uncached_list_flush_dev() changes one rt6_info
matching the disappearing device, it can can transfer the object
to a quarantine list, waiting for a final rt6_uncached_list_del().

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Feb 11, 2022
1 parent e5f80fc commit ba55ef8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions net/ipv6/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ static struct fib6_info *rt6_get_route_info(struct net *net,
struct uncached_list {
spinlock_t lock;
struct list_head head;
struct list_head quarantine;
};

static DEFINE_PER_CPU_ALIGNED(struct uncached_list, rt6_uncached_list);
Expand All @@ -151,7 +152,7 @@ void rt6_uncached_list_del(struct rt6_info *rt)
struct uncached_list *ul = rt->rt6i_uncached_list;

spin_lock_bh(&ul->lock);
list_del(&rt->rt6i_uncached);
list_del_init(&rt->rt6i_uncached);
spin_unlock_bh(&ul->lock);
}
}
Expand All @@ -162,24 +163,33 @@ static void rt6_uncached_list_flush_dev(struct net_device *dev)

for_each_possible_cpu(cpu) {
struct uncached_list *ul = per_cpu_ptr(&rt6_uncached_list, cpu);
struct rt6_info *rt;
struct rt6_info *rt, *safe;

if (list_empty(&ul->head))
continue;

spin_lock_bh(&ul->lock);
list_for_each_entry(rt, &ul->head, rt6i_uncached) {
list_for_each_entry_safe(rt, safe, &ul->head, rt6i_uncached) {
struct inet6_dev *rt_idev = rt->rt6i_idev;
struct net_device *rt_dev = rt->dst.dev;
bool handled = false;

if (rt_idev->dev == dev) {
rt->rt6i_idev = in6_dev_get(blackhole_netdev);
in6_dev_put(rt_idev);
handled = true;
}

if (rt_dev == dev) {
rt->dst.dev = blackhole_netdev;
dev_replace_track(rt_dev, blackhole_netdev,
&rt->dst.dev_tracker,
GFP_ATOMIC);
handled = true;
}
if (handled)
list_move(&rt->rt6i_uncached,
&ul->quarantine);
}
spin_unlock_bh(&ul->lock);
}
Expand Down Expand Up @@ -6727,6 +6737,7 @@ int __init ip6_route_init(void)
struct uncached_list *ul = per_cpu_ptr(&rt6_uncached_list, cpu);

INIT_LIST_HEAD(&ul->head);
INIT_LIST_HEAD(&ul->quarantine);
spin_lock_init(&ul->lock);
}

Expand Down

0 comments on commit ba55ef8

Please sign in to comment.