net: add skb drop reasons for TCP, IP, dev and neigh
Subsystems (6)
cover net: add skb drop reasons for TCP, IP, dev and neigh
From: Menglong Dong <[email protected]>
In this series patches, reasons for skb drops are added to TCP, IP, dev and neigh.
For TCP layer, the path of TCP data receive and enqueue are considered. However, it's more complex for TCP state processing, as I find that it's hard to report skb drop reasons to where it is freed. For example, when skb is dropped in tcp_rcv_state_process(), the reason can be caused by the call of tcp_v4_conn_request(), and it's hard to return a drop reason from tcp_v4_conn_request(). So I just skip such case for this moment.
For IP layer, skb drop reasons are added to the packet outputting path. Seems the reasons are not complex, so I didn't split the commits by functions.
For neighbour part, SKB_DROP_REASON_NEIGH_FAILED and SKB_DROP_REASON_NEIGH_QUEUEFULL are added.
For link layer, reasons are added for both packet inputting and outputting path.
The amount of patches in this series seems a bit too many, maybe I should join some of them? For example, combine the patches of dev to one.
Menglong Dong (19):
net: tcp: introduce tcp_drop_reason()
net: tcp: add skb drop reasons to tcp_v4_rcv()
net: tcp: use kfree_skb_reason() for tcp_v6_rcv()
net: tcp: add skb drop reasons to tcp_v{4,6}_inbound_md5_hash()
net: tcp: add skb drop reasons to tcp_add_backlog()
net: tcp: use kfree_skb_reason() for tcp_v{4,6}_do_rcv()
net: tcp: use tcp_drop_reason() for tcp_rcv_established()
net: tcp: use tcp_drop_reason() for tcp_data_queue()
net: tcp: use tcp_drop_reason() for tcp_data_queue_ofo()
net: ip: add skb drop reasons during ip outputting
net: neigh: use kfree_skb_reason() for __neigh_event_send()
net: neigh: add skb drop reasons to arp_error_report()
net: dev: use kfree_skb_reason() for sch_handle_egress()
net: skb: introduce the function kfree_skb_list_reason()
net: dev: add skb drop reasons to __dev_xmit_skb()
net: dev: use kfree_skb_reason() for enqueue_to_backlog()
net: dev: use kfree_skb_reason() for do_xdp_generic()
net: dev: use kfree_skb_reason() for sch_handle_ingress()
net: dev: use kfree_skb_reason() for __netif_receive_skb_core()
include/linux/skbuff.h | 82 +++++++++++++++++++++++++++++++++++++- include/net/tcp.h | 3 +- include/trace/events/skb.h | 21 ++++++++++ net/core/dev.c | 25 +++++++----- net/core/neighbour.c | 4 +- net/core/skbuff.c | 7 ++-- net/ipv4/arp.c | 2 +- net/ipv4/ip_output.c | 6 +-- net/ipv4/tcp_input.c | 45 ++++++++++++++++----- net/ipv4/tcp_ipv4.c | 36 ++++++++++++----- net/ipv6/ip6_output.c | 6 +-- net/ipv6/tcp_ipv6.c | 42 ++++++++++++++----- 12 files changed, 227 insertions(+), 52 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/19 net: tcp: introduce tcp_drop_reason()
From: Menglong Dong <[email protected]>
For TCP protocol, tcp_drop() is used to free the skb when it needs to be dropped. To make use of kfree_skb_reason() and collect drop reasons, introduce the function tcp_drop_reason().
tcp_drop_reason() will finally call kfree_skb_reason() and pass the drop reason to 'kfree_skb' tracepoint.
PS: __kfree_skb() was used in tcp_drop(), I'm not sure if it's ok to replace it with kfree_skb_reason().
--- net/ipv4/tcp_input.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +11 -2
@@ -4684,10 +4684,19 @@ static bool tcp_ooo_try_coalesce(struct sock *sk,return res; } -static void tcp_drop (struct sock *sk,struct sk_buff *skb) +static void tcp_drop_reason (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason reason) {sk_drops_add (sk, skb); -__kfree_skb (skb); +/* why __kfree_skb() used here before, other than kfree_skb()? +* confusing...... +*/ +kfree_skb_reason (skb, reason); +} + +static inline void tcp_drop (struct sock *sk,struct sk_buff *skb) +{ +tcp_drop_reason (sk, skb,SKB_DROP_REASON_NOT_SPECIFIED ); }/* This one checks to see if we can put data from the
Signature · 1 line
2.34.1
Re: [PATCH net-next 01/19] net: tcp: introduce tcp_drop_reason()
Quoted 24 lines · On Tue, Feb 15, 2022 at 3:30 AM <[email protected]> wrote:
From: Menglong Dong <[email protected]>
For TCP protocol,
tcp_drop()is used to free the skb when it needs to be dropped. To make use ofkfree_skb_reason()and collect drop reasons, introduce the functiontcp_drop_reason().
tcp_drop_reason()will finally callkfree_skb_reason()and pass the drop reason to 'kfree_skb' tracepoint.PS:
__kfree_skb()was used intcp_drop(), I'm not sure if it's ok to replace it withkfree_skb_reason().Signed-off-by Menglong Dong <[email protected]>--- net/ipv4/tcp_input.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)net/ipv4/tcp_input.c +0
-0@@ -4684,10 +4684,19 @@ static bool tcp_ooo_try_coalesce(struct sock *sk,return res;
net/ipv4/tcp_input.c static bool tcp_ooo_try_coalesce(struct sock *sk, · line 4692
Quoted 10 lines
net/ipv4/tcp_input.c +4
-2} -static void tcp_drop (struct sock *sk,struct sk_buff *skb) +static void tcp_drop_reason (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason reason) {sk_drops_add (sk, skb); -__kfree_skb (skb); +/* why __kfree_skb() used here before, other than kfree_skb()? +* confusing......
Do not add comments like that if you do not know the difference...
__kfree_skb() is used by TCP stack because it owns skb in receive queues, and avoids touching skb->users
because it must be one already.
(We made sure not using skb_get() in TCP)
It seems fine to use kfree_skb() in tcp_drop(), it is hardly fast path, and the added cost is pure noise.
David Ahern
maintainerRe: [PATCH net-next 01/19] net: tcp: introduce tcp_drop_reason()
Quoted 19 lines · Eric Dumazet
Quoted 6 lines
net/ipv4/tcp_input.c +0
-0@@ -4684,10 +4684,19 @@ static bool tcp_ooo_try_coalesce(struct sock *sk,return res;net/ipv4/tcp_input.c static bool tcp_ooo_try_coalesce(struct sock *sk, · line 4692
Quoted 10 lines
net/ipv4/tcp_input.c +4
-2} -static void tcp_drop (struct sock *sk,struct sk_buff *skb) +static void tcp_drop_reason (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason reason) {sk_drops_add (sk, skb); -__kfree_skb (skb); +/* why __kfree_skb() used here before, other than kfree_skb()? +* confusing...... Do not add comments like that if you do not know the difference...
Quoted 3 lines
__kfree_skb()is used by TCP stack because it owns skb in receive queues, and avoids touchingskb->users
because it must be one already.
and it bypasses kfree_skb tracepoint which seems by design.
Re: [PATCH net-next 01/19] net: tcp: introduce tcp_drop_reason()
Quoted 21 lines · David Ahern
Quoted 19 lines · Eric Dumazet
Quoted 6 lines
net/ipv4/tcp_input.c +0
-0@@ -4684,10 +4684,19 @@ static bool tcp_ooo_try_coalesce(struct sock *sk,return res;net/ipv4/tcp_input.c static bool tcp_ooo_try_coalesce(struct sock *sk, · line 4692
Quoted 10 lines
net/ipv4/tcp_input.c +4
-2} -static void tcp_drop (struct sock *sk,struct sk_buff *skb) +static void tcp_drop_reason (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason reason) {sk_drops_add (sk, skb); -__kfree_skb (skb); +/* why __kfree_skb() used here before, other than kfree_skb()? +* confusing...... Do not add comments like that if you do not know the difference...
Quoted 5 lines
Quoted 3 lines
__kfree_skb()is used by TCP stack because it owns skb in receive queues, and avoids touchingskb->users
because it must be one already.and it bypasses
kfree_skbtracepoint which seems by design.
Do you mean it shouldn't be traced here?
According to my understanding, __kfree_skb() was used in the beginning as skb->users aren't touched by TCP. Later, tcp_drop() was introduced to record drop count to the socket.
Considering the skb is indeed dropped and no other event is triggered, is it ok to trigger the kfree_skb tracepoint?
Thanks!
Menglong Dong
Re: [PATCH net-next 01/19] net: tcp: introduce tcp_drop_reason()
In reply to Eric DumazetQuoted 39 lines · Eric Dumazet
Quoted 24 lines · On Tue, Feb 15, 2022 at 3:30 AM <[email protected]> wrote:
From: Menglong Dong <[email protected]>
For TCP protocol,
tcp_drop()is used to free the skb when it needs to be dropped. To make use ofkfree_skb_reason()and collect drop reasons, introduce the functiontcp_drop_reason().
tcp_drop_reason()will finally callkfree_skb_reason()and pass the drop reason to 'kfree_skb' tracepoint.PS:
__kfree_skb()was used intcp_drop(), I'm not sure if it's ok to replace it withkfree_skb_reason().Signed-off-by Menglong Dong <[email protected]>--- net/ipv4/tcp_input.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)net/ipv4/tcp_input.c +0
-0@@ -4684,10 +4684,19 @@ static bool tcp_ooo_try_coalesce(struct sock *sk,return res;net/ipv4/tcp_input.c static bool tcp_ooo_try_coalesce(struct sock *sk, · line 4692
Quoted 10 lines
net/ipv4/tcp_input.c +4
-2} -static void tcp_drop (struct sock *sk,struct sk_buff *skb) +static void tcp_drop_reason (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason reason) {sk_drops_add (sk, skb); -__kfree_skb (skb); +/* why __kfree_skb() used here before, other than kfree_skb()? +* confusing...... Do not add comments like that if you do not know the difference...
Quoted 8 lines
__kfree_skb()is used by TCP stack because it owns skb in receive queues, and avoids touchingskb->users
because it must be one already.(We made sure not using
skb_get()in TCP)It seems fine to use
kfree_skb()intcp_drop(), it is hardly fast path, and the added cost is pure noise.
I understand why __kfree_skb() was used now, and it seems this commit is ok (with the comments removed of course). I'll keep it still.
Thanks!
Menglong Dong
PATCH 2/19 net: tcp: add skb drop reasons to tcp_v4_rcv()
In reply to [email protected]From: Menglong Dong <[email protected]>
Use kfree_skb_reason() for some path in tcp_v4_rcv() that missed before, including:
SKB_DROP_REASON_SOCKET_FILTERSKB_DROP_REASON_XFRM_POLICY
--- net/ipv4/tcp_ipv4.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
net/ipv4/tcp_ipv4.c +9 -2
@@ -2057,6 +2057,8 @@ int tcp_v4_rcv(struct sk_buff *skb) iph =ip_hdr (skb);tcp_v4_fill_cb (skb, iph, th); nsk =tcp_check_req (sk, skb, req, false, &req_stolen); + }else { + drop_reason =SKB_DROP_REASON_SOCKET_FILTER ; }if (!nsk) {reqsk_put (req);
@@ -2092,8 +2094,10 @@ int tcp_v4_rcv(struct sk_buff *skb) } } -if (!xfrm4_policy_check (sk,XFRM_POLICY_IN , skb)) +if (!xfrm4_policy_check (sk,XFRM_POLICY_IN , skb)) { + drop_reason =SKB_DROP_REASON_XFRM_POLICY ; goto discard_and_relse; + }if (tcp_v4_inbound_md5_hash (sk, skb, dif, sdif)) goto discard_and_relse;
@@ -2137,8 +2141,10 @@ int tcp_v4_rcv(struct sk_buff *skb) no_tcp_socket: drop_reason =SKB_DROP_REASON_NO_SOCKET ; -if (!xfrm4_policy_check (NULL ,XFRM_POLICY_IN , skb)) +if (!xfrm4_policy_check (NULL ,XFRM_POLICY_IN , skb)) { + drop_reason =SKB_DROP_REASON_XFRM_POLICY ; goto discard_it; + }tcp_v4_fill_cb (skb, iph, th);
@@ -2166,6 +2172,7 @@ int tcp_v4_rcv(struct sk_buff *skb) do_time_wait:if (!xfrm4_policy_check (NULL ,XFRM_POLICY_IN , skb)) { + drop_reason =SKB_DROP_REASON_XFRM_POLICY ;inet_twsk_put (inet_twsk (sk)); goto discard_it; }
Signature · 1 line
2.34.1
PATCH 3/19 net: tcp: use kfree_skb_reason() for tcp_v6_rcv()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace kfree_skb() used in tcp_v6_rcv() with kfree_skb_reason().
--- net/ipv6/tcp_ipv6.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
net/ipv6/tcp_ipv6.c +20 -5
@@ -1627,6 +1627,7 @@ static void tcp_v6_fill_cb(struct sk_buff *skb, const struct ipv6hdr *hdr, INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) { +enum skb_drop_reason drop_reason;int sdif =inet6_sdif (skb);int dif =inet6_iif (skb);const struct tcphdr *th;
@@ -1636,6 +1637,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)int ret;struct net *net =dev_net (skb->dev); + drop_reason =SKB_DROP_REASON_NOT_SPECIFIED ;if (skb->pkt_type !=PACKET_HOST ) goto discard_it;
@@ -1649,8 +1651,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) th = (const struct tcphdr *)skb->data; -if (unlikely (th->doff <sizeof (struct tcphdr )/4 )) +if (unlikely (th->doff <sizeof (struct tcphdr ) /4 )) { + drop_reason =SKB_DROP_REASON_PKT_TOO_SMALL ; goto bad_packet; + }if (!pskb_may_pull (skb, th->doff*4 )) goto discard_it;
@@ -1706,6 +1710,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) hdr =ipv6_hdr (skb);tcp_v6_fill_cb (skb, hdr, th); nsk =tcp_check_req (sk, skb, req, false, &req_stolen); + }else { + drop_reason =SKB_DROP_REASON_SOCKET_FILTER ; }if (!nsk) {reqsk_put (req);
@@ -1741,14 +1747,18 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) } } -if (!xfrm6_policy_check (sk,XFRM_POLICY_IN , skb)) +if (!xfrm6_policy_check (sk,XFRM_POLICY_IN , skb)) { + drop_reason =SKB_DROP_REASON_XFRM_POLICY ; goto discard_and_relse; + }if (tcp_v6_inbound_md5_hash (sk, skb, dif, sdif)) goto discard_and_relse; -if (tcp_filter (sk, skb)) +if (tcp_filter (sk, skb)) { + drop_reason =SKB_DROP_REASON_SOCKET_FILTER ; goto discard_and_relse; + } th = (const struct tcphdr *)skb->data; hdr =ipv6_hdr (skb);tcp_v6_fill_cb (skb, hdr, th);
@@ -1779,13 +1789,17 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)return ret ?-1 :0 ; no_tcp_socket: -if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) + drop_reason =SKB_DROP_REASON_NO_SOCKET ; +if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) { + drop_reason =SKB_DROP_REASON_XFRM_POLICY ; goto discard_it; + }tcp_v6_fill_cb (skb, hdr, th);if (tcp_checksum_complete (skb)) { csum_error: + drop_reason =SKB_DROP_REASON_TCP_CSUM ;trace_tcp_bad_csum (skb);__TCP_INC_STATS (net,TCP_MIB_CSUMERRORS ); bad_packet:
@@ -1795,7 +1809,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) } discard_it: -kfree_skb (skb); +kfree_skb_reason (skb, drop_reason);return 0 ; discard_and_relse:
@@ -1806,6 +1820,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) do_time_wait:if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) { + drop_reason =SKB_DROP_REASON_XFRM_POLICY ;inet_twsk_put (inet_twsk (sk)); goto discard_it; }
Signature · 1 line
2.34.1
PATCH 4/19 net: tcp: add skb drop reasons to tcp_v{4,6}_inbound_md5_hash()
In reply to [email protected]From: Menglong Dong <[email protected]>
Pass the address of drop reason to tcp_v4_inbound_md5_hash() and tcp_v6_inbound_md5_hash() to store the reasons for skb drops when this function fails. Therefore, the drop reason can be passed to kfree_skb_reason() when the skb needs to be freed.
Following drop reasons are added:
SKB_DROP_REASON_TCP_MD5NOTFOUNDSKB_DROP_REASON_TCP_MD5UNEXPECTEDSKB_DROP_REASON_TCP_MD5FAILURE
--- include/linux/skbuff.h | 7 +++++++ include/trace/events/skb.h | 4 ++++ net/ipv4/tcp_ipv4.c | 13 +++++++++---- net/ipv6/tcp_ipv6.c | 11 ++++++++--- 4 files changed, 28 insertions(+), 7 deletions(-)
include/linux/skbuff.h +7 -0
@@ -346,6 +346,13 @@ enum skb_drop_reason {* udp packet drop out of * udp_memory_allocated. */ +SKB_DROP_REASON_TCP_MD5NOTFOUND ,/* No MD5 hash and one +* expected +*/ +SKB_DROP_REASON_TCP_MD5UNEXPECTED ,/* MD5 hash and we're not +* expecting one +*/ +SKB_DROP_REASON_TCP_MD5FAILURE ,/* MD5 hash and its wrong */ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +4 -0
@@ -27,6 +27,10 @@ EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO) \ EM(SKB_DROP_REASON_SOCKET_RCVBUFF, SOCKET_RCVBUFF) \ EM(SKB_DROP_REASON_PROTO_MEM, PROTO_MEM) \ + EM(SKB_DROP_REASON_TCP_MD5NOTFOUND, TCP_MD5NOTFOUND) \ +EM (SKB_DROP_REASON_TCP_MD5UNEXPECTED , \ + TCP_MD5UNEXPECTED) \ + EM(SKB_DROP_REASON_TCP_MD5FAILURE, TCP_MD5FAILURE) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/ipv4/tcp_ipv4.c +9 -4
@@ -1412,7 +1412,8 @@ EXPORT_SYMBOL(tcp_v4_md5_hash_skb);/* Called with rcu_read_lock() */ static bool tcp_v4_inbound_md5_hash (const struct sock *sk,const struct sk_buff *skb, -int dif,int sdif) +int dif,int sdif, +enum skb_drop_reason *reason) {#ifdef CONFIG_TCP_MD5SIG /*
@@ -1445,11 +1446,13 @@ static bool tcp_v4_inbound_md5_hash(const struct sock *sk,return false;if (hash_expected && !hash_location) { + *reason =SKB_DROP_REASON_TCP_MD5NOTFOUND ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPMD5NOTFOUND );return true; }if (!hash_expected && hash_location) { + *reason =SKB_DROP_REASON_TCP_MD5UNEXPECTED ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPMD5UNEXPECTED );return true; }
@@ -1462,6 +1465,7 @@ static bool tcp_v4_inbound_md5_hash(const struct sock *sk, NULL, skb);if (genhash ||memcmp (hash_location, newhash,16 ) !=0 ) { + *reason =SKB_DROP_REASON_TCP_MD5FAILURE ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPMD5FAILURE ); net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n", &iph->saddr, ntohs(th->source),
@@ -1971,13 +1975,13 @@ static void tcp_v4_fill_cb(struct sk_buff *skb, const struct iphdr *iph,int tcp_v4_rcv (struct sk_buff *skb) {struct net *net =dev_net (skb->dev); +enum skb_drop_reason drop_reason;int sdif =inet_sdif (skb);int dif =inet_iif (skb);const struct iphdr *iph;const struct tcphdr *th;bool refcounted;struct sock *sk; -int drop_reason;int ret; drop_reason =SKB_DROP_REASON_NOT_SPECIFIED ;
@@ -2025,7 +2029,8 @@ int tcp_v4_rcv(struct sk_buff *skb)struct sock *nsk; sk = req->rsk_listener; -if (unlikely (tcp_v4_inbound_md5_hash (sk, skb, dif, sdif))) { +if (unlikely (tcp_v4_inbound_md5_hash (sk, skb, dif, sdif, + &drop_reason))) {sk_drops_add (sk, skb);reqsk_put (req); goto discard_it;
@@ -2099,7 +2104,7 @@ int tcp_v4_rcv(struct sk_buff *skb) goto discard_and_relse; } -if (tcp_v4_inbound_md5_hash (sk, skb, dif, sdif)) +if (tcp_v4_inbound_md5_hash (sk, skb, dif, sdif, &drop_reason)) goto discard_and_relse;nf_reset_ct (skb);
net/ipv6/tcp_ipv6.c +8 -3
@@ -775,7 +775,8 @@ static int tcp_v6_md5_hash_skb(char *md5_hash,static bool tcp_v6_inbound_md5_hash (const struct sock *sk,const struct sk_buff *skb, -int dif,int sdif) +int dif,int sdif, +enum skb_drop_reason *reason) {#ifdef CONFIG_TCP_MD5SIG const __u8 *hash_location =NULL ;
@@ -798,11 +799,13 @@ static bool tcp_v6_inbound_md5_hash(const struct sock *sk,return false;if (hash_expected && !hash_location) { + *reason =SKB_DROP_REASON_TCP_MD5NOTFOUND ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPMD5NOTFOUND );return true; }if (!hash_expected && hash_location) { + *reason =SKB_DROP_REASON_TCP_MD5UNEXPECTED ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPMD5UNEXPECTED );return true; }
@@ -813,6 +816,7 @@ static bool tcp_v6_inbound_md5_hash(const struct sock *sk, NULL, skb);if (genhash ||memcmp (hash_location, newhash,16 ) !=0 ) { + *reason =SKB_DROP_REASON_TCP_MD5FAILURE ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPMD5FAILURE ); net_info_ratelimited("MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u L3 index %d\n", genhash ? "failed" : "mismatch",
@@ -1681,7 +1685,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)struct sock *nsk; sk = req->rsk_listener; -if (tcp_v6_inbound_md5_hash (sk, skb, dif, sdif)) { +if (tcp_v6_inbound_md5_hash (sk, skb, dif, sdif, + &drop_reason)) {sk_drops_add (sk, skb);reqsk_put (req); goto discard_it;
@@ -1752,7 +1757,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) goto discard_and_relse; } -if (tcp_v6_inbound_md5_hash (sk, skb, dif, sdif)) +if (tcp_v6_inbound_md5_hash (sk, skb, dif, sdif, &drop_reason)) goto discard_and_relse;if (tcp_filter (sk, skb)) {
Signature · 1 line
2.34.1
PATCH 5/19 net: tcp: add skb drop reasons to tcp_add_backlog()
In reply to [email protected]From: Menglong Dong <[email protected]>
Pass the address of drop_reason to tcp_add_backlog() to store the reasons for skb drops when fails. Following drop reasons are introduced:
SKB_DROP_REASON_SOCKET_BACKLOG
--- include/linux/skbuff.h | 4 ++++ include/net/tcp.h | 3 ++- include/trace/events/skb.h | 1 + net/ipv4/tcp_ipv4.c | 7 +++++-- net/ipv6/tcp_ipv6.c | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-)
include/linux/skbuff.h +4 -0
@@ -353,6 +353,10 @@ enum skb_drop_reason {* expecting one */ SKB_DROP_REASON_TCP_MD5FAILURE ,/* MD5 hash and its wrong */ +SKB_DROP_REASON_SOCKET_BACKLOG ,/* failed to add skb to socket +* backlog (see +* LINUX_MIB_TCPBACKLOGDROP) +*/ SKB_DROP_REASON_MAX, };
include/net/tcp.h +2 -1
@@ -1367,7 +1367,8 @@ static inline bool tcp_checksum_complete(struct sk_buff *skb)__skb_checksum_complete (skb); } -bool tcp_add_backlog (struct sock *sk,struct sk_buff *skb); +bool tcp_add_backlog (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason *reason);#ifdef CONFIG_INET void __sk_defer_free_flush (struct sock *sk);
include/trace/events/skb.h +1 -0
@@ -31,6 +31,7 @@EM (SKB_DROP_REASON_TCP_MD5UNEXPECTED , \ TCP_MD5UNEXPECTED) \ EM(SKB_DROP_REASON_TCP_MD5FAILURE, TCP_MD5FAILURE) \ + EM(SKB_DROP_REASON_SOCKET_BACKLOG, SOCKET_BACKLOG) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/ipv4/tcp_ipv4.c +5 -2
@@ -1811,7 +1811,8 @@ int tcp_v4_early_demux(struct sk_buff *skb)return 0 ; } -bool tcp_add_backlog (struct sock *sk,struct sk_buff *skb) +bool tcp_add_backlog (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason *reason) {u32 limit, tail_gso_size, tail_gso_segs;struct skb_shared_info *shinfo;
@@ -1837,6 +1838,7 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb)if (unlikely (tcp_checksum_complete (skb))) {bh_unlock_sock (sk);trace_tcp_bad_csum (skb); + *reason =SKB_DROP_REASON_TCP_CSUM ;__TCP_INC_STATS (sock_net (sk),TCP_MIB_CSUMERRORS );__TCP_INC_STATS (sock_net (sk),TCP_MIB_INERRS );return true;
@@ -1925,6 +1927,7 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb)if (unlikely (sk_add_backlog (sk, skb, limit))) {bh_unlock_sock (sk); + *reason =SKB_DROP_REASON_SOCKET_BACKLOG ;__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPBACKLOGDROP );return true; }
@@ -2133,7 +2136,7 @@ int tcp_v4_rcv(struct sk_buff *skb)if (!sock_owned_by_user (sk)) { ret =tcp_v4_do_rcv (sk, skb); }else { -if (tcp_add_backlog (sk, skb)) +if (tcp_add_backlog (sk, skb, &drop_reason)) goto discard_and_relse; }bh_unlock_sock (sk);
net/ipv6/tcp_ipv6.c +1 -1
@@ -1784,7 +1784,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)if (!sock_owned_by_user (sk)) { ret =tcp_v6_do_rcv (sk, skb); }else { -if (tcp_add_backlog (sk, skb)) +if (tcp_add_backlog (sk, skb, &drop_reason)) goto discard_and_relse; }bh_unlock_sock (sk);
Signature · 1 line
2.34.1
PATCH 6/19 net: tcp: use kfree_skb_reason() for tcp_v{4,6}_do_rcv()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace kfree_skb() used in tcp_v4_do_rcv() and tcp_v6_do_rcv() with kfree_skb_reason().
--- net/ipv4/tcp_ipv4.c | 5 ++++- net/ipv6/tcp_ipv6.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-)
net/ipv4/tcp_ipv4.c +4 -1
@@ -1708,6 +1708,7 @@ INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *,*/ int tcp_v4_do_rcv (struct sock *sk,struct sk_buff *skb) { +enum skb_drop_reason reason;struct sock *rsk;if (sk->sk_state ==TCP_ESTABLISHED ) {/* Fast path */
@@ -1730,6 +1731,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)return 0 ; } + reason =SKB_DROP_REASON_NOT_SPECIFIED ;if (tcp_checksum_complete (skb)) goto csum_err;
@@ -1757,7 +1759,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) reset:tcp_v4_send_reset (rsk, skb); discard: -kfree_skb (skb); +kfree_skb_reason (skb, reason);/* Be careful here. If this function gets more complicated and * gcc suffers from register pressure on the x86, sk (in %ebx) * might be destroyed here. This current version compiles correctly,
@@ -1766,6 +1768,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)return 0 ; csum_err: + reason =SKB_DROP_REASON_TCP_CSUM ;trace_tcp_bad_csum (skb);TCP_INC_STATS (sock_net (sk),TCP_MIB_CSUMERRORS );TCP_INC_STATS (sock_net (sk),TCP_MIB_INERRS );
net/ipv6/tcp_ipv6.c +3 -1
@@ -1476,6 +1476,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) {struct ipv6_pinfo *np =tcp_inet6_sk (sk);struct sk_buff *opt_skb =NULL ; +enum skb_drop_reason reason;struct tcp_sock *tp;/* Imagine: socket is IPv6. IPv4 packet arrives,
@@ -1563,9 +1564,10 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) discard:if (opt_skb)__kfree_skb (opt_skb); -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; csum_err: + reason =SKB_DROP_REASON_TCP_CSUM ;trace_tcp_bad_csum (skb);TCP_INC_STATS (sock_net (sk),TCP_MIB_CSUMERRORS );TCP_INC_STATS (sock_net (sk),TCP_MIB_INERRS );
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH net-next 06/19] net: tcp: use kfree_skb_reason() for tcp_v{4,6}_do_rcv()
Thank you for the patch! Perhaps something to improve:
Hi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on next-20220214]
[cannot apply to net-next/master rostedt-trace/for-next net/master linus/master v5.17-rc4 v5.17-rc3 v5.17-rc2 v5.17-rc4] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/menglong8-dong-gmail-com/net-add-skb-drop-reasons-for-TCP-IP-dev-and-neigh/20220215-193437 base: 259cbfc98c55ba3b6ef6e61fb7cfc3751dfded1e config: i386-randconfig-a004-20220214 (https://download.01.org/0day-ci/archive/20220215/202202152352.9jAkQxUc-lkp(a)intel.com/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 37f422f4ac31c8b8041c6b62065263314282dab6)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/8619663f7f150a5f5d782d8f6083988f56505777
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review menglong8-dong-gmail-com/net-add-skb-drop-reasons-for-TCP-IP-dev-and-neigh/20220215-193437 git checkout 8619663f7f150a5f5d782d8f6083988f56505777
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/ipv6/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> net/ipv6/tcp_ipv6.c:1556:6: warning: variable 'reason' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (tcp_rcv_state_process(sk, skb))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/ipv6/tcp_ipv6.c:1567:24: note: uninitialized use occurs here
kfree_skb_reason(skb, reason);
^~~~~~
net/ipv6/tcp_ipv6.c:1556:2: note: remove the 'if' if its condition is always false
if (tcp_rcv_state_process(sk, skb))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/ipv6/tcp_ipv6.c:1547:8: warning: variable 'reason' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (tcp_child_process(sk, nsk, skb))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/ipv6/tcp_ipv6.c:1567:24: note: uninitialized use occurs here
kfree_skb_reason(skb, reason);
^~~~~~
net/ipv6/tcp_ipv6.c:1547:4: note: remove the 'if' if its condition is always false
if (tcp_child_process(sk, nsk, skb))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net/ipv6/tcp_ipv6.c:1543:7: warning: variable 'reason' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (!nsk)
^~~~
net/ipv6/tcp_ipv6.c:1567:24: note: uninitialized use occurs here
kfree_skb_reason(skb, reason);
^~~~~~
net/ipv6/tcp_ipv6.c:1543:3: note: remove the 'if' if its condition is always false
if (!nsk)
^~~~~~~~~
net/ipv6/tcp_ipv6.c:1479:2: note: variable 'reason' is declared here
enum skb_drop_reason reason;
^3 warnings generated.
vim +1556 net/ipv6/tcp_ipv6.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 1463
bbd807dfbf2050 Brian Vazquez 2021-02-01 1464 INDIRECT_CALLABLE_DECLARE(struct dst_entry *ipv4_dst_check(struct dst_entry *,
bbd807dfbf2050 Brian Vazquez 2021-02-01 1465 u32));
^1da177e4c3f41 Linus Torvalds 2005-04-16 1466 /* The socket must have it's spinlock held when we get
e994b2f0fb9229 Eric Dumazet 2015-10-02 1467 * here, unless it is a TCP_LISTEN socket.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1468 *
^1da177e4c3f41 Linus Torvalds 2005-04-16 1469 * We have a potential double-lock case here, so even when
^1da177e4c3f41 Linus Torvalds 2005-04-16 1470 * doing backlog processing we use the BH locking scheme.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1471 * This is because we cannot sleep with the original spinlock
^1da177e4c3f41 Linus Torvalds 2005-04-16 1472 * held.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1473 */
d2489c7b6d7d5e Eric Dumazet 2021-11-15 1474 INDIRECT_CALLABLE_SCOPE
d2489c7b6d7d5e Eric Dumazet 2021-11-15 1475 int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
^1da177e4c3f41 Linus Torvalds 2005-04-16 1476 {
93a77c11ae79e8 Eric Dumazet 2019-03-19 1477 struct ipv6_pinfo *np = tcp_inet6_sk(sk);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1478 struct sk_buff *opt_skb = NULL;
8619663f7f150a Menglong Dong 2022-02-15 1479 enum skb_drop_reason reason;
93a77c11ae79e8 Eric Dumazet 2019-03-19 1480 struct tcp_sock *tp;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1481
^1da177e4c3f41 Linus Torvalds 2005-04-16 1482 /* Imagine: socket is IPv6. IPv4 packet arrives,
^1da177e4c3f41 Linus Torvalds 2005-04-16 1483 goes to IPv4 receive handler and backlogged.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1484 From backlog it always goes here. Kerboom...
^1da177e4c3f41 Linus Torvalds 2005-04-16 1485 Fortunately, tcp_rcv_established and rcv_established
^1da177e4c3f41 Linus Torvalds 2005-04-16 1486 handle them correctly, but it is not case with
^1da177e4c3f41 Linus Torvalds 2005-04-16 1487 tcp_v6_hnd_req and tcp_v6_send_reset(). --ANK
^1da177e4c3f41 Linus Torvalds 2005-04-16 1488 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 1489
^1da177e4c3f41 Linus Torvalds 2005-04-16 1490 if (skb->protocol == htons(ETH_P_IP))
^1da177e4c3f41 Linus Torvalds 2005-04-16 1491 return tcp_v4_do_rcv(sk, skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1492
^1da177e4c3f41 Linus Torvalds 2005-04-16 1493 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 1494 * socket locking is here for SMP purposes as backlog rcv
^1da177e4c3f41 Linus Torvalds 2005-04-16 1495 * is currently called with bh processing disabled.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1496 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 1497
^1da177e4c3f41 Linus Torvalds 2005-04-16 1498 /* Do Stevens' IPV6_PKTOPTIONS.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1499
^1da177e4c3f41 Linus Torvalds 2005-04-16 1500 Yes, guys, it is the only place in our code, where we
^1da177e4c3f41 Linus Torvalds 2005-04-16 1501 may make it not affecting IPv4.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1502 The rest of code is protocol independent,
^1da177e4c3f41 Linus Torvalds 2005-04-16 1503 and I do not like idea to uglify IPv4.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1504
^1da177e4c3f41 Linus Torvalds 2005-04-16 1505 Actually, all the idea behind IPV6_PKTOPTIONS
^1da177e4c3f41 Linus Torvalds 2005-04-16 1506 looks not very well thought. For now we latch
^1da177e4c3f41 Linus Torvalds 2005-04-16 1507 options, received in the last packet, enqueued
^1da177e4c3f41 Linus Torvalds 2005-04-16 1508 by tcp. Feel free to propose better solution.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1509 --ANK (980728)
^1da177e4c3f41 Linus Torvalds 2005-04-16 1510 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 1511 if (np->rxopt.all)
7450aaf61f0ae2 Eric Dumazet 2015-11-30 1512 opt_skb = skb_clone(skb, sk_gfp_mask(sk, GFP_ATOMIC));
^1da177e4c3f41 Linus Torvalds 2005-04-16 1513
^1da177e4c3f41 Linus Torvalds 2005-04-16 1514 if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */
8f905c0e7354ef Eric Dumazet 2021-12-20 1515 struct dst_entry *dst;
8f905c0e7354ef Eric Dumazet 2021-12-20 1516
8f905c0e7354ef Eric Dumazet 2021-12-20 1517 dst = rcu_dereference_protected(sk->sk_rx_dst,
8f905c0e7354ef Eric Dumazet 2021-12-20 1518 lockdep_sock_is_held(sk));
5d299f3d3c8a2f Eric Dumazet 2012-08-06 1519
bdeab991918663 Tom Herbert 2011-08-14 1520 sock_rps_save_rxhash(sk, skb);
3d97379a67486b Eric Dumazet 2014-11-11 1521 sk_mark_napi_id(sk, skb);
5d299f3d3c8a2f Eric Dumazet 2012-08-06 1522 if (dst) {
0c0a5ef809f915 Eric Dumazet 2021-10-25 1523 if (sk->sk_rx_dst_ifindex != skb->skb_iif ||
bbd807dfbf2050 Brian Vazquez 2021-02-01 1524 INDIRECT_CALL_1(dst->ops->check, ip6_dst_check,
ef57c1610dd8fb Eric Dumazet 2021-10-25 1525 dst, sk->sk_rx_dst_cookie) == NULL) {
8f905c0e7354ef Eric Dumazet 2021-12-20 1526 RCU_INIT_POINTER(sk->sk_rx_dst, NULL);
5d299f3d3c8a2f Eric Dumazet 2012-08-06 1527 dst_release(dst);
5d299f3d3c8a2f Eric Dumazet 2012-08-06 1528 }
5d299f3d3c8a2f Eric Dumazet 2012-08-06 1529 }
5d299f3d3c8a2f Eric Dumazet 2012-08-06 1530
3d97d88e8091f3 Yafang Shao 2018-05-29 1531 tcp_rcv_established(sk, skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1532 if (opt_skb)
^1da177e4c3f41 Linus Torvalds 2005-04-16 1533 goto ipv6_pktoptions;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1534 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1535 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 1536
12e25e1041d044 Eric Dumazet 2015-06-03 1537 if (tcp_checksum_complete(skb))
^1da177e4c3f41 Linus Torvalds 2005-04-16 1538 goto csum_err;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1539
^1da177e4c3f41 Linus Torvalds 2005-04-16 1540 if (sk->sk_state == TCP_LISTEN) {
079096f103faca Eric Dumazet 2015-10-02 1541 struct sock *nsk = tcp_v6_cookie_check(sk, skb);
079096f103faca Eric Dumazet 2015-10-02 1542
^1da177e4c3f41 Linus Torvalds 2005-04-16 1543 if (!nsk)
^1da177e4c3f41 Linus Torvalds 2005-04-16 1544 goto discard;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1545
^1da177e4c3f41 Linus Torvalds 2005-04-16 1546 if (nsk != sk) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 1547 if (tcp_child_process(sk, nsk, skb))
^1da177e4c3f41 Linus Torvalds 2005-04-16 1548 goto reset;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1549 if (opt_skb)
^1da177e4c3f41 Linus Torvalds 2005-04-16 1550 __kfree_skb(opt_skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1551 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1552 }
47482f132a689a Neil Horman 2011-04-06 1553 } else
bdeab991918663 Tom Herbert 2011-08-14 1554 sock_rps_save_rxhash(sk, skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1555
72ab4a86f7a260 Eric Dumazet 2015-09-29 @1556 if (tcp_rcv_state_process(sk, skb))
^1da177e4c3f41 Linus Torvalds 2005-04-16 1557 goto reset;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1558 if (opt_skb)
^1da177e4c3f41 Linus Torvalds 2005-04-16 1559 goto ipv6_pktoptions;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1560 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1561
^1da177e4c3f41 Linus Torvalds 2005-04-16 1562 reset:
cfb6eeb4c86059 YOSHIFUJI Hideaki 2006-11-14 1563 tcp_v6_send_reset(sk, skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1564 discard:
^1da177e4c3f41 Linus Torvalds 2005-04-16 1565 if (opt_skb)
^1da177e4c3f41 Linus Torvalds 2005-04-16 1566 __kfree_skb(opt_skb);
8619663f7f150a Menglong Dong 2022-02-15 1567 kfree_skb_reason(skb, reason);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1568 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1569 csum_err:
8619663f7f150a Menglong Dong 2022-02-15 1570 reason = SKB_DROP_REASON_TCP_CSUM;
709c0314239992 Jakub Kicinski 2021-05-14 1571 trace_tcp_bad_csum(skb);
c10d9310edf5aa Eric Dumazet 2016-04-29 1572 TCP_INC_STATS(sock_net(sk), TCP_MIB_CSUMERRORS);
c10d9310edf5aa Eric Dumazet 2016-04-29 1573 TCP_INC_STATS(sock_net(sk), TCP_MIB_INERRS);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1574 goto discard;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1575
^1da177e4c3f41 Linus Torvalds 2005-04-16 1576
^1da177e4c3f41 Linus Torvalds 2005-04-16 1577 ipv6_pktoptions:
^1da177e4c3f41 Linus Torvalds 2005-04-16 1578 /* Do you ask, what is it?
^1da177e4c3f41 Linus Torvalds 2005-04-16 1579
^1da177e4c3f41 Linus Torvalds 2005-04-16 1580 1. skb was enqueued by tcp.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1581 2. skb is added to tail of read queue, rather than out of order.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1582 3. socket is not in passive state.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1583 4. Finally, it really contains options, which user wants to receive.
^1da177e4c3f41 Linus Torvalds 2005-04-16 1584 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 1585 tp = tcp_sk(sk);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1586 if (TCP_SKB_CB(opt_skb)->end_seq == tp->rcv_nxt &&
^1da177e4c3f41 Linus Torvalds 2005-04-16 1587 !((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) {
333fad5364d6b4 YOSHIFUJI Hideaki 2005-09-08 1588 if (np->rxopt.bits.rxinfo || np->rxopt.bits.rxoinfo)
870c3151382c98 Eric Dumazet 2014-10-17 1589 np->mcast_oif = tcp_v6_iif(opt_skb);
333fad5364d6b4 YOSHIFUJI Hideaki 2005-09-08 1590 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
0660e03f6b18f1 Arnaldo Carvalho de Melo 2007-04-25 1591 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
82e9f105a28006 Florent Fourcot 2013-12-08 1592 if (np->rxopt.bits.rxflow || np->rxopt.bits.rxtclass)
1397ed35f22d7c Florent Fourcot 2013-12-08 1593 np->rcv_flowinfo = ip6_flowinfo(ipv6_hdr(opt_skb));
df3687ffc6653e Florent Fourcot 2014-01-17 1594 if (np->repflow)
df3687ffc6653e Florent Fourcot 2014-01-17 1595 np->flow_label = ip6_flowlabel(ipv6_hdr(opt_skb));
a224772db8420e Eric Dumazet 2014-09-27 1596 if (ipv6_opt_accepted(sk, opt_skb, &TCP_SKB_CB(opt_skb)->header.h6)) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 1597 skb_set_owner_r(opt_skb, sk);
8ce48623f0cf3d Eric Dumazet 2016-10-12 1598 tcp_v6_restore_cb(opt_skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1599 opt_skb = xchg(&np->pktoptions, opt_skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1600 } else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 1601 __kfree_skb(opt_skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1602 opt_skb = xchg(&np->pktoptions, NULL);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1603 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 1604 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 1605
12c8691de30734 Eric Dumazet 2021-10-25 1606 consume_skb(opt_skb);
^1da177e4c3f41 Linus Torvalds 2005-04-16 1607 return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 1608 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 1609 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH 7/19 net: tcp: use tcp_drop_reason() for tcp_rcv_established()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace tcp_drop() used in tcp_rcv_established() with tcp_drop_reason(). Following drop reasons are added:
SKB_DROP_REASON_TCP_FLAGS
--- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/ipv4/tcp_input.c | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-)
include/linux/skbuff.h +1 -0
@@ -357,6 +357,7 @@ enum skb_drop_reason {* backlog (see * LINUX_MIB_TCPBACKLOGDROP) */ +SKB_DROP_REASON_TCP_FLAGS ,/* TCP flags invalid */ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +1 -0
@@ -32,6 +32,7 @@ TCP_MD5UNEXPECTED) \ EM(SKB_DROP_REASON_TCP_MD5FAILURE, TCP_MD5FAILURE) \ EM(SKB_DROP_REASON_SOCKET_BACKLOG, SOCKET_BACKLOG) \ + EM(SKB_DROP_REASON_TCP_FLAGS, TCP_FLAGS) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/ipv4/tcp_input.c +7 -2
@@ -5790,6 +5790,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,*/ void tcp_rcv_established (struct sock *sk,struct sk_buff *skb) { +enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;const struct tcphdr *th = (const struct tcphdr *)skb->data;struct tcp_sock *tp =tcp_sk (sk);unsigned int len = skb->len;
@@ -5878,6 +5879,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) tp->rcv_rtt_last_tsecr = tp->rx_opt.rcv_tsecr;return ; }else {/* Header too small */ + reason =SKB_DROP_REASON_PKT_TOO_SMALL ;TCP_INC_STATS (sock_net (sk),TCP_MIB_INERRS ); goto discard; }
@@ -5933,8 +5935,10 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)if (len < (th->doff <<2 ) ||tcp_checksum_complete (skb)) goto csum_error; -if (!th->ack && !th->rst && !th->syn) +if (!th->ack && !th->rst && !th->syn) { + reason =SKB_DROP_REASON_TCP_FLAGS ; goto discard; + }/* * Standard slow path.
@@ -5960,12 +5964,13 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)return ; csum_error: + reason =SKB_DROP_REASON_TCP_CSUM ;trace_tcp_bad_csum (skb);TCP_INC_STATS (sock_net (sk),TCP_MIB_CSUMERRORS );TCP_INC_STATS (sock_net (sk),TCP_MIB_INERRS ); discard: -tcp_drop (sk, skb); +tcp_drop_reason (sk, skb, reason); }EXPORT_SYMBOL (tcp_rcv_established);
Signature · 1 line
2.34.1
PATCH 8/19 net: tcp: use tcp_drop_reason() for tcp_data_queue()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace tcp_drop() used in tcp_data_queue() with tcp_drop_reason(). Following drop reasons are introduced:
SKB_DROP_REASON_TCP_ZEROWINDOWSKB_DROP_REASON_TCP_OLD_DATASKB_DROP_REASON_TCP_OVERWINDOW
SKB_DROP_REASON_TCP_OLD_DATA is used for the case that end_seq of skb less than the left edges of receive window. (Maybe there is a better name?)
--- include/linux/skbuff.h | 13 +++++++++++++ include/trace/events/skb.h | 3 +++ net/ipv4/tcp_input.c | 13 +++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-)
include/linux/skbuff.h +13 -0
@@ -358,6 +358,19 @@ enum skb_drop_reason {* LINUX_MIB_TCPBACKLOGDROP) */ SKB_DROP_REASON_TCP_FLAGS ,/* TCP flags invalid */ +SKB_DROP_REASON_TCP_ZEROWINDOW ,/* TCP receive window size is zero, +* see LINUX_MIB_TCPZEROWINDOWDROP +*/ +SKB_DROP_REASON_TCP_OLD_DATA ,/* the TCP data reveived is already +* received before (spurious retrans +* may happened), see +* LINUX_MIB_DELAYEDACKLOST +*/ +SKB_DROP_REASON_TCP_OVERWINDOW ,/* the TCP data is out of window, +* the seq of the first byte exceed +* the right edges of receive +* window +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +3 -0
@@ -33,6 +33,9 @@ EM(SKB_DROP_REASON_TCP_MD5FAILURE, TCP_MD5FAILURE) \ EM(SKB_DROP_REASON_SOCKET_BACKLOG, SOCKET_BACKLOG) \ EM(SKB_DROP_REASON_TCP_FLAGS, TCP_FLAGS) \ + EM(SKB_DROP_REASON_TCP_ZEROWINDOW, TCP_ZEROWINDOW) \ + EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA) \ + EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/ipv4/tcp_input.c +11 -2
@@ -4991,6 +4991,7 @@ void tcp_data_ready(struct sock *sk)static void tcp_data_queue (struct sock *sk,struct sk_buff *skb) {struct tcp_sock *tp =tcp_sk (sk); +enum skb_drop_reason reason;bool fragstolen;int eaten;
@@ -5009,6 +5010,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)skb_dst_drop (skb);__skb_pull (skb,tcp_hdr (skb)->doff *4 ); + reason =SKB_DROP_REASON_NOT_SPECIFIED ; tp->rx_opt.dsack =0 ;/* Queue data for delivery to the user.
@@ -5017,6 +5019,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)*/ if (TCP_SKB_CB (skb)->seq == tp->rcv_nxt) {if (tcp_receive_window (tp) ==0 ) { + reason =SKB_DROP_REASON_TCP_ZEROWINDOW ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPZEROWINDOWDROP ); goto out_of_window; }
@@ -5026,6 +5029,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)if (skb_queue_len (&sk->sk_receive_queue) ==0 )sk_forced_mem_schedule (sk, skb->truesize);else if (tcp_try_rmem_schedule (sk, skb, skb->truesize)) { + reason =SKB_DROP_REASON_PROTO_MEM ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPRCVQDROP ); sk->sk_data_ready (sk); goto drop;
@@ -5062,6 +5066,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)if (!after (TCP_SKB_CB (skb)->end_seq, tp->rcv_nxt)) {tcp_rcv_spurious_retrans (sk, skb);/* A retransmit, 2nd most common case. Force an immediate ack. */ + reason =SKB_DROP_REASON_TCP_OLD_DATA ;NET_INC_STATS (sock_net (sk),LINUX_MIB_DELAYEDACKLOST );tcp_dsack_set (sk,TCP_SKB_CB (skb)->seq,TCP_SKB_CB (skb)->end_seq);
@@ -5069,13 +5074,16 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)tcp_enter_quickack_mode (sk,TCP_MAX_QUICKACKS );inet_csk_schedule_ack (sk); drop: -tcp_drop (sk, skb); +tcp_drop_reason (sk, skb, reason);return ; }/* Out of window. F.e. zero window probe. */ -if (!before (TCP_SKB_CB (skb)->seq, tp->rcv_nxt +tcp_receive_window (tp))) +if (!before (TCP_SKB_CB (skb)->seq, + tp->rcv_nxt +tcp_receive_window (tp))) { + reason =SKB_DROP_REASON_TCP_OVERWINDOW ; goto out_of_window; + }if (before (TCP_SKB_CB (skb)->seq, tp->rcv_nxt)) {/* Partial packet, seq < rcv_next < end_seq */
@@ -5085,6 +5093,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)* remembering D-SACK for its head made in previous line. */ if (!tcp_receive_window (tp)) { + reason =SKB_DROP_REASON_TCP_ZEROWINDOW ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPZEROWINDOWDROP ); goto out_of_window; }
Signature · 1 line
2.34.1
PATCH 9/19 net: tcp: use tcp_drop_reason() for tcp_data_queue_ofo()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace tcp_drop() used in tcp_data_queue_ofo with tcp_drop_reason(). Following drop reasons are introduced:
SKB_DROP_REASON_TCP_OFOMERGE
--- include/linux/skbuff.h | 3 +++ include/trace/events/skb.h | 1 + net/ipv4/tcp_input.c | 10 ++++++---- 3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/skbuff.h +3 -0
@@ -371,6 +371,9 @@ enum skb_drop_reason {* the right edges of receive * window */ +SKB_DROP_REASON_TCP_OFOMERGE ,/* the data of skb is already in +* the ofo queue. +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +1 -0
@@ -36,6 +36,7 @@ EM(SKB_DROP_REASON_TCP_ZEROWINDOW, TCP_ZEROWINDOW) \ EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA) \ EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW) \ + EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/ipv4/tcp_input.c +6 -4
@@ -4782,7 +4782,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)if (unlikely (tcp_try_rmem_schedule (sk, skb, skb->truesize))) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPOFODROP ); sk->sk_data_ready (sk); -tcp_drop (sk, skb); +tcp_drop_reason (sk, skb,SKB_DROP_REASON_PROTO_MEM );return ; }
@@ -4845,7 +4845,8 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)/* All the bits are present. Drop. */ NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPOFOMERGE ); -tcp_drop (sk, skb); +tcp_drop_reason (sk, skb, +SKB_DROP_REASON_TCP_OFOMERGE ); skb =NULL ;tcp_dsack_set (sk, seq, end_seq); goto add_sack;
@@ -4864,7 +4865,8 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) TCP_SKB_CB(skb1)->end_seq);NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPOFOMERGE ); -tcp_drop (sk, skb1); +tcp_drop_reason (sk, skb1, +SKB_DROP_REASON_TCP_OFOMERGE ); goto merge_right; } } else if (tcp_ooo_try_coalesce(sk, skb1,
@@ -4892,7 +4894,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)tcp_dsack_extend (sk,TCP_SKB_CB (skb1)->seq,TCP_SKB_CB (skb1)->end_seq);NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPOFOMERGE ); -tcp_drop (sk, skb1); +tcp_drop_reason (sk, skb1,SKB_DROP_REASON_TCP_OFOMERGE ); }/* If there is no skb after us, we are the last_skb ! */ if (!skb1)
Signature · 1 line
2.34.1
PATCH 10/19 net: ip: add skb drop reasons during ip outputting
In reply to [email protected]From: Menglong Dong <[email protected]>
As kfree_skb() is not used frequently during packet outputting in ip layer, we do this job (add reasons for skb drops) at once.
kfree_skb() is replaced by kfree_skb_reason() in following functions:
__ip_queue_xmit(), ip_finish_output(), ip_mc_finish_output(), ip6_output(), ip6_finish_output(), ip6_finish_output2()
and following drop reasons are added:
SKB_DROP_REASON_IP_OUTNOROUTESSKB_DROP_REASON_BPF_CGROUP_EGRESSSKB_DROP_REASON_IPV6DSIABLED
--- include/linux/skbuff.h | 13 +++++++++++++ include/trace/events/skb.h | 4 ++++ net/ipv4/ip_output.c | 6 +++--- net/ipv6/ip6_output.c | 6 +++--- 4 files changed, 23 insertions(+), 6 deletions(-)
include/linux/skbuff.h +13 -0
@@ -374,6 +374,19 @@ enum skb_drop_reason {SKB_DROP_REASON_TCP_OFOMERGE ,/* the data of skb is already in * the ofo queue. */ +SKB_DROP_REASON_IP_OUTNOROUTES ,/* route lookup failed during +* packet outputting +*/ +SKB_DROP_REASON_BPF_CGROUP_EGRESS ,/* dropped by eBPF program +* with type of BPF_PROG_TYPE_CGROUP_SKB +* and attach type of +* BPF_CGROUP_INET_EGRESS +* during packet sending +*/ +SKB_DROP_REASON_IPV6DSIABLED ,/* IPv6 is disabled on the device, +* see the doc for disable_ipv6 +* in ip-sysctl.rst for detail +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +4 -0
@@ -37,6 +37,10 @@ EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA) \ EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW) \ EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE) \ + EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES) \ +EM (SKB_DROP_REASON_BPF_CGROUP_EGRESS , \ + BPF_CGROUP_EGRESS) \ + EM(SKB_DROP_REASON_IPV6DSIABLED, IPV6DSIABLED) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/ipv4/ip_output.c +3 -3
@@ -317,7 +317,7 @@ static int ip_finish_output(struct net *net, struct sock *sk, struct sk_buff *skcase NET_XMIT_CN :return __ip_finish_output (net, sk, skb) ? : ret;default : -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_BPF_CGROUP_EGRESS );return ret; } }
@@ -337,7 +337,7 @@ static int ip_mc_finish_output(struct net *net, struct sock *sk,case NET_XMIT_SUCCESS :break ;default : -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_BPF_CGROUP_EGRESS );return ret; }
@@ -536,7 +536,7 @@ int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl, no_route:rcu_read_unlock ();IP_INC_STATS (net,IPSTATS_MIB_OUTNOROUTES ); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_IP_OUTNOROUTES );return -EHOSTUNREACH ; }EXPORT_SYMBOL (__ip_queue_xmit);
net/ipv6/ip6_output.c +3 -3
@@ -130,7 +130,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *rcu_read_unlock_bh ();IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTNOROUTES ); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_IP_OUTNOROUTES );return -EINVAL ; }
@@ -202,7 +202,7 @@ static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *scase NET_XMIT_CN :return __ip6_finish_output (net, sk, skb) ? : ret;default : -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_BPF_CGROUP_EGRESS );return ret; } }
@@ -217,7 +217,7 @@ int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb)if (unlikely (idev->cnf.disable_ipv6)) {IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTDISCARDS ); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_IPV6DSIABLED );return 0 ; }
Signature · 1 line
2.34.1
PATCH 11/19 net: neigh: use kfree_skb_reason() for __neigh_event_send()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace kfree_skb() used in __neigh_event_send() with kfree_skb_reason(). Following drop reasons are added:
SKB_DROP_REASON_NEIGH_FAILEDSKB_DROP_REASON_NEIGH_QUEUEFULL
The two reasons above should be the hot path that skb drops in neighbour layer.
--- include/linux/skbuff.h | 9 +++++++++ include/trace/events/skb.h | 2 ++ net/core/neighbour.c | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-)
include/linux/skbuff.h +9 -0
@@ -387,6 +387,15 @@ enum skb_drop_reason {* see the doc for disable_ipv6 * in ip-sysctl.rst for detail */ +SKB_DROP_REASON_NEIGH_FAILED ,/* dropped as the state of +* neighbour is NUD_FAILED +*/ +SKB_DROP_REASON_NEIGH_QUEUEFULL ,/* the skbs that waiting +* for sending on the queue +* of neigh->arp_queue is +* full, and the skbs on the +* tail will be dropped +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +2 -0
@@ -41,6 +41,8 @@EM (SKB_DROP_REASON_BPF_CGROUP_EGRESS , \ BPF_CGROUP_EGRESS) \ EM(SKB_DROP_REASON_IPV6DSIABLED, IPV6DSIABLED) \ + EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \ + EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/core/neighbour.c +2 -2
@@ -1171,7 +1171,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb, neigh->updated = jiffies;write_unlock_bh (&neigh->lock); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_NEIGH_FAILED );return 1 ; } }else if (neigh->nud_state &NUD_STALE ) {
@@ -1193,7 +1193,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb,if (!buff)break ; neigh->arp_queue_len_bytes -= buff->truesize; -kfree_skb (buff); +kfree_skb_reason (buff,SKB_DROP_REASON_NEIGH_QUEUEFULL );NEIGH_CACHE_STAT_INC (neigh->tbl, unres_discards); }skb_dst_force (skb);
Signature · 1 line
2.34.1
PATCH 12/19 net: neigh: add skb drop reasons to arp_error_report()
In reply to [email protected]From: Menglong Dong <[email protected]>
When neighbour become invalid or destroyed, neigh_invalidate() will be called. neigh->ops->error_report() will be called if the neighbour's state is NUD_FAILED, and seems here is the only use of error_report(). So we can tell that the reason of skb drops in arp_error_report() is SKB_DROP_REASON_NEIGH_FAILED.
--- net/ipv4/arp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/arp.c +1 -1
@@ -293,7 +293,7 @@ static int arp_constructor(struct neighbour *neigh)static void arp_error_report (struct neighbour *neigh,struct sk_buff *skb) {dst_link_failure (skb); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_NEIGH_FAILED ); }/* Create and send an arp packet. */
Signature · 1 line
2.34.1
PATCH 13/19 net: dev: use kfree_skb_reason() for sch_handle_egress()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace kfree_skb() used in sch_handle_egress() with kfree_skb_reason(). The drop reason SKB_DROP_REASON_QDISC_EGRESS is introduced. Considering the code path of qdisc egress, we make it distinct with the drop reason of SKB_DROP_REASON_QDISC_DROP in the next commit.
--- include/linux/skbuff.h | 4 ++++ include/trace/events/skb.h | 1 + net/core/dev.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-)
include/linux/skbuff.h +4 -0
@@ -396,6 +396,10 @@ enum skb_drop_reason {* full, and the skbs on the * tail will be dropped */ +SKB_DROP_REASON_QDISC_EGRESS ,/* qdisc of type egress check +* failed (maybe an eBPF program +* is tricking?) +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +1 -0
@@ -43,6 +43,7 @@ EM(SKB_DROP_REASON_IPV6DSIABLED, IPV6DSIABLED) \ EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \ EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ + EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/core/dev.c +1 -1
@@ -3840,7 +3840,7 @@ sch_handle_egress(struct sk_buff *skb, int *ret, struct net_device *dev)case TC_ACT_SHOT :mini_qdisc_qstats_cpu_drop (miniq); *ret =NET_XMIT_DROP ; -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_QDISC_EGRESS );return NULL ;case TC_ACT_STOLEN :case TC_ACT_QUEUED :
Signature · 1 line
2.34.1
PATCH 14/19 net: skb: introduce the function kfree_skb_list_reason()
In reply to [email protected]From: Menglong Dong <[email protected]>
To report reasons of skb drops, introduce the function kfree_skb_list_reason() and make kfree_skb_list() an inline call to it. This function will be used in the next commit in __dev_xmit_skb().
--- include/linux/skbuff.h | 8 +++++++- net/core/skbuff.c | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-)
include/linux/skbuff.h +7 -1
@@ -1196,10 +1196,16 @@ static inline void kfree_skb(struct sk_buff *skb) }void skb_release_head_state (struct sk_buff *skb); -void kfree_skb_list (struct sk_buff *segs); +void kfree_skb_list_reason (struct sk_buff *segs, +enum skb_drop_reason reason);void skb_dump (const char *level,const struct sk_buff *skb,bool full_pkt);void skb_tx_error (struct sk_buff *skb); +static inline void kfree_skb_list (struct sk_buff *segs) +{ +kfree_skb_list_reason (segs,SKB_DROP_REASON_NOT_SPECIFIED ); +} +#ifdef CONFIG_TRACEPOINTS void consume_skb (struct sk_buff *skb);#else
net/core/skbuff.c +4 -3
@@ -777,16 +777,17 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) }EXPORT_SYMBOL (kfree_skb_reason); -void kfree_skb_list (struct sk_buff *segs) +void kfree_skb_list_reason (struct sk_buff *segs, +enum skb_drop_reason reason) {while (segs) {struct sk_buff *next = segs->next; -kfree_skb (segs); +kfree_skb_reason (segs, reason); segs = next; } } -EXPORT_SYMBOL (kfree_skb_list); +EXPORT_SYMBOL (kfree_skb_list_reason);/* Dump skb information and contents. *
Signature · 1 line
2.34.1
PATCH 15/19 net: dev: add skb drop reasons to __dev_xmit_skb()
In reply to [email protected]From: Menglong Dong <[email protected]>
Add reasons for skb drops to __dev_xmit_skb() by replacing kfree_skb_list() with kfree_skb_list_reason(). The drop reason of SKB_DROP_REASON_QDISC_DROP is introduced for qdisc enqueue fails.
--- include/linux/skbuff.h | 4 ++++ include/trace/events/skb.h | 1 + net/core/dev.c | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-)
include/linux/skbuff.h +4 -0
@@ -400,6 +400,10 @@ enum skb_drop_reason {* failed (maybe an eBPF program * is tricking?) */ +SKB_DROP_REASON_QDISC_DROP ,/* dropped by qdisc when packet +* outputting (failed to enqueue to +* current qdisc) +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +1 -0
@@ -44,6 +44,7 @@ EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \ EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \ + EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/core/dev.c +3 -2
@@ -3710,7 +3710,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, no_lock_out:if (unlikely (to_free)) -kfree_skb_list (to_free); +kfree_skb_list_reason (to_free, +SKB_DROP_REASON_QDISC_DROP );return rc; }
@@ -3765,7 +3766,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, }spin_unlock (root_lock);if (unlikely (to_free)) -kfree_skb_list (to_free); +kfree_skb_list_reason (to_free,SKB_DROP_REASON_QDISC_DROP );if (unlikely (contended))spin_unlock (&q->busylock);return rc;
Signature · 1 line
2.34.1
PATCH 16/19 net: dev: use kfree_skb_reason() for enqueue_to_backlog()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace kfree_skb() used in enqueue_to_backlog() with kfree_skb_reason(). The skb drop reason SKB_DROP_REASON_CPU_BACKLOG is introduced for the case of failing to enqueue the skb to the per CPU backlog queue. The further reason can be backlog queue full or RPS flow limition, and I think we needn't to make further distinctions.
--- include/linux/skbuff.h | 6 ++++++ include/trace/events/skb.h | 1 + net/core/dev.c | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-)
include/linux/skbuff.h +6 -0
@@ -404,6 +404,12 @@ enum skb_drop_reason {* outputting (failed to enqueue to * current qdisc) */ +SKB_DROP_REASON_CPU_BACKLOG ,/* failed to enqueue the skb to +* the per CPU backlog queue. This +* can be caused by backlog queue +* full (see netdev_max_backlog in +* net.rst) or RPS flow limit +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +1 -0
@@ -45,6 +45,7 @@ EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \ EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ + EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/core/dev.c +5 -1
@@ -4520,10 +4520,12 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen)static int enqueue_to_backlog (struct sk_buff *skb,int cpu,unsigned int *qtail) { +enum skb_drop_reason reason;struct softnet_data *sd;unsigned long flags;unsigned int qlen; + reason =SKB_DROP_REASON_NOT_SPECIFIED ; sd = &per_cpu (softnet_data, cpu);local_irq_save (flags);
@@ -4550,6 +4552,8 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,____napi_schedule (sd, &sd->backlog); } goto enqueue; + }else { + reason =SKB_DROP_REASON_CPU_BACKLOG ; } drop:
@@ -4559,7 +4563,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,local_irq_restore (flags);atomic_long_inc (&skb->dev->rx_dropped); -kfree_skb (skb); +kfree_skb_reason (skb, reason);return NET_RX_DROP ; }
Signature · 1 line
2.34.1
PATCH 17/19 net: dev: use kfree_skb_reason() for do_xdp_generic()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace kfree_skb() used in do_xdp_generic() with kfree_skb_reason(). The drop reason SKB_DROP_REASON_XDP is introduced for this case.
--- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/core/dev.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-)
include/linux/skbuff.h +1 -0
@@ -410,6 +410,7 @@ enum skb_drop_reason {* full (see netdev_max_backlog in * net.rst) or RPS flow limit */ +SKB_DROP_REASON_XDP ,/* dropped by XDP in input path */ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +1 -0
@@ -46,6 +46,7 @@ EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \ EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ + EM(SKB_DROP_REASON_XDP, XDP) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/core/dev.c +1 -1
@@ -4783,7 +4783,7 @@ int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb) }return XDP_PASS ; out_redir: -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_XDP );return XDP_DROP ; }EXPORT_SYMBOL_GPL (do_xdp_generic);
Signature · 1 line
2.34.1
PATCH 18/19 net: dev: use kfree_skb_reason() for sch_handle_ingress()
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace kfree_skb() used in sch_handle_ingress() with kfree_skb_reason(). Following drop reasons are introduced:
SKB_DROP_REASON_QDISC_INGRESS
--- include/linux/skbuff.h | 4 ++++ include/trace/events/skb.h | 1 + net/core/dev.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-)
include/linux/skbuff.h +4 -0
@@ -411,6 +411,10 @@ enum skb_drop_reason {* net.rst) or RPS flow limit */ SKB_DROP_REASON_XDP ,/* dropped by XDP in input path */ +SKB_DROP_REASON_QDISC_INGRESS ,/* qdisc of type ingress check +* failed (maybe an eBPF program +* is tricking?) +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +1 -0
@@ -47,6 +47,7 @@ EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ EM(SKB_DROP_REASON_XDP, XDP) \ + EM(SKB_DROP_REASON_QDISC_INGRESS, QDISC_INGRESS) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/core/dev.c +1 -1
@@ -5006,7 +5006,7 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,break ;case TC_ACT_SHOT :mini_qdisc_qstats_cpu_drop (miniq); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_QDISC_INGRESS );return NULL ;case TC_ACT_STOLEN :case TC_ACT_QUEUED :
Signature · 1 line
2.34.1
PATCH 19/19 net: dev: use kfree_skb_reason() for __netif_receive_skb_core()
In reply to [email protected]From: Menglong Dong <[email protected]>
Add reason for skb drops to __netif_receive_skb_core() when packet_type not found to handle the skb. For this purpose, the drop reason SKB_DROP_REASON_PTYPE_ABSENT is introduced. Take ether packets for example, this case mainly happens when L3 protocol is not supported.
--- include/linux/skbuff.h | 5 +++++ include/trace/events/skb.h | 1 + net/core/dev.c | 8 +++++--- 3 files changed, 11 insertions(+), 3 deletions(-)
include/linux/skbuff.h +5 -0
@@ -415,6 +415,11 @@ enum skb_drop_reason {* failed (maybe an eBPF program * is tricking?) */ +SKB_DROP_REASON_PTYPE_ABSENT ,/* no packet_type found to handle +* the skb. For an etner packet, +* this means that L3 protocol is +* not supported +*/ SKB_DROP_REASON_MAX, };
include/trace/events/skb.h +1 -0
@@ -48,6 +48,7 @@ EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ EM(SKB_DROP_REASON_XDP, XDP) \ EM(SKB_DROP_REASON_QDISC_INGRESS, QDISC_INGRESS) \ + EM(SKB_DROP_REASON_PTYPE_ABSENT, PTYPE_ABSENT) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/core/dev.c +5 -3
@@ -5323,11 +5323,13 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, *ppt_prev = pt_prev; }else { drop: -if (!deliver_exact) +if (!deliver_exact) {atomic_long_inc (&skb->dev->rx_dropped); -else +kfree_skb_reason (skb,SKB_DROP_REASON_PTYPE_ABSENT ); + }else {atomic_long_inc (&skb->dev->rx_nohandler); -kfree_skb (skb); +kfree_skb (skb); + }/* Jamal, now you will not able to escape explaining * me how you were going to use this. :-) */
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 17 lines · On Tue, 15 Feb 2022 19:27:53 +0800 [email protected] wrote:
From: Menglong Dong <[email protected]>
In this series patches, reasons for skb drops are added to TCP, IP, dev and neigh.
For TCP layer, the path of TCP data receive and enqueue are considered. However, it's more complex for TCP state processing, as I find that it's hard to report skb drop reasons to where it is freed. For example, when skb is dropped in
tcp_rcv_state_process(), the reason can be caused by the call oftcp_v4_conn_request(), and it's hard to return a drop reason fromtcp_v4_conn_request(). So I just skip such case for this moment.For IP layer, skb drop reasons are added to the packet outputting path. Seems the reasons are not complex, so I didn't split the commits by functions.
Quoted 8 lines
For neighbour part,
SKB_DROP_REASON_NEIGH_FAILEDandSKB_DROP_REASON_NEIGH_QUEUEFULLare added.For link layer, reasons are added for both packet inputting and outputting path.
The amount of patches in this series seems a bit too many, maybe I should join some of them? For example, combine the patches of dev to one.
This series does not apply cleanly.
There's no reason to send 19 patches at a time. Please try to send smaller series, that's are easier to review, under 10 patches preferably, certainly under 15.
David Ahern
maintainerQuoted 3 lines · Jakub Kicinski
There's no reason to send 19 patches at a time. Please try to send smaller series, that's are easier to review, under 10 patches preferably, certainly under 15.
+1. It takes time to review code paths and make sure the changes are correct.
Send the first 9 as set; those target the TCP stack and then wait for them to be merged before sending more.
Quoted 11 lines · David Ahern
Quoted 3 lines · Jakub Kicinski
There's no reason to send 19 patches at a time. Please try to send smaller series, that's are easier to review, under 10 patches preferably, certainly under 15.
+1. It takes time to review code paths and make sure the changes are correct.
Send the first 9 as set; those target the TCP stack and then wait for them to be merged before sending more.
Ok, I'll make the amount of patches at a proper level, thanks!