Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1459974lqt; Wed, 20 Mar 2024 05:00:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUdEzSRROCsslCWyhySv2uvmd0mPh7GFKIlX+Krf+EOXkDDRBi7IVYllh7jP7na7NmEyxnjS3AJPMud5dIcW+HlLU8FXSuETdV4zyuHdA== X-Google-Smtp-Source: AGHT+IHAJzBU+hYbgBDt6ht0jdbGaJZiAKh3CjMc9u2DrXMhV0HZBt9EU55xtDt89BlKKBuHmj/d X-Received: by 2002:a05:6808:2206:b0:3c1:ee6f:cd17 with SMTP id bd6-20020a056808220600b003c1ee6fcd17mr2222677oib.2.1710936038833; Wed, 20 Mar 2024 05:00:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710936038; cv=pass; d=google.com; s=arc-20160816; b=qxdPKn8jhXM3zxZMBFv2mZ8/V+1Uo1IKXhWVot66nASJDDNPFKgfXYXkRxI2sEi+ld UZl6oaaLznkoEx173rh5wcHs47fuD7DIU3WJkK9Z7jJNv3qk9taL1NF32BfUx5/91xnG Yr3nXgkbmdJRECkCdDyyDAyvmNjMl1r6Ha/XiN6aUebmaF232i7WF8O8qDmYOAuJRGRk Whno7BM9L7jMSQmfQY7vXHFSZyZaPdsmsR8quYat5T4L8PfjhBGHHNkanfV2qIuX+ZZ1 HKHAJAywCus+IIzb78cvLaLfGGGNJQfju3ggfUVSIV/dCjow1RNP04lys/L5p69j++7H 15wA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gnuuJlg8CyOIvFYxU93Jc0OBKTJisjjoUpkozAZz3Oo=; fh=KGzLpGIQR24ckhO/9V3qPkH3FlqYhqTUHorp1FNPm8Y=; b=cCyJGTSrKSLbqitd93wd5qAk82O9Q7bxJmIWANCCMeCu7BE/OjisGxu/ARZjzgciDA I0iAWqOLuZ8Hp8aR/Tf++vSk1ATV0g5pF1LOsw3S5K3wxT1RmUPoqsVNAPvspHuOn/5Q vbL/XL+KH0icHJ0X3zCiXe2+XpN7yq0o5Ia0LioTrCGChL7RaYnD/375rCZuBpwRXei5 hiVspSAymvHfX7hrtuVZttrWGAkCnC4h5Jbr8iBZ615ebB1tF6LPjsoP/wbAfmEcuYQw ilD8D1OnstiNcj81HXnQRrH4a5fO9Kpljt3KfaogS1Hx73WC2FgfLqD4Uom3rQAt2Fr8 uieA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=BnyhAii6; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-108888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108888-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n15-20020a05622a040f00b00430cadbfb8asi7151611qtx.490.2024.03.20.05.00.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 05:00:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=BnyhAii6; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-108888-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108888-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4DF7E1C228B3 for ; Wed, 20 Mar 2024 12:00:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3125F3FB35; Wed, 20 Mar 2024 12:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="BnyhAii6" Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69A973D0A3; Wed, 20 Mar 2024 12:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710936004; cv=none; b=B+pJI3FukcA8O9P5p4JCroL30Dx3W1xyVaeOiIpjJjzq7jHPUINbZtTi/gtpdKTnLzZs7QO2pazMai8OcU9M8/tUhnX7Sc0l6dOi44e6YiaNrcx57lxT0oyfL/8fo0vufzEpSjeQjExYwDA1CVVeD/oVZ4NlAUfWQaEhuym8gkk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710936004; c=relaxed/simple; bh=aCNMI2Ts9LsYP23ZKHhYEPaahd+dgT55EZua9O1LiII=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BV7IkD/ZKctk9hjfGra3eYxQXmPXoiCbUhQ2LMqS2mo6WeRJbn496X+YssdmSZeAtZGbUsX2ODIjBkLUfTkCaXVz7NbkfkW8Valh8H4HxBPX43JIC+faYV7eSgVmQ64xOJacNPnJawm2FYUAeh4CTtEuezj+zxjdSKVgsWVrg1w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=BnyhAii6; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=gnuuJ lg8CyOIvFYxU93Jc0OBKTJisjjoUpkozAZz3Oo=; b=BnyhAii6r357MqKZ4AKxq C8KLWqo2VAAideDH/7tRynsv0OYS4opFPL8CJE/nt5FHnVt22RE2K0/nUuwNy9/z 2TLQwfq2Xm6WNy9VTUMFn2Gx4S03CZ2Y3voMJqTRYIfajyCk1b0dD1ZhzLc9V18E jz0gIGQu1uGhmkHtuYZv2w= Received: from hpl-virtual-machine.. (unknown [183.223.134.153]) by gzga-smtp-mta-g2-1 (Coremail) with SMTP id _____wD3Pxmjz_plKabBAw--.1525S2; Wed, 20 Mar 2024 19:59:32 +0800 (CST) From: He Peilin To: rostedt@goodmis.org Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, he.peilin@zte.com.cn, jiang.xuexin@zte.com.cn, kuba@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, liu.chun2@zte.com.cn, mhiramat@kernel.org, netdev@vger.kernel.org, xu.xin16@zte.com.cn, yang.yang29@zte.com.cn, zhang.yunkai@zte.com.cn Subject: Re: Re: [PATCH v2] net/ipv4: add tracepoint for icmp_send Date: Wed, 20 Mar 2024 07:59:30 -0400 Message-Id: <20240320115930.7649-1-peilinhe2020@163.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240319102549.7f7f6f53@gandalf.local.home> References: <20240319102549.7f7f6f53@gandalf.local.home> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wD3Pxmjz_plKabBAw--.1525S2 X-Coremail-Antispam: 1Uf129KBjvJXoW3WF1fAr1fCF15uFyrur4fGrg_yoW7AFy5pF yDAFyfKrs7trW7C34fu34aqF15u348uryUKryIqw12k3Wvvr1Utr4jgrn0kFyrCrs0k34a vF4qv345Gw1YqrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jIOJnUUUUU= X-CM-SenderInfo: xshlzxhqkhjiisq6il2tof0z/1tbiZQWnsWXAkoWOKQAAsj > > From: Peilin He > > > > Introduce a tracepoint for icmp_send, which can help users to get more > > detail information conveniently when icmp abnormal events happen. > > > > 1. Giving an usecase example: > > ============================= > > When an application experiences packet loss due to an unreachable UDP > > destination port, the kernel will send an exception message through the > > icmp_send function. By adding a trace point for icmp_send, developers or > > system administrators can obtain detailed information about the UDP > > packet loss, including the type, code, source address, destination address, > > source port, and destination port. This facilitates the trouble-shooting > > of UDP packet loss issues especially for those network-service > > applications. > > > > 2. Operation Instructions: > > ========================== > > Switch to the tracing directory. > > cd /sys/kernel/debug/tracing > > FYI, that directory is obsolete. Please always reference /sys/kernel/tracing. OK. > > Filter for destination port unreachable. > > echo "type==3 && code==3" > events/icmp/icmp_send/filter > > Enable trace event. > > echo 1 > events/icmp/icmp_send/enable > > > > 3. Result View: > > ================ > > udp_client_erro-11370 [002] ...s.12 124.728002: > > icmp_send: icmp_send: type=3, code=3. > > From 127.0.0.1:41895 to 127.0.0.1:6666 ulen=23 > > skbaddr=00000000589b167a > > > > v1->v2: > > Some fixes according to > > https://lore.kernel.org/all/CANn89iL-y9e_VFpdw=sZtRnKRu_tnUwqHuFQTJvJsv-nz1xPDw@mail.gmail.com/ > > 1. adjust the trace_icmp_send() to more protocols than UDP. > > 2. move the calling of trace_icmp_send after sanity checks > > in __icmp_send(). > > > > Signed-off-by: Peilin He > > Reviewed-by: xu xin > > Reviewed-by: Yunkai Zhang > > Cc: Yang Yang > > Cc: Liu Chun > > Cc: Xuexin Jiang > > --- > > include/trace/events/icmp.h | 64 +++++++++++++++++++++++++++++++++++++++++++++ > > net/ipv4/icmp.c | 4 +++ > > 2 files changed, 68 insertions(+) > > create mode 100644 include/trace/events/icmp.h > > > > diff --git a/include/trace/events/icmp.h b/include/trace/events/icmp.h > > new file mode 100644 > > index 000000000000..c3dc337be7bc > > --- /dev/null > > +++ b/include/trace/events/icmp.h > > @@ -0,0 +1,64 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#undef TRACE_SYSTEM > > +#define TRACE_SYSTEM icmp > > + > > +#if !defined(_TRACE_ICMP_H) || defined(TRACE_HEADER_MULTI_READ) > > +#define _TRACE_ICMP_H > > + > > +#include > > +#include > > + > > +TRACE_EVENT(icmp_send, > > + > > + TP_PROTO(const struct sk_buff *skb, int type, int code), > > + > > + TP_ARGS(skb, type, code), > > + > > + TP_STRUCT__entry( > > + __field(__u16, sport) > > + __field(__u16, dport) > > + __field(int, type) > > + __field(int, code) > > + __array(__u8, saddr, 4) > > + __array(__u8, daddr, 4) > > + __field(const void *, skbaddr) > > + __field(unsigned short, ulen) > > Note, to prevent holes, I usually suggest pointers and longs go first, > followed by ints, and then end with char. > > __field(const void *, skbaddr) > __field(int, type) > __field(int, code) > __array(__u8, saddr, 4) > __array(__u8, daddr, 4) > __field(__u16, sport) > __field(__u16, dport) > __field(unsigned short, ulen) > > -- Steve Thank you very much for your suggestion. We will rearrange the parameters in TP_STRUCT_entry, prioritizing pointers and longs, followed by ints, and ending with char. This will be reflected in Patch v3. > > > > + ), > > + > > + TP_fast_assign( > > + struct iphdr *iph = ip_hdr(skb); > > + int proto_4 = iph->protocol; > > + __be32 *p32; > > + > > + __entry->skbaddr = skb; > > + __entry->type = type; > > + __entry->code = code; > > + > > + if (proto_4 == IPPROTO_UDP) { > > + struct udphdr *uh = udp_hdr(skb); > > + __entry->sport = ntohs(uh->source); > > + __entry->dport = ntohs(uh->dest); > > + __entry->ulen = ntohs(uh->len); > > + } else { > > + __entry->sport = 0; > > + __entry->dport = 0; > > + __entry->ulen = 0; > > + } > > + > > + p32 = (__be32 *) __entry->saddr; > > + *p32 = iph->saddr; > > + > > + p32 = (__be32 *) __entry->daddr; > > + *p32 = iph->daddr; > > + ), > > + > > + TP_printk("icmp_send: type=%d, code=%d. From %pI4:%u to %pI4:%u ulen=%d skbaddr=%p", > > + __entry->type, __entry->code, > > + __entry->saddr, __entry->sport, __entry->daddr, > > + __entry->dport, __entry->ulen, __entry->skbaddr) > > +); > > + > > +#endif /* _TRACE_ICMP_H */ > > + > > +/* This part must be outside protection */ > > +#include > > \ No newline at end of file > > diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c > > index e63a3bf99617..21fb41257fe9 100644 > > --- a/net/ipv4/icmp.c > > +++ b/net/ipv4/icmp.c > > @@ -92,6 +92,8 @@ > > #include > > #include > > #include > > +#define CREATE_TRACE_POINTS > > +#include > > > > /* > > * Build xmit assembly blocks > > @@ -672,6 +674,8 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info, > > } > > } > > > > + trace_icmp_send(skb_in, type, code); > > + > > /* Needed by both icmp_global_allow and icmp_xmit_lock */ > > local_bh_disable(); > >