Skip to content

Commit c32f0bd

Browse files
q2venkuba-moo
authored andcommitted
af_unix: Set drop reason in unix_release_sock().
unix_release_sock() is called when the last refcnt of struct file is released. Let's define a new drop reason SKB_DROP_REASON_SOCKET_CLOSE and set it for kfree_skb() in unix_release_sock(). # echo 1 > /sys/kernel/tracing/events/skb/kfree_skb/enable # python3 >>> from socket import * >>> s1, s2 = socketpair(AF_UNIX) >>> s1.send(b'hello world') >>> s2.close() # cat /sys/kernel/tracing/trace_pipe ... python3-280 ... kfree_skb: ... protocol=0 location=unix_release_sock+0x260/0x420 reason: SOCKET_CLOSE To be precise, unix_release_sock() is also called for a new child socket in unix_stream_connect() when something fails, but the new sk does not have skb in the recv queue then and no event is logged. Note that only tcp_inbound_ao_hash() uses a similar drop reason, SKB_DROP_REASON_TCP_CLOSE, and this can be generalised later. Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 454d402 commit c32f0bd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

include/net/dropreason-core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define DEFINE_DROP_REASON(FN, FNe) \
77
FN(NOT_SPECIFIED) \
88
FN(NO_SOCKET) \
9+
FN(SOCKET_CLOSE) \
910
FN(SOCKET_FILTER) \
1011
FN(SOCKET_RCVBUFF) \
1112
FN(PKT_TOO_SMALL) \
@@ -138,6 +139,8 @@ enum skb_drop_reason {
138139
* 3) no valid child socket during 3WHS process
139140
*/
140141
SKB_DROP_REASON_NO_SOCKET,
142+
/** @SKB_DROP_REASON_SOCKET_CLOSE: socket is close()d */
143+
SKB_DROP_REASON_SOCKET_CLOSE,
141144
/** @SKB_DROP_REASON_SOCKET_FILTER: dropped by socket filter */
142145
SKB_DROP_REASON_SOCKET_FILTER,
143146
/** @SKB_DROP_REASON_SOCKET_RCVBUFF: socket receive buff is full */

net/unix/af_unix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,8 @@ static void unix_release_sock(struct sock *sk, int embrion)
715715
if (state == TCP_LISTEN)
716716
unix_release_sock(skb->sk, 1);
717717

718-
/* passed fds are erased in the kfree_skb hook */
719-
kfree_skb(skb);
718+
/* passed fds are erased in the kfree_skb hook */
719+
kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
720720
}
721721

722722
if (path.dentry)

0 commit comments

Comments
 (0)