From patchwork Tue Feb 15 11:27:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746943 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 074F9C433F5 for ; Tue, 15 Feb 2022 11:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237132AbiBOLab (ORCPT ); Tue, 15 Feb 2022 06:30:31 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbiBOLaa (ORCPT ); Tue, 15 Feb 2022 06:30:30 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6ECB108740; Tue, 15 Feb 2022 03:30:20 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id d187so34342894pfa.10; Tue, 15 Feb 2022 03:30:20 -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=PWCUxhFuetzy8XEMuMabWi0zcJlDPvaSTrXNtpeJPaI=; b=lLHLOb7cfmsVYE4qnodW8UZMp0zmQobrutooS/4fuSrgfadDXtEfs6ItYYp0Xjwzo/ ba5d94hP7FEpKar6l/A3lE0p24tPUSZjw2dmkT7/FnrV6KOSvkw31Jnq4N6tlH5eD7/E j7v4YqHw69mfRRj8TTBjAOhVhSxngO/nHCxMSKmxnCtzUm54n+8MJ4Q9h5iXTp6uGG95 LIGCH3baiUTPyEJ7Zon4IY/54Wqk8v4W7FPzQxcY5NjShpQHLI7/eNYcL8CTSzv1+lzU L6a9KKc3NBgHwq3qpxmjXHi19LncG7pSGgnpbCtalPN6GVJOaykc3QOKwjLK9d1psuB5 YVNw== 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=PWCUxhFuetzy8XEMuMabWi0zcJlDPvaSTrXNtpeJPaI=; b=4PcnAv8gTIc5NUM2s19jpm5FlnEECXSIGwc/pJQQ3MUX+yZJnvV6IfyqNS7apvkmbN fByXdmqJyHxhB39fh4qtOVH7OhJ+628cngiBC2WyH1UyjhrW5VVdEDmBnsLEVcEK/vCp 6Vwt1LmGDXnt45KHldvClLvqNdKLo9AFCtto3NfZTBk/YXohm0DAI616uo20w1UclMzf GsIMFmGt86UiUa/NroSo2BFZ1sgOBzHa5IQ+OckLZPGnnPvSd2qf2W5Lu52jz19zfzPo aocAzwRZ52bJwujf7nPI4TOdt6kDu0j7FzgxGYsTa6TF8N3LA3SWBQJPa1fQ7u8MHQHC HSMQ== X-Gm-Message-State: AOAM531UGjPDSnZz05ESk6Ux4azp2+iqKQQerBkVUhdofiTrbc07ARKw 8eQEDUd7EH7n5Q7u2EzsELs= X-Google-Smtp-Source: ABdhPJzfrxFnswR6qy7o+5ZC0YryaUAyDk3vPX+gtBzTwCEo60c2pdc4Y5kwMymWKbi5g+NUFF8a/w== X-Received: by 2002:a62:6d01:: with SMTP id i1mr3475506pfc.45.1644924620400; Tue, 15 Feb 2022 03:30:20 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:30:19 -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 01/19] net: tcp: introduce tcp_drop_reason() Date: Tue, 15 Feb 2022 19:27:54 +0800 Message-Id: <20220215112812.2093852-2-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 collect drop reasons, introduce the function tcp_drop_reason(). tcp_drop_reason() will finally call kfree_skb_reason() and pass the drop reason to 'kfree_skb' tracepoint. PS: __kfree_skb() was used in tcp_drop(), I'm not sure if it's ok to replace it with kfree_skb_reason(). Signed-off-by: Menglong Dong --- net/ipv4/tcp_input.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index af94a6d22a9d..e3811afd1756 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4684,10 +4684,19 @@ static bool tcp_ooo_try_coalesce(struct sock *sk, return res; } -static void tcp_drop(struct sock *sk, struct sk_buff *skb) +static void tcp_drop_reason(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason reason) { sk_drops_add(sk, skb); - __kfree_skb(skb); + /* why __kfree_skb() used here before, other than kfree_skb()? + * confusing...... + */ + kfree_skb_reason(skb, reason); +} + +static inline void tcp_drop(struct sock *sk, struct sk_buff *skb) +{ + tcp_drop_reason(sk, skb, SKB_DROP_REASON_NOT_SPECIFIED); } /* This one checks to see if we can put data from the From patchwork Tue Feb 15 11:27:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746944 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 DBA9BC433EF for ; Tue, 15 Feb 2022 11:30:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237159AbiBOLaz (ORCPT ); Tue, 15 Feb 2022 06:30:55 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237175AbiBOLas (ORCPT ); Tue, 15 Feb 2022 06:30:48 -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 31FD2108BE4; Tue, 15 Feb 2022 03:30:39 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id y5so34381819pfe.4; Tue, 15 Feb 2022 03:30: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=JnniAd21EY8afdlsgFug6BUpPk02YT/3Ko5AD7mlY8M=; b=EzWLPid2Z+SJowrlIhoOYMZgdSusGpE4xyNsetMY5ULLe7gEFA1qDLG9ruIGswluyr UgwrHEVJb4/SiE24t7zTOny9xYaw4QT56+ihTUnSEdHjGsOGHUte4NUcfTIXoc+SCyyM OXqH/KcjZSOi5hiyLeJc3nsDslMKWd2x+dLdWhv+scVS/uiTCe7nXDxpXoLmNSvpEPOs 1T7092/hePMomU5FSTeNJxlyyiTam/obQDkPXUqDWBijrhVIxgbOoQk/ArjRwNEFAPub BEkYAFfNzoOZ4SU7SsZ/eG4MMsRk7SJ49Ut5tz/WOVfnJFQ6IX4e50Yf2uAOaBonQn6H vdrg== 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=uAqoJvf5gvbkOcsrHheKXTxZ2ED/IFeSFj78FxK1vuE88tZYsJdYbIWZLw/fu6GMX1 k2o0RLMl+kZTjHZ20kAneYePQoZlgaCQ9xmyscFW9z6ChXO3jVnGbDCANxKUlx6H0Brd eE+aCvjCNfcbu5NaXd88hFZ+R+p13O5NG22bLYhH7P6TCx48sUKPQjXnYbyyS9ElV4fY Y4lO/f6C3ilsMxamz8bjIc5JfGq/c0uTfVe95kwlgcPgW7lCU0kwx6jCzYR8qxulU43j JSl6tkCMTn8NGhO2Dg0AIrH5lq9RwRck6MzG29UYg4kaD1N18PyOiYDtRRDh34D/GZoZ rKLQ== X-Gm-Message-State: AOAM531228G5yEBRYJ3sTGgGi3nDn4AxTsm0zFlDGRGoKSgMbHCPPCm5 s3xhO69hfjCKIOA+Q56D1Ro= X-Google-Smtp-Source: ABdhPJwN5Ih91tdIz/KopWZlUuhmNrw3qjN8BS1BAPwVKdVyzfSefMsGZEzRYHv/YQeK+QKN5tM20Q== X-Received: by 2002:a63:f508:: with SMTP id w8mr3230195pgh.236.1644924638566; Tue, 15 Feb 2022 03:30:38 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.30.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:30: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 02/19] net: tcp: add skb drop reasons to tcp_v4_rcv() Date: Tue, 15 Feb 2022 19:27:55 +0800 Message-Id: <20220215112812.2093852-3-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 Tue Feb 15 11:27:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746945 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 23888C433F5 for ; Tue, 15 Feb 2022 11:31:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237157AbiBOLbJ (ORCPT ); Tue, 15 Feb 2022 06:31:09 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233225AbiBOLbI (ORCPT ); Tue, 15 Feb 2022 06:31:08 -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 E22EE108579; Tue, 15 Feb 2022 03:30:58 -0800 (PST) Received: by mail-pj1-x1041.google.com with SMTP id v13-20020a17090ac90d00b001b87bc106bdso2457667pjt.4; Tue, 15 Feb 2022 03:30:58 -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=IGwbe9O7s9kGyAba/oCqEBwGzIGpdc8uyBYEv7FAL+Yv68NIULN+o5C6Ea+UY9yPz6 akqBxoQTm22So/5zQS7MeN9XWLd5ZUQg7AvPgkAyp/WtwMyrD7nUAEBwqXlhiYzghZL3 JYUyoYoc7y71Z6gxa0FDSM3LP1pVZMt3+9Gz4xVajJnTO/75qkBUZNARZPA+6al4wXD/ EC4jyKUr4zDjj572P3RJoJ61+jXXp1Hd9Dtnzvu/mlrnH4VurmvAl4MLExhmKp/OU0Vj ecpN0VuWe4KWF/CeyQQcO7ywR5cd06aUkbRRTTqM35PAzs0CsIyEt5EbbLNv+36nvNHR h6qA== 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=gzQ6BGaq98kSeJJE8fyoi9l/cWHuaWwyvg9g/VGu2GRNHY3G0Za4kQOJJQf/leK2Ki tQQeLHZh99UxV06U5s7QxpejVIeIqUlJmAewiZxsq+jcpBluzeUSe9gSx+0PWSCk9XgZ Nb1y6/PXPs8mGS1Imeimsl5j6P/WP3rQP7CFcsuTqnqcdYIJoDULQxPw7T0X1w0zTvh1 rxX5L5N/ln3Ki32knJyOV/jpc2xVkciw3YgQiVf3WZ8ODIgEg+6q+jd+1xKx4jTQvFRV 7WwtvIfqxqtRXXwcx76a4e0cgySnWSJR5l9MxCZvyKITk3sCdIOv3vNdIdeu0Jt9kWc2 czuA== X-Gm-Message-State: AOAM532DUjhQkxNRHWaC0TL5Y8iVVfLSF6ayMKkLH0tdXxazeFLhpOUF jlZQGXCuM+EVCkLcDxepDB4= X-Google-Smtp-Source: ABdhPJxQZIyu+PGvgF4UOkN3FfQLFh8YNePAKEznjwKiMAJtrmH4E+Qk9Cow4/Es3aS1lSqNTbRlrA== X-Received: by 2002:a17:903:32d1:: with SMTP id i17mr3530064plr.55.1644924658483; Tue, 15 Feb 2022 03:30:58 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:30:58 -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 03/19] net: tcp: use kfree_skb_reason() for tcp_v6_rcv() Date: Tue, 15 Feb 2022 19:27:56 +0800 Message-Id: <20220215112812.2093852-4-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 Tue Feb 15 11:27:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746946 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 1A097C4332F for ; Tue, 15 Feb 2022 11:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237173AbiBOLbX (ORCPT ); Tue, 15 Feb 2022 06:31:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235519AbiBOLbW (ORCPT ); Tue, 15 Feb 2022 06:31:22 -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 9922F108774; Tue, 15 Feb 2022 03:31:12 -0800 (PST) Received: by mail-pj1-x1043.google.com with SMTP id a11-20020a17090a740b00b001b8b506c42fso2526760pjg.0; Tue, 15 Feb 2022 03:31:12 -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=o/W/MDHbFd5Rq2iDm90Y0g5Kcc9mfO1A+qu2QJ3GGtxIwBF4ENotRSWnmB6mLQhMaN m42c/J1xV5P32WLS+/ZGmkShGA1WpYPPskLxqTK+JOIjpvRvpu9UkcpP6FNQLXR4TaTP GGOPEuJpkYdSxharpgEEPQENYRJQOjHC9Anbk+SyI1Tpsgzom918/MlhhRyGc9T2yPa8 BHoRlBzDg66Y1hcvY+uQpRjbKO/Qs9K3naIw1L0snLflfam6Dod0swufSJ8+jw37kFjg HBYIWLR1UvSk9ZNyrSFSStu+PiRC8YZa2P00pALbj+um/SaM6jlricZ1RheyalzH07i5 wKrA== 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=jkSHVoOeBj5Be/3DhuAPFN5LWKnqy4dHapEPaQfC64d06BVQYZajcAgG0K9s/vcYkL 95fopky7xUYWb8qtwRqgNms068RoJfmtTZgFm4m2tVAfWNXw46BwST6fePcJWALeW1xf YJFx6DA2rCjK54TGjZWwcv7HYBupMj2bzdbcPDfsBaml2h/F1Ut0cEU39xiwEY4fP32M 9lrmJDhZ7jCPFeRb0aRuQIHRBX2qSvb6e2EggbGhIOJ7CN9oaVtSSE8Xqu3Key2KcgBi 3It70oJetnBF2obQatPglKAeqdoCWQGgdCnA3TPISfna2tnQuzlux85IZUnHXRhs4ga0 /Vpw== X-Gm-Message-State: AOAM532D3qBJE90+JMlJSqKtRvl6DgUqcNnUiMQshobDDqpSI47eii9Y C4B//VOa6qAnfQE4KzIrUHM2xM8sX4o= X-Google-Smtp-Source: ABdhPJywstJtGXNpfJOa15QECXdK3zZ0dCSbGpNkVoIsaEgYBVPihE2XpNjH5tMmJTQbWiIZ9Xs6jA== X-Received: by 2002:a17:902:8a90:: with SMTP id p16mr3772277plo.60.1644924672063; Tue, 15 Feb 2022 03:31:12 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:31:11 -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 04/19] net: tcp: add skb drop reasons to tcp_v{4,6}_inbound_md5_hash() Date: Tue, 15 Feb 2022 19:27:57 +0800 Message-Id: <20220215112812.2093852-5-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 Tue Feb 15 11:27:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746947 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 39D35C433FE for ; Tue, 15 Feb 2022 11:31:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237192AbiBOLbc (ORCPT ); Tue, 15 Feb 2022 06:31:32 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237187AbiBOLbb (ORCPT ); Tue, 15 Feb 2022 06:31:31 -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 7B503108BDD; Tue, 15 Feb 2022 03:31:19 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id j4so12863810plj.8; Tue, 15 Feb 2022 03:31:19 -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=b/77wzRD1mVw0wflJFwy3LjpfPeSHa889rp1wccFpGmeIGS50WLq+z3D2GjyI3Vq8Y Bl3/CyDJrKx8p4NlzxieUzy8D3Hpo5EXyDWINDz+dj5KCf4l9+gYzhzGFbeiIxk1tK7+ ItYueAkjDo1pLwM6/XqZgSj+6VLaNSHtx5n7WOjRoLoKfhJfoSYMsQ4zhYwZzzVM2HwP yJ6Q4gQjrBwQ+o3uOzAEPIqmYPEdO4mtteu1lGZRXCcuHQn9urFwVzNYiMGir053fk+Y 47/N/jnlBHt9d/qQ998MLsRcCwMiyxp6+fYo5vcO1dj1Yi2yakXtjFKJTaKTH6ntBqKc +8zA== 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=hETLc45/b2xkVHKOHHVaM0D+XtB4pPy7ZDHk0Xklrgs7jSoj/f0FBUfvrVifydCo8n fzixKLkWbz+ZRoK0WPiGgMBFFF+Wj+DSQyr9uRFlkFEUwliRUi6kKHIXIVpDMR97fM9M zaW7gGtJhLXYS3kuOHvEgl17TH7PYNgcDthL3fF2L6hID8E9zh5WPMQc6bqkydbHAT9i YoBuKcmOxSadiETEFOcAA0iLXa0ve1lrjIiQJkD+rZ6fc+snmjAcI5YfWXazG0uhY4MB O8R5JDvcMzl9vsIPkQ11LiAGjfjodn7XLu0HBZRkWfwYNd0CuwEzJR3XN3MNLVlY9r1J DvPQ== X-Gm-Message-State: AOAM533L3XB7nCmmN1uThsH5zq3FNvl6d2KqI+GsO0sQuiRrW3lsfi/f 9hD4on6CaSIcxLtEoW1iT6M= X-Google-Smtp-Source: ABdhPJzh16XH32BGyBRkmZGNbIMIDVoyblKCMxYlQsJXqDI/aSXVD3m/WhuucsvWOeOXeBeUMB6fww== X-Received: by 2002:a17:902:ced1:: with SMTP id d17mr3699617plg.37.1644924678996; Tue, 15 Feb 2022 03:31:18 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:31:18 -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 05/19] net: tcp: add skb drop reasons to tcp_add_backlog() Date: Tue, 15 Feb 2022 19:27:58 +0800 Message-Id: <20220215112812.2093852-6-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 Tue Feb 15 11:27:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746948 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 A235BC433F5 for ; Tue, 15 Feb 2022 11:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229704AbiBOLbp (ORCPT ); Tue, 15 Feb 2022 06:31:45 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237204AbiBOLbh (ORCPT ); Tue, 15 Feb 2022 06:31:37 -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 88A3813F; Tue, 15 Feb 2022 03:31:26 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id i10so5248819plr.2; Tue, 15 Feb 2022 03:31:26 -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=hITaZk4Unk8D0kGzc2FEh+66ftm2EDL6Q+hY+NAZC9kemR0U6vIlv5uJfZI5mEmYIH VX9UuhFDNGLrtiAJxx3kb1IrDSMW1gwp+H8A5ZBalvcbiwc5LezWhT3zyJBgWQfy96PP +Hy9ZMqVOOgyEIYwCM7DV2N6hVsXp2ZGnQqqcgSt1Cu82VwBAaKBbada4x3H4IpB29xZ otszGo2K0QxfmVWpwtDXk914od2VxdWoytjymxYlpL3HnA0nOpzY/6Dzv5P1O4l/JHXP U2CnppXpmh33KM03L/CMjDZF8bdKR+4UNCF7rbWL3UhOGjRTyhbtA3h80QqcmLpE3tjU dPDg== 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=Aplan3ysn5X4MNFeRN0YtdmpmS5qE6TxsOu4Sl272Rwx1tRdvTYKqWLUDQz2+yyUJe zYmTjtggsnN6Qm/3P8LWW/A4XNRko9RKq5GM0yJD58kfXQ27lpMGLaUWjZXDB9P2SaME KZM14YaWww91HJihoeJ9w8M0Reqr1j3CaIKt59fD8Vttbp6gIjEnilwHA3c2ndpgZFCM kY8PZfZbqY+b9HtriDd/CBeEVm1Kz1WJ8W6msCy9yRN4+t68R5CCRGor1gg8Y0izqDgT TlcU8/FpS8wsbWY8I51b4NmcojAPuZJcc/nUicYHn3D2HtRz+IaA52ibWWcd82svZ+FR Me/w== X-Gm-Message-State: AOAM531I1WfWO0ktHP/qJvHstLp0G7LdzOoJSFFaF1UHWJuvaaI0GqRM raPst0GtWCAM6aBYucPN/NU= X-Google-Smtp-Source: ABdhPJy9XPJ8vzb9sMMuNQpiDeLO/lvBwFzcUjikL+vVFLrUTRnmnbM3gnS9Hfq141ut/G2lGSyMcA== X-Received: by 2002:a17:90b:38ce:b0:1b9:e0dd:50ec with SMTP id nn14-20020a17090b38ce00b001b9e0dd50ecmr3778623pjb.163.1644924686104; Tue, 15 Feb 2022 03:31:26 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.31.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:31:25 -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 06/19] net: tcp: use kfree_skb_reason() for tcp_v{4,6}_do_rcv() Date: Tue, 15 Feb 2022 19:27:59 +0800 Message-Id: <20220215112812.2093852-7-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 Tue Feb 15 11:28:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746949 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 18E41C433EF for ; Tue, 15 Feb 2022 11:31:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237212AbiBOLbw (ORCPT ); Tue, 15 Feb 2022 06:31:52 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237218AbiBOLbo (ORCPT ); Tue, 15 Feb 2022 06:31:44 -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 7575213E1A; Tue, 15 Feb 2022 03:31:33 -0800 (PST) Received: by mail-pj1-x1042.google.com with SMTP id v5-20020a17090a4ec500b001b8b702df57so2491255pjl.2; Tue, 15 Feb 2022 03:31:33 -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=nIVdMpYcOG2OAazxLh3VIajvOaTi60GKlKehBItfkck=; b=bE93YG0qKCESluDpXBxMBbkJAW0D4o7MMKCbbdON7pGCQYlL2Bo2Fs0jPaS6uDxGWr +t/PgD5JI+7kGhW7H0nbdYVM7oSd1EJfurBlTbO5Q7MFBLfRCggEEbTNpp8kZI11d9Av cGd9LaI015RgClpD5sHf5Dk+i9jVa3Dj8ZGql4LQGM5ReaAvuQOekfngOzqRauvClPvC mknbhN3MSArrzpdbgLFKA8sFrjAQFvvAlIE/TYCcumlg3Hca1UZ+nGVBk0i8jNzzhmr7 N7t2GW2gLakR0Zhbk3BXKxFODPsRftM0Rba4S0D73u4fsY/bbKL4xY0lOR7uocdJTDk2 Nwmw== 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=nIVdMpYcOG2OAazxLh3VIajvOaTi60GKlKehBItfkck=; b=fwWDeup7IFQLzc8eU9JeRRiykXA2wv6OoLD+lc/wcqKOu23g4IKuFFQLfjgnpPmGnf gMIMurOyUm51aBifuR7cRasUGfS3acb4t3zKUCuy7P4ogNTXIfoBn6uJmVC9OHuJo6i6 v24bMcO1ySW29wJi3fZDahcXWVLUJRQYUyCo9lY/XMc/nepxqKfDWIeYlfZzk53kH1PM cnliWg/y0YpG1slYPh0Jumo9nyq8mULiTVa67+bu1fQzdPPh7YcSkK/LANahPPW2F8CV FaPqjjEgbzy36HBsMo9mUIrWNJFt1dDXaCeq3bdjzMTE8y9sFFaMCA2vTPF/egfSRkkB kKug== X-Gm-Message-State: AOAM533iUNSdD+7AGhcReuQ2eWDBtr/KGdOSTNKQ7yln9tqNS9VT6qhc Ti4X17DFLoXkn4yWx0vSrow= X-Google-Smtp-Source: ABdhPJzQ758po3n7LRJDpYfx5y73Pwe1Ne36WKv4YAiJ+omP7a8w7ad7cTBzpTN8SZwd5PJUZJWT0A== X-Received: by 2002:a17:902:8d96:: with SMTP id v22mr3640805plo.77.1644924692974; Tue, 15 Feb 2022 03:31:32 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:31:32 -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 07/19] net: tcp: use tcp_drop_reason() for tcp_rcv_established() Date: Tue, 15 Feb 2022 19:28:00 +0800 Message-Id: <20220215112812.2093852-8-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 e3811afd1756..8cb0ea34aa49 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5790,6 +5790,7 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb, */ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) { + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED; const struct tcphdr *th = (const struct tcphdr *)skb->data; struct tcp_sock *tp = tcp_sk(sk); unsigned int len = skb->len; @@ -5878,6 +5879,7 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) tp->rcv_rtt_last_tsecr = tp->rx_opt.rcv_tsecr; return; } else { /* Header too small */ + reason = SKB_DROP_REASON_PKT_TOO_SMALL; TCP_INC_STATS(sock_net(sk), TCP_MIB_INERRS); goto discard; } @@ -5933,8 +5935,10 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) if (len < (th->doff << 2) || tcp_checksum_complete(skb)) goto csum_error; - if (!th->ack && !th->rst && !th->syn) + if (!th->ack && !th->rst && !th->syn) { + reason = SKB_DROP_REASON_TCP_FLAGS; goto discard; + } /* * Standard slow path. @@ -5960,12 +5964,13 @@ void tcp_rcv_established(struct sock *sk, struct sk_buff *skb) return; csum_error: + reason = SKB_DROP_REASON_TCP_CSUM; trace_tcp_bad_csum(skb); TCP_INC_STATS(sock_net(sk), TCP_MIB_CSUMERRORS); TCP_INC_STATS(sock_net(sk), TCP_MIB_INERRS); discard: - tcp_drop(sk, skb); + tcp_drop_reason(sk, skb, reason); } EXPORT_SYMBOL(tcp_rcv_established); From patchwork Tue Feb 15 11:28:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746950 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 97C8BC433FE for ; Tue, 15 Feb 2022 11:31:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237205AbiBOLcF (ORCPT ); Tue, 15 Feb 2022 06:32:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237207AbiBOLbt (ORCPT ); Tue, 15 Feb 2022 06:31:49 -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 4D72D13FA6; Tue, 15 Feb 2022 03:31:40 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id c3so12874836pls.5; Tue, 15 Feb 2022 03:31:40 -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=Jm4al03lAH79/G+oGH4NcNIm4l9YhtzHtSA+ICE0UDY=; b=qqSisgsZiuPaxe0IZ7smpeOMw4sf+xkumP0JqI1jJyvHbKW99CH/yNlQlljfLrPKS9 yYBuQwYTgbF8Y5otVaVkKa7ze0Ko5pjwtOW/bTmrGAtNpPhNBT+mtw01EFQvyuBPQKCQ ZHoMNNkmCzSRpZng+LWsmoGsBmH7x28xGR0Nk1Qhc16rIX6tB37sWUV1efJ5vPCAVtPi hjTk9LeoC5K/LV7k12HqqbKWNomtNdShjUBY3dJ0u5ohtxPuoJGzHPodWGKn2aokdeCS 5lMdYcBF8b+tvECpa+cG43gS0KV0DORloujSX0UgRybOHkqsoERWTBzeLTxZkpWs1Dbj ZE+Q== 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=Jm4al03lAH79/G+oGH4NcNIm4l9YhtzHtSA+ICE0UDY=; b=scYPM2LCfp6bdVohP/Nd9arz0u1dQ+pRrkTnRhf5ug9MZU1yjKGa7O04x/Q4NjJArY a/3tieBTe/0WvsBQPaTuobiq4+G2b/xUsOw6T4CtiIiH8Uigk1JBE33xgkmYfbGzITda LKmCaZcvY0AzrN3HMhZXt9rhVwRBkVAfHEUkMvIu5rsAiZrNeCt6ZnTpd6DIxEo1N1nA c+5inJEJ/Ul67qy94FLlEwC4ioSofI8SxD51cySx40sZior06/Bo+OoXkQro0n1fZ9f/ yYFHLvRxsfx78R9/LkwGHzwEwhApq8HjcmjkIe0+M9LmIJrYQ0Kf8RnwGPUsn4pVFcKw YfjA== X-Gm-Message-State: AOAM531O7i/uTT/VBRUl/U0qW91hJ9znLcjoJmg3Zx+IMc5zhL25VipQ XrUi1Ras5MfH5q29BHmHmxU= X-Google-Smtp-Source: ABdhPJzqGz9YL/5X21FB+JkGHkSvsavSWcXQgryZn/mcDY+E6HMsAKxW5ugIBuCkPP6iHRYGaGR9Ug== X-Received: by 2002:a17:90a:5204:: with SMTP id v4mr3923199pjh.47.1644924699867; Tue, 15 Feb 2022 03:31:39 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.31.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:31:39 -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 08/19] net: tcp: use tcp_drop_reason() for tcp_data_queue() Date: Tue, 15 Feb 2022 19:28:01 +0800 Message-Id: <20220215112812.2093852-9-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 8cb0ea34aa49..c042711fb5a2 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4991,6 +4991,7 @@ void tcp_data_ready(struct sock *sk) static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) { struct tcp_sock *tp = tcp_sk(sk); + enum skb_drop_reason reason; bool fragstolen; int eaten; @@ -5009,6 +5010,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) skb_dst_drop(skb); __skb_pull(skb, tcp_hdr(skb)->doff * 4); + reason = SKB_DROP_REASON_NOT_SPECIFIED; tp->rx_opt.dsack = 0; /* Queue data for delivery to the user. @@ -5017,6 +5019,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) */ if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt) { if (tcp_receive_window(tp) == 0) { + reason = SKB_DROP_REASON_TCP_ZEROWINDOW; NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPZEROWINDOWDROP); goto out_of_window; } @@ -5026,6 +5029,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) if (skb_queue_len(&sk->sk_receive_queue) == 0) sk_forced_mem_schedule(sk, skb->truesize); else if (tcp_try_rmem_schedule(sk, skb, skb->truesize)) { + reason = SKB_DROP_REASON_PROTO_MEM; NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRCVQDROP); sk->sk_data_ready(sk); goto drop; @@ -5062,6 +5066,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) if (!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) { tcp_rcv_spurious_retrans(sk, skb); /* A retransmit, 2nd most common case. Force an immediate ack. */ + reason = SKB_DROP_REASON_TCP_OLD_DATA; NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOST); tcp_dsack_set(sk, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq); @@ -5069,13 +5074,16 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) tcp_enter_quickack_mode(sk, TCP_MAX_QUICKACKS); inet_csk_schedule_ack(sk); drop: - tcp_drop(sk, skb); + tcp_drop_reason(sk, skb, reason); return; } /* Out of window. F.e. zero window probe. */ - if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt + tcp_receive_window(tp))) + if (!before(TCP_SKB_CB(skb)->seq, + tp->rcv_nxt + tcp_receive_window(tp))) { + reason = SKB_DROP_REASON_TCP_OVERWINDOW; goto out_of_window; + } if (before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { /* Partial packet, seq < rcv_next < end_seq */ @@ -5085,6 +5093,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) * remembering D-SACK for its head made in previous line. */ if (!tcp_receive_window(tp)) { + reason = SKB_DROP_REASON_TCP_ZEROWINDOW; NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPZEROWINDOWDROP); goto out_of_window; } From patchwork Tue Feb 15 11:28:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746951 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 77335C433FE for ; Tue, 15 Feb 2022 11:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232942AbiBOLcH (ORCPT ); Tue, 15 Feb 2022 06:32:07 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235210AbiBOLcD (ORCPT ); Tue, 15 Feb 2022 06:32:03 -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 1E4F919C30; Tue, 15 Feb 2022 03:31:47 -0800 (PST) Received: by mail-pj1-x1041.google.com with SMTP id v13-20020a17090ac90d00b001b87bc106bdso2459882pjt.4; Tue, 15 Feb 2022 03:31:47 -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=W5Xx1rlsjYhtyS/c0HXRmeHBBWJ3wfX66uoRpQ9UrCw=; b=gFkbyq+oUr4b9J1LKUZlR9gGtBmxwygLMAuwe+PV1haFkzloOqWo1huc6sjdpTNnDY ZRqCZNzh3IvR8/MqXyml3/0FYrBC9ukKsF7iOGATO1qn7NxHl/HuIiYpjngN8w56NPQP maMg84vhRXX1ZIxo4oSeSdM8MZUJ63HqW6yxdy2Mrja7wMWPLeeZuxonFjrJP3e8x3ZP tknLTriTjcjSQECyoP5cj3waL8PDLhxin6aJ551oX3Zxd9DkDpoB09T8z66Vh6T6qxHm HKeINFwFZpGHcQ4QGc06sCcccDsw5FVV9xZTwK18FObOQOh06TMBVSO2tR9VtUnRveJD R4Fg== 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=W5Xx1rlsjYhtyS/c0HXRmeHBBWJ3wfX66uoRpQ9UrCw=; b=OlEGYtGAbDrtv57sTcaElarAcVV3jmeVJ6GNxS6RggUcklebz0EotYN0ZzPxY4tCax FvoB0U/Gor3vOUrRX3DRkrizlb7qpb2jcpXsmDYJ5xZMdj80tKWAKWTmOZTWh+SnUW7y xxw6Nk5MTPJoAxGp0SG28yB2+GlSXE8adZdwbiIgqzOA1HZxvgrs73DTUMCJnmdsmdCA wagTZtbQ3Ice+ubpGoL+l8bMnqhObAp02R7Fcl+M2IS+nvnZBgLbiAA9voFBOyX+6PU7 poChmlEvo8KuwQ5xkb4ZNV07jPVmPSujypo69Lovnum9YD7x8KxRwoNP59lo43O/ga/+ d4/w== X-Gm-Message-State: AOAM530pbiqx9rhqjDO0mNgasjCnVoSh7sKV7DYu/QOTYHldCFAIpEEd SliPxbMUVOkCvsxVHy000QM= X-Google-Smtp-Source: ABdhPJxuuFQuA/oVWKAWC61fVgbWY56+La1nygHlqoesSt8l1wJIKNqO8L2bMkjHBn4hUKbwQ2gdYA== X-Received: by 2002:a17:902:e851:: with SMTP id t17mr3785576plg.54.1644924706693; Tue, 15 Feb 2022 03:31:46 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:31:46 -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 09/19] net: tcp: use tcp_drop_reason() for tcp_data_queue_ofo() Date: Tue, 15 Feb 2022 19:28:02 +0800 Message-Id: <20220215112812.2093852-10-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 c042711fb5a2..cb6ad47733f1 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4782,7 +4782,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) if (unlikely(tcp_try_rmem_schedule(sk, skb, skb->truesize))) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPOFODROP); sk->sk_data_ready(sk); - tcp_drop(sk, skb); + tcp_drop_reason(sk, skb, SKB_DROP_REASON_PROTO_MEM); return; } @@ -4845,7 +4845,8 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) /* All the bits are present. Drop. */ NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPOFOMERGE); - tcp_drop(sk, skb); + tcp_drop_reason(sk, skb, + SKB_DROP_REASON_TCP_OFOMERGE); skb = NULL; tcp_dsack_set(sk, seq, end_seq); goto add_sack; @@ -4864,7 +4865,8 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) TCP_SKB_CB(skb1)->end_seq); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPOFOMERGE); - tcp_drop(sk, skb1); + tcp_drop_reason(sk, skb1, + SKB_DROP_REASON_TCP_OFOMERGE); goto merge_right; } } else if (tcp_ooo_try_coalesce(sk, skb1, @@ -4892,7 +4894,7 @@ static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb) tcp_dsack_extend(sk, TCP_SKB_CB(skb1)->seq, TCP_SKB_CB(skb1)->end_seq); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPOFOMERGE); - tcp_drop(sk, skb1); + tcp_drop_reason(sk, skb1, SKB_DROP_REASON_TCP_OFOMERGE); } /* If there is no skb after us, we are the last_skb ! */ if (!skb1) From patchwork Tue Feb 15 11:28:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746952 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 A178CC433F5 for ; Tue, 15 Feb 2022 11:32:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237292AbiBOLcY (ORCPT ); Tue, 15 Feb 2022 06:32:24 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237203AbiBOLcF (ORCPT ); Tue, 15 Feb 2022 06:32:05 -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 550281B7B9; Tue, 15 Feb 2022 03:31:54 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id c10so8781379pfv.8; Tue, 15 Feb 2022 03:31:54 -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=jfI9lhFX9fm5bOhvpIeKtOFzl85DBlhHHLJFTwcXk7E=; b=dYOQpCY3N4DCxoqKc+iyHy72EN9Wh/RQkGNvCd2BkDkhgL58jNwxErlMgskwEUp5MN p92R1RzA3bfqTqV5Phx1cvLaivDOK6cCGGqetF5dyL903OFRSTViQKPFYGUbdm2q51x9 gATTXmkhe/L2hLK+ipt5i17psRZWU67UqL5OuDcuZleJtFgJ9TpjWTcVQumfMJTEvPS5 84HFmR9Iyc5wPFh9L/vYg3Ote2cclijfE9fhe+gB65XJx9O2AKWE8Mh6oUfx9grcWn8H Hy6PoRafFhsl8LR1Sl2lSVFE4b/7b3uaGxM3273zASaXuYA4XxOKfAFdO4tCtMI2vYcp Gbcw== 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=jfI9lhFX9fm5bOhvpIeKtOFzl85DBlhHHLJFTwcXk7E=; b=hdAUghU8hj0Yn7x0ohXitWvqLFPgEWX1Q07xmLnExc2/6A1eq57L7MjxLwNUSipBVS ORuvOex+Q7mrs6SHlkvv0e9u7qfRnxeGf8TC0hMhJBhPx2vaJNNVs8tLLqy+hKUTrd1d BxHcXgBdAVNsjk6Fn79Czol0w8+s7u/hZr5N5YbuIpzRI5nGmKZgdgndk10wazdOLUvB Ro8VWGUC6mmea0LfN7ENzf8euTf2yU/lruCGwitWBFL7FWHdXWAeZuQIZtPe6Vt91qVC Yx920TX1mqDIpJzeYJo8kf4UPEWT8R69CHFYmnbhnVMB118E1VKbgzYPhSHLAjRTWxKv g2tw== X-Gm-Message-State: AOAM5313Tu9ShNpynMQRInh4QZDA0OCd81eFyb/5CaJsSSyuBi9DWQrz H0SmVgmdetCWQ3cjzz7OhQ8= X-Google-Smtp-Source: ABdhPJxoizMI5FWyfJ4R5ufkPNEyGqS8EcnNCcCWUB2b8DIhLRXPfM8MEqLQSSrbs/YrZesIRZkP7w== X-Received: by 2002:a05:6a00:1a89:: with SMTP id e9mr475846pfv.84.1644924713536; Tue, 15 Feb 2022 03:31:53 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:31:53 -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 10/19] net: ip: add skb drop reasons during ip outputting Date: Tue, 15 Feb 2022 19:28:03 +0800 Message-Id: <20220215112812.2093852-11-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 As kfree_skb() is not used frequently during packet outputting in ip layer, we do this job (add reasons for skb drops) at once. kfree_skb() is replaced by kfree_skb_reason() in following functions: __ip_queue_xmit(), ip_finish_output(), ip_mc_finish_output(), ip6_output(), ip6_finish_output(), ip6_finish_output2() and following drop reasons are added: SKB_DROP_REASON_IP_OUTNOROUTES SKB_DROP_REASON_BPF_CGROUP_EGRESS SKB_DROP_REASON_IPV6DSIABLED Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 13 +++++++++++++ include/trace/events/skb.h | 4 ++++ net/ipv4/ip_output.c | 6 +++--- net/ipv6/ip6_output.c | 6 +++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 73ed01d87e43..c7394b4790a0 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -374,6 +374,19 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_OFOMERGE, /* the data of skb is already in * the ofo queue. */ + SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed during + * packet outputting + */ + SKB_DROP_REASON_BPF_CGROUP_EGRESS, /* dropped by eBPF program + * with type of BPF_PROG_TYPE_CGROUP_SKB + * and attach type of + * BPF_CGROUP_INET_EGRESS + * during packet sending + */ + SKB_DROP_REASON_IPV6DSIABLED, /* IPv6 is disabled on the device, + * see the doc for disable_ipv6 + * in ip-sysctl.rst for detail + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 2ab7193313aa..47dedef7b6b8 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -37,6 +37,10 @@ EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA) \ EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW) \ EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE) \ + EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES) \ + EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS, \ + BPF_CGROUP_EGRESS) \ + EM(SKB_DROP_REASON_IPV6DSIABLED, IPV6DSIABLED) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 0c0574eb5f5b..df549b7415fb 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -317,7 +317,7 @@ static int ip_finish_output(struct net *net, struct sock *sk, struct sk_buff *sk case NET_XMIT_CN: return __ip_finish_output(net, sk, skb) ? : ret; default: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS); return ret; } } @@ -337,7 +337,7 @@ static int ip_mc_finish_output(struct net *net, struct sock *sk, case NET_XMIT_SUCCESS: break; default: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS); return ret; } @@ -536,7 +536,7 @@ int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl, no_route: rcu_read_unlock(); IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_OUTNOROUTES); return -EHOSTUNREACH; } EXPORT_SYMBOL(__ip_queue_xmit); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 0c6c971ce0a5..4cd9e5fd25e4 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -130,7 +130,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff * rcu_read_unlock_bh(); IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTNOROUTES); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_OUTNOROUTES); return -EINVAL; } @@ -202,7 +202,7 @@ static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *s case NET_XMIT_CN: return __ip6_finish_output(net, sk, skb) ? : ret; default: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_BPF_CGROUP_EGRESS); return ret; } } @@ -217,7 +217,7 @@ int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb) if (unlikely(idev->cnf.disable_ipv6)) { IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IPV6DSIABLED); return 0; } From patchwork Tue Feb 15 11:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746953 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 D8757C433EF for ; Tue, 15 Feb 2022 11:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231124AbiBOLc0 (ORCPT ); Tue, 15 Feb 2022 06:32:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237276AbiBOLcK (ORCPT ); Tue, 15 Feb 2022 06:32:10 -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 E7F631D0C9; Tue, 15 Feb 2022 03:32:00 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id z16so12492106pfh.3; Tue, 15 Feb 2022 03:32: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=X06QuFP/yl7TqcgHiQEothXnvH7lD4rIikeiUy/iGKA=; b=At1Pl+hpDThg3GfUVuCCz5vj5bbLsK85uqz6To7gZrkAlwMzt7oT3dEqVjzOXXGOwg wPZ8RurgieWHvvSBQDx+Rw1FkgBNuqUOUsX9YbI9C2nZMhZKVM341W1NAKx8C6/ZzlkA d89qt4j9+Eo0Zjp3tbWN514m1OFq+GX4q7NvSCjdALh2a8Mv2sL8krj41AzVioegv0yo 3homwSbFh7MbWc9QZnFqZUKSQrUDeZ/NV45zEc9jsfex37Mybw/DjhUApq7+uZdh/zuc 11JnpsrWoqd2ca5XWAgTX0Ee5ybnklG3TK6q+OnJePhe8ynU0GqObMqubAwkvyaxc5l8 labw== 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=X06QuFP/yl7TqcgHiQEothXnvH7lD4rIikeiUy/iGKA=; b=4zHWXL9DTFSS+uiOCejHzrFqwXD1cDN41F4+60fRQVvlserblo6cuTg6OkpX+APJQc kdZnly5l/BfpDEB941/51nFMtL/76ImulKk1sUZjfQhUTfm2Jzw5tArMTWijIvsg4ewN VWQsGDQRXany6d+3PNMHIg6mIw4v2V+jNVuSa9DP/VBnOU91dkmNMORFN7+cLdK8HIvc wYLK/yyttzQKB0dsr8ko+wsVLBITYfvc+mWP4pXMX79rZtR5BlXbgHXpBq0YM0w4gEmH bF/PFCqKqts0OkVKSOzLaJBmnl2Qwijim0cUujqDhfJyx8f3mezrwL5Vxl8vSdImDVRn SF+g== X-Gm-Message-State: AOAM5337eqxh30Wd71DxyVQyPwPr4cyosRh1LsaZbmv825h9jBAjFNNS kfjoRkYDXH/6UM0J6J43/Wo= X-Google-Smtp-Source: ABdhPJzCMqnT4ZZNKfLuu1n+m4J6Ch0EkyG5spcVLgiXXSpKKQ8Py2pk5vCbpLXk6SC+P0Ig5C+WYQ== X-Received: by 2002:a05:6a00:174d:: with SMTP id j13mr3501886pfc.58.1644924720397; Tue, 15 Feb 2022 03:32:00 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:31: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 11/19] net: neigh: use kfree_skb_reason() for __neigh_event_send() Date: Tue, 15 Feb 2022 19:28:04 +0800 Message-Id: <20220215112812.2093852-12-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 __neigh_event_send() with kfree_skb_reason(). Following drop reasons are added: SKB_DROP_REASON_NEIGH_FAILED SKB_DROP_REASON_NEIGH_QUEUEFULL The two reasons above should be the hot path that skb drops in neighbour layer. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 9 +++++++++ include/trace/events/skb.h | 2 ++ net/core/neighbour.c | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index c7394b4790a0..136af29be256 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -387,6 +387,15 @@ enum skb_drop_reason { * see the doc for disable_ipv6 * in ip-sysctl.rst for detail */ + SKB_DROP_REASON_NEIGH_FAILED, /* dropped as the state of + * neighbour is NUD_FAILED + */ + SKB_DROP_REASON_NEIGH_QUEUEFULL, /* the skbs that waiting + * for sending on the queue + * of neigh->arp_queue is + * full, and the skbs on the + * tail will be dropped + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 47dedef7b6b8..dd06366ded4a 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -41,6 +41,8 @@ EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS, \ BPF_CGROUP_EGRESS) \ EM(SKB_DROP_REASON_IPV6DSIABLED, IPV6DSIABLED) \ + EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \ + EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/core/neighbour.c b/net/core/neighbour.c index ec0bf737b076..c353834e8fa9 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -1171,7 +1171,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb, neigh->updated = jiffies; write_unlock_bh(&neigh->lock); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_FAILED); return 1; } } else if (neigh->nud_state & NUD_STALE) { @@ -1193,7 +1193,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb, if (!buff) break; neigh->arp_queue_len_bytes -= buff->truesize; - kfree_skb(buff); + kfree_skb_reason(buff, SKB_DROP_REASON_NEIGH_QUEUEFULL); NEIGH_CACHE_STAT_INC(neigh->tbl, unres_discards); } skb_dst_force(skb); From patchwork Tue Feb 15 11:28:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746954 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 ABAC2C433FE for ; Tue, 15 Feb 2022 11:32:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237282AbiBOLcm (ORCPT ); Tue, 15 Feb 2022 06:32:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237294AbiBOLcY (ORCPT ); Tue, 15 Feb 2022 06:32:24 -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 BC55B1EAC7; Tue, 15 Feb 2022 03:32:07 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id m22so15163654pfk.6; Tue, 15 Feb 2022 03:32:07 -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=O4Z8Ketg6lyMA/EQQF8dU+j1Mac7Pb0dZ9Rft1nzw4g=; b=PrtQyDh1qBTX3EI/Z4urEK9x28uIecGFO6ov87lhsW2sOQR8tl7jVP7vuo/3NTIQRe FPDBA1Pq2A7C107Vp5THopj0hOfpBK+8LPe3mplRzj81/S7UtCNWpNgJtKANuoYwnxHQ DAsaEs6qpQwUF+WK3SfAKPUhvDC4k+NQA4MsPYQVUiUd0vldYJqUXkepGzEWUEMNPevC +JHuGrWV3L95gVSigaD5kwR3It81ff/V8Fc+0GHAKTvFYd/JHC9j3Wq0auQHoXsr38Mt 3ePum23mkNlh+5Qi1h9RouYhUBSM61z+83Nruac/LWZL2dKODAny7uN3CuMUtaiIYQ0U /P6A== 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=O4Z8Ketg6lyMA/EQQF8dU+j1Mac7Pb0dZ9Rft1nzw4g=; b=MrS6HV6MwHdqUYSFni7fPFNkKMfaKQwZysP4Oz+2AHHuL3T9E8EsVl8dfA2veC2nd3 Eq1hecZ7gRUV9s+lq2upKIsZ9wcLsDeG1TT0BmIiCo/8v78psDA3ihUgx4ckbYt6kvFz 5cRIR/7TOfIMLIZorcxSSrh4zA+efDwlapYBsCQxq8pIdI9JvXKGmrqVDuIOoQJ/3HbV QF/i+AqZv/1u91elO0BDecYND2Arb5YhifGX9liSp37BB0nr1LsAAdXB2334L9i+RZOm f/52s7vddJ1sNttOoFdp7kk2Lqp4Y2kDpZF/VZUgsK4dvmqO7EnOTAbWx7tr7eSG2a4M 4N/A== X-Gm-Message-State: AOAM531BTmcnRhLX1SrYQ+9XS8q9IxqeHbmCQfmNxTYyh+Eg24CE89q4 W95FlgDoIV8RSm+jDDI9KqQ= X-Google-Smtp-Source: ABdhPJwV64v2Uh201W7T6Z2LQGDLjIScOiG3UezVow2lAx6krzVZwC/mSfLTzXL7XlWo6NKeeAvxJg== X-Received: by 2002:a63:1a4e:: with SMTP id a14mr3157207pgm.107.1644924727283; Tue, 15 Feb 2022 03:32:07 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:32:06 -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 12/19] net: neigh: add skb drop reasons to arp_error_report() Date: Tue, 15 Feb 2022 19:28:05 +0800 Message-Id: <20220215112812.2093852-13-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 When neighbour become invalid or destroyed, neigh_invalidate() will be called. neigh->ops->error_report() will be called if the neighbour's state is NUD_FAILED, and seems here is the only use of error_report(). So we can tell that the reason of skb drops in arp_error_report() is SKB_DROP_REASON_NEIGH_FAILED. Signed-off-by: Menglong Dong --- net/ipv4/arp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 4db0325f6e1a..8e4ca4738c43 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -293,7 +293,7 @@ static int arp_constructor(struct neighbour *neigh) static void arp_error_report(struct neighbour *neigh, struct sk_buff *skb) { dst_link_failure(skb); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_FAILED); } /* Create and send an arp packet. */ From patchwork Tue Feb 15 11:28:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746955 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 1FA0DC433FE for ; Tue, 15 Feb 2022 11:32:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237347AbiBOLdE (ORCPT ); Tue, 15 Feb 2022 06:33:04 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237324AbiBOLcZ (ORCPT ); Tue, 15 Feb 2022 06:32:25 -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 982D113FA8; Tue, 15 Feb 2022 03:32:14 -0800 (PST) Received: by mail-pj1-x1043.google.com with SMTP id t4-20020a17090a510400b001b8c4a6cd5dso1855322pjh.5; Tue, 15 Feb 2022 03:32:14 -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=IhNqtUiymJdJP2PFRV84KUeWXIpI5jZ1newpR0JSrRw=; b=U6LBQs22JEn6MCJRQHgPP0aJScUEu08steoCaMHRVWgEEYRnjoqlRv7okneMAFSzrl nWAVXZArFeO6Hn2+X7R8m3DJTNogTca7/AawIYm04ClmXIpVXJJ73Y3S2YMCkkxCxxKD WxrKOdZ95iIumwfK995iAejb91hq2/QEqIhOs6cSOJ2JPXm0m76I6ddG/jGUH4SxiCmF YnUCY4NfLPunNzIdtvkuVoS4KFd/bI9cBgZ+oz+XZD5A4zWRZFqkpNztpaDNDhSGGpfl YqykoF536hegz8MZgYNQL03/0w82esNRbDSqEM8JC+2H1GPMMGfcM5ecQDBY8t5Czfu+ zJMQ== 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=IhNqtUiymJdJP2PFRV84KUeWXIpI5jZ1newpR0JSrRw=; b=Y5PlTcJ1NJHsBsOVrcWjNUubyhEHF3MMM5YmDqsYNFOdXEv61tuLBasu0NGxo7wv0c kpb+/JKY55uxjTs5pH/VQal8isawhJouPrjvNUYTz9GVebbAK+6r+yEhrDYIGVrmRot6 CiWwVi5K9lx9uE70FQnPjRSbRi5IEFXYNG3B6i5evjW4gfURmCl4HAC//SBb30sU46MZ rpQOOmTY59XuUPcQQtxiqoN5hryvNPythxRmX9/XydG7yTjdE/QIcSU63GBSAzedVbVJ thOJUKf/C6DJJRdzSKb4F4xqtdBanPfZ+UEZWBkrZmXCN7bpFvtOuUaOCh6Ig52DBmWl e2oQ== X-Gm-Message-State: AOAM530ER1lTvRVqofQGql5pwnEuF2Fsgz3xxXVl7GSiHTHe4M2FLC8p DWzopj7oA07W9/WD6oA718E= X-Google-Smtp-Source: ABdhPJxv/jNWEqzuXwYilVop3ZnjSaw/2f9/67mqeoDfVOf7SzrRT4uYkaUDB6fzSDYZ4wcC2K10pA== X-Received: by 2002:a17:902:bd8b:: with SMTP id q11mr3620085pls.83.1644924734114; Tue, 15 Feb 2022 03:32:14 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:32:13 -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 13/19] net: dev: use kfree_skb_reason() for sch_handle_egress() Date: Tue, 15 Feb 2022 19:28:06 +0800 Message-Id: <20220215112812.2093852-14-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 sch_handle_egress() with kfree_skb_reason(). The drop reason SKB_DROP_REASON_QDISC_EGRESS is introduced. Considering the code path of qdisc egress, we make it distinct with the drop reason of SKB_DROP_REASON_QDISC_DROP in the next commit. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 4 ++++ include/trace/events/skb.h | 1 + net/core/dev.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 136af29be256..9e19806d9818 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -396,6 +396,10 @@ enum skb_drop_reason { * full, and the skbs on the * tail will be dropped */ + SKB_DROP_REASON_QDISC_EGRESS, /* qdisc of type egress check + * failed (maybe an eBPF program + * is tricking?) + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index dd06366ded4a..a79b64eace9e 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -43,6 +43,7 @@ EM(SKB_DROP_REASON_IPV6DSIABLED, IPV6DSIABLED) \ EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \ EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ + EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/core/dev.c b/net/core/dev.c index 2c3b8744e00c..2a7b7c1b855a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3840,7 +3840,7 @@ sch_handle_egress(struct sk_buff *skb, int *ret, struct net_device *dev) case TC_ACT_SHOT: mini_qdisc_qstats_cpu_drop(miniq); *ret = NET_XMIT_DROP; - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_QDISC_EGRESS); return NULL; case TC_ACT_STOLEN: case TC_ACT_QUEUED: From patchwork Tue Feb 15 11:28:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746956 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 E9B2CC43217 for ; Tue, 15 Feb 2022 11:32:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237324AbiBOLdH (ORCPT ); Tue, 15 Feb 2022 06:33:07 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237336AbiBOLcj (ORCPT ); Tue, 15 Feb 2022 06:32:39 -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 71E641D30D; Tue, 15 Feb 2022 03:32:21 -0800 (PST) Received: by mail-pj1-x1041.google.com with SMTP id a11-20020a17090a740b00b001b8b506c42fso2529927pjg.0; Tue, 15 Feb 2022 03:32:21 -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=SkNAR3lDZcmBWeuKDCFBfpoA/7HZcdiBmnBFE2F5L64=; b=GZ9OUDvX25uu7M0gOzefMn7E7Z5QNqI0GPYYyIBj6wyCj/M5gWNcjRJ8dsZ9SDWoKu 1zdk0aBMj6TcJ8HAjBiuAfz+x7T0t75nG6zpFo+rL6gaHDBX3BYmamGZgg9PqLR4PbTt Akp3DHdHM4oZ9Shhhrmepni2w5wRRRyshklHGe5EB+NryIF3b5+3RU35pQ1L+CYPeC+J E/2YlVsTjnwd3/srfbOZO5mVoDWlUDvVlWXar0iumwtQgGM+9iP9xe1oOKoBG9uq8gWh aMLWJEVrWQQUvZYdkLdgmOEBa/RUa87sRXwvZ/uhHd8NQ1b00OE9UM2j+uRfByW7z1In QX9A== 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=SkNAR3lDZcmBWeuKDCFBfpoA/7HZcdiBmnBFE2F5L64=; b=7z7f6kkJXm6Cwwe+iemP/03iAzVSXrXwSRmFrLFVqeN29xYcdHPZetXcsSDPSOLTtK MJyVW4eXn3sYrEiWm6d1sYsfCkDouE8wzhbBZEEsX0W6rAhCzU265jKJMnLshZ7Sk0CG UAG/k4bZW86B6T1J0hG9pRaeOoHsAPUBx000sTWVKaTA681eEYJgYCr6I7/rCy9TDtdr r8YZ+rQE5AH8Gee7l47Dp6Bw82fUvuUx875go3+N2iCSXYp1jahva/dH6Wy4+HeQcdi0 q4CFOUAiBFkl/aSZYSu+nf4Vr984ahT/fW9xc7KmF2bEhhGLsFS499nmzlgvHOJARfdl +JpQ== X-Gm-Message-State: AOAM532AQI53kMufhlx1+vikl1cls2wrdBEgWclnG9WRZ4yS4Rjjml0C w96fH7La1Y9jo9FbDAe3EBI= X-Google-Smtp-Source: ABdhPJxHzUprbOT7DlhkjIqJGcqlcvTgQN/MMioMl3+q0IHTTgmTJC8SRbCvecqVcelRXWf9gqGcKA== X-Received: by 2002:a17:90a:2949:b0:1b3:1bcd:e7f3 with SMTP id x9-20020a17090a294900b001b31bcde7f3mr3793574pjf.125.1644924740969; Tue, 15 Feb 2022 03:32:20 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:32:20 -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 14/19] net: skb: introduce the function kfree_skb_list_reason() Date: Tue, 15 Feb 2022 19:28:07 +0800 Message-Id: <20220215112812.2093852-15-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 To report reasons of skb drops, introduce the function kfree_skb_list_reason() and make kfree_skb_list() an inline call to it. This function will be used in the next commit in __dev_xmit_skb(). Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 8 +++++++- net/core/skbuff.c | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 9e19806d9818..dc3794b60b1c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1196,10 +1196,16 @@ static inline void kfree_skb(struct sk_buff *skb) } void skb_release_head_state(struct sk_buff *skb); -void kfree_skb_list(struct sk_buff *segs); +void kfree_skb_list_reason(struct sk_buff *segs, + enum skb_drop_reason reason); void skb_dump(const char *level, const struct sk_buff *skb, bool full_pkt); void skb_tx_error(struct sk_buff *skb); +static inline void kfree_skb_list(struct sk_buff *segs) +{ + kfree_skb_list_reason(segs, SKB_DROP_REASON_NOT_SPECIFIED); +} + #ifdef CONFIG_TRACEPOINTS void consume_skb(struct sk_buff *skb); #else diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 9d0388bed0c1..f0c6207f5de7 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -777,16 +777,17 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) } EXPORT_SYMBOL(kfree_skb_reason); -void kfree_skb_list(struct sk_buff *segs) +void kfree_skb_list_reason(struct sk_buff *segs, + enum skb_drop_reason reason) { while (segs) { struct sk_buff *next = segs->next; - kfree_skb(segs); + kfree_skb_reason(segs, reason); segs = next; } } -EXPORT_SYMBOL(kfree_skb_list); +EXPORT_SYMBOL(kfree_skb_list_reason); /* Dump skb information and contents. * From patchwork Tue Feb 15 11:28:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746957 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 0676CC433FE for ; Tue, 15 Feb 2022 11:33:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237335AbiBOLdV (ORCPT ); Tue, 15 Feb 2022 06:33:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbiBOLdD (ORCPT ); Tue, 15 Feb 2022 06:33:03 -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 384C91EC62; Tue, 15 Feb 2022 03:32:28 -0800 (PST) Received: by mail-pj1-x1044.google.com with SMTP id r64-20020a17090a43c600b001b8854e682eso1900426pjg.0; Tue, 15 Feb 2022 03: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=/4py2Bmts28btn/12GBhxHsz4doLzDFjoc4aV2hjupA=; b=Qcm/CLFVet0tiWOoTgyE0pXkLUvRc4lN7XR+bDFYpOSTWknOw0Q5W1ZKe71CQfcosl t8nlMTzn2qqMiUsel1hiZN9hZXmn1vm2w5zfzNEGyHKKUq96LoJb2jUlcVB/Fadiwg9X eX53BZ8yHKZF2uMeRc70S85Ixbubjgbg2dEqQ8hMDWWI9nHXL15ay+hihtCxa78BEvaX 3qnv4xqziEQnoe9gSMYNj3scHMQCao2pXAhWocX7Z9zrY5N302Uy5TsSYhwssUzLXmUJ TEx29IyeUypBtwIL/kgOxeachZOcP/jZOWnj/Zz3aaffUSbNtBUGWN5mtv2PsS6fP7PL wMtw== 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=/4py2Bmts28btn/12GBhxHsz4doLzDFjoc4aV2hjupA=; b=kIGvi+gXbaiuc+vDn4Vpb+Z7VdFeSLJyxilhvGqYGpJtVeY8SqLG4RM9sC6fHNT3jg RYVnIEYyVAs8l8abvRE8r5I6EYs0SPXHcCAGpSVOKhh2qJmid6qprALUgH2BKBPhC56T RW9O8Ptqso5jfggIxWy8kfnwZ2WTHkX7ruoqZSB1ROi9taC9VzdoaI9ZuXOh17iXnyUW 0AT4LwPYyfFfr3IZwwoPUFvHqzYYUiYPGZ1axPbhP4qu5JbpUre7TlaRIxRAQf/RbJaY 5r9rIg1OpXMbVDmzxSOL9XvPQ3g6mE6EMdMHgkh8Bsttk/XufcubSdhctkmBxXpmNKxO l1WQ== X-Gm-Message-State: AOAM530GReiOBIv1bRCyQ1w0OrskMmw9GGqis3/jJnVUZFUtgFCzn230 o8JSI0b+BI234wdnsb3VaOI= X-Google-Smtp-Source: ABdhPJyJYwHg3dZNxWZyk8m5YfvHB4DMBsjIOTCPkBqbh7zrzbsdvwnUjzS0vmzeBFsv/2u6MzBAwQ== X-Received: by 2002:a17:903:2344:: with SMTP id c4mr3782667plh.55.1644924747817; Tue, 15 Feb 2022 03:32:27 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03: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 15/19] net: dev: add skb drop reasons to __dev_xmit_skb() Date: Tue, 15 Feb 2022 19:28:08 +0800 Message-Id: <20220215112812.2093852-16-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 Add reasons for skb drops to __dev_xmit_skb() by replacing kfree_skb_list() with kfree_skb_list_reason(). The drop reason of SKB_DROP_REASON_QDISC_DROP is introduced for qdisc enqueue fails. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 4 ++++ include/trace/events/skb.h | 1 + net/core/dev.c | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index dc3794b60b1c..0f7e5177dbaf 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -400,6 +400,10 @@ enum skb_drop_reason { * failed (maybe an eBPF program * is tricking?) */ + SKB_DROP_REASON_QDISC_DROP, /* dropped by qdisc when packet + * outputting (failed to enqueue to + * current qdisc) + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index a79b64eace9e..356bea7567b5 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -44,6 +44,7 @@ EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \ EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \ + EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/core/dev.c b/net/core/dev.c index 2a7b7c1b855a..55e890964fe2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3710,7 +3710,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, no_lock_out: if (unlikely(to_free)) - kfree_skb_list(to_free); + kfree_skb_list_reason(to_free, + SKB_DROP_REASON_QDISC_DROP); return rc; } @@ -3765,7 +3766,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, } spin_unlock(root_lock); if (unlikely(to_free)) - kfree_skb_list(to_free); + kfree_skb_list_reason(to_free, SKB_DROP_REASON_QDISC_DROP); if (unlikely(contended)) spin_unlock(&q->busylock); return rc; From patchwork Tue Feb 15 11:28:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746958 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 5046BC433EF for ; Tue, 15 Feb 2022 11:33:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236557AbiBOLdY (ORCPT ); Tue, 15 Feb 2022 06:33:24 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237366AbiBOLdG (ORCPT ); Tue, 15 Feb 2022 06:33:06 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C4161EC7C; Tue, 15 Feb 2022 03:32:35 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id d187so34352189pfa.10; Tue, 15 Feb 2022 03: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=hCin9VBadiO8qQl5cVgIoA5kDmxwQm+XKqBpptXE5CA=; b=AesnmJ+XdfuOD2K+xgFhtvTjQ7ZNs2+YlTYrTQAEBM4qVCJF2QdgJaa6tLILBwfozH vAvMcpT0wSl3LbkiD34Z2j0+FlnT7A4lXLCeh0kh30GyhlslXo/WEivhiobN/lTDIjWc QNq4l0L5znk2JtoH1kaPAkyFehtLWwKzh6nlI2qfe4W2FaUE72n7M6g1gngEsiF4ginO Yf+/FFfLtoh869q/hMYkHENzOleXmrN3FcW0PSh18SJvgsBCH0XqheIzlaHzh1xYGOH/ cVKVFxv23jww3lrFpaC2zTm+x+5CLBVWpzRq3M+L7F9RSAz+smWP+PK64QQ9ufUX1bln fPbg== 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=hCin9VBadiO8qQl5cVgIoA5kDmxwQm+XKqBpptXE5CA=; b=yYBXKXowGctWTrycoYpBK7CLzjoW7YbCpetMVBAi5LGXsI1BBJYMPtIWei6LIbuV4Z 4q3YhnVBNU8bx8qsNqDLQ0bL8ZH5pEd19sgOlcaWxLdjyuO8eDgZXHwJIb6EFEuMdyUT EYaqxo8ppTrA9s+WMhPz+tQPwrQifmH9Y3u8EJa0wL/SgVB0RNZQcAFgKvJqS7VxFhPC kAKLKege9BJgCE+fzHFd1xsVbhe3RlkwEGjHiGVzVNrkRm9Kn2zzlPTMgplsjvWrALeC gpS+SuhhwGPN+YezsKmWs5+YA7NebyDmlDLIkJIYQQ30SL4XSOtigqrT5uv+FLADxOMg FXcw== X-Gm-Message-State: AOAM531qAYtUzr/6VlHG5/DFW0zcp2BKluNBgSkhnkmQ+DdNmqcVkVuZ EUMAi1sf7vsdb43ED41Svu4= X-Google-Smtp-Source: ABdhPJxauvFZJwsAuhYpar96BWNRoHG7lqOaMigdjq/aYICVBDl+UJqOHnHXJpNrJlRXtyZvqPn7qg== X-Received: by 2002:a63:2bc5:: with SMTP id r188mr3146784pgr.363.1644924754663; Tue, 15 Feb 2022 03:32:34 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03: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 16/19] net: dev: use kfree_skb_reason() for enqueue_to_backlog() Date: Tue, 15 Feb 2022 19:28:09 +0800 Message-Id: <20220215112812.2093852-17-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 enqueue_to_backlog() with kfree_skb_reason(). The skb drop reason SKB_DROP_REASON_CPU_BACKLOG is introduced for the case of failing to enqueue the skb to the per CPU backlog queue. The further reason can be backlog queue full or RPS flow limition, and I think we needn't to make further distinctions. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 6 ++++++ include/trace/events/skb.h | 1 + net/core/dev.c | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 0f7e5177dbaf..d59fdcd98278 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -404,6 +404,12 @@ enum skb_drop_reason { * outputting (failed to enqueue to * current qdisc) */ + SKB_DROP_REASON_CPU_BACKLOG, /* failed to enqueue the skb to + * the per CPU backlog queue. This + * can be caused by backlog queue + * full (see netdev_max_backlog in + * net.rst) or RPS flow limit + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 356bea7567b5..a1c235daf23b 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -45,6 +45,7 @@ EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \ EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ + EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/core/dev.c b/net/core/dev.c index 55e890964fe2..8fee7adfca88 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4520,10 +4520,12 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen) static int enqueue_to_backlog(struct sk_buff *skb, int cpu, unsigned int *qtail) { + enum skb_drop_reason reason; struct softnet_data *sd; unsigned long flags; unsigned int qlen; + reason = SKB_DROP_REASON_NOT_SPECIFIED; sd = &per_cpu(softnet_data, cpu); local_irq_save(flags); @@ -4550,6 +4552,8 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu, ____napi_schedule(sd, &sd->backlog); } goto enqueue; + } else { + reason = SKB_DROP_REASON_CPU_BACKLOG; } drop: @@ -4559,7 +4563,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu, local_irq_restore(flags); atomic_long_inc(&skb->dev->rx_dropped); - kfree_skb(skb); + kfree_skb_reason(skb, reason); return NET_RX_DROP; } From patchwork Tue Feb 15 11:28:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746959 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 A91BCC433F5 for ; Tue, 15 Feb 2022 11:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236125AbiBOLdo (ORCPT ); Tue, 15 Feb 2022 06:33:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:56258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237294AbiBOLdU (ORCPT ); Tue, 15 Feb 2022 06:33:20 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E371D201A1; Tue, 15 Feb 2022 03:32:41 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id u16so342997pfg.12; Tue, 15 Feb 2022 03: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=YVR6bNBU9Pl8MoQNPuKiEG9Qqnb4IUp54CTPQEoDvoQ=; b=YQfJIKbxHLurxwQh9olo0G1j1ELpLXcq36hFomv9bxZDXotJyrJBRH2qtbjEd2uAn1 +9DuY1MDCfucp8zpW10NCSAL3hnAgtrUMsZmzWXfqpL3EKN9AuEK8LJm5O2SH32gjcaj /iDQf4MWRA1SN21eL2L4j9+dZtNFrgCymkzBhKEhOUVZDssJAWMXH05fcoUlSX25k/yZ ydvTbrQ/9Qzx245O1tI+K5Xi/abT9ieZo8rctcOREYVTPvtvdav0FjWFJfDvbLG3H1Nq iPY7ATOV5CAnJsrOqTNM2ZJPCxU7rTQKbApbj9mqJeVki+W0EBvZhq3jIj79/K5ev9++ oBcw== 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=YVR6bNBU9Pl8MoQNPuKiEG9Qqnb4IUp54CTPQEoDvoQ=; b=n3zSIAvhcKGc9xjuXL2PEQOr0OKYXc7hT7/STaERw3Zy/TOFoBP+c/t4VNVKw1XrUL z7OHlXqOA8pFlUPLmKQyrW9x+Y6E7ap6wF4MDO3VGOsO06zZVgdHhb/A5rRo29ugKkXF BtDxJj5asS8f39igp5/gnmr7L8QvY02rzgVJ0qZiqabPSkCavJvcf1AZ0SmT5qI0HnWk GpL9l+r636z119MySNz2L2oOdDROk9Po0S+utVNZpTaee0zvHTWzOi4CXmaWS8oe7zzT SGVb0IG+waoxX9IrRavJhUXRaRaMbmCkq1HhE8bIFBWm73xl1LPc63+USz1zmEVe6nh1 GtiA== X-Gm-Message-State: AOAM532CoSH4WgnxO4u3/BlYxOnCme9iZbheTl5FneAHeuqVxeShpNs5 jMN7m9yLVoAUibbJA2UFjhs= X-Google-Smtp-Source: ABdhPJwngik4/NwdCkpUv8oH8h3TezojUzGLHnVVrSZml1YnfDLGiUFC8bikMe95Dm3ujYkpYghHbw== X-Received: by 2002:aa7:8e44:: with SMTP id d4mr3891656pfr.4.1644924761506; Tue, 15 Feb 2022 03:32:41 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03:32:40 -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 17/19] net: dev: use kfree_skb_reason() for do_xdp_generic() Date: Tue, 15 Feb 2022 19:28:10 +0800 Message-Id: <20220215112812.2093852-18-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-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 do_xdp_generic() with kfree_skb_reason(). The drop reason SKB_DROP_REASON_XDP is introduced for this case. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/core/dev.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index d59fdcd98278..79b24d5f491d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -410,6 +410,7 @@ enum skb_drop_reason { * full (see netdev_max_backlog in * net.rst) or RPS flow limit */ + SKB_DROP_REASON_XDP, /* dropped by XDP in input path */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index a1c235daf23b..7bc46414a81b 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -46,6 +46,7 @@ EM(SKB_DROP_REASON_QDISC_EGRESS, QDISC_EGRESS) \ EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ + EM(SKB_DROP_REASON_XDP, XDP) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/core/dev.c b/net/core/dev.c index 8fee7adfca88..a2548b7f2708 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4783,7 +4783,7 @@ int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb) } return XDP_PASS; out_redir: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_XDP); return XDP_DROP; } EXPORT_SYMBOL_GPL(do_xdp_generic); From patchwork Tue Feb 15 11:28:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746960 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 D8E01C433FE for ; Tue, 15 Feb 2022 11:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230321AbiBOLdr (ORCPT ); Tue, 15 Feb 2022 06:33:47 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237376AbiBOLdW (ORCPT ); Tue, 15 Feb 2022 06:33:22 -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 C0AA9220CF; Tue, 15 Feb 2022 03:32:48 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id u5so1683083ple.3; Tue, 15 Feb 2022 03: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=0xCICfG2niwYOnpIcsDoi3nvIqDLrd7OmoM+8aXLBIQ=; b=YLAdafujTLdWUAyS3CrkvPklRpmRj/1F27/tT1Ad4Gyd/IxRPZbOxN7iCd++c8QygO Qa1/9rZv8to/jAP52F4m7tYRAQkktRp6f3k8rk1Rjf4Jtkp+Ob0UMcQvVNk7d3YbiBFI pHxYsNbPARMvssfSvptY1VQI06fImoc/C/eaAcmqlhjM0yT+RycUCHaG7PK1LzazKSZc dZLpkIrWC+zEJAG9ESNW4ppaD0XMP43g+kqtZtTkQIWN1irkX72RplatKcUd2oNMF8xQ fyuF0kTlULxix1f5X8l0ZSuxu8ux/n+cNw+egG/PfP+bL1u6PlokWAwUtM445ktqOekw d8MQ== 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=0xCICfG2niwYOnpIcsDoi3nvIqDLrd7OmoM+8aXLBIQ=; b=hdxKCcvuoe6vZRV/4XBIgV+XZ9dosIG9ZEI7G7CQ5Qk7s5D9Unsjnq/X79v8oku3M9 8TuTP2Y7h+PUWkGBurPgC5bf9oBS15LCkuiZioON1meCvTpExyXqb+fMuTJfN7ubdj/+ MARLziPMgL8n78UQ3iFc1yRiivDc6Or+/YtrZYJXBt7TnR1Nmhg1yHDoI+y1ispRvuq2 AXZFk5WupYFX8NEeM41Z3PQPGBpJ2xyQOgue6mskR4oaT71kSvplj9OWotP8Wzz1Ru2c PNxpt3v1nqoNVTuMk4bcK9u2RV8GlXwKSt5WinR0EvANsGer9GdudIwXx22P2VMXtIl7 PTEw== X-Gm-Message-State: AOAM532c6oP/eXAk/G+uaoU/Z4J2Y/YyO19TcuG5bzAZt9kII85IjWfi pvNceGrGt1i2RJ/Yq2x2jqo= X-Google-Smtp-Source: ABdhPJygI/OuYQVzg9zEAI+fUbZRs8BnlWX1TSrUweQX4uedw7yhyxfKKURJekNVsXqmS7rIGBIJOQ== X-Received: by 2002:a17:902:7892:: with SMTP id q18mr3640507pll.106.1644924768343; Tue, 15 Feb 2022 03:32:48 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.32.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03: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 18/19] net: dev: use kfree_skb_reason() for sch_handle_ingress() Date: Tue, 15 Feb 2022 19:28:11 +0800 Message-Id: <20220215112812.2093852-19-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() used in sch_handle_ingress() with kfree_skb_reason(). Following drop reasons are introduced: SKB_DROP_REASON_QDISC_INGRESS Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 4 ++++ include/trace/events/skb.h | 1 + net/core/dev.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 79b24d5f491d..e36e27943104 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -411,6 +411,10 @@ enum skb_drop_reason { * net.rst) or RPS flow limit */ SKB_DROP_REASON_XDP, /* dropped by XDP in input path */ + SKB_DROP_REASON_QDISC_INGRESS, /* qdisc of type ingress check + * failed (maybe an eBPF program + * is tricking?) + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 7bc46414a81b..96a550570dfe 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -47,6 +47,7 @@ EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ EM(SKB_DROP_REASON_XDP, XDP) \ + EM(SKB_DROP_REASON_QDISC_INGRESS, QDISC_INGRESS) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/core/dev.c b/net/core/dev.c index a2548b7f2708..c67e3491c004 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5006,7 +5006,7 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, break; case TC_ACT_SHOT: mini_qdisc_qstats_cpu_drop(miniq); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_QDISC_INGRESS); return NULL; case TC_ACT_STOLEN: case TC_ACT_QUEUED: From patchwork Tue Feb 15 11:28:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12746961 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 C99D6C433EF for ; Tue, 15 Feb 2022 11:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237233AbiBOLds (ORCPT ); Tue, 15 Feb 2022 06:33:48 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237384AbiBOLdX (ORCPT ); Tue, 15 Feb 2022 06:33:23 -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 A0FD913EA5; Tue, 15 Feb 2022 03:32:55 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id c3so12877117pls.5; Tue, 15 Feb 2022 03: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=uvNG3b2ZVAODPVHZbR7OYDshW9r7jcq3KS61WPMxW90=; b=T2fE7+oGkLWvKCMISDbt4bvOr7QIHlkrZlnQet4SeOSLZPVjKT3pWkYg3UDXs1SPRg YBE2wQq4UchSyDXvJgvOnHflX78v6Df2RIBEmfMQl/SODnKmxT1RsFcaWtIyDMHXJl/T VBoYbiekjo6P37OZ9EpcbW2FSIcPd+CFbXw4wXE8ZywQqPcqVX6kcCVmOFaAsbpyhUpX aXnFFKwRumazi6MgnxI+uVHj4JeOjhOTqcBN5yd1J6trqxfJQm30wfRGEvD47gD7WB8R +UXS8UAKw9SxMkktLVN+rNVSFsgMWTohWIh3lay0JL3VITklQIMH8Kq63XDAdAk3QzeO 1TdQ== 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=uvNG3b2ZVAODPVHZbR7OYDshW9r7jcq3KS61WPMxW90=; b=HtY8QPP6c8fUzScDxfb0bUO5pJH40mgmPkbJNyOoIvYrLz485V7yW7xh9wq4CEwgyo fXv+sD1qO88yrJbkDURHuUp72Ycz0O9VbC3Fz2auQ1gu2Kzp9d0vfEsryz375HdCaXaB b2PTe3QbMnUnoIlrKbBcgKOE7ljKZM5h7sEDjEXgr5sagzlWyAazvqBRbZlFXCgAzoVX lFDZo8NnG9Ne7gbgxgixuyA/40urlgpkqBB8NToCFEl5ZqH+P869NYC+RwUexjUpzF8i 8mKi5nKdnAP5hh4hfFjr9wN7kCJShdAXtg1nXFPNLwDkUAZEp6mRsKRgWwuUYczC1zYK NqQQ== X-Gm-Message-State: AOAM531OV2+eSExSInNNEpF2O+rk7dbEuzTTajKaJZ9CtJil3V9Iz1wI NCnDxrbIlap8vk3xvzNu5rc= X-Google-Smtp-Source: ABdhPJw2H1l6j9qqcE3Sp6JhI0pOdJnG6iQ17yFicjP59I0hrTkpTTpS6iQab8ePR5xq32PTvq0Duw== X-Received: by 2002:a17:902:8d96:: with SMTP id v22mr3646721plo.77.1644924775195; Tue, 15 Feb 2022 03:32:55 -0800 (PST) Received: from localhost.localdomain ([203.205.141.113]) by smtp.gmail.com with ESMTPSA id s11sm44515513pfu.58.2022.02.15.03.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 03: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 19/19] net: dev: use kfree_skb_reason() for __netif_receive_skb_core() Date: Tue, 15 Feb 2022 19:28:12 +0800 Message-Id: <20220215112812.2093852-20-imagedong@tencent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220215112812.2093852-1-imagedong@tencent.com> References: <20220215112812.2093852-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Add reason for skb drops to __netif_receive_skb_core() when packet_type not found to handle the skb. For this purpose, the drop reason SKB_DROP_REASON_PTYPE_ABSENT is introduced. Take ether packets for example, this case mainly happens when L3 protocol is not supported. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 5 +++++ include/trace/events/skb.h | 1 + net/core/dev.c | 8 +++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index e36e27943104..b467a5adfeaf 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -415,6 +415,11 @@ enum skb_drop_reason { * failed (maybe an eBPF program * is tricking?) */ + SKB_DROP_REASON_PTYPE_ABSENT, /* no packet_type found to handle + * the skb. For an etner packet, + * this means that L3 protocol is + * not supported + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 96a550570dfe..f649c0a18d29 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -48,6 +48,7 @@ EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ EM(SKB_DROP_REASON_XDP, XDP) \ EM(SKB_DROP_REASON_QDISC_INGRESS, QDISC_INGRESS) \ + EM(SKB_DROP_REASON_PTYPE_ABSENT, PTYPE_ABSENT) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/core/dev.c b/net/core/dev.c index c67e3491c004..90488d05f83b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5323,11 +5323,13 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc, *ppt_prev = pt_prev; } else { drop: - if (!deliver_exact) + if (!deliver_exact) { atomic_long_inc(&skb->dev->rx_dropped); - else + kfree_skb_reason(skb, SKB_DROP_REASON_PTYPE_ABSENT); + } else { atomic_long_inc(&skb->dev->rx_nohandler); - kfree_skb(skb); + kfree_skb(skb); + } /* Jamal, now you will not able to escape explaining * me how you were going to use this. :-) */