Commit 1eeb5043 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

tcp/dccp: do not care about families in inet_twsk_purge()

We lost ability to unload ipv6 module a long time ago.

Instead of calling expensive inet_twsk_purge() twice,
we can handle all families in one round.

Also remove an extra line added in my prior patch,
per Kuniyuki Iwashima feedback.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/netdev/20240327192934.6843-1-kuniyu@amazon.com/Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20240329153203.345203-1-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 58169ec9
...@@ -111,7 +111,7 @@ static inline void inet_twsk_reschedule(struct inet_timewait_sock *tw, int timeo ...@@ -111,7 +111,7 @@ static inline void inet_twsk_reschedule(struct inet_timewait_sock *tw, int timeo
void inet_twsk_deschedule_put(struct inet_timewait_sock *tw); void inet_twsk_deschedule_put(struct inet_timewait_sock *tw);
void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family); void inet_twsk_purge(struct inet_hashinfo *hashinfo);
static inline static inline
struct net *twsk_net(const struct inet_timewait_sock *twsk) struct net *twsk_net(const struct inet_timewait_sock *twsk)
......
...@@ -353,7 +353,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb); ...@@ -353,7 +353,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb);
void tcp_rcv_space_adjust(struct sock *sk); void tcp_rcv_space_adjust(struct sock *sk);
int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp); int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp);
void tcp_twsk_destructor(struct sock *sk); void tcp_twsk_destructor(struct sock *sk);
void tcp_twsk_purge(struct list_head *net_exit_list, int family); void tcp_twsk_purge(struct list_head *net_exit_list);
ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos, ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len, struct pipe_inode_info *pipe, size_t len,
unsigned int flags); unsigned int flags);
......
...@@ -1039,7 +1039,7 @@ static void __net_exit dccp_v4_exit_net(struct net *net) ...@@ -1039,7 +1039,7 @@ static void __net_exit dccp_v4_exit_net(struct net *net)
static void __net_exit dccp_v4_exit_batch(struct list_head *net_exit_list) static void __net_exit dccp_v4_exit_batch(struct list_head *net_exit_list)
{ {
inet_twsk_purge(&dccp_hashinfo, AF_INET); inet_twsk_purge(&dccp_hashinfo);
} }
static struct pernet_operations dccp_v4_ops = { static struct pernet_operations dccp_v4_ops = {
......
...@@ -1119,15 +1119,9 @@ static void __net_exit dccp_v6_exit_net(struct net *net) ...@@ -1119,15 +1119,9 @@ static void __net_exit dccp_v6_exit_net(struct net *net)
inet_ctl_sock_destroy(pn->v6_ctl_sk); inet_ctl_sock_destroy(pn->v6_ctl_sk);
} }
static void __net_exit dccp_v6_exit_batch(struct list_head *net_exit_list)
{
inet_twsk_purge(&dccp_hashinfo, AF_INET6);
}
static struct pernet_operations dccp_v6_ops = { static struct pernet_operations dccp_v6_ops = {
.init = dccp_v6_init_net, .init = dccp_v6_init_net,
.exit = dccp_v6_exit_net, .exit = dccp_v6_exit_net,
.exit_batch = dccp_v6_exit_batch,
.id = &dccp_v6_pernet_id, .id = &dccp_v6_pernet_id,
.size = sizeof(struct dccp_v6_pernet), .size = sizeof(struct dccp_v6_pernet),
}; };
......
...@@ -264,7 +264,7 @@ void __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo, bool rearm) ...@@ -264,7 +264,7 @@ void __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo, bool rearm)
EXPORT_SYMBOL_GPL(__inet_twsk_schedule); EXPORT_SYMBOL_GPL(__inet_twsk_schedule);
/* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */ /* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */
void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family) void inet_twsk_purge(struct inet_hashinfo *hashinfo)
{ {
struct inet_ehash_bucket *head = &hashinfo->ehash[0]; struct inet_ehash_bucket *head = &hashinfo->ehash[0];
unsigned int ehash_mask = hashinfo->ehash_mask; unsigned int ehash_mask = hashinfo->ehash_mask;
...@@ -273,7 +273,6 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family) ...@@ -273,7 +273,6 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
struct sock *sk; struct sock *sk;
for (slot = 0; slot <= ehash_mask; slot++, head++) { for (slot = 0; slot <= ehash_mask; slot++, head++) {
if (hlist_nulls_empty(&head->chain)) if (hlist_nulls_empty(&head->chain))
continue; continue;
...@@ -288,15 +287,13 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family) ...@@ -288,15 +287,13 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
TCPF_NEW_SYN_RECV)) TCPF_NEW_SYN_RECV))
continue; continue;
if (sk->sk_family != family || if (refcount_read(&sock_net(sk)->ns.count))
refcount_read(&sock_net(sk)->ns.count))
continue; continue;
if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
continue; continue;
if (unlikely(sk->sk_family != family || if (refcount_read(&sock_net(sk)->ns.count)) {
refcount_read(&sock_net(sk)->ns.count))) {
sock_gen_put(sk); sock_gen_put(sk);
goto restart; goto restart;
} }
......
...@@ -3501,7 +3501,7 @@ static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list) ...@@ -3501,7 +3501,7 @@ static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list)
{ {
struct net *net; struct net *net;
tcp_twsk_purge(net_exit_list, AF_INET); tcp_twsk_purge(net_exit_list);
list_for_each_entry(net, net_exit_list, exit_list) { list_for_each_entry(net, net_exit_list, exit_list) {
inet_pernet_hashinfo_free(net->ipv4.tcp_death_row.hashinfo); inet_pernet_hashinfo_free(net->ipv4.tcp_death_row.hashinfo);
......
...@@ -388,7 +388,7 @@ void tcp_twsk_destructor(struct sock *sk) ...@@ -388,7 +388,7 @@ void tcp_twsk_destructor(struct sock *sk)
} }
EXPORT_SYMBOL_GPL(tcp_twsk_destructor); EXPORT_SYMBOL_GPL(tcp_twsk_destructor);
void tcp_twsk_purge(struct list_head *net_exit_list, int family) void tcp_twsk_purge(struct list_head *net_exit_list)
{ {
bool purged_once = false; bool purged_once = false;
struct net *net; struct net *net;
...@@ -396,9 +396,9 @@ void tcp_twsk_purge(struct list_head *net_exit_list, int family) ...@@ -396,9 +396,9 @@ void tcp_twsk_purge(struct list_head *net_exit_list, int family)
list_for_each_entry(net, net_exit_list, exit_list) { list_for_each_entry(net, net_exit_list, exit_list) {
if (net->ipv4.tcp_death_row.hashinfo->pernet) { if (net->ipv4.tcp_death_row.hashinfo->pernet) {
/* Even if tw_refcount == 1, we must clean up kernel reqsk */ /* Even if tw_refcount == 1, we must clean up kernel reqsk */
inet_twsk_purge(net->ipv4.tcp_death_row.hashinfo, family); inet_twsk_purge(net->ipv4.tcp_death_row.hashinfo);
} else if (!purged_once) { } else if (!purged_once) {
inet_twsk_purge(&tcp_hashinfo, family); inet_twsk_purge(&tcp_hashinfo);
purged_once = true; purged_once = true;
} }
} }
......
...@@ -2389,15 +2389,9 @@ static void __net_exit tcpv6_net_exit(struct net *net) ...@@ -2389,15 +2389,9 @@ static void __net_exit tcpv6_net_exit(struct net *net)
inet_ctl_sock_destroy(net->ipv6.tcp_sk); inet_ctl_sock_destroy(net->ipv6.tcp_sk);
} }
static void __net_exit tcpv6_net_exit_batch(struct list_head *net_exit_list)
{
tcp_twsk_purge(net_exit_list, AF_INET6);
}
static struct pernet_operations tcpv6_net_ops = { static struct pernet_operations tcpv6_net_ops = {
.init = tcpv6_net_init, .init = tcpv6_net_init,
.exit = tcpv6_net_exit, .exit = tcpv6_net_exit,
.exit_batch = tcpv6_net_exit_batch,
}; };
int __init tcpv6_init(void) int __init tcpv6_init(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment