From patchwork Thu Feb 3 15:37:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12734287 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 20B6AC433F5 for ; Thu, 3 Feb 2022 15:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351305AbiBCPit (ORCPT ); Thu, 3 Feb 2022 10:38:49 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:44082 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349835AbiBCPio (ORCPT ); Thu, 3 Feb 2022 10:38:44 -0500 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 213FBd4o010676; Thu, 3 Feb 2022 15:37:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=mz8Spix1ShjoE1Nfrfza/PYM4UjGTg6N/DcL7p+oX/o=; b=V35keS3o5ffrQVbzuuuEDn6a5/Vr1v48w97X6U3ow8oFUmyu4FDQEZBPulPMT/XzzEgA ZFDFiDihP0ET6YqZ2xhsIFhB8QFWBzaaliEQJglsQGCvHQRvoP7O2B/ts2BF7uJsZcpZ AgkcsYbxDjmMLjcpWSH8bXN6YRlP/kqQcQRmYq/aAYdQt70zWTWxfzBAFYKZDOMTWtUs Uiz1knCpZL+HPp4sOTU9zXJEibklgtxNnsWIBiEU3T1mevkAv4WylprWS2oM29vMWwk9 6QtdlEvYxATcyewPFpTxbm7+KbI/m2R+y5px49YJGfkzznMt6wnP0MQIFGzUsYbvGK7G /Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e0hfs82ce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Feb 2022 15:37:46 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 213FVILx184560; Thu, 3 Feb 2022 15:37:45 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2045.outbound.protection.outlook.com [104.47.57.45]) by aserp3020.oracle.com with ESMTP id 3dvwdaj9de-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Feb 2022 15:37:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cp5oXnj4ZB34dVBZQH19/1L5984cfY/RAdmtHoaGNNEQ4XU61AHnMaC6vxLmJdVEdqY53uRNkB+IpZsTIRLjv8d3lJbvpoV2eQMKi5xC76PPgJwSbXJ5qehCEDcWIMZJc0BxFDUUnO3nBcMLvucqhYeyhVg8h4st3T5PcebQ5NMhV8OkKj87iGUu1u31PE7axR4KdSdzOsrSJmn83kM5tbxKjZ4PxUl8a2awOLuL6PpKB2a6JZt0H8JZwCwTsiBqVBlNAVf/wpKe3vVnTN9+pwJJGQXrmXEnbM7wfxiwzNehpLL/ZOydfo0OvPrILYwiOX+u8MZw4YRl7/QU62noaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mz8Spix1ShjoE1Nfrfza/PYM4UjGTg6N/DcL7p+oX/o=; b=cq773vcdwDRb0YCNcAMvovIvVR4kfTSct53AoDmQAn4wiQmgx2KSI2sG2YUljMT7t66olzHMXRaLOm7MNJee+YSqbQXpq4haBYEe5heJSiaLdjlfntTdnkuuq1gZXDIba0gMXa9jwmyjF2nUk99aNIDp0LwryhFWX/Y9GSNtkeOEyU8kRSETAe8MkNHZegXlMJhPDPjqR4l8nzdXfSY/+Iv2PGM6LyrSotqSNmt9QBTYa37nUGt8ZVcMV5m9fte/QTCduK00WzOoOlibYIFAn0qwpy7wd1iYV31b9wZI0IDtRGD0YtG2JRDH9h38bbbVGJxT++kIY62qHCYzWbwXdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mz8Spix1ShjoE1Nfrfza/PYM4UjGTg6N/DcL7p+oX/o=; b=uKvgEgFmod5ORxnya1xQzcECPdLzrq9q5XpuxnLeUQWRgd/a0UY+UBY1tOEART9tA7r/XvTyeIUbe/c8FJGMB1NV0VmKFARXWhkdBO2i5tyfi8cGyVDfGvp4BSHo6RghY1ZJyt3FG8JU3AqDR66k8838rjX/Bguucfmxco/3IOo= Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by BN7PR10MB2436.namprd10.prod.outlook.com (2603:10b6:406:c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Thu, 3 Feb 2022 15:37:43 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::60be:11d2:239:dcef]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::60be:11d2:239:dcef%7]) with mapi id 15.20.4930.021; Thu, 3 Feb 2022 15:37:43 +0000 From: Dongli Zhang To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, imagedong@tencent.com, joao.m.martins@oracle.com, joe.jin@oracle.com Subject: [PATCH RFC 1/4] net: skb: use line number to trace dropped skb Date: Thu, 3 Feb 2022 07:37:28 -0800 Message-Id: <20220203153731.8992-2-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220203153731.8992-1-dongli.zhang@oracle.com> References: <20220203153731.8992-1-dongli.zhang@oracle.com> X-ClientProxiedBy: BY5PR03CA0017.namprd03.prod.outlook.com (2603:10b6:a03:1e0::27) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 631ef7fe-cdf6-42de-5606-08d9e72b1e62 X-MS-TrafficTypeDiagnostic: BN7PR10MB2436:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:103; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oA4QIzcpH0OFuXr7WANHQ4aGaFyD2jJyOfz16jf/7njuv405w1sRbZdmsANLqT12bS6tPdDTxlTvbC+malH5TsQd2kLVI9T+vnz9f6rVYLoxhX49yyJ/OAFpiPakK5gOdKo0diVsXEeFaLtAYDawPwTHD1+OrH4l9qee/GAd0BA9B0pLUdJBcDjB956AwSumeP22fP0ODo8KIjiWpaGiRpB2wvr/Jt7u2cx+LFlLZ4f50PWpIfcVOC459WgisWUYt6WcIHPFGytLcdNaYAz1P+3oZpmE1RIr+WrmAqEmaXNRAsmyr9GCWHxHE6Qgkg4pNFcgDUBvgtL5X4SdofsXrs5KhYAlBJKjXw7gW2uE5fcWKlQ9LAgaX5Yo76d7CXBoG0mPwrL5bpKWFlXJyJIRTBlVj1evKVX2kZWQgVApi/LQa2ifv89s/DK7jHFr++GTVoYGUz9JR0TdHnCmM2u56z2CQw8cXdIOB9GAzQTAOUHYLBACloGtXQ9uW2Td3AcrLXbnYu/em8pKWzoFQLRmWGwGXTQiBf3inBBbrYbQGCstb5Q8+jRkQeUsJovscsmMJ8XcUYi6SWGHG57UeWhsFVQEVajk/ko6r9Q0yyl0Ym4i/MhBBQ6OvLIdVmXpMKyHGVecSb5NxmQBrT5ToBNTODACQyhY5AnK6r3/UOsZ0a1mh9/anHF667Wi+FJiynLePye3f3OJbPR2rmgkP+UYpA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(44832011)(66476007)(52116002)(6512007)(107886003)(7416002)(2906002)(8936002)(66946007)(6506007)(2616005)(66556008)(4326008)(86362001)(6666004)(508600001)(5660300002)(8676002)(186003)(26005)(6486002)(83380400001)(38100700002)(38350700002)(36756003)(316002)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lXJEIXsVDjL8uZpQC1qH8I/8jU6J+mAonCn8jv9e86+MZaEaNvD+2udCOxZyJO/IzY7DVK+VLIco1torFwX5dm8/RpgvkhWqah5JZ2GyzdgZ2ayA/z3syOipmQ/a3StBoEaq8JUgdI2Q7Z/2EbewwXpt4wdVVEnwShN/CP9HVMrhMTn6PVqer6n2A6XnjzCzTfXl06SQq7me71sVOgRSr34AaMQlb2nNwPRsr+ZPfcPDEuAfXDtWSK1I6jfKEPWgHzh0tLPICE1kmpWAOt3UMJsDwf03LnHPlHkUd7E24jOei2mUo24gprhLo+EOACl/gHvtHcSWSGSfSp4ETwWRLgM0gv6HkIZ12JONWVk3pDuBVCyT954IDeJ9PYkKaZW9bqh1GYyzmhtkWUu0WF0HyqEx7aU8R5SN431bYjO/VmXc+wWVApadZX6TtJKoy8ea5UdThkf3gtUODDIg06odY5YfVekGnAdsT1yi9/mRN+gh9t+8rfrn6bIhguE2fu3auM8Xe6QL3oJr6hwEkQv9Cy8MwShE4iQ8A0X4HQ6QjhQL7V95GGtVZ2w96WU6RztxKm0rkGF91MZSwsrv02BGAg8wRi7bwglhQYgSxvNov51VGIlzr5IE3jxg247ofJuyq8wSUgaZtNPVyUOWaeNwQpbnVN2eRV6U7FClBKmcPJauKvM6gLJCrlumMt8lAEC+izD9P14nZJcB1XHn+yJzyXp75z4bZRi13EPV+uVLYVevd7utp2W7CWeXyvWFHGy4X6r055gq6cMPcEkfpnX8MKgtoKrStUjt0qeAoA5bUx+KW1yUNQD53u41/gTUJgRS0FSy9DP5QDFZIhjfsbskGeCYWsK84+jrGJ0IG0NMraJyzRo4YCg9yLUMzTVMgH3ANroaUrHltCDOePz32LnaHMjRjlNe88YROh2dAgFR5mIVZ5Uqk+L5iL9PkVolt4V82XWRwlyL+u48CIRWJCQFkpcDiwsfEP5uR2uiIVliYk4ZKQVE9eYkyUR9JL3t2wfc3hB7QYZiJh+yAgPTBm4xsCEhd0yYYmfboAk8n65UjdVPUYnlsp1wEYO0jfXDmUieKKph3/ztD9F2rJIkO9bz1btQFkGZ0YShAmDHMAtO09bPTX80CyynAJmrdP1E2cQbADjBZlv0aiMxS5GL9Y3V1pk0bz6nGSdHvoBSLG7MpcNSlrupThzCpEGrHakJ88YlZBfnBoFLrTJfQ1t27yRNptDY3v3Km7YZKAvRt5Oec8AmHUhISrGcWCUu1iJ22g2oH7VxhDR+j+wfngq+aWLluGvCCeO3daIPUkl6GWm9+SuOa/Q6qNq76IAZezhtZ/p+gguQeVwIR63GuE801XUEjEurcMQ9jYAubatl6qrma4yAGC7gesc8WhGEyRCxMB0pEbDu/E2/umjZU9L51bd2CimGZePTyoGo/yvs50AszPcQdHazhm/ug4pZyqKfQItwtOXcJChI1lMqBM3XT2BjvV2hit/FoE/h2UrxR6q92q8axxrGudE1K57jSpzFasHQSVRSyzj8CDdjC8BXdx6PR0wIjBxCtEqpSCko6SsYGwt71PDD0hgLLrOo0ZIcrVsK3HRzUIifWvsOH8v3Vs77PZZoO4heRPD03Aeug0FC7TA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 631ef7fe-cdf6-42de-5606-08d9e72b1e62 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 15:37:43.0725 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Fq6SYid2oDZiQMbJt9MCziyHDAWvCf0LqEUcRj0u9He57Jru+bqMNcvxRjINFxUBhKS1OCQZQQD7gMo5/sbNZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2436 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10247 signatures=673430 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202030096 X-Proofpoint-ORIG-GUID: 3sM4gJ6_7VNWpQ5_R960BF45RQM_A6v8 X-Proofpoint-GUID: 3sM4gJ6_7VNWpQ5_R960BF45RQM_A6v8 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Sometimes the kernel may not directly call kfree_skb() to drop the sk_buff. Instead, it "goto drop" and call kfree_skb() at 'drop'. This make it difficult to track the reason that the sk_buff is dropped. The commit c504e5c2f964 ("net: skb: introduce kfree_skb_reason()") has introduced the kfree_skb_reason() to help track the reason. However, we may need to define many reasons for each driver/subsystem. To avoid introducing so many new reasons, this is to use line number ("__LINE__") to trace where the sk_buff is dropped. As a result, the reason will be generated automatically. Cc: Joao Martins Cc: Joe Jin Signed-off-by: Dongli Zhang --- include/linux/skbuff.h | 21 ++++----------------- include/trace/events/skb.h | 35 ++++++----------------------------- net/core/dev.c | 2 +- net/core/skbuff.c | 9 ++++----- net/ipv4/tcp_ipv4.c | 14 +++++++------- net/ipv4/udp.c | 14 +++++++------- 6 files changed, 29 insertions(+), 66 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8a636e678902..471268a4a497 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -307,21 +307,8 @@ struct sk_buff_head { struct sk_buff; -/* The reason of skb drop, which is used in kfree_skb_reason(). - * en...maybe they should be splited by group? - * - * Each item here should also be in 'TRACE_SKB_DROP_REASON', which is - * used to translate the reason to string. - */ -enum skb_drop_reason { - SKB_DROP_REASON_NOT_SPECIFIED, - SKB_DROP_REASON_NO_SOCKET, - SKB_DROP_REASON_PKT_TOO_SMALL, - SKB_DROP_REASON_TCP_CSUM, - SKB_DROP_REASON_SOCKET_FILTER, - SKB_DROP_REASON_UDP_CSUM, - SKB_DROP_REASON_MAX, -}; +#define SKB_DROP_LINE_NONE 0 +#define SKB_DROP_LINE __LINE__ /* To allow 64K frame to be packed as single skb without frag_list we * require 64K/PAGE_SIZE pages plus 1 additional page to allow for @@ -1103,7 +1090,7 @@ static inline bool skb_unref(struct sk_buff *skb) return true; } -void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason); +void kfree_skb_reason(struct sk_buff *skb, unsigned int line); /** * kfree_skb - free an sk_buff with 'NOT_SPECIFIED' reason @@ -1111,7 +1098,7 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason); */ static inline void kfree_skb(struct sk_buff *skb) { - kfree_skb_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED); + kfree_skb_reason(skb, SKB_DROP_LINE_NONE); } void skb_release_head_state(struct sk_buff *skb); diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index a8a64b97504d..45d1a1757ff1 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -9,56 +9,33 @@ #include #include -#define TRACE_SKB_DROP_REASON \ - EM(SKB_DROP_REASON_NOT_SPECIFIED, NOT_SPECIFIED) \ - EM(SKB_DROP_REASON_NO_SOCKET, NO_SOCKET) \ - EM(SKB_DROP_REASON_PKT_TOO_SMALL, PKT_TOO_SMALL) \ - EM(SKB_DROP_REASON_TCP_CSUM, TCP_CSUM) \ - EM(SKB_DROP_REASON_SOCKET_FILTER, SOCKET_FILTER) \ - EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ - EMe(SKB_DROP_REASON_MAX, MAX) - -#undef EM -#undef EMe - -#define EM(a, b) TRACE_DEFINE_ENUM(a); -#define EMe(a, b) TRACE_DEFINE_ENUM(a); - -TRACE_SKB_DROP_REASON - -#undef EM -#undef EMe -#define EM(a, b) { a, #b }, -#define EMe(a, b) { a, #b } - /* * Tracepoint for free an sk_buff: */ TRACE_EVENT(kfree_skb, TP_PROTO(struct sk_buff *skb, void *location, - enum skb_drop_reason reason), + unsigned int line), - TP_ARGS(skb, location, reason), + TP_ARGS(skb, location, line), TP_STRUCT__entry( __field(void *, skbaddr) __field(void *, location) __field(unsigned short, protocol) - __field(enum skb_drop_reason, reason) + __field(unsigned int, line) ), TP_fast_assign( __entry->skbaddr = skb; __entry->location = location; __entry->protocol = ntohs(skb->protocol); - __entry->reason = reason; + __entry->line = line; ), - TP_printk("skbaddr=%p protocol=%u location=%p reason: %s", + TP_printk("skbaddr=%p protocol=%u location=%p line: %u", __entry->skbaddr, __entry->protocol, __entry->location, - __print_symbolic(__entry->reason, - TRACE_SKB_DROP_REASON)) + __entry->line) ); TRACE_EVENT(consume_skb, diff --git a/net/core/dev.c b/net/core/dev.c index 1baab07820f6..448f390d35d3 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4900,7 +4900,7 @@ static __latent_entropy void net_tx_action(struct softirq_action *h) trace_consume_skb(skb); else trace_kfree_skb(skb, net_tx_action, - SKB_DROP_REASON_NOT_SPECIFIED); + SKB_DROP_LINE); if (skb->fclone != SKB_FCLONE_UNAVAILABLE) __kfree_skb(skb); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 0118f0afaa4f..8572c3bce264 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -761,18 +761,17 @@ EXPORT_SYMBOL(__kfree_skb); /** * kfree_skb_reason - free an sk_buff with special reason * @skb: buffer to free - * @reason: reason why this skb is dropped + * @line: the line where this skb is dropped * * 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. + * hit zero. Meanwhile, pass the drop line to 'kfree_skb' tracepoint. */ -void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) +void kfree_skb_reason(struct sk_buff *skb, unsigned int line) { if (!skb_unref(skb)) return; - trace_kfree_skb(skb, __builtin_return_address(0), reason); + trace_kfree_skb(skb, __builtin_return_address(0), line); __kfree_skb(skb); } EXPORT_SYMBOL(kfree_skb_reason); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index fec656f5a39e..f23af94d1186 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1971,10 +1971,10 @@ int tcp_v4_rcv(struct sk_buff *skb) const struct tcphdr *th; bool refcounted; struct sock *sk; - int drop_reason; + unsigned int drop_line; int ret; - drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; + drop_line = SKB_DROP_LINE_NONE; if (skb->pkt_type != PACKET_HOST) goto discard_it; @@ -1987,7 +1987,7 @@ int tcp_v4_rcv(struct sk_buff *skb) th = (const struct tcphdr *)skb->data; if (unlikely(th->doff < sizeof(struct tcphdr) / 4)) { - drop_reason = SKB_DROP_REASON_PKT_TOO_SMALL; + drop_line = SKB_DROP_LINE; goto bad_packet; } if (!pskb_may_pull(skb, th->doff * 4)) @@ -2095,7 +2095,7 @@ int tcp_v4_rcv(struct sk_buff *skb) nf_reset_ct(skb); if (tcp_filter(sk, skb)) { - drop_reason = SKB_DROP_REASON_SOCKET_FILTER; + drop_line = SKB_DROP_LINE; goto discard_and_relse; } th = (const struct tcphdr *)skb->data; @@ -2130,7 +2130,7 @@ int tcp_v4_rcv(struct sk_buff *skb) return ret; no_tcp_socket: - drop_reason = SKB_DROP_REASON_NO_SOCKET; + drop_line = SKB_DROP_LINE; if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) goto discard_it; @@ -2138,7 +2138,7 @@ int tcp_v4_rcv(struct sk_buff *skb) if (tcp_checksum_complete(skb)) { csum_error: - drop_reason = SKB_DROP_REASON_TCP_CSUM; + drop_line = SKB_DROP_LINE; trace_tcp_bad_csum(skb); __TCP_INC_STATS(net, TCP_MIB_CSUMERRORS); bad_packet: @@ -2149,7 +2149,7 @@ int tcp_v4_rcv(struct sk_buff *skb) discard_it: /* Discard frame. */ - kfree_skb_reason(skb, drop_reason); + kfree_skb_reason(skb, drop_line); return 0; discard_and_relse: diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 090360939401..f0715d1072d7 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2411,9 +2411,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, __be32 saddr, daddr; struct net *net = dev_net(skb->dev); bool refcounted; - int drop_reason; + unsigned int drop_line; - drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; + drop_line = SKB_DROP_LINE_NONE; /* * Validate the packet. @@ -2469,7 +2469,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, if (udp_lib_checksum_complete(skb)) goto csum_error; - drop_reason = SKB_DROP_REASON_NO_SOCKET; + drop_line = SKB_DROP_LINE; __UDP_INC_STATS(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE); icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); @@ -2477,11 +2477,11 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, * Hmm. We got an UDP packet to a port to which we * don't wanna listen. Ignore it. */ - kfree_skb_reason(skb, drop_reason); + kfree_skb_reason(skb, drop_line); return 0; short_packet: - drop_reason = SKB_DROP_REASON_PKT_TOO_SMALL; + drop_line = SKB_DROP_LINE; net_dbg_ratelimited("UDP%s: short packet: From %pI4:%u %d/%d to %pI4:%u\n", proto == IPPROTO_UDPLITE ? "Lite" : "", &saddr, ntohs(uh->source), @@ -2494,7 +2494,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, * RFC1122: OK. Discards the bad packet silently (as far as * the network is concerned, anyway) as per 4.1.3.4 (MUST). */ - drop_reason = SKB_DROP_REASON_UDP_CSUM; + drop_line = SKB_DROP_LINE; net_dbg_ratelimited("UDP%s: bad checksum. From %pI4:%u to %pI4:%u ulen %d\n", proto == IPPROTO_UDPLITE ? "Lite" : "", &saddr, ntohs(uh->source), &daddr, ntohs(uh->dest), @@ -2502,7 +2502,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE); drop: __UDP_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE); - kfree_skb_reason(skb, drop_reason); + kfree_skb_reason(skb, drop_line); return 0; } From patchwork Thu Feb 3 15:37:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12734288 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 CFB23C43219 for ; Thu, 3 Feb 2022 15:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351917AbiBCPiu (ORCPT ); Thu, 3 Feb 2022 10:38:50 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:43678 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351906AbiBCPio (ORCPT ); Thu, 3 Feb 2022 10:38:44 -0500 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 213F9n36024860; Thu, 3 Feb 2022 15:37:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=y5cmkg6mXDlXoJ0Ep4GjPJo3MxoloxdWBKwIVYMUa7k=; b=RNIgFfVIuSFw9tPr9BL0ZJY8ELY0N816/CNUBWD2swi+smDk57cwuScmdiS+LKtN0QGz 2HaPZ41sPJ+hUcTcB4Nh4uQbVhmqK1e/RcIWKpgJNK2i+i97G08UOtdUJMczw+MX02TU SJ43hVdx0bhn3MieN6y4MrKhp3jA2b6qfIOZnI6YHCEWzLsdE6dv/psknTM2gkOvJowg y1+IVy6VJw2ymkr45VBO/hm7lAs8mFuhSV8Gqere7DwGQr3u0t8mbLVNR16T7JMpD2wQ KLgKhmYM0HyWrtJcqxNZgFYBrqFPfSzd3Pdo3ItV0lEZd1H7cdvnmciUeCKU+huVDQoE uw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e0hevr302-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Feb 2022 15:37:47 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 213FVIM0184560; Thu, 3 Feb 2022 15:37:46 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2045.outbound.protection.outlook.com [104.47.57.45]) by aserp3020.oracle.com with ESMTP id 3dvwdaj9de-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Feb 2022 15:37:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cw5JMRMVdPi8OiBOPIx5PMUT/DdcM762JSVcWm4xaPOiA91NJIxephOSYq1mV8GfX02E9N9o2YORu3odvGgy7I8PZc2lfKgKePfTp+qyuRxBEk083fmYkoO7QGLSboFNL8YqPGtbjLu9EjWRo9MFTEs+7esc75qGW18iHNCZwbBCHw+FCr4no+RXP8laDgRT7AvRgTKvLRuNISiUeUuToDJU8tvcV5Pub/S8eYzPabgTnUNDk3oQpqhiNh7WDAPHcwT7o3UOPb0sKx7RbeU86uqIdRXlxKe9DIfrX3G45C3kw0f07LZcDZQEVdi9zVd+gbD5HyOR0UVUsMd+6oNKSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=y5cmkg6mXDlXoJ0Ep4GjPJo3MxoloxdWBKwIVYMUa7k=; b=bBOoYT1PaUw5ZXrC4F8xMU2pnq6QHqxyFzKSD8NlGZlkgX3wr/wCb/fd/ZuJ1bfrFitIYU2gfeeS4NWVlrd+7Aiw4jvpi3bhlayP9PK+ifAQkUrYlzcQI8YOTyooPhWl+MsUeeoPYJSpISNu25x5yNrWxgGtRN4Suc8kqbWpT0+yeGh+ptJlgk65Gj/N3tjmcLcD6NSO7ZBLF4E2uTvFB80mzB/thE56um0sP/ycsFrwgSwXmpGWOzo2DbEqbitynAoFj+/oPVTH+TrkxREEX9bnvZRhK58sT/slgNJJry0GCoSZ1FRGk0ThBZL8Lj4MH6PINqoA63rW7VFDhsKHLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y5cmkg6mXDlXoJ0Ep4GjPJo3MxoloxdWBKwIVYMUa7k=; b=l7V5ZQqDpa8fP/aq9WNK/ocdMdjz5HeJj/o2I16vwWiNZsToFJdPoBZ+ruD8jq2yDpudcTVhmpMwjTGrAf8nEwiDv/gEV/X8Pvx5sDT+v2TEmAb6wZRtC7GyoxdRPjMn96mD19u2vcuF/yOOEKQpqc48pDExM3ofJU/9reNF3hw= Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by BN7PR10MB2436.namprd10.prod.outlook.com (2603:10b6:406:c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Thu, 3 Feb 2022 15:37:44 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::60be:11d2:239:dcef]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::60be:11d2:239:dcef%7]) with mapi id 15.20.4930.021; Thu, 3 Feb 2022 15:37:44 +0000 From: Dongli Zhang To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, imagedong@tencent.com, joao.m.martins@oracle.com, joe.jin@oracle.com Subject: [PATCH RFC 2/4] net: skb: add function name as part of reason Date: Thu, 3 Feb 2022 07:37:29 -0800 Message-Id: <20220203153731.8992-3-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220203153731.8992-1-dongli.zhang@oracle.com> References: <20220203153731.8992-1-dongli.zhang@oracle.com> X-ClientProxiedBy: BY5PR03CA0017.namprd03.prod.outlook.com (2603:10b6:a03:1e0::27) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d122fc48-f27a-41c9-db50-08d9e72b1ea9 X-MS-TrafficTypeDiagnostic: BN7PR10MB2436:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 00QtDgWPKAS9PUmCYIv+5aHN/0wVY2scqoIhJ5fiMFs8zzbU0einsNg8BxLfiqznW983R1NuAtVPprZfbcXYByiIVecGOHO4Fv9nVdmGj65TKrtwgUpoqMlyE+wMBxlJds+v1OfpMnU4qcDkY5SigBRoJDRXnXZ5mCYjNBJfzkv6MZN1+qf5h/kBthMoRN3ghG7easK3jOsf6ShEitTOg7rqVgu1nUA3hz2nZzBlB9DLrbh971qe2No57yArEAW3IysLtnmPBHlAn3MBOP+AclJdgYFGFstBNOKaj2hy5cj7BSiElpYRd8vhSKuK2XxqBsOEE1lkZJXaSPoOtceLDJRs3PLjimZLMfhNMKM3KfXFQsWcrXF7Nyd3ReBEolxm6yjbzOrlXrjrLCJHgpHmVyApsotJPiwTLYAe7JMxpZihX7uLmj3fl+q1zUD4xr2QRah10u9i9fQTkq3ZZVLGrNcxlT3hDPrLseZy+RwZM6LCJI3Ef5jT7fzIUz3L/SuYvUX8xWiNdgPI3JXyoSVXeJ7qcyJ6Ryd+AMVIJIXjAMVKeMXawLjVAuUjg/ih+NI9jkDZuoF6v1sOrzc9C1d/b17KP7MgXuFfZhBb3D+kegbl9Z5cu8NoJVdI8c9FWXfYDnhA6HocaDcESOhZRTCqo2X6jLpnv18615sfu/JDJ+OMjWLmzUWgGYESIkvPVD6wxan5LIm+fx5PfX26mBfJ1A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(44832011)(66476007)(52116002)(6512007)(107886003)(7416002)(2906002)(8936002)(66946007)(6506007)(2616005)(66556008)(4326008)(86362001)(6666004)(508600001)(5660300002)(8676002)(186003)(26005)(6486002)(83380400001)(38100700002)(38350700002)(36756003)(316002)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZsbSjYba4ws7b43EH2+3ctJE7dgN/edWqQPAxXuKUqthz3S7yAUd+pzESTNPrA5udRhAbQnzJfVg2AWF7gJ/FqGeufkkyCDLV15RME1cho9mP+YBFUduF/ejQHnRvwBq7NqpDGISLvQvySr5KEtDIX+SUIFM4rUaPrqloZUEHc0fEsYAdZA5z3ppauBl9Jp5Le78CRkjSot9U+UBhdtF2QKwpxRmpBRHtAY/tV8oqK38FQROZfQm8+rw/jJBnuBk9rYu638clyJtwv9+riXWRLzpbYejCYNDdKvnfnJ5knc/dJ4s5r4hpf1X28GUMiZRu/isPeYroqPJNsRdsHNsDhNnXURLoJApbJG+eoVQveTVdZ7fxu9cwFkC3jj0NcFrkWmZnoMMUoXg6W3tuypGkvwNneNmQdILISTXT74nQNbMpB79pyes2Cwp1zpvfWnssiru4yBRj602xGOUVj15mc60LCaW8eL5B4kvcB+7mDktisd/mr2ArLWLhZ2fcs8LtuZ5l8h5uRCX7/rjOmQa1vROZMnunnn7Lj8+2LjMb52W6aTjt9Fx5MlMGMYbgjLMQO27AWuRIGYcuZmdGb58cnI79eMjQsa9MgM3HlRe2HEpEl6RgCEBXdiK8almpPAO8lxlQiBFwKmUT1c5wjtcekiJbeLw2+5O51y5wl22D1B/T39V02SAAa2yBPfi/eoLd2fIYHkXcSfjUuPrs6eLRLdNOA0fHPbP5Mdt1rlL3vLncSiwBrbfymwr4eFzmDe8FMw+G6sbStcw0HSfFjK5Z1d1v9fn4fg2znBAq+k+ercWD8BJIpISsCn1pcAW1aIoh35bbWrt5Gts4Xkup3F7WIvoPraXbcg00IacP5kp5m+wO+V0ZM0VikvtNCQ16cbS5ocwqgKDV91o1+Sk4hYuiuLCk34OvkZNqfD4T9rLin3zrp9H1l2JC304/oZ2A19qf1qe4N5R9mRSCSKLOnRhTnrNaY4I2rZx2XmkqVlZSeZfjCl/mI1mNwKTN0bYL5o6KjK03JVCj2bTV20E7JigAGVxVPLcRhk6+q8II2gfGAZZ/kv27OxruKhVxKumgs2reEV67a4nQq/smRU65iVQygUCGGvNrd3ws7WQXjNNEjNRsWAQPSlHbQRupYS/itjbW5Na1fvUpe42PCJW3gwBdRxGOantTmAxzQWztMt4sWtL/1029olR7xk6gzwa4cLpLxgyKYkRnzAfUlqa7pvLOt8xvhvSW27L/487z8cH1tcO041aqPtC8vgQ55EoK4f+Ed0a3QwhCfNzgnL6nZeln8kyUQM8RXFmle+WQp9Y6F7cEkMtKzN77WL7nv3UvRY9/mq4TWGw1w9umIJqeatC/1K7qsseEGNYqJ8b9636jQJPOBeR7FdK26f4hqzmnA2hTZ+VehFcWHgm1jA0URd5wrZ8TqCsneWpPIWWgKG4mJJo9OGpfyJ/Usfis7GFVuptMJeWHkCPKABZYviTspP6Ax/mugCpLgEamgNr3jOjoKbHGRKP5yhE7v5n1bRul7WdGTECkIqDz4WSvuIQdReM6yC+sWT6zfg/i7kDK6dsZ1BNFRp/9tN8yuvBRPUtxl13yv1xmzVmg6jjrKryvz5x486UHn61AmPp49+ZcW/hYQc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d122fc48-f27a-41c9-db50-08d9e72b1ea9 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 15:37:43.5412 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mAG6/dnVqcBRXIVVNsysBJFDro6xX3KzWwHZjYgAiJ8PK3c3UWYYtxv30a4fHN5OLZYBlOgpV8ijIDlT2IKLdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2436 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10247 signatures=673430 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202030096 X-Proofpoint-GUID: Jlmht3RoNF0DzJOmZDNLaXn849Ker-z1 X-Proofpoint-ORIG-GUID: Jlmht3RoNF0DzJOmZDNLaXn849Ker-z1 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC In addition to the line number ("__LINE__"), this is to make the function name ("__func__", which is the caller of kfree_skb_reason()) as part of reason. The (function, line) combination is able to uniquely represent where the sk_buff is dropped. The existing trace_kfree_skb() is able to trace the 'location'. While it is fine to either echo 'stacktrace' to the trigger, or trace at userspace via ebpf, the TP_printk will only print %p. With the function name, the TP_printk will tell the function and the line number that the sk_buff is dropped. Cc: Joao Martins Cc: Joe Jin Signed-off-by: Dongli Zhang --- include/linux/skbuff.h | 7 +++++-- include/trace/events/skb.h | 10 ++++++---- net/core/dev.c | 1 + net/core/skbuff.c | 9 ++++++--- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/udp.c | 4 ++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 471268a4a497..10bcbe4f690f 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -309,6 +309,8 @@ struct sk_buff; #define SKB_DROP_LINE_NONE 0 #define SKB_DROP_LINE __LINE__ +#define SKB_DROP_FUNC_NONE "none" +#define SKB_DROP_FUNC __func__ /* To allow 64K frame to be packed as single skb without frag_list we * require 64K/PAGE_SIZE pages plus 1 additional page to allow for @@ -1090,7 +1092,8 @@ static inline bool skb_unref(struct sk_buff *skb) return true; } -void kfree_skb_reason(struct sk_buff *skb, unsigned int line); +void kfree_skb_reason(struct sk_buff *skb, const char *func, + unsigned int line); /** * kfree_skb - free an sk_buff with 'NOT_SPECIFIED' reason @@ -1098,7 +1101,7 @@ void kfree_skb_reason(struct sk_buff *skb, unsigned int line); */ static inline void kfree_skb(struct sk_buff *skb) { - kfree_skb_reason(skb, SKB_DROP_LINE_NONE); + kfree_skb_reason(skb, SKB_DROP_FUNC_NONE, SKB_DROP_LINE_NONE); } void skb_release_head_state(struct sk_buff *skb); diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 45d1a1757ff1..b63bf724809e 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -15,14 +15,15 @@ TRACE_EVENT(kfree_skb, TP_PROTO(struct sk_buff *skb, void *location, - unsigned int line), + const char *function, unsigned int line), - TP_ARGS(skb, location, line), + TP_ARGS(skb, location, function, line), TP_STRUCT__entry( __field(void *, skbaddr) __field(void *, location) __field(unsigned short, protocol) + __string(function, function) __field(unsigned int, line) ), @@ -30,12 +31,13 @@ TRACE_EVENT(kfree_skb, __entry->skbaddr = skb; __entry->location = location; __entry->protocol = ntohs(skb->protocol); + __assign_str(function, function); __entry->line = line; ), - TP_printk("skbaddr=%p protocol=%u location=%p line: %u", + TP_printk("skbaddr=%p protocol=%u location=%p function=%s line=%u", __entry->skbaddr, __entry->protocol, __entry->location, - __entry->line) + __get_str(function), __entry->line) ); TRACE_EVENT(consume_skb, diff --git a/net/core/dev.c b/net/core/dev.c index 448f390d35d3..3dccd3248de9 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4900,6 +4900,7 @@ static __latent_entropy void net_tx_action(struct softirq_action *h) trace_consume_skb(skb); else trace_kfree_skb(skb, net_tx_action, + SKB_DROP_FUNC, SKB_DROP_LINE); if (skb->fclone != SKB_FCLONE_UNAVAILABLE) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 8572c3bce264..f7bceb310912 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -761,17 +761,20 @@ EXPORT_SYMBOL(__kfree_skb); /** * kfree_skb_reason - free an sk_buff with special reason * @skb: buffer to free + * @func: the function where this skb is dropped * @line: the line where this skb is dropped * * Drop a reference to the buffer and free it if the usage count has - * hit zero. Meanwhile, pass the drop line to 'kfree_skb' tracepoint. + * hit zero. Meanwhile, pass the drop function and line to 'kfree_skb' + * tracepoint. */ -void kfree_skb_reason(struct sk_buff *skb, unsigned int line) +void kfree_skb_reason(struct sk_buff *skb, const char *func, + unsigned int line) { if (!skb_unref(skb)) return; - trace_kfree_skb(skb, __builtin_return_address(0), line); + trace_kfree_skb(skb, __builtin_return_address(0), func, line); __kfree_skb(skb); } EXPORT_SYMBOL(kfree_skb_reason); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index f23af94d1186..a1cb1252370b 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2149,7 +2149,7 @@ int tcp_v4_rcv(struct sk_buff *skb) discard_it: /* Discard frame. */ - kfree_skb_reason(skb, drop_line); + kfree_skb_reason(skb, SKB_DROP_FUNC, drop_line); return 0; discard_and_relse: diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index f0715d1072d7..ae86ab56a7dd 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2477,7 +2477,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, * Hmm. We got an UDP packet to a port to which we * don't wanna listen. Ignore it. */ - kfree_skb_reason(skb, drop_line); + kfree_skb_reason(skb, SKB_DROP_FUNC, drop_line); return 0; short_packet: @@ -2502,7 +2502,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE); drop: __UDP_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE); - kfree_skb_reason(skb, drop_line); + kfree_skb_reason(skb, SKB_DROP_FUNC, drop_line); return 0; } From patchwork Thu Feb 3 15:37:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12734290 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 BEC13C433EF for ; Thu, 3 Feb 2022 15:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351955AbiBCPiz (ORCPT ); Thu, 3 Feb 2022 10:38:55 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:50132 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351913AbiBCPir (ORCPT ); Thu, 3 Feb 2022 10:38:47 -0500 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 213F9VeV032744; Thu, 3 Feb 2022 15:37:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=ylrSjp7FTH5Qvlu8+RqdsWATCB5o82UlnqCw5g8dTHw=; b=s7BuFKayrCKVueyc4G/4H2Sisq917xSeGSU8/MDk8i5/9sducZkhaQ1YADZJVPQDylG+ nzlBzcUns64GKMO5aC5jTwH0Q5iO81Eis+X2o0ExUxKg5So+2Mzg67GQF/SxpRnLOy7C 92akTnMkvWbcXzET7PSCSmUrJ80TUC3uOVzWbNuorLjwDx4ymYcs4qmBL68HGwzLJOWv uASXKRcCPOD37u/99+WqETqHgWnXuMIQCS4xnora4PC6o4N5QvtpafPw6lBG8/laNwii So9dbkxxKeOCHhi88xLZNNelt82IgTVfIuccA5D48GEZzWIBChLgm8BId3xtyXowjiS7 iQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e0het835b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Feb 2022 15:37:47 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 213FVIM1184560; Thu, 3 Feb 2022 15:37:46 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2045.outbound.protection.outlook.com [104.47.57.45]) by aserp3020.oracle.com with ESMTP id 3dvwdaj9de-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Feb 2022 15:37:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FxSF0gLLZz3V9Ih7I6+NoVK8e1CiNqq9JoXD0/EAi6MajyvVCg1Ze9ZMUPjsyII/QIA9p46C9ggLO4ZlVcF9/+aqfL8n9eP0mswWZAJ9rTuX4n+70j5rkvi3/zcMJAIbQLLwb0vobUkQJglznx1a0lxUdXFTeyW7f6+4QE+ye8NFQ0zEWojcjkrg2bu9yOBt8EMk/FprO49TKl9VkapjQDVlxsRPI+AhhcPLZKZ92E1p99cw9v7twIS2peBgz6Wo3Phfjs/FYE3p37tPyW22oZCuT8NfBR7VfSparvm2ktcN8iqH8KAfaILthPpC9iT2pNidY/64Egqc1SZFU0bJdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ylrSjp7FTH5Qvlu8+RqdsWATCB5o82UlnqCw5g8dTHw=; b=d26LpnF/fheB1stU5d3vgqRYTdFh7GhT9EcT75AipE2WH54GyyE1qItXGPxubf7EsldjAYqLZgvvbtoxkmYHxOqfWJ0Tn6f024Tv5yNSa0mV+Q4PkI/zlsTEHia3ccblAGM1sUeuq7OgU0imJYYm7UAizNQgOaeexFjrDP9uAVvorULa/DoMOfyDq0sr0gIUGjDDmT85DrVlCX9mPy6fbJN0HyecAkpIuu9rXpdad2qAYBeR4T5B6bpfaChiZGZVJyJ04KOI32D5KZBDSwe7Wl7roKq/Ud2VaES+1OOyCNgNYUItIOtmw4ZKzxCZQwkmIYD3084FAZJqZn6+L+YQHA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ylrSjp7FTH5Qvlu8+RqdsWATCB5o82UlnqCw5g8dTHw=; b=aa7nE3YXg7+SAEnaI6ajGg3UOSMJ69ttXb0Be0JXPU/837WFkUw8O2PAznIyAUV5kcaHcZxZ9YXR4xko+xxoEbRfUiuI6m0wt3oZUIoiUY4k11rTuxOK5BnA5Z6VSbRTOsUYnZhe203p7D4Rnn/mHrVq35yEA5Qtm1/BXsjYrYU= Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by BN7PR10MB2436.namprd10.prod.outlook.com (2603:10b6:406:c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Thu, 3 Feb 2022 15:37:44 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::60be:11d2:239:dcef]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::60be:11d2:239:dcef%7]) with mapi id 15.20.4930.021; Thu, 3 Feb 2022 15:37:44 +0000 From: Dongli Zhang To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, imagedong@tencent.com, joao.m.martins@oracle.com, joe.jin@oracle.com Subject: [PATCH RFC 3/4] net: tun: track dropped skb via kfree_skb_reason() Date: Thu, 3 Feb 2022 07:37:30 -0800 Message-Id: <20220203153731.8992-4-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220203153731.8992-1-dongli.zhang@oracle.com> References: <20220203153731.8992-1-dongli.zhang@oracle.com> X-ClientProxiedBy: BY5PR03CA0017.namprd03.prod.outlook.com (2603:10b6:a03:1e0::27) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ac5b2923-4c89-49d9-2515-08d9e72b1ef6 X-MS-TrafficTypeDiagnostic: BN7PR10MB2436:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WDTm9FjnYlEh/RROa1rzfI/UopFgHLLDDG/63jgIxjFM5tHIIzsB6c3YDO+DS6X4vhWSF4g6udXRpeSr9xkRCwVRWbE4Vl40XyVRmbiWDM832gDQ71g5Ccvoh21vDut5rfHr7ay7OITffIDcyblOAY06Hdljc129wb9cIbOzbjLJ9chS7SrJr7rcZDOLsjx6KwbgXUYROe9Hjl1Ns5k3+zDbLsxQRMdZRuUXf9ECCMfSGMk6MVIkV3IafwyxRdklGqA2vf2/ELNLwwcZsyb7CKawLgNSlaY/rtYqv58GaD3929235UpaVV+xGLwvEo4oEL3JkWYYtv0/Aot623eOVRaYfwbPtBO0AHa8UN29KCBMQu1hqX+h3Zcbwo0i+6WzUoSLItn+PYw1GdADL87tm1s5mR4LyfFtG1v8b4Ae0GyYIIwWZnVagHGzkK5yHyf5bTsnWXGTgdYREbNoU2jYI/Co+5uMon/KLZ1qAjlL4gTPfnTrdoWF82ghNCwHSdD5i/yjp76sOXImug0Bob7EMNsNbc4a/S5LfPvsNcWIiMUWM8J3UZR9tpaY6hVDKWFPfMAfww85RoJuOc206E5nQAe5OrXnMC4b9L2YS71OvxKCdZKH4HGYRkN+V8G2WqbCAIJRnbnGdS1PRLv8GIDRYiC1hPt6ML7J+dWw3CKZjbL5ie137jvLrYRaVVo97PeQFLRmlS0GZ7AO/Wb358nInQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(44832011)(66476007)(52116002)(6512007)(107886003)(7416002)(2906002)(8936002)(66946007)(6506007)(2616005)(66556008)(4326008)(86362001)(6666004)(508600001)(5660300002)(8676002)(186003)(26005)(6486002)(83380400001)(38100700002)(38350700002)(36756003)(316002)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9bKoe/t4QEy/Kc212x7AmIkiKuTv4MpHgYmmVIkQ/Ov86xZ+F0jkrGgn5T44i57aP9gcr4stNECZBucEk4oSgSHJmkhAPFBgZ1yx8fYFTOuDr+rhNVO51vWDj8MexZsJAZPtQ1+QNHj9NB/1TYSOfFebi5z9rxOQuuejEPrtXsM40nutobo0dqiIzO9KW4L1oylBz2JqatG4rWKxqh2p1wk96Hoiy1LdLYqASWpnACpqOjJqpuX10aPwyKXzPbUbf16FMkGtlQGiXXBZ4VusbtwZMIZg54O3St5CG+bBjBtzcMlhwKfu8F484v0mQvDx+0PwKtKCzBub3T/1KY0T7MxSMIX5owhtMKY1qBGu+ozBdgoyzxoE9N14MAsOfAbeA6gS2GCnMRITSvOjhaB9n4VkIT7oP4OcE6Hy4nkPhQ1G16Ha14TdyFH8xK29FRhz1PVVqTMzVLWYmgwA3TYdwg7ZsxNkHDSU4p19ioNIepCJ2WAQEGqvzDKoTH/vBvAli3+ey/kt25PuIsPRCn7Ge2JzQc7tNm5vPwceTKM5H7dZNd7d6dDIj4LJvtXG9k49MIopem2hnenc0dSUhtHYfmox1nrfnVr0QI+Bn4wEXGwXusLr1siieKYyVyY6FX/9QrGoG4YPrE8Si/cKOhcHFgDrYB0K6l/ftnDlmZjwJnHcGwrcp7S6ATRM5pdxCLigCFpNfkxJEqE/c+hR1gv1aYrjvZt6o6yulaeAMUMWQrtDfXOzUSyNJi5E86PZFCJC3NZiXR0lTWB85jCvetHYefMAGqaYmkOyuS2vIGgiNti4SndGhi/pnpV+sxtSpFYLChyf9puhZGwGz/XnrD/2klCs11UIOwQ4x5oxRPCB80vjJsSVQ8A9EhyrWwEi62enbSmgRATTgG1ivsfSYWaGKWEXkUo6iw7YUaCQpj+lnwl83iiBF718ua2mJL9hqTEcNMxS+Mh3i4LLGiM//8QfB2odRD0yd4B7etuQqW2zmhp/T4JdumHAcNsD0v8BvSDwExTwQQ7NueEnMeTrMdpHgR1pWDKJW89uc0mUJGvUg4ZulxGKsSaIzIwilh/eTehNsRNHHIJzSqeCDqLmqyAfxzozVPvnCs70dKEcmGTtFxaG4n4nKObDcMoh0wglSaT1ni31c/2eaQiFNvvzNn422VZI/9W9GmCQf5/sQqzlGbg/gvLt3Lp8PEDQmHv9mifPa1nqUeB8VwoGAX0WJZs0aIL8i9fDaLKNM7cJizVDLSNyIQV5K9WJoK3s2ztvMbrVTem7TA/rJ3qePsCkVcUiJd6lJpXzDWyG2m+L6SFafEAMf52VFy287laeU9XPrawetOe1u8PW2V3ujEe6vmF0iQknc+pYQbDOXMgnAnovJxssOMaGnc4Cu7gQWyEIoh49vNjF6rRCNY5k7OuKIZ7nVAVYscxoKJIQWvqTrBkNdOfhIenOzupDhQMEDjtnLPj6ZgXPNjEXAtoJjGGgo7yyVFwKqFJ75kyLE/OaxgoLzFwW9T4C2MqoNV90JDpoeZCvaH3hn7txAto5oGocTTgU/IQ2yGnuzsVq4PIyHFhhRHWNLrjxAGGohr31ymh1WozxZHjWe96Fu2XD2/DaNTLsb0PhwedAH/R9drrTEaq6Nv8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac5b2923-4c89-49d9-2515-08d9e72b1ef6 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 15:37:44.2287 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TWYPl4UxNewNyjIpADrU48LjAvC14Wp8Ke5Y96ueonlXdZa0QOBznc4nocUNpfgMVUlZWJJb7gX9XD8J3+XW1g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2436 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10247 signatures=673430 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202030096 X-Proofpoint-ORIG-GUID: BkhkClo6Kf4M6C1dk3IxyFlGEfSOl9HI X-Proofpoint-GUID: BkhkClo6Kf4M6C1dk3IxyFlGEfSOl9HI Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The TUN can be used as vhost-net backend. E.g, the tun_net_xmit() is the interface to forward the skb from TUN to vhost-net/virtio-net. However, there are many "goto drop" in the TUN driver. Therefore, the kfree_skb_reason() is involved at each "goto drop" to help userspace ftrace/ebpf to track the reason for the loss of packets. Cc: Joao Martins Cc: Joe Jin Signed-off-by: Dongli Zhang --- drivers/net/tun.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index fed85447701a..8f6c6d23a787 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1062,13 +1062,16 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) struct netdev_queue *queue; struct tun_file *tfile; int len = skb->len; + unsigned int drop_line = SKB_DROP_LINE_NONE; rcu_read_lock(); tfile = rcu_dereference(tun->tfiles[txq]); /* Drop packet if interface is not attached */ - if (!tfile) + if (!tfile) { + drop_line = SKB_DROP_LINE; goto drop; + } if (!rcu_dereference(tun->steering_prog)) tun_automq_xmit(tun, skb); @@ -1078,19 +1081,27 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) /* Drop if the filter does not like it. * This is a noop if the filter is disabled. * Filter can be enabled only for the TAP devices. */ - if (!check_filter(&tun->txflt, skb)) + if (!check_filter(&tun->txflt, skb)) { + drop_line = SKB_DROP_LINE; goto drop; + } if (tfile->socket.sk->sk_filter && - sk_filter(tfile->socket.sk, skb)) + sk_filter(tfile->socket.sk, skb)) { + drop_line = SKB_DROP_LINE; goto drop; + } len = run_ebpf_filter(tun, skb, len); - if (len == 0 || pskb_trim(skb, len)) + if (len == 0 || pskb_trim(skb, len)) { + drop_line = SKB_DROP_LINE; goto drop; + } - if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC))) + if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC))) { + drop_line = SKB_DROP_LINE; goto drop; + } skb_tx_timestamp(skb); @@ -1101,8 +1112,10 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) nf_reset_ct(skb); - if (ptr_ring_produce(&tfile->tx_ring, skb)) + if (ptr_ring_produce(&tfile->tx_ring, skb)) { + drop_line = SKB_DROP_LINE; goto drop; + } /* NETIF_F_LLTX requires to do our own update of trans_start */ queue = netdev_get_tx_queue(dev, txq); @@ -1119,7 +1132,7 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) drop: atomic_long_inc(&dev->tx_dropped); skb_tx_error(skb); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_FUNC, drop_line); rcu_read_unlock(); return NET_XMIT_DROP; } @@ -1717,6 +1730,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, u32 rxhash = 0; int skb_xdp = 1; bool frags = tun_napi_frags_enabled(tfile); + unsigned int drop_line = SKB_DROP_LINE_NONE; if (!(tun->flags & IFF_NO_PI)) { if (len < sizeof(pi)) @@ -1820,9 +1834,10 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, if (err) { err = -EFAULT; + drop_line = SKB_DROP_LINE; drop: atomic_long_inc(&tun->dev->rx_dropped); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_FUNC, drop_line); if (frags) { tfile->napi.skb = NULL; mutex_unlock(&tfile->napi_mutex); @@ -1868,6 +1883,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, break; case IFF_TAP: if (frags && !pskb_may_pull(skb, ETH_HLEN)) { + drop_line = SKB_DROP_LINE; err = -ENOMEM; goto drop; } @@ -1922,6 +1938,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, if (unlikely(!(tun->dev->flags & IFF_UP))) { err = -EIO; rcu_read_unlock(); + drop_line = SKB_DROP_LINE; goto drop; } From patchwork Thu Feb 3 15:37:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongli Zhang X-Patchwork-Id: 12734289 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 EB9F6C4332F for ; Thu, 3 Feb 2022 15:38:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351936AbiBCPiv (ORCPT ); Thu, 3 Feb 2022 10:38:51 -0500 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:49842 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351912AbiBCPir (ORCPT ); Thu, 3 Feb 2022 10:38:47 -0500 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 213F9VeW032744; Thu, 3 Feb 2022 15:37:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2021-07-09; bh=fiMSUoEZKmsk6sl6lfuYto6lgx6LX6oCOGuF6I/Lf78=; b=XOtLqO8+R68pmxgqBkCjcxQnWHydTFmt9Jx2zTiruFj+aBY/rcXYTd/PQbr84DzjO8ad JcS6q1d1mlhsgGgyGC7X3cbyDo6ubQjWFk0fJISyFbr1/A/SHBjWkhnwgZ/0SgPp/bhW zHuL7RgGNnNg9/CEvgdPs5p5f6aBKLUumDs3mtcHyvsoYQAOkqyb/D9BSEqa8v8pfrj4 98A9l1MJ6e1R6BS5RVfxB9GWTBK5Y9hJoMj5PE1m41oYZyu6yczML8m20oVA6YHwa9hY 3enj6G1NHPymDHlsAVPu/vD7rQWaW61gjofZ2i/QtjInUgZNzYLj6y8t5uoNvwGMS/RW dA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3e0het835f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Feb 2022 15:37:48 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 213FVIM2184560; Thu, 3 Feb 2022 15:37:47 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2045.outbound.protection.outlook.com [104.47.57.45]) by aserp3020.oracle.com with ESMTP id 3dvwdaj9de-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Feb 2022 15:37:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iSdcdUlihkHNjZLleKt8eVefHcX447VgjoDy+norsG/Iahf9dxZNcA/nnt+jaKOmSUlW4RG+GOgjgUAvlemVfhU+rct+vIvArPbbJneFo+aqptzBpBjwVdKzSg1u9T6EgG+c9dBJbAarFCTPe/H+ceAfIMyVUTtG4vWBckZxqyyKvbPMnnYajUe073vt4ObUtk5HcdFZHmsEoaZGt6iq5qj/dGfzkMSc5WQBK6xpPC9bAhdb1t5ghd5L7Pub6fRMcoZa6on7yO1WANu0xKXiglDbq4OcTYmceYOMDgeNeb1DtO6VzcenKUMprlO64e4D8Sa48VfPeDh4PMwDqCjSpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fiMSUoEZKmsk6sl6lfuYto6lgx6LX6oCOGuF6I/Lf78=; b=hC4kydUnQkeIbK83AjjnGqIgtCxwjw1WQFu+IZ6g7f6ZtWewGYNV1k1rhNev3HUSGjg4IoaaFTSVsQxHykt5NhDWK3pea+GTxeRLvyFwCFDHi6jjryfFPwW00XgZNTi7ktMW1S5ScHorz/QqU+dPwYt7dU46Y3O0aBGH6Mrv3iHxTQ9ZdE/F64TDRNzGnOjIIaar0y99RjvoEOUhUWufMWcH9jxfDexLQKTlNCWaU8n6tAeoUlgjgk6kwBEwXNc/u2pFYOW605+2yx3/YFHo3xlNLaCnjsKkqNzryxFLIsbcCisv2iOlegv0Uug2CHkxpPf+9xp/MOt/6pLcj7hNxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fiMSUoEZKmsk6sl6lfuYto6lgx6LX6oCOGuF6I/Lf78=; b=CniI9vkPATFD+Yl8Da7KcDo1qVuodwtZXI4OmWDDXZ8yJNmjIFav4qTRr5/Hev/KaZcq7Y160Oa3VJZmK5n7TdadegiJKzgH0TgKm2NM631K/Cprsy5jC5fOg2yE3LQdrqU0ZqtHIgnyORZbyJ14Nd5s0gQ6RI+O5ZwzTJvqdP8= Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by BN7PR10MB2436.namprd10.prod.outlook.com (2603:10b6:406:c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Thu, 3 Feb 2022 15:37:45 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::60be:11d2:239:dcef]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::60be:11d2:239:dcef%7]) with mapi id 15.20.4930.021; Thu, 3 Feb 2022 15:37:45 +0000 From: Dongli Zhang To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, kuba@kernel.org, edumazet@google.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, imagedong@tencent.com, joao.m.martins@oracle.com, joe.jin@oracle.com Subject: [PATCH RFC 4/4] net: tap: track dropped skb via kfree_skb_reason() Date: Thu, 3 Feb 2022 07:37:31 -0800 Message-Id: <20220203153731.8992-5-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220203153731.8992-1-dongli.zhang@oracle.com> References: <20220203153731.8992-1-dongli.zhang@oracle.com> X-ClientProxiedBy: BY5PR03CA0017.namprd03.prod.outlook.com (2603:10b6:a03:1e0::27) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f89b20b2-440d-450b-0ab8-08d9e72b1f5f X-MS-TrafficTypeDiagnostic: BN7PR10MB2436:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aBQyXhklxMrz1ISvXM8aADRSmlvmTYXfjpmmcdME8bzzfeVBYmAEensN95zx9t1/1T2S6jUF1NMq69CB55OsKmiiGk126QWhtMn9Rf2pLW30DNvIPobKydtGZDdgpSjYbaiBgkYcUKLMO0mA89tRjYwqrxgai0rqDsKVJ7z1f8wDmxXFmxHZpy5G82zZtlJ1FSE4rfDkdka8F29O1wzLfgq7WeF05xgwi+1eI6E4aKuE55XoGrRgJ2cZNM2ILBQ4hLYuWyo+scnng60GU55U65pQpV1SPKza6eNkRQPscfcVS1AD8yGt+yGda2uSEtOWufJQ16O4bz5tPVgqdS+OaFpylImdgnvfDbEWlZd7NWMWAJ7nLr6HFKEr2SBOtgBpHoO8E6PRUBra5yl1yKx80MJ2rBzZ8pt5MX5haIsfMpp2YLkdrtne1X+hT7rpDk6z38CHT3wzyF4WOf++FBoiaO6fyr/an9emVfPtQdZr3hFbZsc/64SoH9jk5Z/k6xxnNRcFtDiuPg7iw3RjEqEppyRjNrxRVSAegEN+CkTFmi1rR95ZUs4CUEaBg8uMekIVKm9tp6eeoyR9d+1bOaH8CZcT6w/PRKXv1vXw8+O0zlNQOXxrCbDD1+QV5k5qaNtB7TVflG9QsXRbcu5gVdxkJKIsKspsdozuWu3kwGlx9n7TR08bpq+KnPwLavR5ndePWdmtU1Zu/sAbrN9weCkWgg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(44832011)(66476007)(52116002)(6512007)(107886003)(7416002)(2906002)(8936002)(66946007)(6506007)(2616005)(66556008)(4326008)(86362001)(6666004)(508600001)(5660300002)(8676002)(186003)(26005)(6486002)(83380400001)(38100700002)(38350700002)(36756003)(316002)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kuwVQnooQwYolJl4gx4Jbzab74crPWxuYixVnI4aSDxCwusuT1rKgFHdlpub6aMWSslv9sdbC7XUf+rWY0oV4vYNk3poTaz4wJtCjuytuCAnlWRypErlEZdGixAHED2pnnOL//JuM3cpdGTFsrI6KwxDyQ7RKkMkQFM0OWWqa4sPCkw3oCpy3tneO06uALahg7plZt04ZwqtXItbtgwTQwzu5w49gwuW3QX+mqga/haWbBQKhUT5LPv5WsvGh9D5HPFAtJaix9QlRDRmqvzEjGtRqVX4mFOdxCSs/eU9bdKWpOZ54ZHDmdDus0eSqmn7Vh93KxJRprxRKataI0g19xZ4984T4qgCaJ+eqaQXlRxjzkndKhviRL81gnQL86tb3yzvV2vx9eD/V5lDx3EvM4wgiDM93Ykyov/YJk0KOwVScz1v5RsEb6Rr13Dy+geqVMzMUNKYYsT1UH6oX+1AePHcN1r/+sEicg61RMPYPJ9vs2NFYmxRKg+waE9BtCdUZBoUWWIoIzp7dwXxJIQi0xrMr8xAa9DpUcTvVFTiNvNt84WSfIOksAOw/zdMDxYPYFmxpEoc8mApODgD/0Niu70Y/N3lb/pWybEPMzfuy3C3j754BsPA++WSTijzJVsK6zt2vuBzWndd79o0tYvEO5GgGqyJOw1Rbwnd0amDHCRB+/77QHpoiQ5Ax2sjQhbGe7XiuXaskGiu3Vd3iOF7dhkLAPFQefvMXFzBGMLjBe77zvZ4wDTKvQbmhZErm2869Hm4FCYIY7LoRxusC8FJUxtVN/rt+xrwUSCng680dqPgya3rmkZSn6KIz4C33E9fgmikxK68s7W9/iVSxY6gmhFMr8VcWnIrQ+FBKV2wEFNP9Op7+4FbwoQU30y7EFsj874rZqm4stgN5FtIriAtRT0JMdGF8MsO7ZhIPaPLH2I6FFdCO/5Euv5sUbmvKzBmp4ILqaLVKi6DzsXb2ajbdlG3F+8DPGgD6G+M1xw/83Njy4U/NHil4WzvKUgaqsBSGGCfy7VytH3FCZAugBBQUOHxSK6tMa7hxap+mHwbPX5N7kXbpGt7xbmJqFlmIovAXwPaan3xssRMyySu+JyYCvrz7ZST2eT3RBdb9Eop/QclxZISNzFmcih+AVRacHED858bwHWyINXTG8ZjahoGJ2Qm8qFn7h+No3RWjPgKbtWrDG3yQeSTrPgqrXqKaMcVaAuQ/knqCckJ+Nd0AnWLCTQ+0QV8/pVaxJB5448e/f7uGcbc9bCvw3TmI9pP7n7a5UhFIUMlVm8lr3nGBLjfSMtD7+3b40N3d89oMK6pcUQzkWmuVBq7VDcZRSoWXIx/L9SGN6p18W6Vc9Ewcylt+3mqS/kXb/frwZ/YX1Ww3xlt/a6J+yvFALGO0KQIYbs5E1H2kdL1gTPdBNB3X7yB8/GzJGeW9zwumLE+MwbWrrpbP7TYkX8VOwYRNOMun4pVyGc5srOgAR97lHxN0iQB/G4uSut6U3S0CSrapmb1xZJCBuN9yPzOlVPqCRtGYgggdazGPZqNxeAOGwz96ohK7CLK9VyVrIcrlRp19sNwpx/BWAFwGfP7OiJgXo2V27tCb39QZ+fTnK4kmLQPKMNoUrnczmhVyRYGG46dZBhbpns= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f89b20b2-440d-450b-0ab8-08d9e72b1f5f X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 15:37:44.7130 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QwmVP447cr5j5nCVNlZ39zZJK6nef5DTfvLGRxYqKBtDiELM4XpH1S6xxq/DT8cd9ZXcaYeUhG1AalYeZrL02w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2436 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10247 signatures=673430 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202030096 X-Proofpoint-ORIG-GUID: LRor1LffhsW_LdCVKx6g8dGwFhKy4Fv1 X-Proofpoint-GUID: LRor1LffhsW_LdCVKx6g8dGwFhKy4Fv1 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The TAP can be used as vhost-net backend. E.g., the tap_handle_frame() is the interface to forward the skb from TAP to vhost-net/virtio-net. However, there are many "goto drop" in the TAP driver. Therefore, the kfree_skb_reason() is involved at each "goto drop" to help userspace ftrace/ebpf to track the reason for the loss of packets. Cc: Joao Martins Cc: Joe Jin Signed-off-by: Dongli Zhang --- drivers/net/tap.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/net/tap.c b/drivers/net/tap.c index 8e3a28ba6b28..78828dd1b74b 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c @@ -322,6 +322,7 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) struct tap_dev *tap; struct tap_queue *q; netdev_features_t features = TAP_FEATURES; + unsigned int drop_line = SKB_DROP_LINE_NONE; tap = tap_dev_get_rcu(dev); if (!tap) @@ -343,12 +344,16 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) struct sk_buff *segs = __skb_gso_segment(skb, features, false); struct sk_buff *next; - if (IS_ERR(segs)) + if (IS_ERR(segs)) { + drop_line = SKB_DROP_LINE; goto drop; + } if (!segs) { - if (ptr_ring_produce(&q->ring, skb)) + if (ptr_ring_produce(&q->ring, skb)) { + drop_line = SKB_DROP_LINE; goto drop; + } goto wake_up; } @@ -369,10 +374,14 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) */ if (skb->ip_summed == CHECKSUM_PARTIAL && !(features & NETIF_F_CSUM_MASK) && - skb_checksum_help(skb)) + skb_checksum_help(skb)) { + drop_line = SKB_DROP_LINE; goto drop; - if (ptr_ring_produce(&q->ring, skb)) + } + if (ptr_ring_produce(&q->ring, skb)) { + drop_line = SKB_DROP_LINE; goto drop; + } } wake_up: @@ -383,7 +392,7 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) /* Count errors/drops only here, thus don't care about args. */ if (tap->count_rx_dropped) tap->count_rx_dropped(tap); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_FUNC, drop_line); return RX_HANDLER_CONSUMED; } EXPORT_SYMBOL_GPL(tap_handle_frame); @@ -632,6 +641,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control, int depth; bool zerocopy = false; size_t linear; + unsigned int drop_line = SKB_DROP_LINE_NONE; if (q->flags & IFF_VNET_HDR) { vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz); @@ -696,8 +706,10 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control, else err = skb_copy_datagram_from_iter(skb, 0, from, len); - if (err) + if (err) { + drop_line = SKB_DROP_LINE; goto err_kfree; + } skb_set_network_header(skb, ETH_HLEN); skb_reset_mac_header(skb); @@ -706,8 +718,10 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control, if (vnet_hdr_len) { err = virtio_net_hdr_to_skb(skb, &vnet_hdr, tap_is_little_endian(q)); - if (err) + if (err) { + drop_line = SKB_DROP_LINE; goto err_kfree; + } } skb_probe_transport_header(skb); @@ -738,7 +752,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control, return total_len; err_kfree: - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_FUNC, drop_line); err: rcu_read_lock();