]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tcp: Remove sk->sk_prot->orphan_count.
authorKuniyuki Iwashima <kuniyu@google.com>
Fri, 29 Aug 2025 21:56:38 +0000 (21:56 +0000)
committerJakub Kicinski <kuba@kernel.org>
Mon, 1 Sep 2025 19:52:09 +0000 (12:52 -0700)
TCP tracks the number of orphaned (SOCK_DEAD but not yet destructed)
sockets in tcp_orphan_count.

In some code that was shared with DCCP, tcp_orphan_count is referenced
via sk->sk_prot->orphan_count.

Let's reference tcp_orphan_count directly.

inet_csk_prepare_for_destroy_sock() is moved to inet_connection_sock.c
due to header dependency.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250829215641.711664-1-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.h
include/net/inet_connection_sock.h
include/net/sock.h
include/net/tcp.h
net/ipv4/inet_connection_sock.c
net/ipv4/inet_hashtables.c
net/ipv4/tcp.c
net/ipv4/tcp_ipv4.c
net/ipv6/tcp_ipv6.c

index 000116e47e38d90802c5dd676c0659fab19bcff3..4ee970f3bad6ecd57295915831e36f8c8a3e39dc 100644 (file)
@@ -505,7 +505,7 @@ static void reset_listen_child(struct sock *child)
 
        chtls_send_reset(child, CPL_ABORT_SEND_RST, skb);
        sock_orphan(child);
-       INC_ORPHAN_COUNT(child);
+       tcp_orphan_count_inc();
        if (child->sk_state == TCP_CLOSE)
                inet_csk_destroy_sock(child);
 }
@@ -870,7 +870,7 @@ static void do_abort_syn_rcv(struct sock *child, struct sock *parent)
                 * created only after 3 way handshake is done.
                 */
                sock_orphan(child);
-               INC_ORPHAN_COUNT(child);
+               tcp_orphan_count_inc();
                chtls_release_resources(child);
                chtls_conn_done(child);
        } else {
index 667effc2a23cb78901d65da2712a7e8a66ec81b4..29ceff5a5fcb15aad5c9360eb5f9152536d34286 100644 (file)
@@ -95,7 +95,6 @@ struct deferred_skb_cb {
 #define WSCALE_OK(tp) ((tp)->rx_opt.wscale_ok)
 #define TSTAMP_OK(tp) ((tp)->rx_opt.tstamp_ok)
 #define SACK_OK(tp) ((tp)->rx_opt.sack_ok)
-#define INC_ORPHAN_COUNT(sk) this_cpu_inc(*(sk)->sk_prot->orphan_count)
 
 /* TLS SKB */
 #define skb_ulp_tls_inline(skb)      (ULP_SKB_CB(skb)->ulp.tls.ofld)
index 1735db332aab56173e45e8754c8d17b21e7e77c5..0737d8e178dd14e3f2af25108b0d3b64d34390b7 100644 (file)
@@ -299,14 +299,8 @@ reqsk_timeout(struct request_sock *req, unsigned long max_timeout)
        return (unsigned long)min_t(u64, timeout, max_timeout);
 }
 
-static inline void inet_csk_prepare_for_destroy_sock(struct sock *sk)
-{
-       /* The below has to be done to allow calling inet_csk_destroy_sock */
-       sock_set_flag(sk, SOCK_DEAD);
-       this_cpu_inc(*sk->sk_prot->orphan_count);
-}
-
 void inet_csk_destroy_sock(struct sock *sk);
+void inet_csk_prepare_for_destroy_sock(struct sock *sk);
 void inet_csk_prepare_forced_close(struct sock *sk);
 
 /*
index 73cd3316e288bde912dd96637e52d226575c2ffd..1e7f124871d28e6fc82d659c44082a6490cd5895 100644 (file)
@@ -1353,8 +1353,6 @@ struct proto {
        unsigned int            useroffset;     /* Usercopy region offset */
        unsigned int            usersize;       /* Usercopy region size */
 
-       unsigned int __percpu   *orphan_count;
-
        struct request_sock_ops *rsk_prot;
        struct timewait_sock_ops *twsk_prot;
 
index 16dc9cebb9d25832eac7a6ad590a9e9e47e85142..0fb7923b8367d7733f22bdb48add75a81dccc2ea 100644 (file)
@@ -54,6 +54,16 @@ extern struct inet_hashinfo tcp_hashinfo;
 DECLARE_PER_CPU(unsigned int, tcp_orphan_count);
 int tcp_orphan_count_sum(void);
 
+static inline void tcp_orphan_count_inc(void)
+{
+       this_cpu_inc(tcp_orphan_count);
+}
+
+static inline void tcp_orphan_count_dec(void)
+{
+       this_cpu_dec(tcp_orphan_count);
+}
+
 DECLARE_PER_CPU(u32, tcp_tw_isn);
 
 void tcp_time_wait(struct sock *sk, int state, int timeo);
index 0ef1eacd539d1251112b1f341c2e001d09df83a3..142ff8d86fc2fb1671d5fbed9ee4f81534468a2a 100644 (file)
@@ -1296,12 +1296,19 @@ void inet_csk_destroy_sock(struct sock *sk)
 
        xfrm_sk_free_policy(sk);
 
-       this_cpu_dec(*sk->sk_prot->orphan_count);
+       tcp_orphan_count_dec();
 
        sock_put(sk);
 }
 EXPORT_SYMBOL(inet_csk_destroy_sock);
 
