diff mbox series

[mptcp-next,4/4] mptcp: let mptcp listen dump show listen backlog size

Message ID 20220324135753.25182-5-fw@strlen.de (mailing list archive)
State Superseded, archived
Headers show
Series mptcp: listen dump support | expand

Checks

Context Check Description
matttbe/build success Build and static analysis OK
matttbe/checkpatch success total: 0 errors, 0 warnings, 0 checks, 28 lines checked

Commit Message

Florian Westphal March 24, 2022, 1:57 p.m. UTC
Before:
State   Recv-Q Send-Q  ..
LISTEN       0      0

After:
LISTEN       0     20

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/mptcp/mptcp_diag.c | 10 ++++++++--
 net/mptcp/protocol.c   |  5 ++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

Comments

Paolo Abeni March 24, 2022, 4:45 p.m. UTC | #1
On Thu, 2022-03-24 at 14:57 +0100, Florian Westphal wrote:
> Before:
> State   Recv-Q Send-Q  ..
> LISTEN       0      0
> 
> After:
> LISTEN       0     20
> 
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  net/mptcp/mptcp_diag.c | 10 ++++++++--
>  net/mptcp/protocol.c   |  5 ++++-
>  2 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/net/mptcp/mptcp_diag.c b/net/mptcp/mptcp_diag.c
> index 6a6dfc7eac33..e1babab45e86 100644
> --- a/net/mptcp/mptcp_diag.c
> +++ b/net/mptcp/mptcp_diag.c
> @@ -189,8 +189,14 @@ static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
>  	struct mptcp_sock *msk = mptcp_sk(sk);
>  	struct mptcp_info *info = _info;
>  
> -	r->idiag_rqueue = sk_rmem_alloc_get(sk);
> -	r->idiag_wqueue = sk_wmem_alloc_get(sk);
> +	if (inet_sk_state_load(sk) == TCP_LISTEN) {
> +		r->idiag_rqueue = READ_ONCE(sk->sk_ack_backlog);
> +		r->idiag_wqueue = READ_ONCE(sk->sk_max_ack_backlog);

What about accessing msk->first->sk*ack_backlog instead ? Are there any
possible subtle races? Otherwise sk_ack_backlog will always be 0,
right?

Thanks!

Paolo
Florian Westphal March 24, 2022, 5:35 p.m. UTC | #2
Paolo Abeni <pabeni@redhat.com> wrote:
> > -	r->idiag_rqueue = sk_rmem_alloc_get(sk);
> > -	r->idiag_wqueue = sk_wmem_alloc_get(sk);
> > +	if (inet_sk_state_load(sk) == TCP_LISTEN) {
> > +		r->idiag_rqueue = READ_ONCE(sk->sk_ack_backlog);
> > +		r->idiag_wqueue = READ_ONCE(sk->sk_max_ack_backlog);
> 
> What about accessing msk->first->sk*ack_backlog instead ? Are there any
> possible subtle races? Otherwise sk_ack_backlog will always be 0,
> right?

Yes, msk->first would be better here, will drop this patch
and merge the msk->first bit into preceeding one.
diff mbox series

Patch

diff --git a/net/mptcp/mptcp_diag.c b/net/mptcp/mptcp_diag.c
index 6a6dfc7eac33..e1babab45e86 100644
--- a/net/mptcp/mptcp_diag.c
+++ b/net/mptcp/mptcp_diag.c
@@ -189,8 +189,14 @@  static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	struct mptcp_info *info = _info;
 
-	r->idiag_rqueue = sk_rmem_alloc_get(sk);
-	r->idiag_wqueue = sk_wmem_alloc_get(sk);
+	if (inet_sk_state_load(sk) == TCP_LISTEN) {
+		r->idiag_rqueue = READ_ONCE(sk->sk_ack_backlog);
+		r->idiag_wqueue = READ_ONCE(sk->sk_max_ack_backlog);
+	} else {
+		r->idiag_rqueue = sk_rmem_alloc_get(sk);
+		r->idiag_wqueue = sk_wmem_alloc_get(sk);
+	}
+
 	if (!info)
 		return;
 
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index d3887f628b54..a29cfc4c44a1 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3589,8 +3589,11 @@  static int mptcp_listen(struct socket *sock, int backlog)
 
 	err = ssock->ops->listen(ssock, backlog);
 	inet_sk_state_store(sock->sk, inet_sk_state_load(ssock->sk));
-	if (!err)
+	if (!err) {
 		mptcp_copy_inaddrs(sock->sk, ssock->sk);
+		WRITE_ONCE(sock->sk->sk_max_ack_backlog,
+			   READ_ONCE(ssock->sk->sk_max_ack_backlog));
+	}
 
 unlock:
 	release_sock(sock->sk);