Skip to content

Commit 0e1efe9

Browse files
edumazetdavem330
authored andcommitted
ipv6: avoid taking locks at socket dismantle
ipv6_sock_mc_close() is called for ipv6 sockets at close time, and most of them don't use multicast. Add a test to avoid contention on a shared spinlock. Same heuristic applies for ipv6_sock_ac_close(), to avoid contention on a shared rwlock. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cc86802 commit 0e1efe9

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

net/ipv6/anycast.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ void ipv6_sock_ac_close(struct sock *sk)
189189
struct net *net = sock_net(sk);
190190
int prev_index;
191191

192+
if (!np->ipv6_ac_list)
193+
return;
194+
192195
write_lock_bh(&ipv6_sk_ac_lock);
193196
pac = np->ipv6_ac_list;
194197
np->ipv6_ac_list = NULL;

net/ipv6/mcast.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ void ipv6_sock_mc_close(struct sock *sk)
284284
struct ipv6_mc_socklist *mc_lst;
285285
struct net *net = sock_net(sk);
286286

287+
if (!rcu_access_pointer(np->ipv6_mc_list))
288+
return;
289+
287290
spin_lock(&ipv6_sk_mc_lock);
288291
while ((mc_lst = rcu_dereference_protected(np->ipv6_mc_list,
289292
lockdep_is_held(&ipv6_sk_mc_lock))) != NULL) {

0 commit comments

Comments
 (0)