+void inet_csk_prepare_for_destroy_sock(struct sock *sk)
+{
+       /* The below has to be done to allow calling inet_csk_destroy_sock */
+       sock_set_flag(sk, SOCK_DEAD);
+       tcp_orphan_count_inc();
+}
+
 /* This function allows to force a closure of a socket after the call to
  * tcp_create_openreq_child().
  */
@@ -1369,7 +1376,7 @@ static void inet_child_forget(struct sock *sk, struct request_sock *req,
 
        sock_orphan(child);
 
-       this_cpu_inc(*sk->sk_prot->orphan_count);
+       tcp_orphan_count_inc();
 
        if (sk->sk_protocol == IPPROTO_TCP && tcp_rsk(req)->tfo_listener) {
                BUG_ON(rcu_access_pointer(tcp_sk(child)->fastopen_rsk) != req);
index 4bc2b1921d2b9db4b531175e6e2348a67d19acb1..ef4ccfd46ff6740e48ffff0556c2e5703632aaa6 100644 (file)
@@ -707,7 +707,7 @@ bool inet_ehash_nolisten(struct sock *sk, struct sock *osk, bool *found_dup_sk)
        if (ok) {
                sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
        } else {
-               this_cpu_inc(*sk->sk_prot->orphan_count);
+               tcp_orphan_count_inc();
                inet_sk_set_state(sk, TCP_CLOSE);
                sock_set_flag(sk, SOCK_DEAD);
                inet_csk_destroy_sock(sk);
index 9bc8317e92b7952871f07ae11a9c2eaa7d3a9e65..40b774b4f587a98f3519d7e00c463da61b1e3873 100644 (file)
@@ -3195,7 +3195,7 @@ adjudge_to_death:
        /* remove backlog if any, without releasing ownership. */
        __release_sock(sk);
 
-       this_cpu_inc(tcp_orphan_count);
+       tcp_orphan_count_inc();
 
        /* Have we already been destroyed by a softirq or backlog? */
        if (state != TCP_CLOSE && sk->sk_state == TCP_CLOSE)
index 7c1d612afca18b424b32ee5e97b99a68062d8436..1e58a8a9ff7ae373c1e5ff11d3ec687f0fa744dc 100644 (file)
@@ -3517,7 +3517,6 @@ struct proto tcp_prot = {
        .leave_memory_pressure  = tcp_leave_memory_pressure,
        .stream_memory_free     = tcp_stream_memory_free,
        .sockets_allocated      = &tcp_sockets_allocated,
-       .orphan_count           = &tcp_orphan_count,
 
        .memory_allocated       = &net_aligned_data.tcp_memory_allocated,
        .per_cpu_fw_alloc       = &tcp_memory_per_cpu_fw_alloc,
index b4e56b8772730579cb85f10b147a15acce03f8e4..07ba321567702fac32ab7bc901bb636e618782b9 100644 (file)
@@ -2353,7 +2353,6 @@ struct proto tcpv6_prot = {
        .per_cpu_fw_alloc       = &tcp_memory_per_cpu_fw_alloc,
 
        .memory_pressure        = &tcp_memory_pressure,
-       .orphan_count           = &tcp_orphan_count,
        .sysctl_mem             = sysctl_tcp_mem,
        .sysctl_wmem_offset     = offsetof(struct net, ipv4.sysctl_tcp_wmem),
        .sysctl_rmem_offset     = offsetof(struct net, ipv4.sysctl_tcp_rmem),