Lines Matching +full:loss +full:- +full:of +full:- +full:lock
1 // SPDX-License-Identifier: GPL-2.0-only
3 * INET An implementation of the TCP/IP protocol suite for the LINUX
5 * interface as the means of communication with the user level.
21 * inet_twsk_bind_unhash - unhash a timewait socket from bind hash
26 * bind hash lock must be held by caller.
27 * Returns 1 if caller should call inet_twsk_put() after lock release.
32 struct inet_bind2_bucket *tb2 = tw->tw_tb2; in inet_twsk_bind_unhash()
33 struct inet_bind_bucket *tb = tw->tw_tb; in inet_twsk_bind_unhash()
39 tw->tw_tb = NULL; in inet_twsk_bind_unhash()
40 tw->tw_tb2 = NULL; in inet_twsk_bind_unhash()
41 inet_bind2_bucket_destroy(hashinfo->bind2_bucket_cachep, tb2); in inet_twsk_bind_unhash()
42 inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb); in inet_twsk_bind_unhash()
50 struct inet_hashinfo *hashinfo = tw->tw_dr->hashinfo; in inet_twsk_kill()
51 spinlock_t *lock = inet_ehash_lockp(hashinfo, tw->tw_hash); in inet_twsk_kill() local
54 spin_lock(lock); in inet_twsk_kill()
56 spin_unlock(lock); in inet_twsk_kill()
59 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), tw->tw_num, in inet_twsk_kill()
60 hashinfo->bhash_size)]; in inet_twsk_kill()
62 twsk_net(tw), tw->tw_num); in inet_twsk_kill()
64 spin_lock(&bhead->lock); in inet_twsk_kill()
65 spin_lock(&bhead2->lock); in inet_twsk_kill()
67 spin_unlock(&bhead2->lock); in inet_twsk_kill()
68 spin_unlock(&bhead->lock); in inet_twsk_kill()
70 refcount_dec(&tw->tw_dr->tw_refcount); in inet_twsk_kill()
76 struct module *owner = tw->tw_prot->owner; in inet_twsk_free()
78 kmem_cache_free(tw->tw_prot->twsk_prot->twsk_slab, tw); in inet_twsk_free()
84 if (refcount_dec_and_test(&tw->tw_refcnt)) in inet_twsk_put()
92 hlist_nulls_add_head_rcu(&tw->tw_node, list); in inet_twsk_add_node_rcu()
114 struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, sk->sk_hash); in inet_twsk_hashdance_schedule()
115 spinlock_t *lock = inet_ehash_lockp(hashinfo, sk->sk_hash); in inet_twsk_hashdance_schedule() local
119 Note, that any socket with inet->num != 0 MUST be bound in in inet_twsk_hashdance_schedule()
122 bhead = &hashinfo->bhash[inet_bhashfn(twsk_net(tw), inet->inet_num, in inet_twsk_hashdance_schedule()
123 hashinfo->bhash_size)]; in inet_twsk_hashdance_schedule()
124 bhead2 = inet_bhashfn_portaddr(hashinfo, sk, twsk_net(tw), inet->inet_num); in inet_twsk_hashdance_schedule()
127 spin_lock(&bhead->lock); in inet_twsk_hashdance_schedule()
128 spin_lock(&bhead2->lock); in inet_twsk_hashdance_schedule()
130 tw->tw_tb = icsk->icsk_bind_hash; in inet_twsk_hashdance_schedule()
131 WARN_ON(!icsk->icsk_bind_hash); in inet_twsk_hashdance_schedule()
133 tw->tw_tb2 = icsk->icsk_bind2_hash; in inet_twsk_hashdance_schedule()
134 WARN_ON(!icsk->icsk_bind2_hash); in inet_twsk_hashdance_schedule()
135 sk_add_bind_node((struct sock *)tw, &tw->tw_tb2->owners); in inet_twsk_hashdance_schedule()
137 spin_unlock(&bhead2->lock); in inet_twsk_hashdance_schedule()
138 spin_unlock(&bhead->lock); in inet_twsk_hashdance_schedule()
140 spin_lock(lock); in inet_twsk_hashdance_schedule()
143 inet_twsk_add_node_rcu(tw, &ehead->chain); in inet_twsk_hashdance_schedule()
147 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); in inet_twsk_hashdance_schedule()
156 * - one reference for bhash chain. in inet_twsk_hashdance_schedule()
157 * - one reference for ehash chain. in inet_twsk_hashdance_schedule()
158 * - one reference for timer. in inet_twsk_hashdance_schedule()
162 refcount_set(&tw->tw_refcnt, 3); in inet_twsk_hashdance_schedule()
166 spin_unlock(lock); in inet_twsk_hashdance_schedule()
184 if (refcount_read(&dr->tw_refcount) - 1 >= in inet_twsk_alloc()
185 READ_ONCE(dr->sysctl_max_tw_buckets)) in inet_twsk_alloc()
188 tw = kmem_cache_alloc(sk->sk_prot_creator->twsk_prot->twsk_slab, in inet_twsk_alloc()
193 tw->tw_dr = dr; in inet_twsk_alloc()
195 tw->tw_daddr = inet->inet_daddr; in inet_twsk_alloc()
196 tw->tw_rcv_saddr = inet->inet_rcv_saddr; in inet_twsk_alloc()
197 tw->tw_bound_dev_if = sk->sk_bound_dev_if; in inet_twsk_alloc()
198 tw->tw_tos = inet->tos; in inet_twsk_alloc()
199 tw->tw_num = inet->inet_num; in inet_twsk_alloc()
200 tw->tw_state = TCP_TIME_WAIT; in inet_twsk_alloc()
201 tw->tw_substate = state; in inet_twsk_alloc()
202 tw->tw_sport = inet->inet_sport; in inet_twsk_alloc()
203 tw->tw_dport = inet->inet_dport; in inet_twsk_alloc()
204 tw->tw_family = sk->sk_family; in inet_twsk_alloc()
205 tw->tw_reuse = sk->sk_reuse; in inet_twsk_alloc()
206 tw->tw_reuseport = sk->sk_reuseport; in inet_twsk_alloc()
207 tw->tw_hash = sk->sk_hash; in inet_twsk_alloc()
208 tw->tw_ipv6only = 0; in inet_twsk_alloc()
209 tw->tw_transparent = inet_test_bit(TRANSPARENT, sk); in inet_twsk_alloc()
210 tw->tw_prot = sk->sk_prot_creator; in inet_twsk_alloc()
211 atomic64_set(&tw->tw_cookie, atomic64_read(&sk->sk_cookie)); in inet_twsk_alloc()
213 timer_setup(&tw->tw_timer, tw_timer_handler, 0); in inet_twsk_alloc()
219 refcount_set(&tw->tw_refcnt, 0); in inet_twsk_alloc()
221 __module_get(tw->tw_prot->owner); in inet_twsk_alloc()
232 /* This is for handling early-kills of TIME_WAIT sockets.
238 struct inet_hashinfo *hashinfo = tw->tw_dr->hashinfo; in inet_twsk_deschedule_put()
239 spinlock_t *lock = inet_ehash_lockp(hashinfo, tw->tw_hash); in inet_twsk_deschedule_put() local
249 * The ehash lock synchronizes these two: in inet_twsk_deschedule_put()
250 * After acquiring the lock, the timer is always scheduled (else in inet_twsk_deschedule_put()
252 * the ehash lock only after completing the timer initialization. in inet_twsk_deschedule_put()
254 * Without grabbing the ehash lock, we get: in inet_twsk_deschedule_put()
258 * 4) cpu x tries to start timer, but mod_timer is a noop post-shutdown in inet_twsk_deschedule_put()
259 * -> timer refcount is never decremented. in inet_twsk_deschedule_put()
261 spin_lock(lock); in inet_twsk_deschedule_put()
263 spin_unlock(lock); in inet_twsk_deschedule_put()
265 if (timer_shutdown_sync(&tw->tw_timer)) in inet_twsk_deschedule_put()
277 * RATIONALE: if FIN arrived and we entered TIME-WAIT state, in __inet_twsk_schedule()
279 * FINs (or previous seqments) are lost (probability of such event in __inet_twsk_schedule()
281 * time to detect the loss is about RTO*(2^N - 1) with exponential in __inet_twsk_schedule()
286 * Well, 240 consumes too much of resources 8) in __inet_twsk_schedule()
295 * of PAWS. in __inet_twsk_schedule()
303 BUG_ON(mod_timer(&tw->tw_timer, jiffies + timeo)); in __inet_twsk_schedule()
304 refcount_inc(&tw->tw_dr->tw_refcount); in __inet_twsk_schedule()
306 mod_timer_pending(&tw->tw_timer, jiffies + timeo); in __inet_twsk_schedule()
314 struct inet_ehash_bucket *head = &hashinfo->ehash[0]; in inet_twsk_purge()
315 unsigned int ehash_mask = hashinfo->ehash_mask; in inet_twsk_purge()
321 if (hlist_nulls_empty(&head->chain)) in inet_twsk_purge()
328 sk_nulls_for_each_rcu(sk, node, &head->chain) { in inet_twsk_purge()
335 if (refcount_read(&sock_net(sk)->ns.count)) in inet_twsk_purge()
338 if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) in inet_twsk_purge()
341 if (refcount_read(&sock_net(sk)->ns.count)) { in inet_twsk_purge()
353 inet_csk_reqsk_queue_drop_and_put(req->rsk_listener, in inet_twsk_purge()
359 /* If the nulls value we got at the end of this lookup is in inet_twsk_purge()