diff mbox series

[net-next,v2,2/3] net: skb: use auto-generation to convert skb drop reason to string

Message ID 20220530081201.10151-3-imagedong@tencent.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series reorganize the code of the enum skb_drop_reason | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 5746 this patch: 5747
netdev/cc_maintainers warning 2 maintainers not CCed: cong.wang@bytedance.com flyingpeng@tencent.com
netdev/build_clang fail Errors and warnings before: 1224 this patch: 1225
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 5894 this patch: 5895
netdev/checkpatch warning WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Menglong Dong May 30, 2022, 8:12 a.m. UTC
From: Menglong Dong <imagedong@tencent.com>

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' 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.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
 include/net/dropreason.h   |  4 ++
 include/trace/events/skb.h | 89 +-------------------------------------
 net/core/.gitignore        |  1 +
 net/core/Makefile          | 23 +++++++++-
 net/core/drop_monitor.c    | 13 ------
 5 files changed, 28 insertions(+), 102 deletions(-)
 create mode 100644 net/core/.gitignore

Comments

kernel test robot May 30, 2022, 10:01 a.m. UTC | #1
Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/menglong8-dong-gmail-com/reorganize-the-code-of-the-enum-skb_drop_reason/20220530-161614
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 7e062cda7d90543ac8c7700fc7c5527d0c0f22ad
config: nios2-defconfig (https://download.01.org/0day-ci/archive/20220530/202205301730.inNRSOxX-lkp@intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/73e3b002fb9086fc734ba4dcc3041f9bb56eb1a2
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review menglong8-dong-gmail-com/reorganize-the-code-of-the-enum-skb_drop_reason/20220530-161614
        git checkout 73e3b002fb9086fc734ba4dcc3041f9bb56eb1a2
        # save the config file
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 ARCH=nios2 

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):
Philip Li May 30, 2022, 2:23 p.m. UTC | #2
On Mon, May 30, 2022 at 06:01:36PM +0800, kernel test robot wrote:
> Hi,
> 
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on net-next/master]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/menglong8-dong-gmail-com/reorganize-the-code-of-the-enum-skb_drop_reason/20220530-161614
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 7e062cda7d90543ac8c7700fc7c5527d0c0f22ad
> config: nios2-defconfig (https://download.01.org/0day-ci/archive/20220530/202205301730.inNRSOxX-lkp@intel.com/config)
> compiler: nios2-linux-gcc (GCC) 11.3.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/intel-lab-lkp/linux/commit/73e3b002fb9086fc734ba4dcc3041f9bb56eb1a2
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review menglong8-dong-gmail-com/reorganize-the-code-of-the-enum-skb_drop_reason/20220530-161614
>         git checkout 73e3b002fb9086fc734ba4dcc3041f9bb56eb1a2
>         # save the config file
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 ARCH=nios2 
> 
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):

Kindly ignore this report, the report itself has issue with empty
warnings here. We will check and resolve this.

> 
> -- 
> 0-DAY CI Kernel Test Service
> https://01.org/lkp
kernel test robot May 30, 2022, 3:25 p.m. UTC | #3
Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/menglong8-dong-gmail-com/reorganize-the-code-of-the-enum-skb_drop_reason/20220530-161614
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 7e062cda7d90543ac8c7700fc7c5527d0c0f22ad
config: hexagon-randconfig-r041-20220530 (https://download.01.org/0day-ci/archive/20220530/202205302341.XYygIEYb-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 0776c48f9b7e69fa447bee57c7c0985caa856be9)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/73e3b002fb9086fc734ba4dcc3041f9bb56eb1a2
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review menglong8-dong-gmail-com/reorganize-the-code-of-the-enum-skb_drop_reason/20220530-161614
        git checkout 73e3b002fb9086fc734ba4dcc3041f9bb56eb1a2
        # save the config file
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=hexagon 

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):
Jakub Kicinski May 30, 2022, 8:13 p.m. UTC | #4
On Mon, 30 May 2022 16:12:00 +0800 menglong8.dong@gmail.com wrote:
> From: Menglong Dong <imagedong@tencent.com>
> 
> 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 <linux/kernel.h>

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 <net/dropreason.h>\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
Menglong Dong June 1, 2022, 3:27 a.m. UTC | #5
On Tue, May 31, 2022 at 4:13 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon, 30 May 2022 16:12:00 +0800 menglong8.dong@gmail.com wrote:
> > From: Menglong Dong <imagedong@tencent.com>
> >
> > 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 <linux/kernel.h>
>
> Why?

