Skip to content

Commit 8002d44

Browse files
q2vendavem330
authored andcommitted
tcp: Check hlist_empty(&tb->bhash2) instead of hlist_empty(&tb->owners).
We use hlist_empty(&tb->owners) to check if the bhash bucket has a socket. We can check the child bhash2 buckets instead. For this to work, the bhash2 bucket must be freed before the bhash bucket. Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b82ba72 commit 8002d44

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

net/ipv4/inet_connection_sock.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void inet_csk_update_fastreuse(struct inet_bind_bucket *tb,
474474
kuid_t uid = sock_i_uid(sk);
475475
bool reuse = sk->sk_reuse && sk->sk_state != TCP_LISTEN;
476476

477-
if (hlist_empty(&tb->owners)) {
477+
if (hlist_empty(&tb->bhash2)) {
478478
tb->fastreuse = reuse;
479479
if (sk->sk_reuseport) {
480480
tb->fastreuseport = FASTREUSEPORT_ANY;
@@ -566,7 +566,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
566566
}
567567

568568
if (!found_port) {
569-
if (!hlist_empty(&tb->owners)) {
569+
if (!hlist_empty(&tb->bhash2)) {
570570
if (sk->sk_reuse == SK_FORCE_REUSE ||
571571
(tb->fastreuse > 0 && reuse) ||
572572
sk_reuseport_match(tb, sk))
@@ -608,11 +608,10 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
608608

609609
fail_unlock:
610610
if (ret) {
611+
if (bhash2_created)
612+
inet_bind2_bucket_destroy(hinfo->bind2_bucket_cachep, tb2);
611613
if (bhash_created)
612614
inet_bind_bucket_destroy(hinfo->bind_bucket_cachep, tb);
613-
if (bhash2_created)
614-
inet_bind2_bucket_destroy(hinfo->bind2_bucket_cachep,
615-
tb2);
616615
}
617616
if (head2_lock_acquired)
618617
spin_unlock(&head2->lock);

net/ipv4/inet_hashtables.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct inet_bind_bucket *inet_bind_bucket_create(struct kmem_cache *cachep,
8888
*/
8989
void inet_bind_bucket_destroy(struct kmem_cache *cachep, struct inet_bind_bucket *tb)
9090
{
91-
if (hlist_empty(&tb->owners)) {
91+
if (hlist_empty(&tb->bhash2)) {
9292
__hlist_del(&tb->node);
9393
kmem_cache_free(cachep, tb);
9494
}
@@ -195,7 +195,6 @@ static void __inet_put_port(struct sock *sk)
195195
__sk_del_bind_node(sk);
196196
inet_csk(sk)->icsk_bind_hash = NULL;
197197
inet_sk(sk)->inet_num = 0;
198-
inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
199198

200199
spin_lock(&head2->lock);
201200
if (inet_csk(sk)->icsk_bind2_hash) {
@@ -207,6 +206,7 @@ static void __inet_put_port(struct sock *sk)
207206
}
208207
spin_unlock(&head2->lock);
209208

209+
inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
210210
spin_unlock(&head->lock);
211211
}
212212

@@ -1062,7 +1062,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
10621062
if (tb->fastreuse >= 0 ||
10631063
tb->fastreuseport >= 0)
10641064
goto next_port;
1065-
WARN_ON(hlist_empty(&tb->owners));
1065+
WARN_ON(hlist_empty(&tb->bhash2));
10661066
if (!check_established(death_row, sk,
10671067
port, &tw))
10681068
goto ok;

net/ipv4/inet_timewait_sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ void inet_twsk_bind_unhash(struct inet_timewait_sock *tw,
3737

3838
__hlist_del(&tw->tw_bind_node);
3939
tw->tw_tb = NULL;
40-
inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
4140

4241
__hlist_del(&tw->tw_bind2_node);
4342
tw->tw_tb2 = NULL;
4443
inet_bind2_bucket_destroy(hashinfo->bind2_bucket_cachep, tb2);
44+
inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
4545

4646
__sock_put((struct sock *)tw);
4747
}

0 commit comments

Comments
 (0)