Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+7 -37
-2
include/net/inet6_hashtables.h
··· 167 167 const struct in6_addr *daddr, const __be16 dport, 168 168 const int dif); 169 169 170 - int inet6_hash(struct sock *sk); 171 - 172 170 static inline bool inet6_match(const struct net *net, const struct sock *sk, 173 171 const struct in6_addr *saddr, 174 172 const struct in6_addr *daddr,
-1
include/net/inet_hashtables.h
··· 289 289 bool inet_ehash_insert(struct sock *sk, struct sock *osk, bool *found_dup_sk); 290 290 bool inet_ehash_nolisten(struct sock *sk, struct sock *osk, 291 291 bool *found_dup_sk); 292 - int __inet_hash(struct sock *sk, struct sock *osk); 293 292 int inet_hash(struct sock *sk); 294 293 void inet_unhash(struct sock *sk); 295 294
+6 -22
net/ipv4/inet_hashtables.c
··· 739 739 return reuseport_alloc(sk, inet_rcv_saddr_any(sk)); 740 740 } 741 741 742 - int __inet_hash(struct sock *sk, struct sock *osk) 742 + int inet_hash(struct sock *sk) 743 743 { 744 744 struct inet_hashinfo *hashinfo = tcp_get_hashinfo(sk); 745 745 struct inet_listen_hashbucket *ilb2; 746 746 int err = 0; 747 747 748 + if (sk->sk_state == TCP_CLOSE) 749 + return 0; 750 + 748 751 if (sk->sk_state != TCP_LISTEN) { 749 752 local_bh_disable(); 750 - inet_ehash_nolisten(sk, osk, NULL); 753 + inet_ehash_nolisten(sk, NULL, NULL); 751 754 local_bh_enable(); 752 755 return 0; 753 756 } ··· 775 772 776 773 return err; 777 774 } 778 - EXPORT_IPV6_MOD(__inet_hash); 779 - 780 - int inet_hash(struct sock *sk) 781 - { 782 - int err = 0; 783 - 784 - if (sk->sk_state != TCP_CLOSE) 785 - err = __inet_hash(sk, NULL); 786 - 787 - return err; 788 - } 775 + EXPORT_IPV6_MOD(inet_hash); 789 776 790 777 void inet_unhash(struct sock *sk) 791 778 { ··· 793 800 * avoid circular locking dependency on PREEMPT_RT. 794 801 */ 795 802 spin_lock(&ilb2->lock); 796 - if (sk_unhashed(sk)) { 797 - spin_unlock(&ilb2->lock); 798 - return; 799 - } 800 - 801 803 if (rcu_access_pointer(sk->sk_reuseport_cb)) 802 804 reuseport_stop_listen_sock(sk); 803 805 ··· 803 815 spinlock_t *lock = inet_ehash_lockp(hashinfo, sk->sk_hash); 804 816 805 817 spin_lock_bh(lock); 806 - if (sk_unhashed(sk)) { 807 - spin_unlock_bh(lock); 808 - return; 809 - } 810 818 __sk_nulls_del_node_init_rcu(sk); 811 819 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 812 820 spin_unlock_bh(lock);
-11
net/ipv6/inet6_hashtables.c
··· 368 368 __inet6_check_established); 369 369 } 370 370 EXPORT_SYMBOL_GPL(inet6_hash_connect); 371 - 372 - int inet6_hash(struct sock *sk) 373 - { 374 - int err = 0; 375 - 376 - if (sk->sk_state != TCP_CLOSE) 377 - err = __inet_hash(sk, NULL); 378 - 379 - return err; 380 - } 381 - EXPORT_SYMBOL_GPL(inet6_hash);
+1 -1
net/ipv6/tcp_ipv6.c
··· 2355 2355 .splice_eof = tcp_splice_eof, 2356 2356 .backlog_rcv = tcp_v6_do_rcv, 2357 2357 .release_cb = tcp_release_cb, 2358 - .hash = inet6_hash, 2358 + .hash = inet_hash, 2359 2359 .unhash = inet_unhash, 2360 2360 .get_port = inet_csk_get_port, 2361 2361 .put_port = inet_put_port,