From patchwork Wed Feb 16 03:54:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747910 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1843DC4332F for ; Wed, 16 Feb 2022 03:55:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245105AbiBPDzR (ORCPT ); Tue, 15 Feb 2022 22:55:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245094AbiBPDzP (ORCPT ); Tue, 15 Feb 2022 22:55:15 -0500 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38E93F5402; Tue, 15 Feb 2022 19:55:04 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id i10so1027997plr.2; Tue, 15 Feb 2022 19:55:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lgdlyhNIvtAukMCB9p+w3nagDPuFMbvyfD2Rz3/nNMQ=; b=c/b/Tg49janS6+LjvyXrPHSdiQ2Y+PV43YxUzO7BnsDE9FYiv13Akw0iz51yqyK/d5 kk9wD+fQ6bViJRrPTgwUv17xKORkk5LwogsQQA+YnkiT6TEJ1phBXHuRRcujcMxxW1lW 6QE4a9qRRTBgyY56IOUlPGirZC8LbnfxaaqPvs64bENW+YBlxxtIQjZnyFPamA2xnINh K1qY/43+68Qz0yHDD9w24FonBCTBztm3oD4ENDaac7E0W/vvqWbZUt/dxKvWMTm2g5gO FGN1mWxtbR1CkmJRebrNcad2y3m7EY5bG0liaMd7uzUCOBd+Sd+yR8IWb/qwpZvKjWeF 4Ylg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lgdlyhNIvtAukMCB9p+w3nagDPuFMbvyfD2Rz3/nNMQ=; b=u0ssqlaBuIOSH6wT+3a5p0WYy1hpEzgju0LoL10kclUJkGllQ3e90i28EcJbuFmYkO xkQllxbSxUD4ozwMCP514yNVFttuqfLCgud6TQtrqf3gxqhvXoh/FdtiH+QdwPhz4RxS U/COaZ+hK7mil8MpisNSseLB6QlIJJKSh9G6fE5AxyzITl+pqW3obICsq72I8aQeQnsC hzNKx9FM6X0IiZWdEzNWfEsYtCLQ9frrQ7MtMNmQPg+XRu5C/+D95x9QkWKI3HNn9J7/ Nruxq+6s6aUb8SjlAZNC6uen5pvvV1QMLs1GrszRrfyBjlWSnz0cozD4D2z2/UU9rD8I dBJA== X-Gm-Message-State: AOAM532byjw4DOb3aYB6pVutOB4QG+jNBnYoPsDzpwEZy2Cg81BLl6xD QBmecpSfZK40ALI+QNDgnZw= X-Google-Smtp-Source: ABdhPJwn2tin0nBtol+lptHDksIAW/XkMFGoH0u3MT3KMivqPD6KKyrQChIKyshzgxcDHQTNsGCetw== X-Received: by 2002:a17:90b:104:b0:1b8:d212:9b8e with SMTP id p4-20020a17090b010400b001b8d2129b8emr8051706pjz.11.1644983703793; Tue, 15 Feb 2022 19:55:03 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:03 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 1/9] net: tcp: introduce tcp_drop_reason() Date: Wed, 16 Feb 2022 11:54:18 +0800 Message-Id: <20220216035426.2233808-2-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong 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 pass the drop reason to it, introduce the function tcp_drop_reason(). Meanwhile, make tcp_drop() an inline call to tcp_drop_reason(). Signed-off-by: Menglong Dong --- net/ipv4/tcp_input.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index af94a6d22a9d..0a2740add404 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4684,10 +4684,16 @@ 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); + 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 From patchwork Wed Feb 16 03:54:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747911 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B254AC433FE for ; Wed, 16 Feb 2022 03:55:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245220AbiBPDz1 (ORCPT ); Tue, 15 Feb 2022 22:55:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245195AbiBPDzW (ORCPT ); Tue, 15 Feb 2022 22:55:22 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5107DEB142; Tue, 15 Feb 2022 19:55:11 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id q132so1013160pgq.7; Tue, 15 Feb 2022 19:55:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JnniAd21EY8afdlsgFug6BUpPk02YT/3Ko5AD7mlY8M=; b=NfTBFGX7gvJvRiNCHTGTJDbDv/wEIRthB3YzRRXj0BesMCjUamTM5V1gTbt09ttcsU Va7dgtsPxqnQHyY9BXWaDMbB0SHWQ4kRUBGDhy3T/trasEzJHmKOnDSbpugHAQcbAcP4 chKuv0O4an5RnxyR6Ri1koSPn/JiOn0j1qxAbiU9/ekEIsnujJbIxMBSp/nlpL9RmbOi yQE/I/XOqMrrPYxDB9Ba3gvkC1kG6aoRZDCnBPlzKiMiG2YCczHA4XLrYdGu7QRbQy9F zpUz9kVtfrJkxa1M/69iJMZI7myly7gga+Nw/WyRKdDBDQCsFz/U3DIksL43RHvxiNZj Hitg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JnniAd21EY8afdlsgFug6BUpPk02YT/3Ko5AD7mlY8M=; b=sAIMVOKyQ7Ri2TstdSWAvlgTVpdAV3J1Q8HCEvN3IXgx5+NIwWEA+0/1fUpq7UFNu2 hMgOUUePYQcke3ICGb3VLMFpMYaXoGYe0ZWOof+rhe+ObFRnyqPZFAAcyq4WUl4BKW2z mUBsQJgUqnQQw0mvPUsQrZcNdWSbhOi7r6GkMkZt0krHj56cniUobe83mOExHfGfp4SI s3Cvs5N0Kj1/5g3loiyQmBOoD96881qHVGozRrQWBb16TrLtCgE6rKeOWRgnLSnpuJcU mNprSZMShCxCv95Az8Duxoh45AozYy8j+15uuu70VSR/toPmzfCorn0ziez9BNqYPHVy uXfg== X-Gm-Message-State: AOAM531PNGaykvUoOuXDaQ1LHsh30/6OQf15NBgjA4YJOrCw0PBTcMN6 p9xzWAtSv9yO3vJdCjCdIBc= X-Google-Smtp-Source: ABdhPJz9gt4T2YB/tfTdjqKaq6JYEGVA4o+vErDCEW2PWFcC5woxon3gInnjc9VDb+1m4M9nC9Mc5Q== X-Received: by 2002:a62:8f8f:0:b0:4e0:7729:2429 with SMTP id n137-20020a628f8f000000b004e077292429mr934328pfd.47.1644983710853; Tue, 15 Feb 2022 19:55:10 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:10 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 2/9] net: tcp: add skb drop reasons to tcp_v4_rcv() Date: Wed, 16 Feb 2022 11:54:19 +0800 Message-Id: <20220216035426.2233808-3-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Use kfree_skb_reason() for some path in tcp_v4_rcv() that missed before, including: SKB_DROP_REASON_SOCKET_FILTER SKB_DROP_REASON_XFRM_POLICY Signed-off-by: Menglong Dong --- net/ipv4/tcp_ipv4.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 6873f46fc8ba..a93921fb498f 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -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; } From patchwork Wed Feb 16 03:54:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747912 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3999C433FE for ; Wed, 16 Feb 2022 03:55:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245334AbiBPDzb (ORCPT ); Tue, 15 Feb 2022 22:55:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237587AbiBPDz3 (ORCPT ); Tue, 15 Feb 2022 22:55:29 -0500 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47AA5F68C1; Tue, 15 Feb 2022 19:55:18 -0800 (PST) Received: by mail-pj1-x1042.google.com with SMTP id n19-20020a17090ade9300b001b9892a7bf9so5270416pjv.5; Tue, 15 Feb 2022 19:55:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FopBqDGN1xvSfvHr1/isUkSeSoRhL/jVtgtKDPYdFpU=; b=CYVNGMa8rDwkhf7bAgvaLIinbioqCYjgemaj4yyS0OXyzdWILVe4owz3oI0pLlckSY mEb1MJdZGFDRV4prg82yBQw5+f16MhiEC6oSiehKrLemdaQ5LTuCwQfZ8ZcUPXmLER7u 0s0f+llVp/lJRwCNX3wembmUEroNGoKjTl5UEJ5OEC5ktsgNOslNiZ3+N0jC+F08agE5 Eu9Y4AsmnufaRWUQkkPwuosBZBGaqQxbMAIKpOKU5Le2ON+3i6BSqjreQgiy/4N+MAga dVYyK0KgfdMfr85a8eKp+x8GNZ497kHo3FUUmqDPPxW39XS1HIhMZ1uZKf48pjcVuZZq Wq5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FopBqDGN1xvSfvHr1/isUkSeSoRhL/jVtgtKDPYdFpU=; b=tcBZ4hbSIRCPa586Sz4uWIlLMdDnTR4pB2DTuC38IJIewsEqtxD7zsWDoBBsWaYHl3 RApzmhC66/ZYwCZ219MXqKcE9RVmW/KydsRLqdCSLYF7Pvsm5rVpjF/VOJLxMBh/dbHF 5wQzG2Jhj83HOv/vFFaM4xt5KIKHapJxw3LYl+lztajjp6T5a4WK2ZTQRorE1gch6byv crHpzJ5JojrnOQ5LMO0QwI3Po00vulwZ4izMGJT4O1BBKrWD7TFMftbliCBYS+OdCP+C 8t10aTMzuaPVvyKN3ANKkScDfRuqsLAg8nom2QysOquM3wCC6tNL1ZqUkCl2h4elGi6C FxxA== X-Gm-Message-State: AOAM531J26jKD499oQC7KXMVRDe9ISnCK7u20DCkvN+awXdGPZn5ZlA7 kFVCF7tK5h7QAFooGQ2SZBY= X-Google-Smtp-Source: ABdhPJxVxw7qFEjG4EejSaTzDq5m9WoyT3km2NahQju/FMrU285HmaSfJJXLJW3r3hIpZO7mhUwU0w== X-Received: by 2002:a17:90a:7e16:b0:1b8:2c11:73da with SMTP id i22-20020a17090a7e1600b001b82c1173damr752883pjl.156.1644983717901; Tue, 15 Feb 2022 19:55:17 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:17 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 3/9] net: tcp: use kfree_skb_reason() for tcp_v6_rcv() Date: Wed, 16 Feb 2022 11:54:20 +0800 Message-Id: <20220216035426.2233808-4-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() used in tcp_v6_rcv() with kfree_skb_reason(). Signed-off-by: Menglong Dong --- net/ipv6/tcp_ipv6.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 0c648bf07f39..402ffbacc371 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -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; } From patchwork Wed Feb 16 03:54:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747913 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C69B2C433F5 for ; Wed, 16 Feb 2022 03:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245377AbiBPDzo (ORCPT ); Tue, 15 Feb 2022 22:55:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245303AbiBPDzg (ORCPT ); Tue, 15 Feb 2022 22:55:36 -0500 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F3F9F9FBB; Tue, 15 Feb 2022 19:55:25 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id w1so1010558plb.6; Tue, 15 Feb 2022 19:55:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uARmFS+nDgVE7FjyHb31xPiMhFDOkZcIRfsfMlKqLac=; b=W96QghDLRJIgptWu4fLEMODL2iUGYfI4s3l4lvFDiXDSrEvA/mlAm/2CSJMMiH6eAF G/ndqkuVU1lBgmS1KauITrngRxBTOO7ZmOiUGlC0AAs36nPJ3Rlc/PcdFzb5WAfJfBGG ZwcKGVDsohurDx68zH7ejZB+gwyHf6HwciBC0vjZZlpUqu5XlnrP8UejqAjw52kgRuAu 15GbVrQuJyFRE7rrBVdutCwo/ZhBkEndnfx5ed+pWaZ22uOr1DVun/i+yR36PlAk2iVz PMcVT40lTwY24SdHCKQrqcMB8w963C/wATNlhrsOEJaXntewnE7p3nN580sXkA8GV/6V Dayg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uARmFS+nDgVE7FjyHb31xPiMhFDOkZcIRfsfMlKqLac=; b=jXCggllJXsb8S9U8oTKmgadObZR+yfRpewaU0FHk1lCl+QlETQpvlkM7RLuz9JaS7m JlVwri7QGr8NMxsmjm5sIljsVJrydoUH3P7+8CVLeIUvyTvOHHdxRQIw3uqLwD5q6c8b WKJ71wwytw1mPsfUX0qoMyl/qp9pdI72cNHLJ1vUhtYClDKOwvfpPZqp4fNT52mUYiXQ nlZ7CXu5eipKrSku0IBbMlIkFlhxS9X7zf3MmLghFp4c6m25+4N5pXGMe4hfvVsX/qRz fl3gqghDaxE1ZoyS6RvBP4zLyJBrIGQQgGrkGqt8A8FeFGg4ofp+qmNidF4Alzr6SkU9 IYVQ== X-Gm-Message-State: AOAM5315XyLwR+A0kx03oZTsTB9q530gsH+8yE/9nbU710pvZzuw+B60 ad6Kiu/YJO5oPZWcvR3vA8s= X-Google-Smtp-Source: ABdhPJzzXzNKb20ALtRnB5E0498QAT9AuCFhOJIFPSwXlB2hv+ZJhavO+aqLDae0QQncv5sQGsJQ3Q== X-Received: by 2002:a17:90a:6943:b0:1b9:e285:e4a3 with SMTP id j3-20020a17090a694300b001b9e285e4a3mr731452pjm.153.1644983724948; Tue, 15 Feb 2022 19:55:24 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:24 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 4/9] net: tcp: add skb drop reasons to tcp_v{4,6}_inbound_md5_hash() Date: Wed, 16 Feb 2022 11:54:21 +0800 Message-Id: <20220216035426.2233808-5-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong 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_MD5NOTFOUND SKB_DROP_REASON_TCP_MD5UNEXPECTED SKB_DROP_REASON_TCP_MD5FAILURE Signed-off-by: Menglong Dong --- 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(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index a5adbf6b51e8..aea46b38cffa 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -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, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index cfcfd26399f7..46c06b0be850 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -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 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index a93921fb498f..3e7ab605dddc 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -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); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 402ffbacc371..dfefbc1eac5d 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -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)) { From patchwork Wed Feb 16 03:54:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747914 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5120DC433F5 for ; Wed, 16 Feb 2022 03:55:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344015AbiBPD4C (ORCPT ); Tue, 15 Feb 2022 22:56:02 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245319AbiBPDzo (ORCPT ); Tue, 15 Feb 2022 22:55:44 -0500 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 781261017C8; Tue, 15 Feb 2022 19:55:32 -0800 (PST) Received: by mail-pj1-x1044.google.com with SMTP id v5-20020a17090a4ec500b001b8b702df57so5311018pjl.2; Tue, 15 Feb 2022 19:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4mL7mLVT3JQWo1KYz/axuOVYLZG4n3zDx8r/aWnHrQ8=; b=TuzNJxPTntiryRaC5zi2FWYSofCaGhb4t+UPTdCzppSs0nwnhzDpNQnqfNhhyzaHUE wsJjaIpkuY9TFM+VpAg7et2ocfguDNxPYvNU/OocH8AzJ4YRt/7WHtA1Z+xWnSN/uRid GNhN1n/R6nEaKOeC5yHbCERZ2rrq5irFAb5T1DtVVd2lP5X63AS3o9Z/Tahl+ObGjbdY 7mLhlWb3nkYQ7nb28gESR1F4BrGTogQsCCMKq/Hqu+WczrDfr2i5E70I3ON9dpmB3U6O ur1To67/K4HqIjsNjxmPKzYIaCYLG/WnHz96+1BbZivJqeXxl8/MN3Yc9cNoxW0AlO3T qWcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4mL7mLVT3JQWo1KYz/axuOVYLZG4n3zDx8r/aWnHrQ8=; b=wwJdmrp1pjVAt9NpdP39x/hub5KqpW/GEIDSJD/0cNYGZwBiEetNU99Fgn+WXDMNZ1 zP98qNg4y2vgPOzEZQJ8ung9MAMMzo6oyojRctwjUfKUk1fOz6FcuXIFbPx/YCpl5Dra zfqx8CC0r0GC3Jp6O52YFH42BAGfMx03VCegmwow/suwXj3rZyhfD1FbvfGkMS5IZWBp x1ymI1w2IUtDsvjnEs5ym81uZHM84xF+kS9MdbYdzPqE421y6wii7xDpnoIxCb/efDgF AnxfqB+72HuOxjyvD8DS5TManSn9GwDBMlz6ws4Fx9rcizPyXkv7aKYhNDLxv+BiCqLQ urfg== X-Gm-Message-State: AOAM531tsxH7pZXJFBTdpHf0IGnlk3Uqh/YuhQOcTU9NpQC6Epd/GfJa 23k7h21IN+JuTFHYUE0lS9A= X-Google-Smtp-Source: ABdhPJzSs38yFrs33E86V/4NEJivw8B/kHbicdjOTPv9wIuhQaFDOevHDZJw/oQSu5LFkueGCQdzzg== X-Received: by 2002:a17:90a:8591:b0:1b9:da10:2127 with SMTP id m17-20020a17090a859100b001b9da102127mr7942075pjn.13.1644983732021; Tue, 15 Feb 2022 19:55:32 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.55.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:31 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 5/9] net: tcp: add skb drop reasons to tcp_add_backlog() Date: Wed, 16 Feb 2022 11:54:22 +0800 Message-Id: <20220216035426.2233808-6-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong 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 Signed-off-by: Menglong Dong --- 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(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index aea46b38cffa..9a4424ceb7cb 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -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, }; diff --git a/include/net/tcp.h b/include/net/tcp.h index eff2487d972d..04f4650e0ff0 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -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); diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 46c06b0be850..bfccd77e9071 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -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 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 3e7ab605dddc..15ef1bcff84f 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -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); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index dfefbc1eac5d..15090fe5af90 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -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); From patchwork Wed Feb 16 03:54:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747915 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DD14C433FE for ; Wed, 16 Feb 2022 03:55:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245406AbiBPD4E (ORCPT ); Tue, 15 Feb 2022 22:56:04 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343713AbiBPDzu (ORCPT ); Tue, 15 Feb 2022 22:55:50 -0500 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D1AEF65F5; Tue, 15 Feb 2022 19:55:39 -0800 (PST) Received: by mail-pj1-x1042.google.com with SMTP id b8so1307745pjb.4; Tue, 15 Feb 2022 19:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EZoukMGiWXk1HvbuQEBDTM8Ki/Xg0Kqyx/8NN8gbO9E=; b=EVm+tVf2ob8Bd6hyOZxaiciBkLNRKhy/EBpSFT+cBRzIH7Ri8w6Jh7P6eZ37/+I3O9 EkF1aAtMePZh9l5I3yPqlV5jT7Wa0wH0SiD8X2W68NQS+G/yGhx4PG37DDbpif2/9LGQ 4wwpC7mmMzAWkJsJvc+jKCaqF9YI21IUG8RyHi2RQ7MGIvOWsDeZJtHrEZy+yJiFHZ0I mhY1ocLYU6tXr7jRCq0AHyagEISi42OpHnhcHuQyR8TynzbztdGrnfeKGsJeipgXQPJA a5SlmUYU9KIPByXXjChd3Nc336TJpjYIV3IJVttfUg63I0xOyxzzcvabmQ/Z2rYZIO71 1f9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EZoukMGiWXk1HvbuQEBDTM8Ki/Xg0Kqyx/8NN8gbO9E=; b=eQm0frnsuP3jJvZ8i8QFhR93XglmKcjBEl7BQlLz784psR8J5wuek9xyxVNFLbGCx1 jFawQdsk6E/zJLYKVB9Y0vxp+n+SuZXw0TYyu6DnZD+nKGAx8OCVVoORgP3HKcoiNAT3 2Nu4GeFKf84kpbNE2c6dKYbsOSZv8d5isWvV4fHTpmOOpuOMmsUWfYxNEbG8q0tMi7wI EHjsYF7h6jhpAlNcL4MfQyGM2rPZVv+hVMW7r/M16+2QEgIQvwaanL4e88tMZ8aKZflC YloYqpsmXWQikeSqmjiL7Q3EwsYVhtpCTPykTOnsRITedxVZhAxIUhm24pfEZbzGGsyu 5VKQ== X-Gm-Message-State: AOAM5301iJvmV9Vhhe4gdYrFt762TZyZoOYmxOCtQtNOBqvGhFpyM0sy YNOFRXRYh15plXatkcHJt8s= X-Google-Smtp-Source: ABdhPJyU9BV6vwbfISPw6NBlVM3EGCGhdymUXNk1IdlFwiV0htoID4GvR7obIfHk4OFOMp5UuTcJ0A== X-Received: by 2002:a17:90a:3e4e:b0:1b9:bda3:10f5 with SMTP id t14-20020a17090a3e4e00b001b9bda310f5mr744386pjm.112.1644983739080; Tue, 15 Feb 2022 19:55:39 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:38 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 6/9] net: tcp: use kfree_skb_reason() for tcp_v{4,6}_do_rcv() Date: Wed, 16 Feb 2022 11:54:23 +0800 Message-Id: <20220216035426.2233808-7-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() used in tcp_v4_do_rcv() and tcp_v6_do_rcv() with kfree_skb_reason(). Signed-off-by: Menglong Dong --- net/ipv4/tcp_ipv4.c | 5 ++++- net/ipv6/tcp_ipv6.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 15ef1bcff84f..036b855c1b14 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -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); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 15090fe5af90..4d4af9b15c83 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -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); From patchwork Wed Feb 16 03:54:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747916 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51F8DC433FE for ; Wed, 16 Feb 2022 03:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344091AbiBPD4F (ORCPT ); Tue, 15 Feb 2022 22:56:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343930AbiBPDz6 (ORCPT ); Tue, 15 Feb 2022 22:55:58 -0500 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AFD7CFBB1; Tue, 15 Feb 2022 19:55:46 -0800 (PST) Received: by mail-pj1-x1043.google.com with SMTP id h7-20020a17090a648700b001b927560c2bso1257327pjj.1; Tue, 15 Feb 2022 19:55:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NL6+oOg9BoEJhsiZNe7wPYYFUharzAidvKkvvsL+WNk=; b=pj5y8uwaXXcKNihB9eq1gRevxhm9wC1nPUlPIKeVQM19ITbpsXcmn/fIyT9pNe2Xvb Tv3rKpAuv3FXlU44gndLQ/b8xxW8E2KG22/k/jHy7cVqctZtrzpy1KI+CYTcFxKFiN24 C1abD6uS2ZCClW77Wqjz+G2OEFumVkptmOR+pT5lubrtqqOA8aMFVy4E8qV2tL8j7ugj jwZppq3u8sfAbwdNMHyZ5jxolUe0aZFBRVnQnxTaZH2d936LBKmKN0tMB3Dd6GkJ2hAv MFiKYKliX/sbfqW99vU8CV13sNr+t3HOY7Xwq4g7saIBacwnu7BeN2hmUpylvZ58F1dz KNiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NL6+oOg9BoEJhsiZNe7wPYYFUharzAidvKkvvsL+WNk=; b=xCuvuXWnC2pnQu8cw27KO20P5AGfcDcKWQ+NJgs7xQ355hC2YgGNa4RkZJYxFjJ8Aw BZ0JoqQoGtLHjkaxEzj8qjZ4WThDzZxnjdQ3rnaUFoZwdfHJukATUMmrLbOuoglINvd/ N6giuD40K+6AHFx6+1Ksl3ABfiV+OoCCp4r3/UCreReK84Sv/AY1InTzgK1tC+nGzU3J u89qKmooxeWJrb5zO3xXUm6SmwmXmb+ZPyz6KQrxaIaJHQ6gb8L7yTkuTMz7aQhVIEJp jiYzydys5QY511QasvAD15H1mm7P1O0Au/AxobjEIWOFYM30cNscQFQXuoR1ybIFwPPW bx2A== X-Gm-Message-State: AOAM533/oTagTgDNAig9tf71Ga+NmARckWi8oCnyALKCtBdGGH5SNp8C pLvJzPEm3043QXaGdWAp/j4= X-Google-Smtp-Source: ABdhPJwmLnHfva1jmPJbG3R2cVxrdg7+JNLclPKDQOEMR4UdldpkPVNxDyLNpyjoI+kcmnV54tiSYA== X-Received: by 2002:a17:903:2451:b0:14d:a225:74e0 with SMTP id l17-20020a170903245100b0014da22574e0mr813732pls.84.1644983746115; Tue, 15 Feb 2022 19:55:46 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:45 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 7/9] net: tcp: use tcp_drop_reason() for tcp_rcv_established() Date: Wed, 16 Feb 2022 11:54:24 +0800 Message-Id: <20220216035426.2233808-8-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace tcp_drop() used in tcp_rcv_established() with tcp_drop_reason(). Following drop reasons are added: SKB_DROP_REASON_TCP_FLAGS Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/ipv4/tcp_input.c | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 9a4424ceb7cb..dcf9d8bd0079 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -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, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index bfccd77e9071..d332e7313a61 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -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 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 0a2740add404..16ee1127e25d 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5787,6 +5787,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; @@ -5875,6 +5876,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; } @@ -5930,8 +5932,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. @@ -5957,12 +5961,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); From patchwork Wed Feb 16 03:54:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747917 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99583C433EF for ; Wed, 16 Feb 2022 03:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245504AbiBPD4P (ORCPT ); Tue, 15 Feb 2022 22:56:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245738AbiBPD4F (ORCPT ); Tue, 15 Feb 2022 22:56:05 -0500 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA42F47D2; Tue, 15 Feb 2022 19:55:53 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id i10so1029350plr.2; Tue, 15 Feb 2022 19:55:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Igd5WmRzlfBkM7QudgasudwGUSnfgQe6ubQS3rivJ9o=; b=EGAcxrqWnPxkhekrnbSeeyVpChoXg63+bQSizt6L6IiwZDcQYHmE91p2cNLXQFB9vR PQKtJWDc4Q8+VaHLYV4KJ7und/jATXRDLN7gulOwBSHaWwsARkOZL3ZcmWWnyu+j5BfW /VA93rDc+FXC5OghRhAFDb+tUlXI21hizYC50RsJVXWrhZ26dqlGY4Kc14//qSvaAays po5YZfivOjYmOlqpM0/rX9f6D7p+Qqlrpcsw+9udIWJovwj8S/0sjH7qV4g3ZXW/Xy7Z 4KMYE5pVkIkBfcglVWMF7a2T2YXveLHLjFNws8EcWkG7vmyM97tiwkh2qoCzKk+f0EwH /Vig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Igd5WmRzlfBkM7QudgasudwGUSnfgQe6ubQS3rivJ9o=; b=Su51g1WKt/xgV4TtR1yyub3OdYH/pyv/Htj3hsEE5ldEqGddoBC5/KwX0dBVccx+2V IO/28ZhOFVyiXV2QwhmLWvay6t0EAdOjp+qv0aVGBUIcpr7cD+UI22XqYycWo/bi9ZOK 4dY+vkh0K2nR+wxli51NCkPVsESCgjB4UKcxPpI0pR/kQ4H7FrSsEPj9kBDFRBF4EEvN E9MTQg4NUtAt4JtIs3XnTyQi7Ygh2s9ilv/ltMOokRdlWJuCD7rJxANbB9FeUPTxEZam c9vEf5jrBkNTd3sVqcEfQ2c3XdSoqu0ul3UcG1+i/PBosRt4EcSf0XjwjgnaUjCFAxiP bpLg== X-Gm-Message-State: AOAM533KVGYHI76t8HAwWyttInbC0CoblnvOXZKGbsME17KSDzCIyDfa wFuBc6uiSZ8aQaVF3n0XuJzHhPNAX2c= X-Google-Smtp-Source: ABdhPJxcb2aSMf+fZCMQX+nVvm6YiWqC8rEz23edP+K15bZ24/vBrYsLE0OHDez1kJT06ducgUUzpQ== X-Received: by 2002:a17:90a:13c3:b0:1b8:d015:66d2 with SMTP id s3-20020a17090a13c300b001b8d01566d2mr8114321pjf.96.1644983753164; Tue, 15 Feb 2022 19:55:53 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:52 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 8/9] net: tcp: use tcp_drop_reason() for tcp_data_queue() Date: Wed, 16 Feb 2022 11:54:25 +0800 Message-Id: <20220216035426.2233808-9-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace tcp_drop() used in tcp_data_queue() with tcp_drop_reason(). Following drop reasons are introduced: SKB_DROP_REASON_TCP_ZEROWINDOW SKB_DROP_REASON_TCP_OLD_DATA SKB_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?) Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 13 +++++++++++++ include/trace/events/skb.h | 3 +++ net/ipv4/tcp_input.c | 13 +++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index dcf9d8bd0079..62a0d7d78f6f 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -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, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index d332e7313a61..cc1c8f7eaf72 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -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 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 16ee1127e25d..0a4ca818d580 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4988,6 +4988,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; @@ -5006,6 +5007,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. @@ -5014,6 +5016,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; } @@ -5023,6 +5026,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; @@ -5059,6 +5063,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); @@ -5066,13 +5071,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 */ @@ -5082,6 +5090,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; } From patchwork Wed Feb 16 03:54:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12747918 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A912CC433FE for ; Wed, 16 Feb 2022 03:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245622AbiBPD4Y (ORCPT ); Tue, 15 Feb 2022 22:56:24 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245598AbiBPD4S (ORCPT ); Tue, 15 Feb 2022 22:56:18 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF41100755; Tue, 15 Feb 2022 19:56:00 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id c10so1075504pfv.8; Tue, 15 Feb 2022 19:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZjE2za8E6rbwX5jEVaF9Cp+T5JL4P0j5o1dlD0LxMeg=; b=Cg+Cbe4EpSorYD3QMbtbyA5bvY5hKIEjZ5VaFTUETucTnBj939nbRgCHC0bvcl+VnG clt124pEC81A2FUP3bl4GY8gwSd2OEeMrL6TPCVCZIryyLKZExLeL0Y2GE+fsmn34c3Y fNsgMH+2lAV3ouV6R9Z8URryC21fpD+vokBpVfQTdXJspqsEH9GulhS+sHqAsqk6T6TU na9u0fPQywZEVHhwIebVXYonbf66e2wyNIHnScRWru/gsfLWAGq2Y3T0O1JjrIlSjQ9d HEROXOOjhxae/J+5LGep+Zlf5vIPrtIW50txM+ItUsrpBLtUIwxSOCv0M9MvsP34hbPl fFSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZjE2za8E6rbwX5jEVaF9Cp+T5JL4P0j5o1dlD0LxMeg=; b=wBvXeBvULFRHb+qSjGPzooPhZifCHoIdqN/ZZFS/oxRhttK7bxuVGgaZQnQV3aXANL bkJPlI21L3YosQxbr4cCOI6oGduNCH6VXHakLwx9JapZN+CyiUwG5Hi9P7T3oGYH5aKp THDiR8Zaukf881ebkPGpFPBadMpn1rTRZfxgQmd2+ouJzwv4YJcmprwJl8mphs1n3fpE mfHhCHvprjGh1IVjGVsPf7RSY5HZsZ9pZjOQJJUymu2zQErimNWhsmm8GZAnmUU9LNBE 0bbl8JsfyEfIcH6o/Jtswp0DCe1a5zF7L6h2RAEAWWENO19mqdPXQYIkNsLgb21EK/IA TVmg== X-Gm-Message-State: AOAM532KRW76uhiaRoy1dWXVkMZBboaRfNYLT+nIba6RdQ/Snvb5CWTJ ce1bGFLQGjetrsQOq8WMTuE= X-Google-Smtp-Source: ABdhPJzdAVEDWvBUtRoWX8Ol5FNdxdQRWpFxv1xoWcExFOcyHL8l1GJItbEqfdyR78j5Xs0u0+tVQQ== X-Received: by 2002:a63:1651:0:b0:342:b566:57c4 with SMTP id 17-20020a631651000000b00342b56657c4mr712433pgw.258.1644983760278; Tue, 15 Feb 2022 19:56:00 -0800 (PST) Received: from localhost.localdomain ([203.205.141.110]) by smtp.gmail.com with ESMTPSA id nn16sm19099668pjb.2.2022.02.15.19.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:55:59 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, imagedong@tencent.com, talalahmad@google.com, keescook@chromium.org, ilias.apalodimas@linaro.org, alobakin@pm.me, memxor@gmail.com, atenart@kernel.org, bigeasy@linutronix.de, pabeni@redhat.com, linyunsheng@huawei.com, arnd@arndb.de, yajun.deng@linux.dev, roopa@nvidia.com, willemb@google.com, vvs@virtuozzo.com, cong.wang@bytedance.com, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, flyingpeng@tencent.com Subject: [PATCH net-next 9/9] net: tcp: use tcp_drop_reason() for tcp_data_queue_ofo() Date: Wed, 16 Feb 2022 11:54:26 +0800 Message-Id: <20220216035426.2233808-10-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220216035426.2233808-1-imagedong@tencent.com> References: <20220216035426.2233808-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace tcp_drop() used in tcp_data_queue_ofo with tcp_drop_reason(). Following drop reasons are introduced: SKB_DROP_REASON_TCP_OFOMERGE Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 3 +++ include/trace/events/skb.h | 1 + net/ipv4/tcp_input.c | 10 ++++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 62a0d7d78f6f..73ed01d87e43 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -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, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index cc1c8f7eaf72..2ab7193313aa 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -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 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 0a4ca818d580..1fc422af11f8 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4779,7 +4779,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; } @@ -4842,7 +4842,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; @@ -4861,7 +4862,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, @@ -4889,7 +4891,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)