From patchwork Fri Feb 18 08:31: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: 12751067 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 CBBE1C433FE for ; Fri, 18 Feb 2022 08:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232548AbiBRIcq (ORCPT ); Fri, 18 Feb 2022 03:32:46 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbiBRIco (ORCPT ); Fri, 18 Feb 2022 03:32:44 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FFC425EA6; Fri, 18 Feb 2022 00:32:28 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id y11so1771984pfi.11; Fri, 18 Feb 2022 00:32:28 -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=qXyadzniFJOfhRBYAKfqrSomXBnkvK/Ai3Oflic3yqBYaekSjrGhSXYElON5LYhZ5m s4Z+y+r+jvLVsvrgl+nm0Ed7ovIF6AQDmguNllxJSvywMA4KZ/1kKzLCkShhy3NNRJ5g oldQ0aR6TzehoPtZDUvHHOXkcn28k5S6BhXi1Bj3num2rfNODvHCNnvOUs0TYl5b2DfS 6JpPAktdLF0pNaJydzdxmhW91C9n526Eu/mz9s8jZoSrK/aVRvRTXw/DkErOz/LADNcC ZZO84CBPg90UWaHRH/vjKwRPYmlH2F6+EKpJ5xyuTtMelWoyKULeuPDyt8Oih9U1IwWB 8MPA== 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=YXIq5zn4iq+vrqZ6Ah21Htds9MNfqFMdXG1p9uArA7SBQ8sPFrMDKzNu5/SRQq/vj4 0Ohs15PUBbPKDWuHGzNjcfhWKkkOPz+PHpndsSwNO+R0lVJBJ7CS6xGBjPZQeoXrdPlL rdXW3TJaaWwwUBz2CSHnpTsmhgjwJbJdjB0hbrjIsMiymfcQAsosb8eu/c8oLY8ylYkH IWGQ2zQh7c4VHtiOyEuhjLUgFpcA0wVeK2F1mdv46wHt05VPsTD6xV+8pCGfdMGbi17D vgRyET5koBNsT7+OahlDUnBkoaF+Lt2i34gguqlMwIYRp9cdCb5IcQgVCm1+ubj6lW0f lOtg== X-Gm-Message-State: AOAM532WIbk+M4Nrh6GMbBvzvGD7qFDtsbDN2QaXWeF53qjagDJ0Af0c LAhqyzg6SwfkD0yyAoKQAEI= X-Google-Smtp-Source: ABdhPJyT0dh3bXiuZ71M4x+8NPtNL7vA/3YVOxWQ+/iLO9jYZMnaNjGZosV9F2uZ9cH2zqt1AoNumQ== X-Received: by 2002:a05:6a00:1591:b0:4f0:ef0b:dc24 with SMTP id u17-20020a056a00159100b004f0ef0bdc24mr1102419pfk.2.1645173147717; Fri, 18 Feb 2022 00:32:27 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:32:27 -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 v2 1/9] net: tcp: introduce tcp_drop_reason() Date: Fri, 18 Feb 2022 16:31:25 +0800 Message-Id: <20220218083133.18031-2-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 Fri Feb 18 08:31: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: 12751068 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 AD9FAC433EF for ; Fri, 18 Feb 2022 08:32:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232226AbiBRIc5 (ORCPT ); Fri, 18 Feb 2022 03:32:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232554AbiBRIcw (ORCPT ); Fri, 18 Feb 2022 03:32:52 -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 1211A24F31; Fri, 18 Feb 2022 00:32:35 -0800 (PST) Received: by mail-pj1-x1043.google.com with SMTP id t4-20020a17090a510400b001b8c4a6cd5dso7835940pjh.5; Fri, 18 Feb 2022 00:32:35 -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=Uulva2KWmsdcj3WdFocX86X8oyJLuG3VvVOvhPBGz0g=; b=ABkf2KBSZNefI7aybQ2TggL07NL0RYWykhmelBhGCNzrECioXEmSIvOuFENA0zDLZG KbNHycPdmyc0vx0aRkbVekfa7isK1nBx7RsPhtwHbxL7Ta0zE0ZgR6ZU650Y5PV2YspO 7nEcwsCAjV1pAbb2kKEjcN2kckZOrLoPq8/U/MUpDxvY6JI3Z10/AEei9dk4GqUlQyT6 bwFDydLgHQtVq6k7SQtNtl9WuuBsJL+JV91dwWqTCuiZXtVTNu3Bxh7i0r411Mhz1ubO N1euh5x8+N6HxiDUCxb/D3kMRLni1LcJqyzVbixkDOIoeSsUBpLhOpp/JuAfK8k7yAkB Da3g== 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=Uulva2KWmsdcj3WdFocX86X8oyJLuG3VvVOvhPBGz0g=; b=R4pDhX1/xDjyvg3OhOzvA+/yglHBbVRZ9uPzk/ZZd5qhOVLhnqHI2NIdsiT9ntQGie y/wCXoMhOb0s2iJcNbMbMBkBMC7Lm6IW+g1Pb12ZT/Jq/0xAYpuDZL3TbYA3ruNITaU7 yHNUYFISJyu5yaJ1xwxvRjnltnFo6EKcAf34xi9VoWfUl7k87FnXz8YnYYEuWlQvwN+p yGoN8+V7tNs0oNLzfFjoph11VbqRr1iyUzctZbkYaY4w0sc9pkxLDOemo/m9ZcnGvRD+ r3/O+c2KiwJZQU8z0lVahZgmvyOcmP4T+U1A3PQKq+eMFkrSku48MLBxAPRQqrX693D0 5dNg== X-Gm-Message-State: AOAM531HKFxYgddqzAdviZX3/JZj0C7/eSQXs+vnybwxaCQf89gKxyuo ZtHATjXqtWnktw5aG5ER7WI= X-Google-Smtp-Source: ABdhPJw0qvzicG7470oQ/pGWBGJAuQxoMBrfzo+xIDJwhvTwfmX4zdSLBQOVQiwDdh+xG3Sh7dQkcg== X-Received: by 2002:a17:902:d705:b0:14e:e5a2:1b34 with SMTP id w5-20020a170902d70500b0014ee5a21b34mr6397853ply.88.1645173154599; Fri, 18 Feb 2022 00:32:34 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:32:34 -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 v2 2/9] net: tcp: add skb drop reasons to tcp_v4_rcv() Date: Fri, 18 Feb 2022 16:31:26 +0800 Message-Id: <20220218083133.18031-3-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 --- v2: - let NO_SOCKET trump the XFRM failure --- net/ipv4/tcp_ipv4.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 6873f46fc8ba..a3beab01e9a7 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; @@ -2166,6 +2170,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 Fri Feb 18 08:31:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12751069 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 0F9A7C433FE for ; Fri, 18 Feb 2022 08:32:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232673AbiBRIdH (ORCPT ); Fri, 18 Feb 2022 03:33:07 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232608AbiBRIdF (ORCPT ); Fri, 18 Feb 2022 03:33:05 -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 1352725C4C; Fri, 18 Feb 2022 00:32:41 -0800 (PST) Received: by mail-pj1-x1042.google.com with SMTP id v8-20020a17090a634800b001bb78857ccdso9411562pjs.1; Fri, 18 Feb 2022 00:32:41 -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=1aXicT9qw5QUx4C+4Sp32SMUaBke04euNccpEFm6KM8=; b=AxWREr1taEu/Em4kI82NR3yADVU4HC5JmCrNMATYwZcfqZjmzX/jNtM6BOUDTjf0pf ckYm4VNoI/ViwsBDpGCnykAUhQPwWw5qH/DSRK0/HIqxNQUx45Y/JC2FX+z8rOBG8rNc ciA6ylL/rm6fqnPr0Kt3gEEyvzynmtmzhiCnKq+IrUUyR0AdbyVL40HyTxDir907uoaC EzWzu0mAGBh9wkhWkEjuhALmXSIjVCbNxlXKPXhI6N/7WxV74HWwp9xzGaDZLbl+3kaD hR4n/AzpePYLviI3asplmzv5M0sfFZ1G0DztTmvzgBQfQlrIRhN/JyoWde+qKrfvM3ud 7fPA== 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=1aXicT9qw5QUx4C+4Sp32SMUaBke04euNccpEFm6KM8=; b=1ntOmv+dnX89ai7BXs1QVnwRBg2NWvmRhIbzUEYBEScGZxQVoQ1LMN7flzj+VCQJw4 3qvrt4KHgOxhAIqXEBihW5lZGC/vwfPd7H+pf3peorqQJHA5bvk5xMxNwibnL7aLU/2S LndzsiUOvJkviqM/Fn77OBZn3pL29ECI7FRwSgw5XAPYHWdcD0hP4JCyxD4Mcprv0Xme BouSywpVKgOd+AWlsjjy8gpOoCq8xaslhnmW7WW6g4kapjhi2N1wYMgl2RJPoutHvN+P zgkLEfcQ56C6BX/5ULcTRrUF7Q74W3k1GB9DSac3fFwMRJMB0Q3BunWqzjT8qJvoMiZW hlWQ== X-Gm-Message-State: AOAM531cLnutVoSKDnggd28JfOqxnxGwe0iPtMlDJk5Ula5OGmQ8wGG2 7mm9ppS39Zz87GYlHmzl66SrcbI+Y6I= X-Google-Smtp-Source: ABdhPJyElHfHGU29zw2n/hQXAdUksNN5Ta5aMaIBj6MG9qCJGwAmhVSptlDknzSjscPDr4T8ST20FQ== X-Received: by 2002:a17:902:8bc1:b0:14c:f41b:b3b6 with SMTP id r1-20020a1709028bc100b0014cf41bb3b6mr6614828plo.168.1645173161475; Fri, 18 Feb 2022 00:32:41 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:32:41 -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 v2 3/9] net: tcp: use kfree_skb_reason() for tcp_v6_rcv() Date: Fri, 18 Feb 2022 16:31:27 +0800 Message-Id: <20220218083133.18031-4-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 --- v2: - let NO_SOCKET trump the XFRM failure --- net/ipv6/tcp_ipv6.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 0c648bf07f39..0aa17073df1a 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,6 +1789,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) return ret ? -1 : 0; no_tcp_socket: + drop_reason = SKB_DROP_REASON_NO_SOCKET; if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) goto discard_it; @@ -1786,6 +1797,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) 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 +1807,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 +1818,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 Fri Feb 18 08:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12751070 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 2096BC433EF for ; Fri, 18 Feb 2022 08:33:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232690AbiBRId1 (ORCPT ); Fri, 18 Feb 2022 03:33:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232654AbiBRIdG (ORCPT ); Fri, 18 Feb 2022 03:33:06 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5FBA2DD44; Fri, 18 Feb 2022 00:32:48 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id s16so7216389pgs.13; Fri, 18 Feb 2022 00:32:48 -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=t1JcfESLshia0hfZycViI4NCFCf3p6OKuHoudYWw9ZA=; b=nW1lmzUWrykSgiE/tTu7hLPrzSoBOmVu8KhT2CwzKOtoEltuMIChHFFssB84S2vJle +i7nMinoTX1xU6o3XQmn9HBfT/HC3R5oYYB/wdWB+fgAL//7DZqE0h2Zw4BSNRbfES3U M+w4/aHF1aO11jpwOMaOW8Xl3hJFr5h0aKZUpHefWt+ZkmkVpBM5IBgEVtoZSKPFClgv LBKX3ZitBWt9+cGHaq+ne6b0C1lWsKhtpVAttUQcHdXb4F1xHIFWzVdSEZwpsvFxIt9W rzMJ5dunERiioXDPTFJ47f/ZxmLoh5VbGw/maw60xDhS5qw/+MAdmnRVTC1RNjGekzwX g41g== 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=t1JcfESLshia0hfZycViI4NCFCf3p6OKuHoudYWw9ZA=; b=IeVlCLd3mTwl/xQZJggQuJyZI5yHit3cqvZDdPQFpljEsMfjj+LgZuJUzgDWRxRFxN Wq0V5a/65u80qXYDa3kYgD3WGTetoKG535tQiZJDZPmpuYtWalwCeAjdBfF63lzbaZr7 aQo4nIrvU7O3Ha8AtMMy+h7ACEb+yRfyuHJWGMDnTxhk/NgrGV5D9ozwhY99m6nK0CkH sAeoRRo+qy5xxkj7tVCiirM+QpjAMgecp4sL83CmUjaQxBkQAI3tBXSSu6cXBsN/Hz7K a6GdAR8o/U7nxoCut/KXFqKznbqDHEfh9FTMSJrZDiht5TEoaXeSlAJlSDqKuOFGMyEB qUXA== X-Gm-Message-State: AOAM5326Avp2Ixsj99Z+JPaaerTtTsFwBdsTe1H6kH+R0U9Eu76hT7MQ d5+6hyFjoLxx4fzDiKSBWC8= X-Google-Smtp-Source: ABdhPJyYZfppkZR2mWdHy47N4ktkhPj+VteDGTdrW+jkzIQv2uBzjpPCaa3OsFgd0fNHyFwLdijFJg== X-Received: by 2002:a63:3202:0:b0:365:84d4:4705 with SMTP id y2-20020a633202000000b0036584d44705mr5453321pgy.201.1645173168382; Fri, 18 Feb 2022 00:32:48 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:32:47 -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 v2 4/9] net: tcp: add skb drop reasons to tcp_v{4,6}_inbound_md5_hash() Date: Fri, 18 Feb 2022 16:31:28 +0800 Message-Id: <20220218083133.18031-5-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 SKB_DROP_REASON_TCP_MD5* above correspond to LINUX_MIB_TCPMD5* Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 12 ++++++++++++ include/trace/events/skb.h | 4 ++++ net/ipv4/tcp_ipv4.c | 13 +++++++++---- net/ipv6/tcp_ipv6.c | 11 ++++++++--- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index a5adbf6b51e8..46678eb587ff 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -346,6 +346,18 @@ enum skb_drop_reason { * udp packet drop out of * udp_memory_allocated. */ + SKB_DROP_REASON_TCP_MD5NOTFOUND, /* no MD5 hash and one + * expected, corresponding + * to LINUX_MIB_TCPMD5NOTFOUND + */ + SKB_DROP_REASON_TCP_MD5UNEXPECTED, /* MD5 hash and we're not + * expecting one, corresponding + * to LINUX_MIB_TCPMD5UNEXPECTED + */ + SKB_DROP_REASON_TCP_MD5FAILURE, /* MD5 hash and its wrong, + * corresponding to + * LINUX_MIB_TCPMD5FAILURE + */ 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 a3beab01e9a7..d3c417119057 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 0aa17073df1a..1262b790b146 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 Fri Feb 18 08:31:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12751071 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 69221C433FE for ; Fri, 18 Feb 2022 08:33:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231966AbiBRIdb (ORCPT ); Fri, 18 Feb 2022 03:33:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231841AbiBRIdZ (ORCPT ); Fri, 18 Feb 2022 03:33:25 -0500 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D71C52A700; Fri, 18 Feb 2022 00:32:55 -0800 (PST) Received: by mail-pj1-x1041.google.com with SMTP id h14-20020a17090a130e00b001b88991a305so11736734pja.3; Fri, 18 Feb 2022 00:32:55 -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=s+JTI3zBcAIU19bzstokvhw0NSWTjQ3vfsBVHnK1D70=; b=RKkHHgQDMSAiGAVxSqwZZHRQfaFz2Z/KkMKTP+rAgoMH1W7l4Wom2gxAKVmCLmRl3O Rr47npgVBX3e3/+BOfNSatTRrHbD/SAX3gJRnoLpSYuB+R2UyMlGuDIa/QfgenxD8D2R RvQf4qIusTw5Xai23SKtrPyLOzYNAVwmOtfGdPv81Pvwu6PPOZu6BSadwbBudO5yuIhx dMj4sLlDpV98UrVloCBsOT1ZjHup3yZHLoZGW6W2dOqrDZD81yVqsz6lGQ4nM+XfzGSr 6HUJStakJe1XNGjrsuEOih3QKkWKLiMeV6oXgRZd4IPFk2CeKbzZHB91sVNkZ0+nRQNd dXKQ== 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=s+JTI3zBcAIU19bzstokvhw0NSWTjQ3vfsBVHnK1D70=; b=Mxe9k4rRA8x7x1C/Z/mucwCRKlIFvFTO7vw3ukd1yyvKF1jpsR3GYp7tl85urYOIoM fpiOqJe0FB++oSYDonDklwrDz3gny0jAOY7S91P/1zLOG7pGEBAPnRoQ2mILFSK2813n EUPT4oQxlYKWaW1fkTSAIzB3fzSpeqW0M+44CoJ8twqqO6hfwCfL8bY1jLZyt/dK3kYV yEuGPG8pQ2NjeSCaTjGZob5qYpI21OoqcsRGa9jNTDDU1hGN2q1sOA3pYIlyJl595nHY voeLrhi+LnzKTAUc+D5cPfTzwBzJgmLiVsHS8DwF0kPZq+X5SUmyY2LzLy9uBwcA8Z1s r1MA== X-Gm-Message-State: AOAM530DfXszcvJBPfoeafcPDRXpnRvYsRmQYpoaLP8EPGrN8kqub3rr hLbsUgB6PhmCKTJ/24FsOMc= X-Google-Smtp-Source: ABdhPJwO+BdsM5qZ8jm+3wj8bM+hGg2kVReq6SXxMqHq+gE6GfWNYIsESMEo/9u6xYiPkL+6Tvf0ag== X-Received: by 2002:a17:90b:47c4:b0:1b9:b213:5f7b with SMTP id kc4-20020a17090b47c400b001b9b2135f7bmr7223194pjb.86.1645173175310; Fri, 18 Feb 2022 00:32:55 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:32:54 -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 v2 5/9] net: tcp: add skb drop reasons to tcp_add_backlog() Date: Fri, 18 Feb 2022 16:31:29 +0800 Message-Id: <20220218083133.18031-6-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 46678eb587ff..f7f33c79945b 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -358,6 +358,10 @@ enum skb_drop_reason { * corresponding to * LINUX_MIB_TCPMD5FAILURE */ + 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 d3c417119057..cbca8637ba2f 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 1262b790b146..abf0ad547858 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 Fri Feb 18 08:31:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12751072 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 D8F0FC433F5 for ; Fri, 18 Feb 2022 08:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232702AbiBRIdw (ORCPT ); Fri, 18 Feb 2022 03:33:52 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232705AbiBRId1 (ORCPT ); Fri, 18 Feb 2022 03:33:27 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1CD73298D; Fri, 18 Feb 2022 00:33:02 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id y11so1786731pfa.6; Fri, 18 Feb 2022 00:33:02 -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=YfkPNEIHP/FZToJsJM5n11iuHLqEk1bkFf9s+J4zLMU=; b=Uaq1KCzE6admxBBALvA+MlP8pUcKALVyyfGfN7v+Vg8P19XBpFx9jlgFakpFSn2VV/ GtY537oMOrzNk5DOnM/CtSwGiOsXuCTYtQNnEwRXfc/NwkIDWzogw+pczuV6HPth0WKw ixv/+Jp1FPWnMKJKu2QiENeo3oK18y9lZDPl7f1lnxOqe/f4XvpDikJ0nU00R9TEUT39 MBCFG+MmPcHO4VSHJEkbO8vbeuu9SzEd+ErvnLfArI66JRNa4udnfMyvPY8uU8S8YOpB 86l26jjw79pilm75HZU3Y31ollS7fv0K8HWQ1bRD5EugKMX8jY7HcuKAh4R0MHXQG7Vq S1rQ== 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=YfkPNEIHP/FZToJsJM5n11iuHLqEk1bkFf9s+J4zLMU=; b=wnrMEbx1fFnvtn4BbqaYtUvfzSaIfJoxh3oLJMqp1wXfMxoACPSWoqhQ6rWZrRJTMK F02GlatVbCTBOLEx4H3iRDW52x/6dbocz2GrLeM4fsTjE0BKSBtul0QWmJiyANDCM0fs T11YJ+hsyCyHLfpF2BQrvnsYdDZM5557yxaykBhTibw0jFvZh19bXb90RY6chJ+Df+Lz QvzAQKeytdpDsovR5FIt6dPjJu8CG5Yv18Ae4jUwljjBH1HRvBvjLh3KMo+fbO44l80s OjGZltCCSRqSZZAj9fUE2yacz7Ip5JLECudHGmYrAx1YuD7uGNdJndj+iw1JdlLMfzH1 V4Sg== X-Gm-Message-State: AOAM530Et821TS2pNvEU7Y7NJTSiPYN7+71+v3GutUiycWmGPbaAA2Jm ypd9DU6qaOk/sQzWdPjeIrA= X-Google-Smtp-Source: ABdhPJw1hwitH4AXxbFdwx8kafHPrRcC0gAVufHWSCrohSJHFIWogyhRcMMZY/RxvPamytdVtScYCw== X-Received: by 2002:aa7:8d42:0:b0:4bd:265:def4 with SMTP id s2-20020aa78d42000000b004bd0265def4mr6743779pfe.24.1645173182262; Fri, 18 Feb 2022 00:33:02 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:33:01 -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 v2 6/9] net: tcp: use kfree_skb_reason() for tcp_v{4,6}_do_rcv() Date: Fri, 18 Feb 2022 16:31:30 +0800 Message-Id: <20220218083133.18031-7-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 --- v2: - init 'reason' properly in tcp_v6_do_rcv() --- net/ipv4/tcp_ipv4.c | 5 ++++- net/ipv6/tcp_ipv6.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index cbca8637ba2f..d42824aedc36 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 abf0ad547858..91cee8010285 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, @@ -1510,6 +1511,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) if (np->rxopt.all) opt_skb = skb_clone(skb, sk_gfp_mask(sk, GFP_ATOMIC)); + reason = SKB_DROP_REASON_NOT_SPECIFIED; if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */ struct dst_entry *dst; @@ -1563,9 +1565,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 Fri Feb 18 08:31:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12751073 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 62CE9C433FE for ; Fri, 18 Feb 2022 08:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232764AbiBRId4 (ORCPT ); Fri, 18 Feb 2022 03:33:56 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232608AbiBRId2 (ORCPT ); Fri, 18 Feb 2022 03:33:28 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B8292AE26; Fri, 18 Feb 2022 00:33:09 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id s16so7216995pgs.13; Fri, 18 Feb 2022 00:33:09 -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=vhN6bGLbUWbV7gm+QxrfCTvNwDyT7gtYG2Niy8n6URM=; b=cJiqm4iS05FYDROdQbLPJvRPiOP9H4Treic7Ab6z/vSFOtEJK8fYYWvMesJMJXRsmA L0yu02jst1wMdzij7bwQKba+G/UbfPuQzrepNTOwVVve1W0kvW5vQhQAsZlxUwK6aTTo INqyKfjbR/ZldXsdVL35wZ2v8Jrjmpq0nWI6fEIZTlYrF3RvlnQ3RE+m4CyUcgbe9Obr lI9ESnbJxyKI4jrL5bKqSqebkXr/+DQLbRCJN+KNkOWjNSUyko+BnXHImnrBSHBn4sx1 tEQqxah71ktCHyqANwgE5gzQjkvK9s7UAzX/rLO9SKGUoDMDDp3Kw42d0STyUJR8PhFi xbug== 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=vhN6bGLbUWbV7gm+QxrfCTvNwDyT7gtYG2Niy8n6URM=; b=lLO/ip5F1e3V3t0S+bSfY9M9nnHSUiQZ/VjRg3SYje2TjyODUeXwbODlodacSQRpG8 oXSMC27vHpmJr4ilWFHZbE6EcZLiiWtSLNiW6T7B7c9YFGLY00XzGngekubu2q7CILI0 kFwNH8iKNSiD5u4KHML8Tfk9Aunef8m2BmK1Uto0FgOnG3WeoTJQDwCWvBizrr+1ck17 znAbVi6BtPWnD3gx4VQrUgnhB4xmngGyrpZzDIxQXTb/wL4EBn9WlCuhtDiqozf6NqrV YXy+KMWW7Q/xgRXHf3E6O3b5INi7alFtQy071UF8+uoWOOMyb1EqMZzSxEvEzJ0ovaTF 3nAA== X-Gm-Message-State: AOAM530KFGwwpYkPmzC3uqdAM3mZLZqvNooElAyDnoEqbW3is60gY6Ci Qic/t1776iTZHZpSCt4Cwdg= X-Google-Smtp-Source: ABdhPJwvpy9+oteNIVS+TPB9BK2QKLCnNcvdZbNLxvEmkiJUxEr7JfT6dmwe49yvvmB3EcMO9pC9kg== X-Received: by 2002:a63:1421:0:b0:372:d575:7842 with SMTP id u33-20020a631421000000b00372d5757842mr5475718pgl.182.1645173189124; Fri, 18 Feb 2022 00:33:09 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:33:08 -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 v2 7/9] net: tcp: use tcp_drop_reason() for tcp_rcv_established() Date: Fri, 18 Feb 2022 16:31:31 +0800 Message-Id: <20220218083133.18031-8-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 f7f33c79945b..671db9f49efe 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -362,6 +362,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 Fri Feb 18 08:31:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12751074 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 17C0BC4332F for ; Fri, 18 Feb 2022 08:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232627AbiBRId7 (ORCPT ); Fri, 18 Feb 2022 03:33:59 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232629AbiBRIdc (ORCPT ); Fri, 18 Feb 2022 03:33:32 -0500 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B94725C4C; Fri, 18 Feb 2022 00:33:16 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id w1so6621635plb.6; Fri, 18 Feb 2022 00:33:16 -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=CnPw+SLQUtzseS65MwNzRbWbFNodU4McbKZ2wtyrVIA=; b=ZVQAnISRPMaxHWHqHDM4q8heSVYwKVjtUiYaMRPa3kXCrNgXaTYcZ427kTw42ThFtx +5uVXt0TG1/fF4d0Khy2HryMB9awd/uf/jBKjGyjaDfDMbgJf1po9BvPwx5SXDcAkfpg q9qJO4JKWry/IdWM+LztyXFQPJOJu7VehvjHKygIGBDNDySccgXlFb1PZwr/8maJu4Kf Lg2frmOs17BNVT2A0qlfhXJet04VpjfGjcpuLe0g+REYdmOstvDN5oT8BZh69iBh6AFI XKYkAj/zTJdBQL0vvm+/W740m9z7G1Sl1vWVbnHR+aG4GfGZrMGcCAGkY799Qo3FtbcS mBJg== 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=CnPw+SLQUtzseS65MwNzRbWbFNodU4McbKZ2wtyrVIA=; b=avcUg7alD8Xc9c0XB5THLDAHxTLjwW16ew2csYzMxpbHpmFzBAZLD3Ugfa5J7m1gWX gh+gtMsl8p/+N27n1l1Nh67M1/HikuJcUuRRJv5yGKkUAZuPIv8r1DQ8DtLynd1ay7zX NfyIsL8uU2sF8HW4qqUfEipQpBxwd7LLl7cxyNGPkthXgSMN0YwzMviuRjoECCKf6EZ6 S73yJx6KzzVoiVEUsgQOJiPwvGwdNulX7P1FBfol0Jx5GjMk7XFOBY+xjYRzYEsyoHqU JydtsL2BZnKA13a1Vwi6EWbmIO83TGvzd43kYt1wxMBlXDEYMt/4c5Hmm4kcIrOUC//1 r91A== X-Gm-Message-State: AOAM530BmsRcncVHR3pq10GSd7Ha1RrH9zDpH4T3av9VS26OPLKMVLw7 LCjVSfJP24mvGgiF63d08C8= X-Google-Smtp-Source: ABdhPJwtxNzioT31sVOH9mI9E13/KfSlI9QYc+gnmYgma6B/KvxpI0mRZWOEqw4F/nym0eQBFIFU5Q== X-Received: by 2002:a17:90b:146:b0:1b9:e01c:16f3 with SMTP id em6-20020a17090b014600b001b9e01c16f3mr7118213pjb.18.1645173196014; Fri, 18 Feb 2022 00:33:16 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.33.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:33:15 -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 v2 8/9] net: tcp: use tcp_drop_reason() for tcp_data_queue() Date: Fri, 18 Feb 2022 16:31:32 +0800 Message-Id: <20220218083133.18031-9-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 671db9f49efe..554ef2c848ee 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -363,6 +363,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 Fri Feb 18 08:31:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12751078 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 B5FAFC433F5 for ; Fri, 18 Feb 2022 08:34:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232554AbiBRIeT (ORCPT ); Fri, 18 Feb 2022 03:34:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232746AbiBRIdj (ORCPT ); Fri, 18 Feb 2022 03:33:39 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 690D72C647; Fri, 18 Feb 2022 00:33:23 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id y11so1787316pfa.6; Fri, 18 Feb 2022 00:33:23 -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=6+BkML9iaRNDFcXeRLhjMQPtsJIgMk1H7r/pJuUNY9w=; b=MKBu7mUkUf4BMB8MtRcQl0JJQUKrewgqpd5RM2/SP+IbZbugS7jkvwPWCEGaplJUWt 3J8WUJTYTYk5okR56O9VSui9VfQDcIoxrCSVevjjc7wTAU78wwb4DH0dryzXYiF9OE86 CM8nthfCB8DFS4xgPbydz6SLxURd9ic2OS3500fmyPTp+5qBRwEqeoioPo6LnIkUuQzn 3siJTmTHqgSRorziOOTNnlpJ0VEW8qVNZzBpzPLYm5xV5QVQf3x0dDJYxEjWeqSdK6Ha 0wQfEM1rLkP8v7i/0oJpqyYlXCaamFrLeQF2mTW3rIdFdhXQkFPXuztWEvSl7qZdA+Fm hWiA== 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=6+BkML9iaRNDFcXeRLhjMQPtsJIgMk1H7r/pJuUNY9w=; b=vHitKh89jWGnigdjpigaN+bNaPBwV1mot1CeB4SgALL/5rMVgAu1z2Uv6TbgazoI8r q0kvRFbfEaBzdwQlVna09IHBd3g78zvpxiv4BeZP5Ou/Qzcuatc27664P6kkkjwWl128 IiFxDM9s9VhnMOfj5g1LxCKFc56DrvcYg2JHagItPSuWxuaKJVMzHrrmB/06/CzFw7Gu gM7j0DAZnYwbRKQF7+FMSHhF9xJ8p6f+TFZHJXWQ/OIuAYkrzR5fT3IF2TdNVkyw0Zl/ QUBlI7x6FTeIqOV03sRmckktmmeYyO9Wn9NTSFjHaog5Y9w7aunjLCEou4WyclGL4W2g S2+g== X-Gm-Message-State: AOAM5306l24P9eTkJQ9Hv7PUgW2JexBcnBIS74j/40DCbe+EJt9UpZm5 cxVczNocTdBF6gWuyurNQjI= X-Google-Smtp-Source: ABdhPJy1zr2CdJu+Vb7q12ljdy+DnqtXWBVH9QP6pNXRZWCiz7WFlKSs4tlYRTE57gXTfBeafjtcNg== X-Received: by 2002:a63:f055:0:b0:362:d557:2ccb with SMTP id s21-20020a63f055000000b00362d5572ccbmr5473790pgj.377.1645173202910; Fri, 18 Feb 2022 00:33:22 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id m23sm1963530pff.201.2022.02.18.00.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 00:33:22 -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 v2 9/9] net: tcp: use tcp_drop_reason() for tcp_data_queue_ofo() Date: Fri, 18 Feb 2022 16:31:33 +0800 Message-Id: <20220218083133.18031-10-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218083133.18031-1-imagedong@tencent.com> References: <20220218083133.18031-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 | 4 ++++ include/trace/events/skb.h | 1 + net/ipv4/tcp_input.c | 10 ++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 554ef2c848ee..a3e90efe6586 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -376,6 +376,10 @@ 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, corresponding to + * LINUX_MIB_TCPOFOMERGE + */ 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)