Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2055500rwe; Fri, 2 Sep 2022 07:55:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR7LxdWaMKoNFvGlb4EiEfR5edLa/RcFDirIjM1h50aVmT//AaJ5pep+4wjnTryaHQOBfsHO X-Received: by 2002:a63:4c50:0:b0:429:983d:22f1 with SMTP id m16-20020a634c50000000b00429983d22f1mr31368573pgl.213.1662130550557; Fri, 02 Sep 2022 07:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662130550; cv=none; d=google.com; s=arc-20160816; b=Xde8C/gDXXMY1kTzCvN7eKc63MFQgNcgMDtyBSVpyO7r6LdFa60Uyi7pqCTsCWA1S2 g9JATE7KvXfvBA3VmWacXheLt6qFsTlm60BiMhKO+pdjUmSNsipuPsDzbECSnncnWuPd FKPDevVq8bZ9xhWdkLClO5rqj/EWiSa/mQ/ZoYwtNMOIxmcBTAyHJfZ626z4hhANrlo5 laZVQFHLchp1EUenmMgjzWgZuIqK+Qk1i9YbxufrMcgMIvD5eymrgbiTpZGvRvQyQ7B4 L3YBm2zaf6HaCwfSkM9oa6hbFtK1RmIPJnyJdsaN5ZlqNKJ0oPksT5mink3Vppyz5PrJ w5kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pQHd4Y2HFdXOT5DR3FQZobMOsT1BdBSXvdeJW3il5t0=; b=ktHN4ce46R0Y53OCMe5TOBT/OrZweGnTWgSJEBlG0UPMPNGxpqetHTsKPQxUX0lRFQ Cz4caetdrbQUw4b8oMbu/8MA4QiWkuu1BuO6Sy3XqI9Akfqn2meNPtwty/sRpY5FU0Ef z6uFOMKiRDKKdEC5rwBcVLxrzc9Z3izqHfxN7paJ5Pkuqf02rUiY2dzla2kZJVF+yHNO e0jhoo0I2P/WjI+UQmj5/2sbzgE9TfdbHX7ZtLQ4LdRCo2nhk5FJNar+3UJnhoKjH64H 9rrRsp2RA2PdsiC05RlmH5K57j+P9/zKzD0Pz2YpOGoGF5WzoSzu9+m6PHg8dJCQTddt GY8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RJG7HoMM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020a65494e000000b0041b557cea68si2119439pgs.25.2022.09.02.07.55.38; Fri, 02 Sep 2022 07:55:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RJG7HoMM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236098AbiIBOy6 (ORCPT + 99 others); Fri, 2 Sep 2022 10:54:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236080AbiIBOyL (ORCPT ); Fri, 2 Sep 2022 10:54:11 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B30B33358; Fri, 2 Sep 2022 07:18:32 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id jm11so1957835plb.13; Fri, 02 Sep 2022 07:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=pQHd4Y2HFdXOT5DR3FQZobMOsT1BdBSXvdeJW3il5t0=; b=RJG7HoMMF7UKQ4QBfTQkKWC2he0TRV2am0Plzv4cQ6qfiJgOmG+lU02i8yah3mV2Ij h+mtDlXeLhYqpr7oGQ7o108D0Z+HLzUq796Nrd6WFV7auRS3j0JuuZ2aGn39ecVwhzni VoHYsuQ5wK3dg6Hn0XTYc40h99JROBEW6KPX/Q6EnFKqduvzQnYYhSJE3iE2+Z78IZoX wRAHupo3hySblxDuub5DcP1WgdzJlXggqORqB0eGsgOgtDVm6fmiVJPMLvzOhJRf0xJ3 oipwEKxi6rripH1UiByzISh1+QInpBSdhc2e3qDS8sA3CG8gQ8h0RcwzDrTacwtKl2Ow idGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=pQHd4Y2HFdXOT5DR3FQZobMOsT1BdBSXvdeJW3il5t0=; b=LpOL4sFZEtVkC8Uow9T5T8yCkbZVkmIBW2ftl1/J6wwjaQnz9OYVaNsQL5Bu5bnv1z kCr1fIzo+kYnvUYoAwJ2LQ5v3JpBG4LpqTgzzEl84FFoPMd2XM6PPfNz/VIWeFSfSBFY Uf/0Z1+yZiQOCwap0NVs8HW0Ml+dZWo5+BifoYhN7k2iWdxtwjXEORVNy2wz5gEdUO01 X61AMFXzK4DoLquVCY5j0LxVXt+bb0Gh63T0DEk11+dx0Z09tVSaKHjdmXGvngw+Gpkc iLjDb/erjbMmhcBF9CoqfFxIIOvh1d7mQSFexaeS2qcrAeBeVfMFkXqve86u4VPr3ZaD mvHw== X-Gm-Message-State: ACgBeo1u++Epy5NJQq4eyl0yFvsau8ftxIZu/AVduN1Pmza8Tz+kgL7a obnCkc4UmlGJOO4OimGT6Q7Hr6zCmLg= X-Received: by 2002:a17:902:780f:b0:173:5ec:f51d with SMTP id p15-20020a170902780f00b0017305ecf51dmr35975122pll.33.1662128311509; Fri, 02 Sep 2022 07:18:31 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.27]) by smtp.gmail.com with ESMTPSA id 4-20020a620504000000b00537b1aa9191sm1834506pff.178.2022.09.02.07.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 07:18:30 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com, kuba@kernel.org Cc: davem@davemloft.net, pabeni@redhat.com, rostedt@goodmis.org, mingo@redhat.com, imagedong@tencent.com, dsahern@kernel.org, flyingpeng@tencent.com, dongli.zhang@oracle.com, robh@kernel.org, asml.silence@gmail.com, luiz.von.dentz@intel.com, vasily.averin@linux.dev, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM Date: Fri, 2 Sep 2022 22:17:15 +0800 Message-Id: <20220902141715.1038615-1-imagedong@tencent.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Menglong Dong As Eric reported, the 'reason' field is not presented when trace the kfree_skb event by perf: $ perf record -e skb:kfree_skb -a sleep 10 $ perf script ip_defrag 14605 [021] 221.614303: skb:kfree_skb: skbaddr=0xffff9d2851242700 protocol=34525 location=0xffffffffa39346b1 reason: The cause seems to be passing kernel address directly to TP_printk(), which is not right. As the enum 'skb_drop_reason' is not exported to user space through TRACE_DEFINE_ENUM(), perf can't get the drop reason string from the 'reason' field, which is a number. Therefore, we introduce the macro DEFINE_DROP_REASON(), which is used to define the trace enum by TRACE_DEFINE_ENUM(). With the help of DEFINE_DROP_REASON(), now we can remove the auto-generate that we introduced in the commit ec43908dd556 ("net: skb: use auto-generation to convert skb drop reason to string"), and define the string array 'drop_reasons'. Hmmmm...now we come back to the situation that have to maintain drop reasons in both enum skb_drop_reason and DEFINE_DROP_REASON. But they are both in dropreason.h, which makes it easier. After this commit, now the format of kfree_skb is like this: $ cat /tracing/events/skb/kfree_skb/format name: kfree_skb ID: 1524 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:void * skbaddr; offset:8; size:8; signed:0; field:void * location; offset:16; size:8; signed:0; field:unsigned short protocol; offset:24; size:2; signed:0; field:enum skb_drop_reason reason; offset:28; size:4; signed:0; print fmt: "skbaddr=%p protocol=%u location=%p reason: %s", REC->skbaddr, REC->protocol, REC->location, __print_symbolic(REC->reason, { 1, "NOT_SPECIFIED" }, { 2, "NO_SOCKET" } ...... Reported-by: Eric Dumazet Signed-off-by: Menglong Dong --- v2: - undef FN/FNe after use it (Jakub Kicinski) --- include/net/dropreason.h | 67 ++++++++++++++++++++++++++++++++++++++ include/trace/events/skb.h | 15 ++++++++- net/core/.gitignore | 1 - net/core/Makefile | 22 +------------ net/core/skbuff.c | 6 +++- 5 files changed, 87 insertions(+), 24 deletions(-) delete mode 100644 net/core/.gitignore diff --git a/include/net/dropreason.h b/include/net/dropreason.h index fae9b40e54fa..c1cbcdbaf149 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -3,6 +3,73 @@ #ifndef _LINUX_DROPREASON_H #define _LINUX_DROPREASON_H +#define DEFINE_DROP_REASON(FN, FNe) \ + FN(NOT_SPECIFIED) \ + FN(NO_SOCKET) \ + FN(PKT_TOO_SMALL) \ + FN(TCP_CSUM) \ + FN(SOCKET_FILTER) \ + FN(UDP_CSUM) \ + FN(NETFILTER_DROP) \ + FN(OTHERHOST) \ + FN(IP_CSUM) \ + FN(IP_INHDR) \ + FN(IP_RPFILTER) \ + FN(UNICAST_IN_L2_MULTICAST) \ + FN(XFRM_POLICY) \ + FN(IP_NOPROTO) \ + FN(SOCKET_RCVBUFF) \ + FN(PROTO_MEM) \ + FN(TCP_MD5NOTFOUND) \ + FN(TCP_MD5UNEXPECTED) \ + FN(TCP_MD5FAILURE) \ + FN(SOCKET_BACKLOG) \ + FN(TCP_FLAGS) \ + FN(TCP_ZEROWINDOW) \ + FN(TCP_OLD_DATA) \ + FN(TCP_OVERWINDOW) \ + FN(TCP_OFOMERGE) \ + FN(TCP_RFC7323_PAWS) \ + FN(TCP_INVALID_SEQUENCE) \ + FN(TCP_RESET) \ + FN(TCP_INVALID_SYN) \ + FN(TCP_CLOSE) \ + FN(TCP_FASTOPEN) \ + FN(TCP_OLD_ACK) \ + FN(TCP_TOO_OLD_ACK) \ + FN(TCP_ACK_UNSENT_DATA) \ + FN(TCP_OFO_QUEUE_PRUNE) \ + FN(TCP_OFO_DROP) \ + FN(IP_OUTNOROUTES) \ + FN(BPF_CGROUP_EGRESS) \ + FN(IPV6DISABLED) \ + FN(NEIGH_CREATEFAIL) \ + FN(NEIGH_FAILED) \ + FN(NEIGH_QUEUEFULL) \ + FN(NEIGH_DEAD) \ + FN(TC_EGRESS) \ + FN(QDISC_DROP) \ + FN(CPU_BACKLOG) \ + FN(XDP) \ + FN(TC_INGRESS) \ + FN(UNHANDLED_PROTO) \ + FN(SKB_CSUM) \ + FN(SKB_GSO_SEG) \ + FN(SKB_UCOPY_FAULT) \ + FN(DEV_HDR) \ + FN(DEV_READY) \ + FN(FULL_RING) \ + FN(NOMEM) \ + FN(HDR_TRUNC) \ + FN(TAP_FILTER) \ + FN(TAP_TXFILTER) \ + FN(ICMP_CSUM) \ + FN(INVALID_PROTO) \ + FN(IP_INADDRERRORS) \ + FN(IP_INNOROUTES) \ + FN(PKT_TOO_BIG) \ + FNe(MAX) + /** * enum skb_drop_reason - the reasons of skb drops * diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 45264e4bb254..50a974f7dfb4 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -9,6 +9,15 @@ #include #include +#undef FN +#define FN(reason) TRACE_DEFINE_ENUM(SKB_DROP_REASON_##reason); +DEFINE_DROP_REASON(FN, FN) + +#undef FN +#undef FNe +#define FN(reason) { SKB_DROP_REASON_##reason, #reason }, +#define FNe(reason) { SKB_DROP_REASON_##reason, #reason } + /* * Tracepoint for free an sk_buff: */ @@ -35,9 +44,13 @@ TRACE_EVENT(kfree_skb, TP_printk("skbaddr=%p protocol=%u location=%p reason: %s", __entry->skbaddr, __entry->protocol, __entry->location, - drop_reasons[__entry->reason]) + __print_symbolic(__entry->reason, + DEFINE_DROP_REASON(FN, FNe))) ); +#undef FN +#undef FNe + TRACE_EVENT(consume_skb, TP_PROTO(struct sk_buff *skb), diff --git a/net/core/.gitignore b/net/core/.gitignore deleted file mode 100644 index df1e74372cce..000000000000 --- a/net/core/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dropreason_str.c diff --git a/net/core/Makefile b/net/core/Makefile index e8ce3bd283a6..5857cec87b83 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -5,7 +5,7 @@ obj-y := sock.o request_sock.o skbuff.o datagram.o stream.o scm.o \ gen_stats.o gen_estimator.o net_namespace.o secure_seq.o \ - flow_dissector.o dropreason_str.o + flow_dissector.o obj-$(CONFIG_SYSCTL) += sysctl_net_core.o @@ -40,23 +40,3 @@ obj-$(CONFIG_NET_SOCK_MSG) += skmsg.o obj-$(CONFIG_BPF_SYSCALL) += sock_map.o obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o obj-$(CONFIG_OF) += of_net.o - -clean-files := dropreason_str.c - -quiet_cmd_dropreason_str = GEN $@ -cmd_dropreason_str = awk -F ',' 'BEGIN{ print "\#include \n"; \ - print "const char * const drop_reasons[] = {" }\ - /^enum skb_drop/ { dr=1; }\ - /^\};/ { dr=0; }\ - /^\tSKB_DROP_REASON_/ {\ - if (dr) {\ - sub(/\tSKB_DROP_REASON_/, "", $$1);\ - printf "\t[SKB_DROP_REASON_%s] = \"%s\",\n", $$1, $$1;\ - }\ - }\ - END{ print "};" }' $< > $@ - -$(obj)/dropreason_str.c: $(srctree)/include/net/dropreason.h - $(call cmd,dropreason_str) - -$(obj)/dropreason_str.o: $(obj)/dropreason_str.c diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 48ecfbf29174..f1b8b20fc20b 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -91,7 +91,11 @@ static struct kmem_cache *skbuff_ext_cache __ro_after_init; int sysctl_max_skb_frags __read_mostly = MAX_SKB_FRAGS; EXPORT_SYMBOL(sysctl_max_skb_frags); -/* The array 'drop_reasons' is auto-generated in dropreason_str.c */ +#undef FN +#define FN(reason) [SKB_DROP_REASON_##reason] = #reason, +const char * const drop_reasons[] = { + DEFINE_DROP_REASON(FN, FN) +}; EXPORT_SYMBOL(drop_reasons); /** -- 2.37.2