Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5856200ioo; Wed, 1 Jun 2022 14:13:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8dR0N4Py2bsmxdaD3MwOKUte9AR7IjlGuus9Y5WwBGWwETDuEwO082Kt6L/9vlGkTWHhH X-Received: by 2002:a17:90b:3510:b0:1e0:b82:7558 with SMTP id ls16-20020a17090b351000b001e00b827558mr36331194pjb.21.1654118011550; Wed, 01 Jun 2022 14:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654118011; cv=none; d=google.com; s=arc-20160816; b=ytrCdS0m878E+nr5GSkCyIYgZpQLI298kyDDoGGGpeZABVqUYnYL4qnXALZ6AB5tL0 9BVstE+2Yw1FbuLeQp2BjvlSVQSzaa8KWwuidn+x09TXMCkpkNCAGa5wzbArHR056sk7 hejqtnoh+VbPWG+w1rxYzk+SqZtAFJ+OCEvbG40PzO6E7o/rzTpCtVl+1diGPDVfOlYV hkDa6RIUvja6CZ46obFkItttlcsvYCwAEVYEq9PCS7e9SmoIQ7MUVV16OvHDJy/kdD6Y W1Ngq7lItHBtIK+RnNa1Ac+VTV2VZt+IFgc66SmZjZT9WjHT6Bt6yYgUK4uLT1C0h2xt Genw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=395viuHJejApiTeprp6jWCBapW5x5v6oJtrj7i5w8J8=; b=VRRmr+H2xpoQXmIPmf1VsER4tVtzZxCPxyPg8NYgYpQj93pkQ+OtNUn8wSv3vclbUA x7cEJT2xoavVlGJHQMqDybfc9QBv/7mit/509+qGOAYp1N4lQI8R260hyo7FgXGphzNK F+kgx3G69SyFKIZxocUOfreOinT7yt+JIR8IcslQu62npyCjgk6WQN9V1s0NglFE4eYs vzr2m5bRdZGLZ9TWGgTXgfmDdU8CRj76JulaJJ7wm5IUeMtD53uYwGIum0jSgMQKBnv3 aX12SEpEVYB8nDztSpEMemCHAoS4wtr8zb37K8IPCaz5E/8ag+SvmC1lgYsvRCNp224Y +bUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D2Tz2KPP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c9-20020a17090a020900b001e08647560asi7305978pjc.145.2022.06.01.14.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 14:13:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D2Tz2KPP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8697522447E; Wed, 1 Jun 2022 13:04:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241175AbiE3UNT (ORCPT + 99 others); Mon, 30 May 2022 16:13:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235259AbiE3UNR (ORCPT ); Mon, 30 May 2022 16:13:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3006CE25; Mon, 30 May 2022 13:13:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CE38AB80ED2; Mon, 30 May 2022 20:13:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EC01C385B8; Mon, 30 May 2022 20:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653941593; bh=IyPskumtuU2sLSwhSBmkDFek1VnDLMcF+obJ0NF+o/U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=D2Tz2KPPrsUmuqH5STuOqut8buTDr6ggZPNJ1cIfSfdoTeSLizUOgTtEYrNO/Has0 AACyHIYhh02gas1nLyAiF6Zl8JswNzGvjO4o1xNGmC7u4jVHxAj6byUnNhmlX5pheE l13c9t+OFMZ9w2F4+zGO5aHbKli2cwl4qnW5Kts3Hm7dL4yI6pBqCUerBkOhNklxBB 84qBsAH4XkZQmrUIsluCDOIPc2d0K2ZTcsW7CuvkbW0zsuq2IBm3VNU0dsaWYXsUfO 8WsVuQrfq406hbfK8SCDp2uf8c8rww2uVrFfCMDPajPcdr7SLsmRM1zNFfNYUW7yj4 zn73vYpJoSx3w== Date: Mon, 30 May 2022 13:13:11 -0700 From: Jakub Kicinski To: menglong8.dong@gmail.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, nhorman@tuxdriver.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, imagedong@tencent.com, dsahern@kernel.org, talalahmad@google.com, keescook@chromium.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH net-next v2 2/3] net: skb: use auto-generation to convert skb drop reason to string Message-ID: <20220530131311.40914ab7@kernel.org> In-Reply-To: <20220530081201.10151-3-imagedong@tencent.com> References: <20220530081201.10151-1-imagedong@tencent.com> <20220530081201.10151-3-imagedong@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Mon, 30 May 2022 16:12:00 +0800 menglong8.dong@gmail.com wrote: > From: Menglong Dong > > It is annoying to add new skb drop reasons to 'enum skb_drop_reason' > and TRACE_SKB_DROP_REASON in trace/event/skb.h, and it's easy to forget > to add the new reasons we added to TRACE_SKB_DROP_REASON. > > TRACE_SKB_DROP_REASON is used to convert drop reason of type number > to string. For now, the string we passed to user space is exactly the > same as the name in 'enum skb_drop_reason' with a 'SKB_DROP_REASON_' > prefix. Therefore, we can use 'auto-generation' to generate these > drop reasons to string at build time. > > The new header 'dropreason_str.h' Not any more. > will be generated, and the > __DEFINE_SKB_DROP_REASON() in it can do the converting job. Meanwhile, > we use a global array to store these string, which can be used both > in drop_monitor and 'kfree_skb' tracepoint. > diff --git a/include/net/dropreason.h b/include/net/dropreason.h > index ecd18b7b1364..460de425297c 100644 > --- a/include/net/dropreason.h > +++ b/include/net/dropreason.h > @@ -3,6 +3,8 @@ > #ifndef _LINUX_DROPREASON_H > #define _LINUX_DROPREASON_H > > +#include Why? > +dropreason_str.c > \ No newline at end of file Heed the warning. > diff --git a/net/core/Makefile b/net/core/Makefile > index a8e4f737692b..3c7f99ff6d89 100644 > --- a/net/core/Makefile > +++ b/net/core/Makefile > @@ -4,7 +4,8 @@ > # > > 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 > + gen_stats.o gen_estimator.o net_namespace.o secure_seq.o \ > + flow_dissector.o dropreason_str.o > > obj-$(CONFIG_SYSCTL) += sysctl_net_core.o > > @@ -39,3 +40,23 @@ 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 "};\nEXPORT_SYMBOL(drop_reasons);" }' $< > $@ > + > +$(obj)/dropreason_str.c: $(srctree)/include/net/dropreason.h > + $(call cmd,dropreason_str) I'm getting this: awk: cmd. line:1: warning: regexp escape sequence `\;' is not a known regexp operator