tcp: small code reorg
Subsystems (3)
cover tcp: small code reorg
Replace a WARN_ON_ONCE() that never triggered
to DEBUG_NET_WARN_ON_ONCE() in reqsk_free().
Move inet_reqsk_alloc() and reqsk_alloc() to inet_connection_sock.c, to unclutter net/ipv4/tcp_input.c and include/net/request_sock.h
Eric Dumazet (3):
tcp: small changes in reqsk_put() and reqsk_free()
tcp: move inet_reqsk_alloc() close to inet_reqsk_clone()
tcp: move reqsk_alloc() to inet_connection_sock.c
include/net/request_sock.h | 37 ++------------------- net/ipv4/inet_connection_sock.c | 58 +++++++++++++++++++++++++++++++++ net/ipv4/tcp_input.c | 25 -------------- 3 files changed, 60 insertions(+), 60 deletions(-)
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
PATCH 1/3 tcp: small changes in reqsk_put() and reqsk_free()
In reqsk_free(), use DEBUG_NET_WARN_ON_ONCE() instead of WARN_ON_ONCE() for a condition which never fired.
In reqsk_put() directly call __reqsk_free(), there is no point checking rsk_refcnt again right after a transition to zero.
--- include/net/request_sock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/net/request_sock.h +2 -2
@@ -172,14 +172,14 @@ static inline void __reqsk_free(struct request_sock *req)static inline void reqsk_free (struct request_sock *req) { -WARN_ON_ONCE (refcount_read (&req->rsk_refcnt) !=0 ); +DEBUG_NET_WARN_ON_ONCE (refcount_read (&req->rsk_refcnt) !=0 );__reqsk_free (req); }static inline void reqsk_put (struct request_sock *req) {if (refcount_dec_and_test (&req->rsk_refcnt)) -reqsk_free (req); +__reqsk_free (req); }/*
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
Re: [PATCH net-next 1/3] tcp: small changes in reqsk_put() and reqsk_free()
Date: Wed, 5 Jun 2024 07:15:51 +0000
From: Eric Dumazet <[email protected]>
Quoted 7 lines
In
reqsk_free(), useDEBUG_NET_WARN_ON_ONCE()instead ofWARN_ON_ONCE()for a condition which never fired.In
reqsk_put()directly call__reqsk_free(), there is no point checkingrsk_refcntagain right after a transition to zero.Signed-off-by Eric Dumazet <[email protected]>
PATCH 2/3 tcp: move inet_reqsk_alloc() close to inet_reqsk_clone()
In reply to Eric Dumazetinet_reqsk_alloc() does not belong to tcp_input.c, move it to inet_connection_sock.c instead.
--- net/ipv4/inet_connection_sock.c | 25 +++++++++++++++++++++++++ net/ipv4/tcp_input.c | 25 ------------------------- 2 files changed, 25 insertions(+), 25 deletions(-)
net/ipv4/inet_connection_sock.c +25 -0
@@ -911,6 +911,31 @@ int inet_rtx_syn_ack(const struct sock *parent, struct request_sock *req) }EXPORT_SYMBOL (inet_rtx_syn_ack); +struct request_sock *inet_reqsk_alloc (const struct request_sock_ops *ops, +struct sock *sk_listener, +bool attach_listener) +{ +struct request_sock *req =reqsk_alloc (ops, sk_listener, + attach_listener); + +if (req) { +struct inet_request_sock *ireq =inet_rsk (req); + + ireq->ireq_opt =NULL ; +#if IS_ENABLED (CONFIG_IPV6 ) + ireq->pktopts =NULL ; +#endif +atomic64_set (&ireq->ir_cookie,0 ); + ireq->ireq_state =TCP_NEW_SYN_RECV ; +write_pnet (&ireq->ireq_net,sock_net (sk_listener)); + ireq->ireq_family = sk_listener->sk_family; + req->timeout =TCP_TIMEOUT_INIT ; + } + +return req; +} +EXPORT_SYMBOL (inet_reqsk_alloc); +static struct request_sock *inet_reqsk_clone (struct request_sock *req,struct sock *sk) {
net/ipv4/tcp_input.c +0 -25
@@ -6986,31 +6986,6 @@ static void tcp_openreq_init(struct request_sock *req,#endif } -struct request_sock *inet_reqsk_alloc (const struct request_sock_ops *ops, -struct sock *sk_listener, -bool attach_listener) -{ -struct request_sock *req =reqsk_alloc (ops, sk_listener, - attach_listener); - -if (req) { -struct inet_request_sock *ireq =inet_rsk (req); - - ireq->ireq_opt =NULL ; -#if IS_ENABLED (CONFIG_IPV6 ) - ireq->pktopts =NULL ; -#endif -atomic64_set (&ireq->ir_cookie,0 ); - ireq->ireq_state =TCP_NEW_SYN_RECV ; -write_pnet (&ireq->ireq_net,sock_net (sk_listener)); - ireq->ireq_family = sk_listener->sk_family; - req->timeout =TCP_TIMEOUT_INIT ; - } - -return req; -} -EXPORT_SYMBOL (inet_reqsk_alloc); -/* * Return true if a syncookie should be sent */
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
Re: [PATCH net-next 2/3] tcp: move inet_reqsk_alloc() close to inet_reqsk_clone()
Date: Wed, 5 Jun 2024 07:15:52 +0000
From: Eric Dumazet <[email protected]>
Quoted 4 lines
inet_reqsk_alloc()does not belong totcp_input.c, move it toinet_connection_sock.cinstead.Signed-off-by Eric Dumazet <[email protected]>
PATCH 3/3 tcp: move reqsk_alloc() to inet_connection_sock.c
In reply to Eric Dumazetreqsk_alloc() has a single caller, no need to expose it in include/net/request_sock.h.
--- include/net/request_sock.h | 33 --------------------------------- net/ipv4/inet_connection_sock.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-)
include/net/request_sock.h +0 -33
@@ -128,39 +128,6 @@ static inline struct sock *skb_steal_sock(struct sk_buff *skb,return sk; } -static inline struct request_sock * -reqsk_alloc_noprof (const struct request_sock_ops *ops,struct sock *sk_listener, -bool attach_listener) -{ -struct request_sock *req; - - req =kmem_cache_alloc_noprof (ops->slab,GFP_ATOMIC | __GFP_NOWARN); -if (!req) -return NULL ; - req->rsk_listener =NULL ; -if (attach_listener) { -if (unlikely (!refcount_inc_not_zero (&sk_listener->sk_refcnt))) { -kmem_cache_free (ops->slab, req); -return NULL ; - } - req->rsk_listener = sk_listener; - } - req->rsk_ops = ops; -req_to_sk (req)->sk_prot = sk_listener->sk_prot; -sk_node_init (&req_to_sk (req)->sk_node); -sk_tx_queue_clear (req_to_sk (req)); - req->saved_syn =NULL ; - req->syncookie =0 ; - req->timeout =0 ; - req->num_timeout =0 ; - req->num_retrans =0 ; - req->sk =NULL ; -refcount_set (&req->rsk_refcnt,0 ); - -return req; -} -#define reqsk_alloc (...) alloc_hooks(reqsk_alloc_noprof(__VA_ARGS__)) -static inline void __reqsk_free (struct request_sock *req) { req->rsk_ops->destructor (req);
net/ipv4/inet_connection_sock.c +33 -0
@@ -911,6 +911,39 @@ int inet_rtx_syn_ack(const struct sock *parent, struct request_sock *req) }EXPORT_SYMBOL (inet_rtx_syn_ack); +static struct request_sock * +reqsk_alloc_noprof (const struct request_sock_ops *ops,struct sock *sk_listener, +bool attach_listener) +{ +struct request_sock *req; + + req =kmem_cache_alloc_noprof (ops->slab,GFP_ATOMIC | __GFP_NOWARN); +if (!req) +return NULL ; + req->rsk_listener =NULL ; +if (attach_listener) { +if (unlikely (!refcount_inc_not_zero (&sk_listener->sk_refcnt))) { +kmem_cache_free (ops->slab, req); +return NULL ; + } + req->rsk_listener = sk_listener; + } + req->rsk_ops = ops; +req_to_sk (req)->sk_prot = sk_listener->sk_prot; +sk_node_init (&req_to_sk (req)->sk_node); +sk_tx_queue_clear (req_to_sk (req)); + req->saved_syn =NULL ; + req->syncookie =0 ; + req->timeout =0 ; + req->num_timeout =0 ; + req->num_retrans =0 ; + req->sk =NULL ; +refcount_set (&req->rsk_refcnt,0 ); + +return req; +} +#define reqsk_alloc (...) alloc_hooks(reqsk_alloc_noprof(__VA_ARGS__)) +struct request_sock *inet_reqsk_alloc (const struct request_sock_ops *ops,struct sock *sk_listener,bool attach_listener)
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
Re: [PATCH net-next 3/3] tcp: move reqsk_alloc() to inet_connection_sock.c
From: Eric Dumazet <[email protected]>
Date: Wed, 5 Jun 2024 07:15:53 +0000
Quoted 4 lines
reqsk_alloc()has a single caller, no need to expose it ininclude/net/request_sock.h.Signed-off-by Eric Dumazet <[email protected]>
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Wed, 5 Jun 2024 07:15:50 +0000 you wrote:
Replace a
WARN_ON_ONCE()that never triggered
toDEBUG_NET_WARN_ON_ONCE()inreqsk_free().Move
inet_reqsk_alloc()andreqsk_alloc()toinet_connection_sock.c, to unclutternet/ipv4/tcp_input.candinclude/net/request_sock.h[...]
Here is the summary with links:
- [net-next,1/3] tcp: small changes in reqsk_put() and reqsk_free()
https://git.kernel.org/netdev/net-next/c/c34506406dd5 - [net-next,2/3] tcp: move inet_reqsk_alloc() close to inet_reqsk_clone() https://git.kernel.org/netdev/net-next/c/adbe695a9765 - [net-next,3/3] tcp: move reqsk_alloc() to inet_connection_sock.c https://git.kernel.org/netdev/net-next/c/6971d2167282
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html