Oh, you noticed it. To simplify the code in dropreason_str.c, as
EXPORT_SYMBOL() is used. Okay, I'll move it to the generation
part.

>
> > +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 <net/dropreason.h>\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
>

Enn...I think this warning comes from the "/\}\;/ { dr=0; }\" part.
Let me do more investigation.

Thanks!
Menglong Dong
Jakub Kicinski June 1, 2022, 3:43 a.m. UTC | #6
On Wed, 1 Jun 2022 11:27:41 +0800 Menglong Dong wrote:
> > > +#include <linux/kernel.h>  
> >
> > Why?  
> 
> Oh, you noticed it. To simplify the code in dropreason_str.c, as
> EXPORT_SYMBOL() is used. Okay, I'll move it to the generation
> part.

IMHO you can move the EXPORT_SYMBOL() to skbuff.c, with a comment
saying that the array itself is in an auto-generated source.
Avoid avoid to "echo" both the EXPORT and the include.
diff mbox series

Patch

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 <linux/kernel.h>
+
 /* The reason of skb drop, which is used in kfree_skb_reason().
  * en...maybe they should be splited by group?
  *
@@ -181,4 +183,6 @@  enum skb_drop_reason {
 			SKB_DR_SET(name, reason);		\
 	} while (0)
 
+extern const char * const drop_reasons[];
+
 #endif
diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
index a477bf907498..45264e4bb254 100644
--- a/include/trace/events/skb.h
+++ b/include/trace/events/skb.h
@@ -9,92 +9,6 @@ 
 #include <linux/netdevice.h>
 #include <linux/tracepoint.h>
 
-#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)			\
-	EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP)	\
-	EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST)		\
-	EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM)			\
-	EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR)			\
-	EM(SKB_DROP_REASON_IP_RPFILTER, IP_RPFILTER)		\
-	EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST,		\
-	   UNICAST_IN_L2_MULTICAST)				\
-	EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY)		\
-	EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO)		\
-	EM(SKB_DROP_REASON_SOCKET_RCVBUFF, SOCKET_RCVBUFF)	\
-	EM(SKB_DROP_REASON_PROTO_MEM, PROTO_MEM)		\
-	EM(SKB_DROP_REASON_TCP_MD5NOTFOUND, TCP_MD5NOTFOUND)	\
-	EM(SKB_DROP_REASON_TCP_MD5UNEXPECTED,			\
-	   TCP_MD5UNEXPECTED)					\
-	EM(SKB_DROP_REASON_TCP_MD5FAILURE, TCP_MD5FAILURE)	\
-	EM(SKB_DROP_REASON_SOCKET_BACKLOG, SOCKET_BACKLOG)	\
-	EM(SKB_DROP_REASON_TCP_FLAGS, TCP_FLAGS)		\
-	EM(SKB_DROP_REASON_TCP_ZEROWINDOW, TCP_ZEROWINDOW)	\
-	EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA)		\
-	EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW)	\
-	EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE)		\
-	EM(SKB_DROP_REASON_TCP_OFO_DROP, TCP_OFO_DROP)		\
-	EM(SKB_DROP_REASON_TCP_RFC7323_PAWS, TCP_RFC7323_PAWS)	\
-	EM(SKB_DROP_REASON_TCP_INVALID_SEQUENCE,		\
-	   TCP_INVALID_SEQUENCE)				\
-	EM(SKB_DROP_REASON_TCP_RESET, TCP_RESET)		\
-	EM(SKB_DROP_REASON_TCP_INVALID_SYN, TCP_INVALID_SYN)	\
-	EM(SKB_DROP_REASON_TCP_CLOSE, TCP_CLOSE)		\
-	EM(SKB_DROP_REASON_TCP_FASTOPEN, TCP_FASTOPEN)		\
-	EM(SKB_DROP_REASON_TCP_OLD_ACK, TCP_OLD_ACK)		\
-	EM(SKB_DROP_REASON_TCP_TOO_OLD_ACK, TCP_TOO_OLD_ACK)	\
-	EM(SKB_DROP_REASON_TCP_ACK_UNSENT_DATA,			\
-	   TCP_ACK_UNSENT_DATA)					\
-	EM(SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE,			\
-	  TCP_OFO_QUEUE_PRUNE)					\
-	EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES)	\
-	EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS,			\
-	   BPF_CGROUP_EGRESS)					\
-	EM(SKB_DROP_REASON_IPV6DISABLED, IPV6DISABLED)		\
-	EM(SKB_DROP_REASON_NEIGH_CREATEFAIL, NEIGH_CREATEFAIL)	\
-	EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED)		\
-	EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL)	\
-	EM(SKB_DROP_REASON_NEIGH_DEAD, NEIGH_DEAD)		\
-	EM(SKB_DROP_REASON_TC_EGRESS, TC_EGRESS)		\
-	EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP)		\
-	EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG)		\
-	EM(SKB_DROP_REASON_XDP, XDP)				\
-	EM(SKB_DROP_REASON_TC_INGRESS, TC_INGRESS)		\
-	EM(SKB_DROP_REASON_UNHANDLED_PROTO, UNHANDLED_PROTO)	\
-	EM(SKB_DROP_REASON_SKB_CSUM, SKB_CSUM)			\
-	EM(SKB_DROP_REASON_SKB_GSO_SEG, SKB_GSO_SEG)		\
-	EM(SKB_DROP_REASON_SKB_UCOPY_FAULT, SKB_UCOPY_FAULT)	\
-	EM(SKB_DROP_REASON_DEV_HDR, DEV_HDR)			\
-	EM(SKB_DROP_REASON_DEV_READY, DEV_READY)		\
-	EM(SKB_DROP_REASON_FULL_RING, FULL_RING)		\
-	EM(SKB_DROP_REASON_NOMEM, NOMEM)			\
-	EM(SKB_DROP_REASON_HDR_TRUNC, HDR_TRUNC)		\
-	EM(SKB_DROP_REASON_TAP_FILTER, TAP_FILTER)		\
-	EM(SKB_DROP_REASON_TAP_TXFILTER, TAP_TXFILTER)		\
-	EM(SKB_DROP_REASON_ICMP_CSUM, ICMP_CSUM)		\
-	EM(SKB_DROP_REASON_INVALID_PROTO, INVALID_PROTO)	\
-	EM(SKB_DROP_REASON_IP_INADDRERRORS, IP_INADDRERRORS)	\
-	EM(SKB_DROP_REASON_IP_INNOROUTES, IP_INNOROUTES)	\
-	EM(SKB_DROP_REASON_PKT_TOO_BIG, PKT_TOO_BIG)		\
-	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:
  */
