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 commitec43908dd5
("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" } ...... Fixes:ec43908dd5
("net: skb: use auto-generation to convert skb drop reason to string") Link: https://lore.kernel.org/netdev/CANn89i+bx0ybvE55iMYf5GJM48WwV1HNpdm9Q6t-HaEstqpCSA@mail.gmail.com/ Reported-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Menglong Dong <imagedong@tencent.com> Signed-off-by: David S. Miller <davem@davemloft.net>
94 lines
1.8 KiB
C
94 lines
1.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#undef TRACE_SYSTEM
|
|
#define TRACE_SYSTEM skb
|
|
|
|
#if !defined(_TRACE_SKB_H) || defined(TRACE_HEADER_MULTI_READ)
|
|
#define _TRACE_SKB_H
|
|
|
|
#include <linux/skbuff.h>
|
|
#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:
|
|
*/
|
|
TRACE_EVENT(kfree_skb,
|
|
|
|
TP_PROTO(struct sk_buff *skb, void *location,
|
|
enum skb_drop_reason reason),
|
|
|
|
TP_ARGS(skb, location, reason),
|
|
|
|
TP_STRUCT__entry(
|
|
__field(void *, skbaddr)
|
|
__field(void *, location)
|
|
__field(unsigned short, protocol)
|
|
__field(enum skb_drop_reason, reason)
|
|
),
|
|
|
|
TP_fast_assign(
|
|
__entry->skbaddr = skb;
|
|
__entry->location = location;
|
|
__entry->protocol = ntohs(skb->protocol);
|
|
__entry->reason = reason;
|
|
),
|
|
|
|
TP_printk("skbaddr=%p protocol=%u location=%p reason: %s",
|
|
__entry->skbaddr, __entry->protocol, __entry->location,
|
|
__print_symbolic(__entry->reason,
|
|
DEFINE_DROP_REASON(FN, FNe)))
|
|
);
|
|
|
|
#undef FN
|
|
#undef FNe
|
|
|
|
TRACE_EVENT(consume_skb,
|
|
|
|
TP_PROTO(struct sk_buff *skb),
|
|
|
|
TP_ARGS(skb),
|
|
|
|
TP_STRUCT__entry(
|
|
__field( void *, skbaddr )
|
|
),
|
|
|
|
TP_fast_assign(
|
|
__entry->skbaddr = skb;
|
|
),
|
|
|
|
TP_printk("skbaddr=%p", __entry->skbaddr)
|
|
);
|
|
|
|
TRACE_EVENT(skb_copy_datagram_iovec,
|
|
|
|
TP_PROTO(const struct sk_buff *skb, int len),
|
|
|
|
TP_ARGS(skb, len),
|
|
|
|
TP_STRUCT__entry(
|
|
__field( const void *, skbaddr )
|
|
__field( int, len )
|
|
),
|
|
|
|
TP_fast_assign(
|
|
__entry->skbaddr = skb;
|
|
__entry->len = len;
|
|
),
|
|
|
|
TP_printk("skbaddr=%p len=%d", __entry->skbaddr, __entry->len)
|
|
);
|
|
|
|
#endif /* _TRACE_SKB_H */
|
|
|
|
/* This part must be outside protection */
|
|
#include <trace/define_trace.h>
|