From patchwork Fri Jun 17 10:05: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: 12885418 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 C7BECC433EF for ; Fri, 17 Jun 2022 10:06:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235899AbiFQKGE (ORCPT ); Fri, 17 Jun 2022 06:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381515AbiFQKGA (ORCPT ); Fri, 17 Jun 2022 06:06:00 -0400 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 5AE3569B55; Fri, 17 Jun 2022 03:06:00 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id y196so3771722pfb.6; Fri, 17 Jun 2022 03:06:00 -0700 (PDT) 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=OJ5yUeHxRXLRRzyu6F8edZ4SeRLkQ7Rllpb1jK/oYWI=; b=UrF55YHxLMU6QHm6J8TLYPtEfIkqwfe0O8uamlTEz5NszzYX682VTp/aQpuQ5d+kKF RQblj0WjdLLLK1i/wk6dN/VBp9s5zimfIEggJIxUCu1ltlMpIGqeCXzrdrO+m5GmOa95 sqY8dlQBxn1Chgv6O42Kws6H0+Q41OpO84GP/E+ssxsxD3QnkIX9r7yBpiD7iBC3LhY9 sLI+rhrXY2+zvIIiJzQn09YCxe4HcuGkpytKAUIXW4UO1z76+yOypv72pLg7VswUkVFe nhm91kGCHHvMuuxdj/TLyHrixdIQ1lPVCsa8An97nDHD24T01lbmTnFBUwD+3DUC6y8B UHcw== 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=OJ5yUeHxRXLRRzyu6F8edZ4SeRLkQ7Rllpb1jK/oYWI=; b=aDMVFXb+zuk9rO9lUwaTJxvLSmlXU4uFYoLssfX6wJeVdj1YsKIh+CWWCwlRHfrclX /KarWw8G2XbleoDqgutPARO81xGvjrGdXmuOTWdBDHu3nTd/meJoGHZT73spSabTDx8N 3t5lTQZJ8kbaiELjuIBWGnxLp3KEEMFKMkOXCFCwrEMe2ZskD9VW5YjdqnQn38k676/r rKf5bG1D74n0WuWUdy9uXaiMgfQESsA8Z1fuFgg5/SmOedxWQDeY/jLHiCI+TJMJfIMR VOzbgcu3XTgP6zaCOlhieZNnoSDnVDBPHm1/+RF1IZFUdAg0Wcl2PIvVUvliiGZsV1Uz PXiA== X-Gm-Message-State: AJIora+PeLu1R11qujYjatQgVvtJl3f9nRzzRJprsNBtxgopcYNXBjXu 2UxcgsutI9O4Yk8KA7ql3A8= X-Google-Smtp-Source: AGRyM1tSIKhlmAce4fjeM+Fqrme9x3Y81iFgvbv4cpKUyD1VLVf+kDX7l32ibcOcMmod7cwLTyUpvQ== X-Received: by 2002:a05:6a00:23c2:b0:51b:c431:65bf with SMTP id g2-20020a056a0023c200b0051bc43165bfmr9371074pfc.20.1655460359870; Fri, 17 Jun 2022 03:05:59 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.10]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001621ce92196sm3126210plw.86.2022.06.17.03.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 03:05:59 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v4 1/8] net: skb: use SKB_NOT_DROPPED in kfree_skb_reason() as consume_skb() Date: Fri, 17 Jun 2022 18:05:07 +0800 Message-Id: <20220617100514.7230-2-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617100514.7230-1-imagedong@tencent.com> References: <20220617100514.7230-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 Inorder to simply the code, allow SKB_NOT_DROPPED to be passed to kfree_skb_reason(), suggested by Eric. Therefore, consume_skb(skb) can be replaced with kfree_skb_reason(skb, SKB_NOT_DROPPED). Not sure if it is suitable to make consume_skb() a simple call to kfree_skb_reason(skb, SKB_NOT_DROPPED), as this can increase the function call chain. Signed-off-by: Menglong Dong --- net/core/skbuff.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b661040c100e..92f01b59ae40 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -769,15 +769,22 @@ EXPORT_SYMBOL(__kfree_skb); * Drop a reference to the buffer and free it if the usage count has * hit zero. Meanwhile, pass the drop reason to 'kfree_skb' * tracepoint. + * + * When the reason is SKB_NOT_DROPPED, it means that the packet is + * freed normally, and the event 'consume_skb' will be triggered. */ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) { if (!skb_unref(skb)) return; - DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX); + DEBUG_NET_WARN_ON_ONCE(reason < 0 || reason >= SKB_DROP_REASON_MAX); + + if (reason) + trace_kfree_skb(skb, __builtin_return_address(0), reason); + else + trace_consume_skb(skb); - trace_kfree_skb(skb, __builtin_return_address(0), reason); __kfree_skb(skb); } EXPORT_SYMBOL(kfree_skb_reason); From patchwork Fri Jun 17 10:05: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: 12885419 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 62167C433EF for ; Fri, 17 Jun 2022 10:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381535AbiFQKGO (ORCPT ); Fri, 17 Jun 2022 06:06:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381527AbiFQKGF (ORCPT ); Fri, 17 Jun 2022 06:06:05 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A368169B49; Fri, 17 Jun 2022 03:06:04 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id z14so3703315pgh.0; Fri, 17 Jun 2022 03:06:04 -0700 (PDT) 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=toFzfxDcNAOLYWQB4b127Zf224IUbbcInL430hwlC3I=; b=m/K/ZcQRryr4Xlr0v5REGMR30LJwzC3O2GyiCJp08cqaWP1Y0T54zISfmUVzBjRJt3 /SKm2oKX5hi5JnVgpK+7azQzzFgG60oXsGQEUZhUnE8urkg+1yhq5B+eYXkz/9ZxhD2U FzRuGLTOMRZOpYBRXXuZKqNcFpLkZLcfEHN/gvo8iRWkXvTy6+vKye74zXOpSuDyQu9k BCsOgO+tQgAiba0xv2X/n9sl85XQKDHv+Le578OWBwZmeglM+ZoSue9RpdOwCxXv6VWF lRLopjiaCiPqFZCBU9fG9YLshapwxMU/2OWVOJLFhSl/QbzSkL89LNf55qFsq8n7I077 Ba8g== 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=toFzfxDcNAOLYWQB4b127Zf224IUbbcInL430hwlC3I=; b=cnTHTL/33UKnnzAjgtJ2zG7eL/veQonwyh5BQL8riI219Yt8H0SqLwX/TcORuPyZXP +/0i9eLqlV1C4rigSphGOew9HgbWx4WW/kYkwb2KAJU0aqfxwgO72hXPZ0t+ghvIrQeR ft6rpGGtNSC4g0bP0J9jVM0aEAEUVCLpMl0uD335wh5oKvmvYzX7nmx7Pdu98NXfzFIn GX6L1IEg/zLNRXkQaJPGX4kQJsj5FTpMdXD+DYXHEHHPRQRoY4+VkXg25EEcuMmCFrxm RZYXuuT9E2lhXMRmj6vBzrgN/xoiAmrjFbOBFw8vLiK1c5FBiIAVJFuRBojeN/xayBEB jQhQ== X-Gm-Message-State: AJIora+v+S6CjbFx54wOTdnKLv1En61O2etwonhIigyzi1OyCwfRUG1t WNdOs4suZA2wdQashJ4ibA4= X-Google-Smtp-Source: AGRyM1uYaxI5XhllOVt2OFUzd4dcRE3gABnJZUQV1e5tLsQ+Kf6ppgHA+qzSuAuFslUsZq+R1101sQ== X-Received: by 2002:a63:a749:0:b0:40c:57e0:86c0 with SMTP id w9-20020a63a749000000b0040c57e086c0mr1422414pgo.265.1655460364127; Fri, 17 Jun 2022 03:06:04 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.10]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001621ce92196sm3126210plw.86.2022.06.17.03.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 03:06:03 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v4 2/8] net: skb: introduce __skb_queue_purge_reason() Date: Fri, 17 Jun 2022 18:05:08 +0800 Message-Id: <20220617100514.7230-3-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617100514.7230-1-imagedong@tencent.com> References: <20220617100514.7230-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 Introduce __skb_queue_purge_reason() to empty a skb list with drop reason and make __skb_queue_purge() an inline call to it. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 82edf0359ab3..8d5445c3d3e7 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3020,18 +3020,24 @@ static inline int skb_orphan_frags_rx(struct sk_buff *skb, gfp_t gfp_mask) } /** - * __skb_queue_purge - empty a list + * __skb_queue_purge_reason - empty a list with specific drop reason * @list: list to empty + * @reason: drop reason * * Delete all buffers on an &sk_buff list. Each buffer is removed from * the list and one reference dropped. This function does not take the * list lock and the caller must hold the relevant locks to use it. */ -static inline void __skb_queue_purge(struct sk_buff_head *list) +static inline void __skb_queue_purge_reason(struct sk_buff_head *list, + enum skb_drop_reason reason) { struct sk_buff *skb; while ((skb = __skb_dequeue(list)) != NULL) - kfree_skb(skb); + kfree_skb_reason(skb, reason); +} +static inline void __skb_queue_purge(struct sk_buff_head *list) +{ + __skb_queue_purge_reason(list, SKB_DROP_REASON_NOT_SPECIFIED); } void skb_queue_purge(struct sk_buff_head *list); From patchwork Fri Jun 17 10:05: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: 12885421 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 188F0C433EF for ; Fri, 17 Jun 2022 10:06:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381551AbiFQKGS (ORCPT ); Fri, 17 Jun 2022 06:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381548AbiFQKGM (ORCPT ); Fri, 17 Jun 2022 06:06:12 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E73EC69CDA; Fri, 17 Jun 2022 03:06:08 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id d129so3658191pgc.9; Fri, 17 Jun 2022 03:06:08 -0700 (PDT) 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=GmjrKEQYPgZPTRJ4jJxsOeeTsxk0UvR5BruchnIbbJc=; b=Enz4V2596oes7IbJYm70KLIeo5JzCNIU54ba9Nm1Z4dJzp+wClwJBdffn+wj9gRuCm nC2tpQEcignXLDOXxgR3t+ohF7jTjzy4KQROJ3V3owzYe8SE4i46+w9SGubMow5mqDJ3 ntLrJY+Bz6FzRGt8RTMJJvJ0YOZ2aKhYXkGscIjYQ+kRfEB0wjEqAvDrxfyuO6e2yBVb zvHcYBxsvkpVnQXJqVzI1fseh4CR0JlvzzNLcxYbbRHcGYPwSebvbZ30DPxnK3516iQG mB1JXJhXDDB+i7lnqTGh5gUUIjpHCiSdZKWrB0ziMmhwu1zqZ6FGzVQpGG/ch9FNO11A NM+g== 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=GmjrKEQYPgZPTRJ4jJxsOeeTsxk0UvR5BruchnIbbJc=; b=NEBhVY//0xLLTm1O6MLq+ljveSn0bx0X7goNGmZOVKZve+G1LnoeDk7RiOuR2TerW1 sMlTbPn8ARETrjm63+uEYY9/BhN3E4Ka258ZM4OQwLos4w9w3swDEyObTu9RyjRwh+Hn 65W1EsZBqZXcb9V4CWAuhjNqeWfSvnApqexnjfgaYWnTa8YmXc4Yq6kXymfZMUepWtiq SUH0sbbAj32xKt4BN1sWyRiZhZCzmPycFzv38eFlazwkxShtoMKk/MQnrqZL5WisnYks kaN9xt4zk6Es4uz+LTNzwNDq927bgLvjaMqku679Gj4OPwkFnzs/ZrfoZvSnhYZlXP9B GbNw== X-Gm-Message-State: AJIora8Wdll8pzGHQbtqrvBiTNnNcTQRvIXRRnq5sx7dn7T0m+LMe+ZE 6D7XlHTTs2XEMBngfpNJP/A= X-Google-Smtp-Source: AGRyM1slAtqEO/HbfBYWwj2l3NgjEhIZniAjvVXkYVrnISCJ1/u+NqE5wWeluDl1GyZxAxNz9hVI1A== X-Received: by 2002:a05:6a00:9a1:b0:51b:c452:34a9 with SMTP id u33-20020a056a0009a100b0051bc45234a9mr9332454pfg.34.1655460368357; Fri, 17 Jun 2022 03:06:08 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.10]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001621ce92196sm3126210plw.86.2022.06.17.03.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 03:06:07 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v4 3/8] net: sock: introduce sk_stream_kill_queues_reason() Date: Fri, 17 Jun 2022 18:05:09 +0800 Message-Id: <20220617100514.7230-4-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617100514.7230-1-imagedong@tencent.com> References: <20220617100514.7230-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 Introduce the function sk_stream_kill_queues_reason() and make the origin sk_stream_kill_queues() an inline call to it. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/net/sock.h | 8 +++++++- net/core/stream.c | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 657873e2d90f..208c87807f23 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1139,12 +1139,18 @@ int sk_stream_wait_connect(struct sock *sk, long *timeo_p); int sk_stream_wait_memory(struct sock *sk, long *timeo_p); void sk_stream_wait_close(struct sock *sk, long timeo_p); int sk_stream_error(struct sock *sk, int flags, int err); -void sk_stream_kill_queues(struct sock *sk); +void sk_stream_kill_queues_reason(struct sock *sk, + enum skb_drop_reason reason); void sk_set_memalloc(struct sock *sk); void sk_clear_memalloc(struct sock *sk); void __sk_flush_backlog(struct sock *sk); +static inline void sk_stream_kill_queues(struct sock *sk) +{ + sk_stream_kill_queues_reason(sk, SKB_DROP_REASON_NOT_SPECIFIED); +} + static inline bool sk_flush_backlog(struct sock *sk) { if (unlikely(READ_ONCE(sk->sk_backlog.tail))) { diff --git a/net/core/stream.c b/net/core/stream.c index 06b36c730ce8..a562b23a1a6e 100644 --- a/net/core/stream.c +++ b/net/core/stream.c @@ -190,10 +190,11 @@ int sk_stream_error(struct sock *sk, int flags, int err) } EXPORT_SYMBOL(sk_stream_error); -void sk_stream_kill_queues(struct sock *sk) +void sk_stream_kill_queues_reason(struct sock *sk, + enum skb_drop_reason reason) { /* First the read buffer. */ - __skb_queue_purge(&sk->sk_receive_queue); + __skb_queue_purge_reason(&sk->sk_receive_queue, reason); /* Next, the write queue. */ WARN_ON(!skb_queue_empty(&sk->sk_write_queue)); @@ -209,4 +210,4 @@ void sk_stream_kill_queues(struct sock *sk) * have gone away, only the net layer knows can touch it. */ } -EXPORT_SYMBOL(sk_stream_kill_queues); +EXPORT_SYMBOL(sk_stream_kill_queues_reason); From patchwork Fri Jun 17 10:05: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: 12885420 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 4CDA6C43334 for ; Fri, 17 Jun 2022 10:06:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381518AbiFQKGQ (ORCPT ); Fri, 17 Jun 2022 06:06:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381525AbiFQKGN (ORCPT ); Fri, 17 Jun 2022 06:06:13 -0400 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 19A8369B49; Fri, 17 Jun 2022 03:06:13 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x138so3757309pfc.12; Fri, 17 Jun 2022 03:06:13 -0700 (PDT) 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=nLTpWfEYARxnaBZe2tmsRz6wbhK6fZ6IiWkByiKDceA=; b=MTh/VJ/tPqf9Tn4PdIuUuCnQnJbjOY07iXIBuJxeLqPfIaaxEh6MwuhScJYveVC7uV cIOLCVe59Y+XxUsWlvf7slHWxaODld9L4nZWZY2BnM3RPOZsHSmXMa+tJP8ZTCQdiAMt bl5qG8AuyRIpuO24OuNHvFS/KjtRziOh17bEpyTRddNV2Z2xAtW7uacdicJZapDhkDgg nacnAKz12TzUTzkvp3BDfI91N1LNwn5ABKLSV9jZ0SCXCMKZRiTAkEsFXS1SRIH3RYAb 3I0uK7GAyHQQh1RyLO6/EUFb85Ugy1OtYw2obxQDE9FQGulaJ9G88lonyC690YyTmozu aiPA== 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=nLTpWfEYARxnaBZe2tmsRz6wbhK6fZ6IiWkByiKDceA=; b=1iid+DgEvVxwnSM6r1gglBpOcgjIFHvmJWvR75L+8oTn5HBLaw6XIWjMpTPwzdFfD+ 4v4DBluOQSIa/kZvPKQRo/2n8hWafirXkMLMiZqs6nG0HQ7eYQwtLQv7VjBJGAPc1zGa 3CUmWBtiFY7kedD6CyP8IXeUHtipVE6ai39gINbHs1nllXwYwbUIle1+b15Sbq498pow Z/OPOT/y6EIWhXCbeN5Je/rXCLtxM022xzQvD8wXi4gB9ZJYwqX1xyN+ma46SMy9H/T4 gnDON5Wk8IfY2IxiujciavWh6Qrwdb1UTOAP0i61uozHN6Bfcr9HtHupefbutTdVJ8j6 3BHg== X-Gm-Message-State: AJIora+DVF1BZqUcoXuISFykPO2LnCEmLwkU8tGYySeiEBjJdpJEz1qE mA/yJA0oChH06eNs7ifeLUw= X-Google-Smtp-Source: AGRyM1svebNa295jU6OfIPgr5/df3AH5N3J7cq6DaBlh3kkmtgQRigFEocIov36fxPtUPtGMsUmcGA== X-Received: by 2002:a63:dd56:0:b0:405:34ac:9bc9 with SMTP id g22-20020a63dd56000000b0040534ac9bc9mr8489797pgj.324.1655460372657; Fri, 17 Jun 2022 03:06:12 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.10]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001621ce92196sm3126210plw.86.2022.06.17.03.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 03:06:12 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v4 4/8] net: inet: add skb drop reason to inet_csk_destroy_sock() Date: Fri, 17 Jun 2022 18:05:10 +0800 Message-Id: <20220617100514.7230-5-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617100514.7230-1-imagedong@tencent.com> References: <20220617100514.7230-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 skb dropping in inet_csk_destroy_sock() seems to be a common case. Add the new drop reason 'SKB_DROP_REASON_SOCKET_DESTROIED' and apply it to inet_csk_destroy_sock() to stop confusing users with 'NOT_SPECIFIED'. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/net/dropreason.h | 5 +++++ net/ipv4/inet_connection_sock.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index fae9b40e54fa..3c6f1e299c35 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -231,6 +231,11 @@ enum skb_drop_reason { * MTU) */ SKB_DROP_REASON_PKT_TOO_BIG, + /** + * @SKB_DROP_REASON_SOCKET_DESTROYED: socket is destroyed and the + * skb in its receive or send queue are all dropped + */ + SKB_DROP_REASON_SOCKET_DESTROYED, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index c0b7e6c21360..1812060f24cb 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1129,7 +1129,7 @@ void inet_csk_destroy_sock(struct sock *sk) sk->sk_prot->destroy(sk); - sk_stream_kill_queues(sk); + sk_stream_kill_queues_reason(sk, SKB_DROP_REASON_SOCKET_DESTROYED); xfrm_sk_free_policy(sk); From patchwork Fri Jun 17 10:05: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: 12885422 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 DCC8BC43334 for ; Fri, 17 Jun 2022 10:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381549AbiFQKGf (ORCPT ); Fri, 17 Jun 2022 06:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381568AbiFQKG3 (ORCPT ); Fri, 17 Jun 2022 06:06:29 -0400 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 23F5069B49; Fri, 17 Jun 2022 03:06:18 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id y6so3750599pfr.13; Fri, 17 Jun 2022 03:06:17 -0700 (PDT) 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=bWwL0xApFdW9J/7uAC+LHaUOfa9kdtXxTtubM/dGCJc=; b=qi6tIbhVzacrdhQ/G/+Z0vNCd8nGylfKWbEvipScXbrkSUsHpKs7wOvC7JqBsXSclW 0vaby8AEz3l+5zRg6QzC/vzlfUF04rE9Ym7DekFST7lZLwL2tsdYqSsbscVEJGPF6wSU jTh0hW67crLHb6nQ47mFaQBT4oAu0zLj+YA6KGxP6/uauzOh6fiJqmXCbVv65xRoNn+E QHzKmwNHGWLKV879xPeqmQbMLz7IHn06qeBySpDdmmpyvQhmZZV+GHSuHh9PKFvCPryb AmYzI9SUhESbHOoHTCrFM9h9r525JKNq+yJTD6p8Ly/ECIkYwFBnCZnEd45AVtbifcaH zY/g== 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=bWwL0xApFdW9J/7uAC+LHaUOfa9kdtXxTtubM/dGCJc=; b=emlvyIMX2TNyZQ2Sr3imxq7ygulWhHx12fch5UuBKjLwoZjiltT+bL7aUcurTC2tDG e2mE0kDex5fy3TiZtW6gK7j7yhBboq00wkeOKMAm2obX8fGDcR79G/5+y/ZJEuwUXEkL MXsFJNu15vmgsCLowqfKRNn7dNHgOy3OBwQs9+tCfxFwuH5GgMtZcCgogoLsCEwXB4F6 fm8zDTEnIaqO2aCxaHJP4T3s4IlzQR7uZMDq+DOvDnnGtGBdDElCSmSg9hk3VRAoUnQ+ 3aeoBdcccazE0scDJQ2lx3q/GoYBFYxna0+Dm+W3su1MzmdDf4bBDMsG5ZINe96ugQng M87w== X-Gm-Message-State: AJIora8ar2mL6SRmJlvB7hsAILmCbe9R8WlmQVlUPMjy3GuYgUktMWB6 xNudwVozb4vS7P8rVVe9gSc= X-Google-Smtp-Source: AGRyM1vPZxaAun2vTDvGKVE09SNfRQIfFp45aS52G15Af0Ue98ofYzWbJ6Z0ndQzMcyrVbEVHh4w8g== X-Received: by 2002:a63:e344:0:b0:3fe:7f8:c644 with SMTP id o4-20020a63e344000000b003fe07f8c644mr8247525pgj.382.1655460377150; Fri, 17 Jun 2022 03:06:17 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.10]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001621ce92196sm3126210plw.86.2022.06.17.03.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 03:06:16 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng , kernel test robot Subject: [PATCH net-next v4 5/8] net: tcp: add skb drop reasons to tcp connect requesting Date: Fri, 17 Jun 2022 18:05:11 +0800 Message-Id: <20220617100514.7230-6-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617100514.7230-1-imagedong@tencent.com> References: <20220617100514.7230-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 In order to get skb drop reasons during tcp connect requesting code path, we have to pass the pointer of the 'reason' as a new function argument of conn_request() in 'struct inet_connection_sock_af_ops'. As the return value of conn_request() can be positive or negative or 0, it's not flexible to make it return drop reasons. As the return value of tcp_conn_request() is 0, so we can treat it as bool and make it return the skb drop reasons. The new drop reasons 'LISTENOVERFLOWS' and 'TCP_REQQFULLDROP' are added, which are used for 'accept queue' and 'request queue' full. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong Reported-by: kernel test robot --- v2: - fix compile error reported by kernel test rebot --- include/net/dropreason.h | 10 ++++++++++ include/net/inet_connection_sock.h | 3 ++- include/net/tcp.h | 9 +++++---- net/dccp/dccp.h | 3 ++- net/dccp/input.c | 3 ++- net/dccp/ipv4.c | 3 ++- net/dccp/ipv6.c | 5 +++-- net/ipv4/tcp_input.c | 22 ++++++++++++++-------- net/ipv4/tcp_ipv4.c | 9 ++++++--- net/ipv6/tcp_ipv6.c | 12 ++++++++---- net/mptcp/subflow.c | 8 +++++--- 11 files changed, 59 insertions(+), 28 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index 3c6f1e299c35..74512e60ab12 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -236,6 +236,16 @@ enum skb_drop_reason { * skb in its receive or send queue are all dropped */ SKB_DROP_REASON_SOCKET_DESTROYED, + /** + * @SKB_DROP_REASON_LISTENOVERFLOWS: accept queue of the listen + * socket is full, corresponding to LINUX_MIB_LISTENOVERFLOWS + */ + SKB_DROP_REASON_LISTENOVERFLOWS, + /** + * @SKB_DROP_REASON_TCP_REQQFULLDROP: request queue of the listen + * socket is full, corresponding to LINUX_MIB_TCPREQQFULLDROP + */ + SKB_DROP_REASON_TCP_REQQFULLDROP, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h index 077cd730ce2f..7717c59ab3d7 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -37,7 +37,8 @@ struct inet_connection_sock_af_ops { void (*send_check)(struct sock *sk, struct sk_buff *skb); int (*rebuild_header)(struct sock *sk); void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb); - int (*conn_request)(struct sock *sk, struct sk_buff *skb); + int (*conn_request)(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason); struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb, struct request_sock *req, struct dst_entry *dst, diff --git a/include/net/tcp.h b/include/net/tcp.h index 1e99f5c61f84..16da150150c3 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -443,7 +443,8 @@ void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb); void tcp_v4_mtu_reduced(struct sock *sk); void tcp_req_err(struct sock *sk, u32 seq, bool abort); void tcp_ld_RTO_revert(struct sock *sk, u32 seq); -int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb); +int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason); struct sock *tcp_create_openreq_child(const struct sock *sk, struct request_sock *req, struct sk_buff *skb); @@ -2034,9 +2035,9 @@ void tcp4_proc_exit(void); #endif int tcp_rtx_synack(const struct sock *sk, struct request_sock *req); -int tcp_conn_request(struct request_sock_ops *rsk_ops, - const struct tcp_request_sock_ops *af_ops, - struct sock *sk, struct sk_buff *skb); +enum skb_drop_reason tcp_conn_request(struct request_sock_ops *rsk_ops, + const struct tcp_request_sock_ops *af_ops, + struct sock *sk, struct sk_buff *skb); /* TCP af-specific functions */ struct tcp_sock_af_ops { diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h index 7dfc00c9fb32..8c1241ae8449 100644 --- a/net/dccp/dccp.h +++ b/net/dccp/dccp.h @@ -255,7 +255,8 @@ void dccp_done(struct sock *sk); int dccp_reqsk_init(struct request_sock *rq, struct dccp_sock const *dp, struct sk_buff const *skb); -int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb); +int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason); struct sock *dccp_create_openreq_child(const struct sock *sk, const struct request_sock *req, diff --git a/net/dccp/input.c b/net/dccp/input.c index 2cbb757a894f..e12baa56ca59 100644 --- a/net/dccp/input.c +++ b/net/dccp/input.c @@ -576,6 +576,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb, const int old_state = sk->sk_state; bool acceptable; int queued = 0; + SKB_DR(reason); /* * Step 3: Process LISTEN state @@ -606,7 +607,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb, */ rcu_read_lock(); local_bh_disable(); - acceptable = inet_csk(sk)->icsk_af_ops->conn_request(sk, skb) >= 0; + acceptable = inet_csk(sk)->icsk_af_ops->conn_request(sk, skb, &reason) >= 0; local_bh_enable(); rcu_read_unlock(); if (!acceptable) diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c index da6e3b20cd75..b0e8fcabf93b 100644 --- a/net/dccp/ipv4.c +++ b/net/dccp/ipv4.c @@ -581,7 +581,8 @@ static struct request_sock_ops dccp_request_sock_ops __read_mostly = { .syn_ack_timeout = dccp_syn_ack_timeout, }; -int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb) +int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { struct inet_request_sock *ireq; struct request_sock *req; diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c index fd44638ec16b..f01d6a05c7bf 100644 --- a/net/dccp/ipv6.c +++ b/net/dccp/ipv6.c @@ -314,7 +314,8 @@ static struct request_sock_ops dccp6_request_sock_ops = { .syn_ack_timeout = dccp_syn_ack_timeout, }; -static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb) +static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { struct request_sock *req; struct dccp_request_sock *dreq; @@ -324,7 +325,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb) struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); if (skb->protocol == htons(ETH_P_IP)) - return dccp_v4_conn_request(sk, skb); + return dccp_v4_conn_request(sk, skb, reason); if (!ipv6_unicast_destination(skb)) return 0; /* discard, don't send a reset here */ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 2e2a9ece9af2..8617e7a8f841 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6453,13 +6453,14 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) */ rcu_read_lock(); local_bh_disable(); - acceptable = icsk->icsk_af_ops->conn_request(sk, skb) >= 0; + reason = SKB_NOT_DROPPED_YET; + acceptable = icsk->icsk_af_ops->conn_request(sk, skb, &reason) >= 0; local_bh_enable(); rcu_read_unlock(); if (!acceptable) return 1; - consume_skb(skb); + kfree_skb_reason(skb, reason); return 0; } SKB_DR_SET(reason, TCP_FLAGS); @@ -6879,9 +6880,9 @@ u16 tcp_get_syncookie_mss(struct request_sock_ops *rsk_ops, } EXPORT_SYMBOL_GPL(tcp_get_syncookie_mss); -int tcp_conn_request(struct request_sock_ops *rsk_ops, - const struct tcp_request_sock_ops *af_ops, - struct sock *sk, struct sk_buff *skb) +enum skb_drop_reason tcp_conn_request(struct request_sock_ops *rsk_ops, + const struct tcp_request_sock_ops *af_ops, + struct sock *sk, struct sk_buff *skb) { struct tcp_fastopen_cookie foc = { .len = -1 }; __u32 isn = TCP_SKB_CB(skb)->tcp_tw_isn; @@ -6893,6 +6894,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, bool want_cookie = false; struct dst_entry *dst; struct flowi fl; + SKB_DR(reason); /* TW buckets are converted to open requests without * limitations, they conserve resources and peer is @@ -6901,12 +6903,15 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, if ((net->ipv4.sysctl_tcp_syncookies == 2 || inet_csk_reqsk_queue_is_full(sk)) && !isn) { want_cookie = tcp_syn_flood_action(sk, rsk_ops->slab_name); - if (!want_cookie) + if (!want_cookie) { + SKB_DR_SET(reason, TCP_REQQFULLDROP); goto drop; + } } if (sk_acceptq_is_full(sk)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS); + SKB_DR_SET(reason, LISTENOVERFLOWS); goto drop; } @@ -6962,6 +6967,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, */ pr_drop_req(req, ntohs(tcp_hdr(skb)->source), rsk_ops->family); + SKB_DR_SET(reason, TCP_REQQFULLDROP); goto drop_and_release; } @@ -7014,7 +7020,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, } } reqsk_put(req); - return 0; + return SKB_NOT_DROPPED_YET; drop_and_release: dst_release(dst); @@ -7022,6 +7028,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, __reqsk_free(req); drop: tcp_listendrop(sk); - return 0; + return reason; } EXPORT_SYMBOL(tcp_conn_request); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index fe8f23b95d32..e1064273062a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1458,17 +1458,20 @@ const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = { .send_synack = tcp_v4_send_synack, }; -int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb) +int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { /* Never answer to SYNs send to broadcast or multicast */ if (skb_rtable(skb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) goto drop; - return tcp_conn_request(&tcp_request_sock_ops, - &tcp_request_sock_ipv4_ops, sk, skb); + *reason = tcp_conn_request(&tcp_request_sock_ops, + &tcp_request_sock_ipv4_ops, sk, skb); + return *reason; drop: tcp_listendrop(sk); + *reason = SKB_DROP_REASON_IP_INADDRERRORS; return 0; } EXPORT_SYMBOL(tcp_v4_conn_request); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index f37dd4aa91c6..dbe356a166c5 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1148,24 +1148,28 @@ u16 tcp_v6_get_syncookie(struct sock *sk, struct ipv6hdr *iph, return mss; } -static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) +static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { if (skb->protocol == htons(ETH_P_IP)) - return tcp_v4_conn_request(sk, skb); + return tcp_v4_conn_request(sk, skb, reason); if (!ipv6_unicast_destination(skb)) goto drop; if (ipv6_addr_v4mapped(&ipv6_hdr(skb)->saddr)) { __IP6_INC_STATS(sock_net(sk), NULL, IPSTATS_MIB_INHDRERRORS); + *reason = SKB_DROP_REASON_IP_INADDRERRORS; return 0; } - return tcp_conn_request(&tcp6_request_sock_ops, - &tcp_request_sock_ipv6_ops, sk, skb); + *reason = tcp_conn_request(&tcp6_request_sock_ops, + &tcp_request_sock_ipv6_ops, sk, skb); + return *reason; drop: tcp_listendrop(sk); + *reason = SKB_DROP_REASON_IP_INADDRERRORS; return 0; /* don't send reset */ } diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 8841e8cd9ad8..5a1d05c3a1ef 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -532,7 +532,8 @@ static int subflow_v6_rebuild_header(struct sock *sk) struct request_sock_ops mptcp_subflow_request_sock_ops; static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops __ro_after_init; -static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb) +static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); @@ -556,14 +557,15 @@ static struct inet_connection_sock_af_ops subflow_v6_specific __ro_after_init; static struct inet_connection_sock_af_ops subflow_v6m_specific __ro_after_init; static struct proto tcpv6_prot_override; -static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb) +static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); pr_debug("subflow=%p", subflow); if (skb->protocol == htons(ETH_P_IP)) - return subflow_v4_conn_request(sk, skb); + return subflow_v4_conn_request(sk, skb, reason); if (!ipv6_unicast_destination(skb)) goto drop; From patchwork Fri Jun 17 10:05: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: 12885423 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 F27C5C43334 for ; Fri, 17 Jun 2022 10:06:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381615AbiFQKGw (ORCPT ); Fri, 17 Jun 2022 06:06:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381580AbiFQKGe (ORCPT ); Fri, 17 Jun 2022 06:06:34 -0400 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 C7E6669CD3; Fri, 17 Jun 2022 03:06:21 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x138so3757309pfc.12; Fri, 17 Jun 2022 03:06:21 -0700 (PDT) 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=3Gn96qHlAoOUfAbi7BjXnxvBjcQcrs/ECG334HuI7sY=; b=Ts1MZdgJkC2/9j5vyPjBafloOsTkLrk9OwOwpXSF9iyE7EveUfQS0T38F5Lu+L0mKU R+W7prqkkFVo3/o86RSdJ0n7XNjps+4kRVJVUkSZd46Z/HOEBN9Fdm/V+B9yaXg+I7rW SD/vwiGoGMzkWeeju4ZlAhkpEDzMXu6bD+H3nFnboF89ZIS0O5xMQKp/mgDil4BzUbeW NheUTBfQip2m3oukAeadxxLXiRC1qrUQIFWPLYKZb+mEt/xTwyioTM4chSk0GX8c7nfY E04+shTSIz5vlAoeCHMGT0KJYt3mYOLsz750EqYpXYi2S4OmqqI/baDUrgQ5dH+EWgRT RTRA== 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=3Gn96qHlAoOUfAbi7BjXnxvBjcQcrs/ECG334HuI7sY=; b=PyeijKUFLjanXQqUFl8vPahKmgGb1lLKz1FCnk1SC/2hOKp6EE4LWyjcBeCXl12hHd jclWi/B3FoeAPWjZca7mdj030YRFx07J6VCN+oz1LGbkSXUzFJ/Grt710HSt92wh0gPa lBSsKrv7yerXmVmJ0QbBceG3ezMlzmUgiHEv/AR4CO1eXoXu3di1C9n1zuL16SmKItxk D83FhaIGjWssiSpWGGDZq9ZmMqeijGfyNDP133E0pw2YA645P0Mb1tveEuUmRwW+bNuK TdIdkSdTMyIQlTlROb2laAnHRSPybkylki0qBJlrRHc2ACFVf5DR7CdGy62IAMIIu0G+ XKSg== X-Gm-Message-State: AJIora+37S8eqgTghXHMKaztQ/2w7QmprrUpescNqPnM7AGVM6UFnEY0 1469FFkgQ/8hZEeltSBB1wc= X-Google-Smtp-Source: AGRyM1sVX1ASEstPSF1wQrJpQQnyxI+ZfDd7zM26b85Zn9RXnY4DfUoxWfSk7r+t1i8QCbWvhMbAmQ== X-Received: by 2002:a63:2a47:0:b0:3fe:2437:5d25 with SMTP id q68-20020a632a47000000b003fe24375d25mr8616143pgq.539.1655460381469; Fri, 17 Jun 2022 03:06:21 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.10]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001621ce92196sm3126210plw.86.2022.06.17.03.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 03:06:21 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v4 6/8] net: tcp: add skb drop reasons to tcp tw code path Date: Fri, 17 Jun 2022 18:05:12 +0800 Message-Id: <20220617100514.7230-7-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617100514.7230-1-imagedong@tencent.com> References: <20220617100514.7230-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 In order to get the reasons of skb drops, add a function argument of type 'enum skb_drop_reason *reason' to tcp_timewait_state_process(). In the origin code, all packets to time-wait socket are treated as dropping with kfree_skb(), which can make users confused. Therefore, we use consume_skb() for the skbs that are 'good'. We can check the value of 'reason' to decide use kfree_skb() or consume_skb(). The new reason 'TIMEWAIT' is added for the case that the skb is dropped as the socket in time-wait state. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong Reported-by: Eric Dumazet --- v2: - skb is not freed on TCP_TW_ACK and 'ret' is not initizalized, fix it (Eric Dumazet) --- include/net/dropreason.h | 6 ++++++ include/net/tcp.h | 7 ++++--- net/ipv4/tcp_ipv4.c | 8 ++++++-- net/ipv4/tcp_minisocks.c | 23 +++++++++++++++++++---- net/ipv6/tcp_ipv6.c | 7 +++++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index 74512e60ab12..90cdb7321926 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -246,6 +246,12 @@ enum skb_drop_reason { * socket is full, corresponding to LINUX_MIB_TCPREQQFULLDROP */ SKB_DROP_REASON_TCP_REQQFULLDROP, + /** + * @SKB_DROP_REASON_TIMEWAIT: socket is in time-wait state and all + * packet that received will be treated as 'drop', except a good + * 'SYN' packet + */ + SKB_DROP_REASON_TIMEWAIT, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/include/net/tcp.h b/include/net/tcp.h index 16da150150c3..1a88fabf0cce 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -379,9 +379,10 @@ enum tcp_tw_status { }; -enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, - struct sk_buff *skb, - const struct tcphdr *th); +enum tcp_tw_status +tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, + const struct tcphdr *th, + enum skb_drop_reason *reason); struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, struct request_sock *req, bool fastopen, bool *lost_race); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index e1064273062a..f2ed9763d504 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1975,6 +1975,7 @@ int tcp_v4_rcv(struct sk_buff *skb) reqsk_put(req); goto discard_it; } + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; if (tcp_checksum_complete(skb)) { reqsk_put(req); goto csum_error; @@ -2049,6 +2050,7 @@ int tcp_v4_rcv(struct sk_buff *skb) if (drop_reason) goto discard_and_relse; + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; nf_reset_ct(skb); if (tcp_filter(sk, skb)) { @@ -2104,7 +2106,6 @@ int tcp_v4_rcv(struct sk_buff *skb) } discard_it: - SKB_DR_OR(drop_reason, NOT_SPECIFIED); /* Discard frame. */ kfree_skb_reason(skb, drop_reason); return 0; @@ -2128,7 +2129,8 @@ int tcp_v4_rcv(struct sk_buff *skb) inet_twsk_put(inet_twsk(sk)); goto csum_error; } - switch (tcp_timewait_state_process(inet_twsk(sk), skb, th)) { + switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, + &drop_reason)) { case TCP_TW_SYN: { struct sock *sk2 = inet_lookup_listener(dev_net(skb->dev), &tcp_hashinfo, skb, @@ -2144,6 +2146,8 @@ int tcp_v4_rcv(struct sk_buff *skb) refcounted = false; goto process; } + /* TCP_FLAGS or NO_SOCKET? */ + SKB_DR_SET(drop_reason, TCP_FLAGS); } /* to ACK */ fallthrough; diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 6854bb1fb32b..dd640574d00f 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -83,13 +83,15 @@ tcp_timewait_check_oow_rate_limit(struct inet_timewait_sock *tw, */ enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, - const struct tcphdr *th) + const struct tcphdr *th, + enum skb_drop_reason *reason) { struct tcp_options_received tmp_opt; struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw); bool paws_reject = false; tmp_opt.saw_tstamp = 0; + *reason = SKB_DROP_REASON_NOT_SPECIFIED; if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) { tcp_parse_options(twsk_net(tw), skb, &tmp_opt, 0, NULL); @@ -113,11 +115,16 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, return tcp_timewait_check_oow_rate_limit( tw, skb, LINUX_MIB_TCPACKSKIPPEDFINWAIT2); - if (th->rst) + if (th->rst) { + SKB_DR_SET(*reason, TCP_RESET); goto kill; + } - if (th->syn && !before(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt)) + if (th->syn && !before(TCP_SKB_CB(skb)->seq, + tcptw->tw_rcv_nxt)) { + SKB_DR_SET(*reason, TCP_FLAGS); return TCP_TW_RST; + } /* Dup ACK? */ if (!th->ack || @@ -143,6 +150,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, } inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN); + + /* skb should be free normally on this case. */ + *reason = SKB_NOT_DROPPED_YET; return TCP_TW_ACK; } @@ -174,6 +184,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, * protocol bug yet. */ if (twsk_net(tw)->ipv4.sysctl_tcp_rfc1337 == 0) { + SKB_DR_SET(*reason, TCP_RESET); kill: inet_twsk_deschedule_put(tw); return TCP_TW_SUCCESS; @@ -219,8 +230,10 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, return TCP_TW_SYN; } - if (paws_reject) + if (paws_reject) { + SKB_DR_SET(*reason, TCP_RFC7323_PAWS); __NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWSESTABREJECTED); + } if (!th->rst) { /* In this case we must reset the TIMEWAIT timer. @@ -232,9 +245,11 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, if (paws_reject || th->ack) inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN); + SKB_DR_OR(*reason, TIMEWAIT); return tcp_timewait_check_oow_rate_limit( tw, skb, LINUX_MIB_TCPACKSKIPPEDTIMEWAIT); } + SKB_DR_SET(*reason, TCP_RESET); inet_twsk_put(tw); return TCP_TW_SUCCESS; } diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index dbe356a166c5..9aeb0a7b7c12 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1644,6 +1644,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) reqsk_put(req); goto discard_it; } + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; if (tcp_checksum_complete(skb)) { reqsk_put(req); goto csum_error; @@ -1715,6 +1716,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) if (drop_reason) goto discard_and_relse; + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; if (tcp_filter(sk, skb)) { drop_reason = SKB_DROP_REASON_SOCKET_FILTER; goto discard_and_relse; @@ -1766,7 +1768,6 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) } discard_it: - SKB_DR_OR(drop_reason, NOT_SPECIFIED); kfree_skb_reason(skb, drop_reason); return 0; @@ -1790,7 +1791,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) goto csum_error; } - switch (tcp_timewait_state_process(inet_twsk(sk), skb, th)) { + switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, + &drop_reason)) { case TCP_TW_SYN: { struct sock *sk2; @@ -1810,6 +1812,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) refcounted = false; goto process; } + SKB_DR_SET(drop_reason, TCP_FLAGS); } /* to ACK */ fallthrough; From patchwork Fri Jun 17 10:05:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12885424 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 811C2C433EF for ; Fri, 17 Jun 2022 10:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381553AbiFQKGz (ORCPT ); Fri, 17 Jun 2022 06:06:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381561AbiFQKGf (ORCPT ); Fri, 17 Jun 2022 06:06:35 -0400 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 3BE5269CF2; Fri, 17 Jun 2022 03:06:26 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id s37so3755805pfg.11; Fri, 17 Jun 2022 03:06:26 -0700 (PDT) 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=znh2PNtoibcoEX3lHKZShGCnVxaqXpJ6Xkl88GOSiI4=; b=VtZkGBr43CPRYhfMIU8Atai8DQstwXo8C4MuY8b+KkLTvx8xQ0rKyKMFHD0HiS8U9L u6xUxRRZN43yVcxkEklaQg0t2fCXqvNlqczMSL7HmSORSUkQufLN9074Gkm9UbXQEfzj H9mvO5s/4gn7iSfaoAvhTTFCt0OJKi8hqmMiAUudf6/PtQrLbDtx0m4uKwyUoq7Nkpps iTPHKju/xd1B3DeVFNgXVFA7A5xw7q/ZlsEXQiA7ZVj7BhyaBY2wMi2BbrySOjt3XKVd aQh7BhKhu4tmGI/ZoHX+m8uSswJ+37sYXCD14GU8YMeYZXC6uZfd9VUEZeZwsp0VLCm1 KSkg== 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=znh2PNtoibcoEX3lHKZShGCnVxaqXpJ6Xkl88GOSiI4=; b=tKfQ8hLuDpU5CKGhsae0SO3lHsu63uH3KQM+PlivroM5yaTmDrCxFUl7OYEdfaSd3s LmyIn+iHdhjR23lJcNr5YMi2oEPxUrw+B57b8EuXQuDzk8WNfZGsP3bk4SjaMjla/gLP zkfrk581QOa7HQIlx1TBzNUpCbCaz6xNB+N92RrPJI4/GABaMkKVd7Umc0PZFiOY7KNl vFTQ5KkEtDNzw0nPT3f/tjlPQmfUxNo8h8qwZKltYZ/L0adO4rsAoa3UkuilOA3NWCW8 TR9l0D+LAx7WKc+UZnOuaCK4ocKquVcrsmtbVGm4HKx7VRxKPJ5/y3jcew6GbutcYnfL D0lQ== X-Gm-Message-State: AJIora+Tjmf7aJ6Sw+ckLNlerEHJvnXEX+hO4kKJAdRs3nbX0ihO5Cmi nqiRrTBJHbVJY/b7c982Ggk= X-Google-Smtp-Source: AGRyM1uxxtd19Tq/acnbsqEqlXzwX17JOw2no1Ng67/PSXMSIt4TN1bbN3ZsdK9jzga/9wH6NwO24Q== X-Received: by 2002:a63:f415:0:b0:408:808b:238f with SMTP id g21-20020a63f415000000b00408808b238fmr8237583pgi.469.1655460385742; Fri, 17 Jun 2022 03:06:25 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.10]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001621ce92196sm3126210plw.86.2022.06.17.03.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 03:06:25 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v4 7/8] net: tcp: add skb drop reasons to route_req() Date: Fri, 17 Jun 2022 18:05:13 +0800 Message-Id: <20220617100514.7230-8-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617100514.7230-1-imagedong@tencent.com> References: <20220617100514.7230-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 skb drop reasons to the route_req() in struct tcp_request_sock_ops. Following functions are involved: tcp_v4_route_req() tcp_v6_route_req() subflow_v4_route_req() subflow_v6_route_req() And the new reason SKB_DROP_REASON_LSM is added, which is used when skb is dropped by LSM. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/net/dropreason.h | 2 ++ include/net/tcp.h | 3 ++- net/ipv4/tcp_input.c | 2 +- net/ipv4/tcp_ipv4.c | 14 +++++++++++--- net/ipv6/tcp_ipv6.c | 14 +++++++++++--- net/mptcp/subflow.c | 10 ++++++---- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index 90cdb7321926..d3143598125e 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -252,6 +252,8 @@ enum skb_drop_reason { * 'SYN' packet */ SKB_DROP_REASON_TIMEWAIT, + /** @SKB_DROP_REASON_LSM: dropped by LSM */ + SKB_DROP_REASON_LSM, /** * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be * used as a real 'reason' diff --git a/include/net/tcp.h b/include/net/tcp.h index 1a88fabf0cce..d8895076d448 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2073,7 +2073,8 @@ struct tcp_request_sock_ops { struct dst_entry *(*route_req)(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req); + struct request_sock *req, + enum skb_drop_reason *reason); u32 (*init_seq)(const struct sk_buff *skb); u32 (*init_ts_off)(const struct net *net, const struct sk_buff *skb); int (*send_synack)(const struct sock *sk, struct dst_entry *dst, diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 8617e7a8f841..ed55616bc2a0 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6945,7 +6945,7 @@ enum skb_drop_reason tcp_conn_request(struct request_sock_ops *rsk_ops, /* Note: tcp_v6_init_req() might override ir_iif for link locals */ inet_rsk(req)->ir_iif = inet_request_bound_dev_if(sk, skb); - dst = af_ops->route_req(sk, skb, &fl, req); + dst = af_ops->route_req(sk, skb, &fl, req, &reason); if (!dst) goto drop_and_free; diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index f2ed9763d504..8accb49f3808 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1423,14 +1423,22 @@ static void tcp_v4_init_req(struct request_sock *req, static struct dst_entry *tcp_v4_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req) + struct request_sock *req, + enum skb_drop_reason *reason) { + struct dst_entry *dst; + tcp_v4_init_req(req, sk, skb); - if (security_inet_conn_request(sk, skb, req)) + if (security_inet_conn_request(sk, skb, req)) { + SKB_DR_SET(*reason, LSM); return NULL; + } - return inet_csk_route_req(sk, &fl->u.ip4, req); + dst = inet_csk_route_req(sk, &fl->u.ip4, req); + if (!dst) + SKB_DR_SET(*reason, IP_OUTNOROUTES); + return dst; } struct request_sock_ops tcp_request_sock_ops __read_mostly = { diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 9aeb0a7b7c12..fbe37f4a73ee 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -802,14 +802,22 @@ static void tcp_v6_init_req(struct request_sock *req, static struct dst_entry *tcp_v6_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req) + struct request_sock *req, + enum skb_drop_reason *reason) { + struct dst_entry *dst; + tcp_v6_init_req(req, sk, skb); - if (security_inet_conn_request(sk, skb, req)) + if (security_inet_conn_request(sk, skb, req)) { + SKB_DR_SET(*reason, LSM); return NULL; + } - return inet6_csk_route_req(sk, &fl->u.ip6, req, IPPROTO_TCP); + dst = inet6_csk_route_req(sk, &fl->u.ip6, req, IPPROTO_TCP); + if (!dst) + SKB_DR_SET(*reason, IP_OUTNOROUTES); + return dst; } struct request_sock_ops tcp6_request_sock_ops __read_mostly = { diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 5a1d05c3a1ef..654cc602ff2c 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -285,7 +285,8 @@ EXPORT_SYMBOL_GPL(mptcp_subflow_init_cookie_req); static struct dst_entry *subflow_v4_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req) + struct request_sock *req, + enum skb_drop_reason *reason) { struct dst_entry *dst; int err; @@ -293,7 +294,7 @@ static struct dst_entry *subflow_v4_route_req(const struct sock *sk, tcp_rsk(req)->is_mptcp = 1; subflow_init_req(req, sk); - dst = tcp_request_sock_ipv4_ops.route_req(sk, skb, fl, req); + dst = tcp_request_sock_ipv4_ops.route_req(sk, skb, fl, req, reason); if (!dst) return NULL; @@ -311,7 +312,8 @@ static struct dst_entry *subflow_v4_route_req(const struct sock *sk, static struct dst_entry *subflow_v6_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req) + struct request_sock *req, + enum skb_drop_reason *reason) { struct dst_entry *dst; int err; @@ -319,7 +321,7 @@ static struct dst_entry *subflow_v6_route_req(const struct sock *sk, tcp_rsk(req)->is_mptcp = 1; subflow_init_req(req, sk); - dst = tcp_request_sock_ipv6_ops.route_req(sk, skb, fl, req); + dst = tcp_request_sock_ipv6_ops.route_req(sk, skb, fl, req, reason); if (!dst) return NULL; From patchwork Fri Jun 17 10:05:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12885425 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 88B31CCA479 for ; Fri, 17 Jun 2022 10:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381580AbiFQKG5 (ORCPT ); Fri, 17 Jun 2022 06:06:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381589AbiFQKGf (ORCPT ); Fri, 17 Jun 2022 06:06:35 -0400 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 7413F6A00E; Fri, 17 Jun 2022 03:06:30 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id e24so3612763pjt.0; Fri, 17 Jun 2022 03:06:30 -0700 (PDT) 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=ZSd1yz1StmlsSTd9BfuHe3OLRwFqoxjg2aovIcJmQPk=; b=nr4qFfoz7Jj0rGWJj6nHPKLrPzuliNtD+weNnfNBRV5HuxSaAmJdyixsurGap6UEES VwvyoHsAYr390nW/baAi13ZDJegHt+gbSEGdSrWQGy6TJuOTKVrOq7I2OaeAOvpn55ib d3sMP4wVs/Y9hptdCn7K/0RYSfNsXh1DheJTMujQxzJC8XzlB8+xYpbQJMiprlAYR2ys dacTUOF89daOHuVhPGvy1TDa6gyO/4vKNrJ3opAJkOc36V//1RWUbSZNFQAFfQlVKt9k x+IyaKgDhgIVUtLoEmZYvbbmhXA1Or7GyhDozsaje+Y9thRDSjvMFS6nxUdDGXScuBfe pb+A== 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=ZSd1yz1StmlsSTd9BfuHe3OLRwFqoxjg2aovIcJmQPk=; b=PjVBjyM9wa8jIkBJqeKe3g3hJVYns+c0td2iBZ4pK8Ye0/ud5B+u+er4OBf5qibadX AUxUNNFlShLXc48Ms0RB5+QD6FW2J6841GAiAotGlCj3u9V3nYNPM+ca7Op392LpAv/1 OpTxp2L9GzqBy0CPzosN1UjA8icalEzgHbP1SjUOTHt80odV0XR93g5QVoipAAwb8t1s minKeboh1C7fospWr2GdIh1hxro+xV4rY1wMslLSi77k95l8Lz293gdCjxH9GJouyrDJ MQDt9X2aaqJQfj7DvzxDrp8+Bjkkb5QhAqHNKN5YvuHfKJJZ/rEqrRrX3iY4zDY9Hjpu L4EQ== X-Gm-Message-State: AJIora9SXpxO+7gQibBOGHkms0E2BTym3ielKCq+b8fIDUoUmgoTG9ak Yw580xquOzHaWEQORlz1HXk= X-Google-Smtp-Source: AGRyM1uc6PJPwDol3jfNMupP56Qua4mdaNKPTbLIj+TOVvUclQrHqFKvzd9/8ex69tcvWEypuPj47Q== X-Received: by 2002:a17:90a:4402:b0:1ea:9d75:9941 with SMTP id s2-20020a17090a440200b001ea9d759941mr20757861pjg.187.1655460389902; Fri, 17 Jun 2022 03:06:29 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.10]) by smtp.gmail.com with ESMTPSA id h10-20020a170902f7ca00b001621ce92196sm3126210plw.86.2022.06.17.03.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 03:06:29 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v4 8/8] net: tcp: use LINUX_MIB_TCPABORTONLINGER in tcp_rcv_state_process() Date: Fri, 17 Jun 2022 18:05:14 +0800 Message-Id: <20220617100514.7230-9-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220617100514.7230-1-imagedong@tencent.com> References: <20220617100514.7230-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 The statistics for 'tp->linger2 < 0' in tcp_rcv_state_process() seems more accurate to be LINUX_MIB_TCPABORTONLINGER. Signed-off-by: Menglong Dong --- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index ed55616bc2a0..cf4bc4b9be0c 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6580,7 +6580,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (tp->linger2 < 0) { tcp_done(sk); - NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONLINGER); return 1; } if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq &&