[PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM

menglong8.dong@gmail.com posted 1 patch 3 years, 7 months ago
There is a newer version of this series
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
[PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by menglong8.dong@gmail.com 3 years, 7 months ago
From: Menglong Dong <imagedong@tencent.com>

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 <edumazet@google.com>
Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
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 <linux/netdevice.h>
 #include <linux/tracepoint.h>
 
+#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 <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 "};" }' $< > $@
-
-$(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
Re: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by Eric Dumazet 3 years, 7 months ago
On Fri, Sep 2, 2022 at 7:18 AM <menglong8.dong@gmail.com> wrote:
>
> From: Menglong Dong <imagedong@tencent.com>
>
> 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 <edumazet@google.com>

Note that I also provided the sha1 of the faulty patch.

You should add a corresponding Fixes: tag, to help both humans and bots.

This would also hint that this patch should target net tree, not net-next ?

> Signed-off-by: Menglong Dong <imagedong@tencent.com>
> ---
> v2:
> - undef FN/FNe after use it (Jakub Kicinski)

I would love some feedback from Steven :)
Re: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by Steven Rostedt 3 years, 7 months ago
On Fri, 2 Sep 2022 08:43:07 -0700
Eric Dumazet <edumazet@google.com> wrote:

> > ---
> > v2:
> > - undef FN/FNe after use it (Jakub Kicinski)  
> 
> I would love some feedback from Steven :)

The undef should be fine. I usually do not, but that's more of a preference
than a rule.

As long as the undef is done after the C portion of where the macro is used:

+#undef FN
+#define FN(reason)	TRACE_DEFINE_ENUM(SKB_DROP_REASON_##reason);
+DEFINE_DROP_REASON(FN, FN) <<<--- C portion

+#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)))  <<<--- C portion
 );
 
+#undef FN
+#undef FNe

So for this part: Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve
Re: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by Eric Dumazet 3 years, 5 months ago
On Mon, Sep 5, 2022 at 7:37 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Fri, 2 Sep 2022 08:43:07 -0700
> Eric Dumazet <edumazet@google.com> wrote:
>
> > > ---
> > > v2:
> > > - undef FN/FNe after use it (Jakub Kicinski)
> >
> > I would love some feedback from Steven :)
>
> The undef should be fine. I usually do not, but that's more of a preference
> than a rule.
>
> As long as the undef is done after the C portion of where the macro is used:
>
> +#undef FN
> +#define FN(reason)     TRACE_DEFINE_ENUM(SKB_DROP_REASON_##reason);
> +DEFINE_DROP_REASON(FN, FN) <<<--- C portion
>
> +#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)))  <<<--- C portion
>  );
>
> +#undef FN
> +#undef FNe
>
> So for this part: Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>
> -- Steve

This seems broken again (tried on latest net-next tree)

perf script
            sshd 12192 [006]   200.090602: skb:kfree_skb:
skbaddr=0x2fa000400000 protocol=7844 location=0x2fa000001ea4 reason:
         swapper     0 [030]   200.497468: skb:kfree_skb:
skbaddr=0xba00400001 protocol=65535 location=0x9080c62800000000
reason:
 kworker/30:1-ev   308 [030]   200.497476: skb:kfree_skb:
skbaddr=0xba00400001 protocol=65535 location=0x9080c62800000000
reason:
         swapper     0 [009]   200.957881: skb:kfree_skb:
skbaddr=0x2fa400400000 protocol=12195 location=0x2fa400002fa3 reason:
         swapper     0 [026]   201.515769: skb:kfree_skb:
skbaddr=0xb600400001 protocol=65535 location=0x9080c62800000000
reason:
 kworker/26:1-mm   276 [026]   201.515797: skb:kfree_skb:
skbaddr=0xb600400001 protocol=65535 location=0x9080c62800000000
reason:
 kworker/26:1-mm   276 [026]   201.515802: skb:kfree_skb:
skbaddr=0x2f9f00400000 protocol=12189 location=0x2f9f00002f9d reason:
         swapper     0 [030]   201.521484: skb:kfree_skb:
skbaddr=0xba00400001 protocol=65535 location=0x9080c62800000000
reason:
 kworker/30:1-ev   308 [030]   201.521491: skb:kfree_skb:
skbaddr=0x2fa100400000 protocol=12192 location=0x2fa100002fa0 reason:
Re: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by Steven Rostedt 3 years, 5 months ago
On Thu, 27 Oct 2022 08:32:02 -0700
Eric Dumazet <edumazet@google.com> wrote:

> This seems broken again (tried on latest net-next tree)
> 
> perf script

Do you also have the latest perf and the latest libtraceevent installed?

-- Steve

>             sshd 12192 [006]   200.090602: skb:kfree_skb:
> skbaddr=0x2fa000400000 protocol=7844 location=0x2fa000001ea4 reason:
>          swapper     0 [030]   200.497468: skb:kfree_skb:
> skbaddr=0xba00400001 protocol=65535 location=0x9080c62800000000
> reason:
>  kworker/30:1-ev   308 [030]   200.497476: skb:kfree_skb:
> skbaddr=0xba00400001 protocol=65535 location=0x9080c62800000000
> reason:
>          swapper     0 [009]   200.957881: skb:kfree_skb:
> skbaddr=0x2fa400400000 protocol=12195 location=0x2fa400002fa3 reason:
>          swapper     0 [026]   201.515769: skb:kfree_skb:
> skbaddr=0xb600400001 protocol=65535 location=0x9080c62800000000
> reason:
>  kworker/26:1-mm   276 [026]   201.515797: skb:kfree_skb:
> skbaddr=0xb600400001 protocol=65535 location=0x9080c62800000000
> reason:
>  kworker/26:1-mm   276 [026]   201.515802: skb:kfree_skb:
> skbaddr=0x2f9f00400000 protocol=12189 location=0x2f9f00002f9d reason:
>          swapper     0 [030]   201.521484: skb:kfree_skb:
> skbaddr=0xba00400001 protocol=65535 location=0x9080c62800000000
> reason:
>  kworker/30:1-ev   308 [030]   201.521491: skb:kfree_skb:
> skbaddr=0x2fa100400000 protocol=12192 location=0x2fa100002fa0 reason:
Re: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by Eric Dumazet 3 years, 5 months ago
On Thu, Oct 27, 2022 at 8:43 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Thu, 27 Oct 2022 08:32:02 -0700
> Eric Dumazet <edumazet@google.com> wrote:
>
> > This seems broken again (tried on latest net-next tree)
> >
> > perf script
>
> Do you also have the latest perf and the latest libtraceevent installed?
>

I tried a more recent perf binary we have, but it is also not right.

I guess I will have to request a new perf binary at Google :/

perf5 script
         swapper     0 [030]  4147.704606: skb:kfree_skb: [UNKNOWN EVENT]
 kworker/30:1-ev   308 [030]  4147.704615: skb:kfree_skb: [UNKNOWN EVENT]
         swapper     0 [030]  4148.048173: skb:kfree_skb: [UNKNOWN EVENT]
 kworker/30:1-ev   308 [030]  4148.048179: skb:kfree_skb: [UNKNOWN EVENT]
         swapper     0 [008]  4148.048773: skb:kfree_skb: [UNKNOWN EVENT]
         swapper     0 [030]  4148.112271: skb:kfree_skb: [UNKNOWN EVENT]
 kworker/30:1-ev   308 [030]  4148.112280: skb:kfree_skb: [UNKNOWN EVENT]
         swapper     0 [030]  4148.720149: skb:kfree_skb: [UNKNOWN EVENT]
 kworker/30:1-ev   308 [030]  4148.720155: skb:kfree_skb: [UNKNOWN EVENT]
         swapper     0 [030]  4149.072141: skb:kfree_skb: [UNKNOWN EVENT]
 kworker/30:1-ev   308 [030]  4149.072149: skb:kfree_skb: [UNKNOWN EVENT]
Re: [Internet]Re: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by imagedong(董梦龙) 3 years, 5 months ago
> On 2022/10/28 00:29,“Eric Dumazet”<edumazet@google.com> write:
> 
> On Thu, Oct 27, 2022 at 8:43 AM Steven Rostedt <rostedt@goodmis.org> wrote:
> >
> > On Thu, 27 Oct 2022 08:32:02 -0700
> > Eric Dumazet <edumazet@google.com> wrote:
> >
> > > This seems broken again (tried on latest net-next tree)
> > >
> > > perf script
> >
> > Do you also have the latest perf and the latest libtraceevent installed?
> >
> 
> I tried a more recent perf binary we have, but it is also not right.
> 
> I guess I will have to request a new perf binary at Google :/
> 

Ennn...I just have a try, and it seems fine:

sudo perf script
         swapper     0 [049] 401460.138078: skb:kfree_skb: skbaddr=0xffff8881076d2400 protocol=2048 location=0xffffffff81d86546 reason: TCP_INVALID_SEQUENCE
              nc 429418 [006] 401465.652282: skb:kfree_skb: skbaddr=0xffff8881ea66cf00 protocol=0 location=0xffffffff81e0b48f reason: NOT_SPECIFIED
              nc 429418 [006] 401465.652293: skb:kfree_skb: skbaddr=0xffff8881ea66cf00 protocol=0 location=0xffffffff81e0b48f reason: NOT_SPECIFIED
              nc 429418 [006] 401465.652538: skb:kfree_skb: skbaddr=0xffff888133c014e8 protocol=2048 location=0xffffffff81d983a1 reason: NO_SOCKET

The version of the perf I used is 6.0.3-1:

  sudo apt info linux-perf
  Package: linux-perf
  Version: 6.0.3-1


Thanks!
Menglong Dong

> perf5 script
>          swapper     0 [030]  4147.704606: skb:kfree_skb: [UNKNOWN EVENT]
>  kworker/30:1-ev   308 [030]  4147.704615: skb:kfree_skb: [UNKNOWN EVENT]
>          swapper     0 [030]  4148.048173: skb:kfree_skb: [UNKNOWN EVENT]
>  kworker/30:1-ev   308 [030]  4148.048179: skb:kfree_skb: [UNKNOWN EVENT]
>          swapper     0 [008]  4148.048773: skb:kfree_skb: [UNKNOWN EVENT]
>          swapper     0 [030]  4148.112271: skb:kfree_skb: [UNKNOWN EVENT]
>  kworker/30:1-ev   308 [030]  4148.112280: skb:kfree_skb: [UNKNOWN EVENT]
>          swapper     0 [030]  4148.720149: skb:kfree_skb: [UNKNOWN EVENT]
>  kworker/30:1-ev   308 [030]  4148.720155: skb:kfree_skb: [UNKNOWN EVENT]
>          swapper     0 [030]  4149.072141: skb:kfree_skb: [UNKNOWN EVENT]
>  kworker/30:1-ev   308 [030]  4149.072149: skb:kfree_skb: [UNKNOWN EVENT]

Re: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by Steven Rostedt 3 years, 5 months ago
On Thu, 27 Oct 2022 09:28:42 -0700
Eric Dumazet <edumazet@google.com> wrote:

> I tried a more recent perf binary we have, but it is also not right.
> 
> I guess I will have to request a new perf binary at Google :/

You could always use trace-cmd ;-)

-- Steve
Re: [PATCH net-next v2] net: skb: export skb drop reaons to user by TRACE_DEFINE_ENUM
Posted by Menglong Dong 3 years, 7 months ago
On Fri, Sep 2, 2022 at 11:43 PM Eric Dumazet <edumazet@google.com> wrote:
>
> On Fri, Sep 2, 2022 at 7:18 AM <menglong8.dong@gmail.com> wrote:
> >
> > From: Menglong Dong <imagedong@tencent.com>
> >
> > 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 <edumazet@google.com>
>
> Note that I also provided the sha1 of the faulty patch.
>
> You should add a corresponding Fixes: tag, to help both humans and bots.
>

Okay, I'll add the Fixes tag......and  the Link tag.

> This would also hint that this patch should target net tree, not net-next ?
>

It seems that the net tree is more suitable. I'll change it.

Thanks!

> > Signed-off-by: Menglong Dong <imagedong@tencent.com>
> > ---
> > v2:
> > - undef FN/FNe after use it (Jakub Kicinski)
>
> I would love some feedback from Steven :)

Hi, Steven! Do you have any feedback? Yes, I add the
TRACE_DEFINE_ENUM() back! (Hmm...I deleted it before,
without knowing its function :/ )

Thanks!
Menglong Dong