Skip to content

Commit 2d33191

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp/dccp: use rcu locking in inet_diag_find_one_icsk()
RX packet processing holds rcu_read_lock(), so we can remove pairs of rcu_read_lock()/rcu_read_unlock() in lookup functions if inet_diag also holds rcu before calling them. This is needed anyway as __inet_lookup_listener() and inet6_lookup_listener() will soon no longer increment refcount on the found listener. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ee3cf32 commit 2d33191

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

net/ipv4/inet_diag.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ struct sock *inet_diag_find_one_icsk(struct net *net,
356356
{
357357
struct sock *sk;
358358

359+
rcu_read_lock();
359360
if (req->sdiag_family == AF_INET)
360361
sk = inet_lookup(net, hashinfo, NULL, 0, req->id.idiag_dst[0],
361362
req->id.idiag_dport, req->id.idiag_src[0],
@@ -376,9 +377,11 @@ struct sock *inet_diag_find_one_icsk(struct net *net,
376377
req->id.idiag_if);
377378
}
378379
#endif
379-
else
380+
else {
381+
rcu_read_unlock();
380382
return ERR_PTR(-EINVAL);
381-
383+
}
384+
rcu_read_unlock();
382385
if (!sk)
383386
return ERR_PTR(-ENOENT);
384387

net/ipv4/inet_hashtables.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ struct sock *__inet_lookup_listener(struct net *net,
220220
bool select_ok = true;
221221
u32 phash = 0;
222222

223-
rcu_read_lock();
224223
begin:
225224
result = NULL;
226225
hiscore = 0;
@@ -269,7 +268,6 @@ struct sock *__inet_lookup_listener(struct net *net,
269268
goto begin;
270269
}
271270
}
272-
rcu_read_unlock();
273271
return result;
274272
}
275273
EXPORT_SYMBOL_GPL(__inet_lookup_listener);
@@ -312,7 +310,6 @@ struct sock *__inet_lookup_established(struct net *net,
312310
unsigned int slot = hash & hashinfo->ehash_mask;
313311
struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
314312

315-
rcu_read_lock();
316313
begin:
317314
sk_nulls_for_each_rcu(sk, node, &head->chain) {
318315
if (sk->sk_hash != hash)
@@ -339,7 +336,6 @@ struct sock *__inet_lookup_established(struct net *net,
339336
out:
340337
sk = NULL;
341338
found:
342-
rcu_read_unlock();
343339
return sk;
344340
}
345341
EXPORT_SYMBOL_GPL(__inet_lookup_established);

net/ipv6/inet6_hashtables.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ struct sock *__inet6_lookup_established(struct net *net,
6969
struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
7070

7171

72-
rcu_read_lock();
7372
begin:
7473
sk_nulls_for_each_rcu(sk, node, &head->chain) {
7574
if (sk->sk_hash != hash)
@@ -90,7 +89,6 @@ struct sock *__inet6_lookup_established(struct net *net,
9089
out:
9190
sk = NULL;
9291
found:
93-
rcu_read_unlock();
9492
return sk;
9593
}
9694
EXPORT_SYMBOL(__inet6_lookup_established);
@@ -138,7 +136,6 @@ struct sock *inet6_lookup_listener(struct net *net,
138136
unsigned int hash = inet_lhashfn(net, hnum);
139137
struct inet_listen_hashbucket *ilb = &hashinfo->listening_hash[hash];
140138

141-
rcu_read_lock();
142139
begin:
143140
result = NULL;
144141
hiscore = 0;
@@ -187,7 +184,6 @@ struct sock *inet6_lookup_listener(struct net *net,
187184
goto begin;
188185
}
189186
}
190-
rcu_read_unlock();
191187
return result;
192188
}
193189
EXPORT_SYMBOL_GPL(inet6_lookup_listener);

0 commit comments

Comments
 (0)