diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2025-09-22 11:38:47 -0700 | 
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2025-09-22 11:38:48 -0700 | 
| commit | 78e87f9d5358a5131191e439ef9a0c9f7c64423f (patch) | |
| tree | c1b999f046c844921304aa9fcccc463bc06023c8 | |
| parent | 50d51cef555ee42fe47dd51b71366a77895e5f0b (diff) | |
| parent | bb6f9445666e1ed9f39c805e153243a65ea05257 (diff) | |
Merge branch 'tcp-clean-up-inet_hash-and-inet_unhash'
Kuniyuki Iwashima says:
====================
tcp: Clean up inet_hash() and inet_unhash().
While reviewing the ehash fix series from Xuanqiang Luo [0],
I noticed that inet_twsk_hashdance_schedule() checks the
retval of __sk_nulls_del_node_init_rcu(), which looks confusing.
The test exists from the pre-git era:
  $ git blame -L:tcp_tw_hashdance net/ipv4/tcp_minisocks.c e48c414ee61f4~
Patch 3 is to clarify that the retval check is unnecessary in
inet_twsk_hashdance_schedule(), but I'll delegate its removal
to the Xuanqiang's series.
Patch 1 & 2 are minor cleanups.
[0]: https://lore.kernel.org/netdev/20250916103054.719584-4-xuanqiang.luo@linux.dev/
====================
Link: https://patch.msgid.link/20250919083706.1863217-1-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
| -rw-r--r-- | include/net/inet6_hashtables.h | 2 | ||||
| -rw-r--r-- | include/net/inet_hashtables.h | 1 | ||||
| -rw-r--r-- | net/ipv4/inet_hashtables.c | 28 | ||||
| -rw-r--r-- | net/ipv6/inet6_hashtables.c | 11 | ||||
| -rw-r--r-- | net/ipv6/tcp_ipv6.c | 2 | 
5 files changed, 7 insertions, 37 deletions
diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h index 1f985d2012ce..282e29237d93 100644 --- a/include/net/inet6_hashtables.h +++ b/include/net/inet6_hashtables.h @@ -167,8 +167,6 @@ struct sock *inet6_lookup(const struct net *net, struct sk_buff *skb, int doff,  			  const struct in6_addr *daddr, const __be16 dport,  			  const int dif); -int inet6_hash(struct sock *sk); -  static inline bool inet6_match(const struct net *net, const struct sock *sk,  			       const struct in6_addr *saddr,  			       const struct in6_addr *daddr, diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index a3b32241c2f2..b787be651ce7 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h @@ -289,7 +289,6 @@ int inet_hashinfo2_init_mod(struct inet_hashinfo *h);  bool inet_ehash_insert(struct sock *sk, struct sock *osk, bool *found_dup_sk);  bool inet_ehash_nolisten(struct sock *sk, struct sock *osk,  			 bool *found_dup_sk); -int __inet_hash(struct sock *sk, struct sock *osk);  int inet_hash(struct sock *sk);  void inet_unhash(struct sock *sk); diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index ef4ccfd46ff6..4eb933f56fe6 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -739,15 +739,18 @@ static int inet_reuseport_add_sock(struct sock *sk,  	return reuseport_alloc(sk, inet_rcv_saddr_any(sk));  } -int __inet_hash(struct sock *sk, struct sock *osk) +int inet_hash(struct sock *sk)  {  	struct inet_hashinfo *hashinfo = tcp_get_hashinfo(sk);  	struct inet_listen_hashbucket *ilb2;  	int err = 0; +	if (sk->sk_state == TCP_CLOSE) +		return 0; +  	if (sk->sk_state != TCP_LISTEN) {  		local_bh_disable(); -		inet_ehash_nolisten(sk, osk, NULL); +		inet_ehash_nolisten(sk, NULL, NULL);  		local_bh_enable();  		return 0;  	} @@ -772,17 +775,7 @@ unlock:  	return err;  } -EXPORT_IPV6_MOD(__inet_hash); - -int inet_hash(struct sock *sk) -{ -	int err = 0; - -	if (sk->sk_state != TCP_CLOSE) -		err = __inet_hash(sk, NULL); - -	return err; -} +EXPORT_IPV6_MOD(inet_hash);  void inet_unhash(struct sock *sk)  { @@ -800,11 +793,6 @@ void inet_unhash(struct sock *sk)  		 * avoid circular locking dependency on PREEMPT_RT.  		 */  		spin_lock(&ilb2->lock); -		if (sk_unhashed(sk)) { -			spin_unlock(&ilb2->lock); -			return; -		} -  		if (rcu_access_pointer(sk->sk_reuseport_cb))  			reuseport_stop_listen_sock(sk); @@ -815,10 +803,6 @@ void inet_unhash(struct sock *sk)  		spinlock_t *lock = inet_ehash_lockp(hashinfo, sk->sk_hash);  		spin_lock_bh(lock); -		if (sk_unhashed(sk)) { -			spin_unlock_bh(lock); -			return; -		}  		__sk_nulls_del_node_init_rcu(sk);  		sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);  		spin_unlock_bh(lock); diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index a3a9ea49fee2..5e1da088d8e1 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c @@ -368,14 +368,3 @@ int inet6_hash_connect(struct inet_timewait_death_row *death_row,  				   __inet6_check_established);  }  EXPORT_SYMBOL_GPL(inet6_hash_connect); - -int inet6_hash(struct sock *sk) -{ -	int err = 0; - -	if (sk->sk_state != TCP_CLOSE) -		err = __inet_hash(sk, NULL); - -	return err; -} -EXPORT_SYMBOL_GPL(inet6_hash); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index d1e5b2a186fb..9622c2776ade 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -2355,7 +2355,7 @@ struct proto tcpv6_prot = {  	.splice_eof		= tcp_splice_eof,  	.backlog_rcv		= tcp_v6_do_rcv,  	.release_cb		= tcp_release_cb, -	.hash			= inet6_hash, +	.hash			= inet_hash,  	.unhash			= inet_unhash,  	.get_port		= inet_csk_get_port,  	.put_port		= inet_put_port,  | 
