* [PATCH] af_unix: Show number of inflight fds for sockets in TCP_LISTEN state too
@ 2022-08-16 21:51 Kirill Tkhai
2022-08-22 10:40 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Kirill Tkhai @ 2022-08-16 21:51 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Eric Dumazet, Alexander Viro, Kirill Tkhai
TCP_LISTEN sockets is a special case. They preserve skb with a newly
connected sock till accept() makes it fully functional socket.
Receive queue of such socket may grow after connected peer
send messages there. Since these messages may contain scm_fds,
we should expose correct fdinfo::scm_fds for listening socket too.
Signed-off-by: Kirill Tkhai <tkhai@ya.ru>
---
net/unix/af_unix.c | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 3c7e8049eba1..5c7756b57d2f 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -785,15 +785,45 @@ static int unix_set_peek_off(struct sock *sk, int val)
}
#ifdef CONFIG_PROC_FS
+static int unix_count_nr_fds(struct sock *sk)
+{
+ struct sk_buff *skb;
+ struct unix_sock *u;
+ int nr_fds = 0;
+
+ spin_lock(&sk->sk_receive_queue.lock);
+ skb = skb_peek(&sk->sk_receive_queue);
+ while (skb) {
+ u = unix_sk(skb->sk);
+ nr_fds += atomic_read(&u->scm_stat.nr_fds);
+ skb = skb_peek_next(skb, &sk->sk_receive_queue);
+ }
+ spin_unlock(&sk->sk_receive_queue.lock);
+
+ return nr_fds;
+}
+
static void unix_show_fdinfo(struct seq_file *m, struct socket *sock)
{
struct sock *sk = sock->sk;
struct unix_sock *u;
+ int nr_fds;
if (sk) {
- u = unix_sk(sock->sk);
- seq_printf(m, "scm_fds: %u\n",
- atomic_read(&u->scm_stat.nr_fds));
+ u = unix_sk(sk);
+ if (sock->type == SOCK_DGRAM) {
+ nr_fds = atomic_read(&u->scm_stat.nr_fds);
+ goto out_print;
+ }
+
+ unix_state_lock(sk);
+ if (sk->sk_state != TCP_LISTEN)
+ nr_fds = atomic_read(&u->scm_stat.nr_fds);
+ else
+ nr_fds = unix_count_nr_fds(sk);
+ unix_state_unlock(sk);
+out_print:
+ seq_printf(m, "scm_fds: %u\n", nr_fds);
}
}
#else
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] af_unix: Show number of inflight fds for sockets in TCP_LISTEN state too
2022-08-16 21:51 [PATCH] af_unix: Show number of inflight fds for sockets in TCP_LISTEN state too Kirill Tkhai
@ 2022-08-22 10:40 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-22 10:40 UTC (permalink / raw)
To: Kirill Tkhai; +Cc: netdev, davem, edumazet, viro
Hello:
This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:
On Wed, 17 Aug 2022 00:51:54 +0300 you wrote:
> TCP_LISTEN sockets is a special case. They preserve skb with a newly
> connected sock till accept() makes it fully functional socket.
> Receive queue of such socket may grow after connected peer
> send messages there. Since these messages may contain scm_fds,
> we should expose correct fdinfo::scm_fds for listening socket too.
>
> Signed-off-by: Kirill Tkhai <tkhai@ya.ru>
>
> [...]
Here is the summary with links:
- af_unix: Show number of inflight fds for sockets in TCP_LISTEN state too
https://git.kernel.org/netdev/net-next/c/de4370892443
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-22 10:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16 21:51 [PATCH] af_unix: Show number of inflight fds for sockets in TCP_LISTEN state too Kirill Tkhai
2022-08-22 10:40 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.