@@ -121,8 +35,7 @@  TRACE_EVENT(kfree_skb,
 
 	TP_printk("skbaddr=%p protocol=%u location=%p reason: %s",
 		  __entry->skbaddr, __entry->protocol, __entry->location,
-		  __print_symbolic(__entry->reason,
-				   TRACE_SKB_DROP_REASON))
+		  drop_reasons[__entry->reason])
 );
 
 TRACE_EVENT(consume_skb,
diff --git a/net/core/.gitignore b/net/core/.gitignore
new file mode 100644
index 000000000000..104e30010785
--- /dev/null
+++ b/net/core/.gitignore
@@ -0,0 +1 @@ 
+dropreason_str.c
\ No newline at end of file
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 <net/dropreason.h>\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)
+
+$(obj)/dropreason_str.o: $(obj)/dropreason_str.c
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index 41cac0e4834e..4ad1decce724 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -48,19 +48,6 @@ 
 static int trace_state = TRACE_OFF;
 static bool monitor_hw;
 
-#undef EM
-#undef EMe
-
-#define EM(a, b)	[a] = #b,
-#define EMe(a, b)	[a] = #b
-
-/* drop_reasons is used to translate 'enum skb_drop_reason' to string,
- * which is reported to user space.
- */
-static const char * const drop_reasons[] = {
-	TRACE_SKB_DROP_REASON
-};
-
 /* net_dm_mutex
  *
  * An overall lock guarding every operation coming from userspace.