From patchwork Fri Aug 18 09:01:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357499 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 259EE17FE1; Fri, 18 Aug 2023 09:01:56 +0000 (UTC) Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2F9A4231; Fri, 18 Aug 2023 02:01:34 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bf1935f6c2so4881465ad.1; Fri, 18 Aug 2023 02:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349289; x=1692954089; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yjo2nSusQS/qrdkLkrw+FknH/a8T5MRr2OaKIcA4HTI=; b=Brd/xnuWG/1z9EXVnSiXPFO1zhCbPYsomZyUCVXH95WIXO5xjBD/vTinLB1gKhfHVz G030SR2QZwT1djzrfevbRaehostrqXUdCMFJb4034ge448y+H9i3XjwvtBJA7YS1vFgA 2BA43lktTZ9XlXLZfnT3m3obNpZTsiI3pIVjAFsxGVrB3D5jdfomWaDb4USdNVq3oNGh iCMIhSe0MxJ6YCWPIytITQCNHh/sqaBT4R4Yru17MyamNy7RppVk6z5v9Xh5yMSJTVC9 4+5oHgXVSh0dwQdOrxypmzp1IIwBPxBNdw63uu/EzbCNBVyyvVlmXENqotQBElZ2ONLB ugbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349289; x=1692954089; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yjo2nSusQS/qrdkLkrw+FknH/a8T5MRr2OaKIcA4HTI=; b=NGYGC1jzG7Hti2GJtl1de0tD6IM9gme7MqyUcHT+yeHHjjTyZ+2x+bRMx1oT6uQ3oY 39+ry2IHvpsd5kjMthABrySE3XPveKzAsws+8ahvYCdZabzH0v/vEhhV1KuBNWW96OPQ 29kDYJ3C4xK2US804OhqBe1KrgWLPJi0+kffzNUSnryIGnfStWR2XIqQsyXMaBp4C29T rMclJ+/IPkDwfbO7Po31Lbv7udf7XZykBpv115GDjz/S5m6PRVsN8976hIl69uceWDyU tyeENPcrS3E8E4/YRmivKY4g6c+hVy+rovswDVR7OWis0BF8r/V9JDZ3RTD0FEEqeKt9 WDKA== X-Gm-Message-State: AOJu0YyYdGaxPZU0W0KUGX/jG7PU7QQk4egPn/pUYVRRMp//U6Tl4wqF 6T7ZuHPFtcjLiZQS2nakWw== X-Google-Smtp-Source: AGHT+IFUcTs3CJWbj66sHsUFM0c/MihJ8cd7uzAWCLQoNe+q8frH0q5GpA1cBSeQkYMU0slJrIrMpA== X-Received: by 2002:a17:903:186:b0:1bc:5e36:9ab4 with SMTP id z6-20020a170903018600b001bc5e369ab4mr2465679plg.21.1692349289368; Fri, 18 Aug 2023 02:01:29 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:01:29 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 1/9] samples/bpf: fix warning with ignored-attributes Date: Fri, 18 Aug 2023 18:01:11 +0900 Message-Id: <20230818090119.477441-2-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net Currently, compiling the bpf programs will result the warning with the ignored attribute as follows. This commit fixes the warning by adding cf-protection option. In file included from ./arch/x86/include/asm/linkage.h:6: ./arch/x86/include/asm/ibt.h:77:8: warning: 'nocf_check' attribute ignored; use -fcf-protection to enable the attribute [-Wignored-attributes] extern __noendbr u64 ibt_save(bool disable); ^ ./arch/x86/include/asm/ibt.h:32:34: note: expanded from macro '__noendbr' ^ Signed-off-by: Daniel T. Lee --- samples/bpf/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 595b98d825ce..b32cb8a62335 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -440,7 +440,7 @@ $(obj)/%.o: $(src)/%.c -Wno-gnu-variable-sized-type-not-at-end \ -Wno-address-of-packed-member -Wno-tautological-compare \ -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \ - -fno-asynchronous-unwind-tables \ + -fno-asynchronous-unwind-tables -fcf-protection \ -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \ -O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \ $(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \ From patchwork Fri Aug 18 09:01:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357500 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF56D17FE1; Fri, 18 Aug 2023 09:01:57 +0000 (UTC) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC4A1423A; Fri, 18 Aug 2023 02:01:35 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-68872cadc7cso581944b3a.1; Fri, 18 Aug 2023 02:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349295; x=1692954095; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VVL2uL0YfoWa6hUpsOGj+GWrUBMv+KAl85kdKYemUFM=; b=Unej7sgI7UpKElD6Xjm3W80ojN4WUKKgr5bcZ2BaPa3OIPAkvW1J2KsY1/ftg2KVxq tVtCpDMKRod3+Dq+LxM7RiVr7fWIfjDOHeWHRsIHjEUMqGjVjo+iFACARphN7cYLkTyN 0hB58hrcZLDfRtuUPz3QJOV2pOaLfZNWdF27fE9vHJjrwGQtT0DNqPO1jbICUEu6cwUu d7fa4D+eZ8Q/G2JZFs6FqIQKi4/sARFqPgKuSsHhfavU/bSvpunK7SahOBibdd06jDz4 aGGxCB2E4T+/3U3Hhp5itip0oqsU9Zlf3lmgsAQlw+AwgYn9SwhdNugdmbQSrtZ5fs/B 3iog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349295; x=1692954095; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VVL2uL0YfoWa6hUpsOGj+GWrUBMv+KAl85kdKYemUFM=; b=RnSqGvd6kw43HGFl0iNaCkztJ69oCoI1WFVe81YeDwZLC5dUd/HTzu/aYqUw5VeQIg R61BNSYPmtvDrakSpCqBdyVPS2eUUUJkde5PQVESeKrSHUzhL2lqo+SOEXEssLh8G83X pX9rZquihgEY7CY3kfMFFEKDFDVkwqmZRPXx7V7hwpTQf8fu6WzFjENAxX+abdfkvfK7 Li4WKv3tLMGUZJtXRf7hggHPVMXrb9SOpaMJfxmPvrPOqe7LzxQdcBO6bQ0lRj7I35v5 kwx2N6xeOJ+mP5dsb/f832REEK+By0GucUzLa5LRbkrqucxuGuUJIoIBD3yhHifyYr73 nsoA== X-Gm-Message-State: AOJu0YywRHWixfaFsLiuxO6QcbO5yhWnXSkfkjVnAfvAkB+QgGMPqqIs RabuocNa39qLKNTD8vKgxg== X-Google-Smtp-Source: AGHT+IHf2Wd9drm5Ks37lUHzdQNY64cR+wCLztgLoJPZkd/clnY4QsiBZMiiyCIIqnAd0FQrQpsbbw== X-Received: by 2002:a05:6a20:ddaf:b0:137:53d1:3e2 with SMTP id kw47-20020a056a20ddaf00b0013753d103e2mr1853407pzb.41.1692349294731; Fri, 18 Aug 2023 02:01:34 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:01:32 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 2/9] samples/bpf: convert to vmlinux.h with tracing programs Date: Fri, 18 Aug 2023 18:01:12 +0900 Message-Id: <20230818090119.477441-3-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net This commit replaces separate headers with a single vmlinux.h to tracing programs. Thanks to that, we no longer need to define the argument structure for tracing programs directly. For example, argument for the sched_switch tracpepoint (sched_switch_args) can be replaced with the vmlinux.h provided trace_event_raw_sched_switch. Additional defines have been added to the BPF program either directly or through the inclusion of net_shared.h. Defined values are PERF_MAX_STACK_DEPTH, IFNAMSIZ constants and __stringify() macro. This change enables the BPF program to access internal structures with BTF generated "vmlinux.h" header. Signed-off-by: Daniel T. Lee --- samples/bpf/net_shared.h | 2 ++ samples/bpf/offwaketime_kern.c | 21 ++++++--------------- samples/bpf/spintest_kern.c | 10 ++++++---- samples/bpf/test_overhead_tp.bpf.c | 29 ++--------------------------- samples/bpf/tracex1_kern.c | 5 ++--- samples/bpf/tracex3_kern.c | 4 +--- samples/bpf/tracex4_kern.c | 3 +-- samples/bpf/tracex5_kern.c | 7 +++---- samples/bpf/tracex6_kern.c | 3 +-- samples/bpf/tracex7_kern.c | 3 +-- 10 files changed, 25 insertions(+), 62 deletions(-) diff --git a/samples/bpf/net_shared.h b/samples/bpf/net_shared.h index e9429af9aa44..88cc52461c98 100644 --- a/samples/bpf/net_shared.h +++ b/samples/bpf/net_shared.h @@ -17,6 +17,8 @@ #define TC_ACT_OK 0 #define TC_ACT_SHOT 2 +#define IFNAMSIZ 16 + #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define bpf_ntohs(x) __builtin_bswap16(x) diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime_kern.c index 23f12b47e9e5..8e5105811178 100644 --- a/samples/bpf/offwaketime_kern.c +++ b/samples/bpf/offwaketime_kern.c @@ -4,14 +4,15 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include -#include -#include +#include "vmlinux.h" #include -#include #include #include +#ifndef PERF_MAX_STACK_DEPTH +#define PERF_MAX_STACK_DEPTH 127 +#endif + #define _(P) \ ({ \ typeof(P) val; \ @@ -111,18 +112,8 @@ static inline int update_counts(void *ctx, u32 pid, u64 delta) #if 1 /* taken from /sys/kernel/tracing/events/sched/sched_switch/format */ -struct sched_switch_args { - unsigned long long pad; - char prev_comm[TASK_COMM_LEN]; - int prev_pid; - int prev_prio; - long long prev_state; - char next_comm[TASK_COMM_LEN]; - int next_pid; - int next_prio; -}; SEC("tracepoint/sched/sched_switch") -int oncpu(struct sched_switch_args *ctx) +int oncpu(struct trace_event_raw_sched_switch *ctx) { /* record previous thread sleep time */ u32 pid = ctx->prev_pid; diff --git a/samples/bpf/spintest_kern.c b/samples/bpf/spintest_kern.c index 455da77319d9..15740b16a3f7 100644 --- a/samples/bpf/spintest_kern.c +++ b/samples/bpf/spintest_kern.c @@ -4,14 +4,15 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include -#include +#include "vmlinux.h" #include -#include -#include #include #include +#ifndef PERF_MAX_STACK_DEPTH +#define PERF_MAX_STACK_DEPTH 127 +#endif + struct { __uint(type, BPF_MAP_TYPE_HASH); __type(key, long); @@ -60,6 +61,7 @@ SEC("kprobe/_raw_spin_lock_irq")PROG(p11) SEC("kprobe/_raw_spin_trylock")PROG(p12) SEC("kprobe/_raw_spin_lock")PROG(p13) SEC("kprobe/_raw_spin_lock_bh")PROG(p14) + /* and to inner bpf helpers */ SEC("kprobe/htab_map_update_elem")PROG(p15) SEC("kprobe/__htab_percpu_map_update_elem")PROG(p16) diff --git a/samples/bpf/test_overhead_tp.bpf.c b/samples/bpf/test_overhead_tp.bpf.c index 8b498328e961..5dc08b587978 100644 --- a/samples/bpf/test_overhead_tp.bpf.c +++ b/samples/bpf/test_overhead_tp.bpf.c @@ -8,40 +8,15 @@ #include /* from /sys/kernel/tracing/events/task/task_rename/format */ -struct task_rename { - __u64 pad; - __u32 pid; - char oldcomm[TASK_COMM_LEN]; - char newcomm[TASK_COMM_LEN]; - __u16 oom_score_adj; -}; SEC("tracepoint/task/task_rename") -int prog(struct task_rename *ctx) +int prog(struct trace_event_raw_task_rename *ctx) { return 0; } /* from /sys/kernel/tracing/events/fib/fib_table_lookup/format */ -struct fib_table_lookup { - __u64 pad; - __u32 tb_id; - int err; - int oif; - int iif; - __u8 proto; - __u8 tos; - __u8 scope; - __u8 flags; - __u8 src[4]; - __u8 dst[4]; - __u8 gw4[4]; - __u8 gw6[16]; - __u16 sport; - __u16 dport; - char name[16]; -}; SEC("tracepoint/fib/fib_table_lookup") -int prog2(struct fib_table_lookup *ctx) +int prog2(struct trace_event_raw_fib_table_lookup *ctx) { return 0; } diff --git a/samples/bpf/tracex1_kern.c b/samples/bpf/tracex1_kern.c index ef30d2b353b0..bb78bdbffa87 100644 --- a/samples/bpf/tracex1_kern.c +++ b/samples/bpf/tracex1_kern.c @@ -4,9 +4,8 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include -#include -#include +#include "vmlinux.h" +#include "net_shared.h" #include #include #include diff --git a/samples/bpf/tracex3_kern.c b/samples/bpf/tracex3_kern.c index bde6591cb20c..7cc60f10d2e5 100644 --- a/samples/bpf/tracex3_kern.c +++ b/samples/bpf/tracex3_kern.c @@ -4,10 +4,8 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include -#include +#include "vmlinux.h" #include -#include #include #include diff --git a/samples/bpf/tracex4_kern.c b/samples/bpf/tracex4_kern.c index eb0f8fdd14bf..ca826750901a 100644 --- a/samples/bpf/tracex4_kern.c +++ b/samples/bpf/tracex4_kern.c @@ -4,9 +4,8 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include +#include "vmlinux.h" #include -#include #include #include diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5_kern.c index 64a1f7550d7e..8cd697ee7047 100644 --- a/samples/bpf/tracex5_kern.c +++ b/samples/bpf/tracex5_kern.c @@ -4,15 +4,14 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#include +#include "vmlinux.h" +#include "syscall_nrs.h" #include -#include -#include #include -#include "syscall_nrs.h" #include #include +#define __stringify(x) #x #define PROG(F) SEC("kprobe/"__stringify(F)) int bpf_func_##F struct { diff --git a/samples/bpf/tracex6_kern.c b/samples/bpf/tracex6_kern.c index acad5712d8b4..6ad82e68f998 100644 --- a/samples/bpf/tracex6_kern.c +++ b/samples/bpf/tracex6_kern.c @@ -1,6 +1,5 @@ -#include +#include "vmlinux.h" #include -#include #include struct { diff --git a/samples/bpf/tracex7_kern.c b/samples/bpf/tracex7_kern.c index c5a92df8ac31..ab8d6704a5a4 100644 --- a/samples/bpf/tracex7_kern.c +++ b/samples/bpf/tracex7_kern.c @@ -1,5 +1,4 @@ -#include -#include +#include "vmlinux.h" #include #include From patchwork Fri Aug 18 09:01:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357501 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A08517FE1; Fri, 18 Aug 2023 09:02:02 +0000 (UTC) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B482A3C38; Fri, 18 Aug 2023 02:01:39 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1bee82fab5aso5431085ad.3; Fri, 18 Aug 2023 02:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349298; x=1692954098; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nR7hlSJcI/VDbkyc3cWMIqYJqOI92tz/pqZv4Rktqzo=; b=M4LiOPl+7JPgFuJFwukrLow+Vw3SWeqzqerJ+fxrDnR8VvC33r6OqoBIdTD7lFA189 WAy/n3aB4ogRrvMH1BC1zTzVmvthOjm4n+gFtUkFzhJOuYKucFk95aIvj3pCtNwAAB6G zHp4ZzackBry5tAF4iEaqp1XC4sdIHAF/dg2Sr9R1SYdG/hHbqZaRIqN2THxbbYh1IKc +IEtWsLZtukZnwfxQfs3OKPqzlf/4yW2deWSIuphvNwvLyr8Zowe/s4WNGx/D2b3Gjtm aZGc4JCAbpD6r0VirGtMHtvlU50avCSQcm4SiUwydAUvw7kuBvrkNyYXysgZxy2gXJt2 TIdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349298; x=1692954098; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nR7hlSJcI/VDbkyc3cWMIqYJqOI92tz/pqZv4Rktqzo=; b=XXYT1MoMtNbGgpd2H/1KyjA+IREN4oQGwogP9PXv8HyKDJeP2mti5xKT3gy0HjbLCP NzSYijcCuYyhNqEtlAjLJsW1kGgOrYJ8IPnIOIGAERifzhnIhqE6B1HZxhk4Wspd3ANX ZHQEOxhLQjzVrurGn4M0ECbJF/1ZO8QkGObZ6jY0YGJ7L4hX0+ITNFW8DIMYXkFavnNc KhxPpMAefEWV2VmEOMqhF0ewCNIVMo/hHfw6cxpfB0OGjLQN0fqKQZgj2r1HF/2NrO2S c74vhy1d3vDixOX6MG5Q1VxUeAzXWMuTUCzTK3PDwlH1XwCidv5Ak1/dYhq44Nm+naE4 lISg== X-Gm-Message-State: AOJu0YzUhHY9iHu0b4QEo1/mZ1sm5bhGoi9ZWn0AMd2W1gziEP4H+Egf k3HXy5fJSu7F9NOXYx6UGg== X-Google-Smtp-Source: AGHT+IE7n45xF68sI+mFXv22ohUPodCh5cj1bJF3Yfg0oPyMovpsTuLYkM2cjrvLB2w9f12gscBy7w== X-Received: by 2002:a17:903:186:b0:1b0:6e16:b92c with SMTP id z6-20020a170903018600b001b06e16b92cmr2002367plg.54.1692349298510; Fri, 18 Aug 2023 02:01:38 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:01:38 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 3/9] samples/bpf: unify bpf program suffix to .bpf with tracing programs Date: Fri, 18 Aug 2023 18:01:13 +0900 Message-Id: <20230818090119.477441-4-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net Currently, BPF programs typically have a suffix of .bpf.c. However, some programs still utilize a mixture of _kern.c suffix alongside the naming convention. In order to achieve consistency in the naming of these programs, this commit unifies the inconsistency in the naming convention of BPF kernel programs. Signed-off-by: Daniel T. Lee --- samples/bpf/Makefile | 18 +++++++++--------- .../{offwaketime_kern.c => offwaketime.bpf.c} | 0 samples/bpf/offwaketime_user.c | 2 +- .../bpf/{spintest_kern.c => spintest.bpf.c} | 0 samples/bpf/spintest_user.c | 2 +- samples/bpf/{tracex1_kern.c => tracex1.bpf.c} | 0 samples/bpf/tracex1_user.c | 2 +- samples/bpf/{tracex3_kern.c => tracex3.bpf.c} | 0 samples/bpf/tracex3_user.c | 2 +- samples/bpf/{tracex4_kern.c => tracex4.bpf.c} | 0 samples/bpf/tracex4_user.c | 2 +- samples/bpf/{tracex5_kern.c => tracex5.bpf.c} | 0 samples/bpf/tracex5_user.c | 2 +- samples/bpf/{tracex6_kern.c => tracex6.bpf.c} | 0 samples/bpf/tracex6_user.c | 2 +- samples/bpf/{tracex7_kern.c => tracex7.bpf.c} | 0 samples/bpf/tracex7_user.c | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) rename samples/bpf/{offwaketime_kern.c => offwaketime.bpf.c} (100%) rename samples/bpf/{spintest_kern.c => spintest.bpf.c} (100%) rename samples/bpf/{tracex1_kern.c => tracex1.bpf.c} (100%) rename samples/bpf/{tracex3_kern.c => tracex3.bpf.c} (100%) rename samples/bpf/{tracex4_kern.c => tracex4.bpf.c} (100%) rename samples/bpf/{tracex5_kern.c => tracex5.bpf.c} (100%) rename samples/bpf/{tracex6_kern.c => tracex6.bpf.c} (100%) rename samples/bpf/{tracex7_kern.c => tracex7.bpf.c} (100%) diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index b32cb8a62335..f90bcd3696bd 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -124,21 +124,21 @@ always-y := $(tprogs-y) always-y += sockex1_kern.o always-y += sockex2_kern.o always-y += sockex3_kern.o -always-y += tracex1_kern.o +always-y += tracex1.bpf.o always-y += tracex2.bpf.o -always-y += tracex3_kern.o -always-y += tracex4_kern.o -always-y += tracex5_kern.o -always-y += tracex6_kern.o -always-y += tracex7_kern.o +always-y += tracex3.bpf.o +always-y += tracex4.bpf.o +always-y += tracex5.bpf.o +always-y += tracex6.bpf.o +always-y += tracex7.bpf.o always-y += sock_flags.bpf.o always-y += test_probe_write_user.bpf.o always-y += trace_output.bpf.o always-y += tcbpf1_kern.o always-y += tc_l2_redirect_kern.o always-y += lathist_kern.o -always-y += offwaketime_kern.o -always-y += spintest_kern.o +always-y += offwaketime.bpf.o +always-y += spintest.bpf.o always-y += map_perf_test.bpf.o always-y += test_overhead_tp.bpf.o always-y += test_overhead_raw_tp.bpf.o @@ -333,7 +333,7 @@ $(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h $(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h $(obj)/xdp_router_ipv4_user.o: $(obj)/xdp_router_ipv4.skel.h -$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h +$(obj)/tracex5.bpf.o: $(obj)/syscall_nrs.h $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h $(obj)/hbm.o: $(src)/hbm.h $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime.bpf.c similarity index 100% rename from samples/bpf/offwaketime_kern.c rename to samples/bpf/offwaketime.bpf.c diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c index b6eedcb98fb9..5557b5393642 100644 --- a/samples/bpf/offwaketime_user.c +++ b/samples/bpf/offwaketime_user.c @@ -105,7 +105,7 @@ int main(int argc, char **argv) return 2; } - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); diff --git a/samples/bpf/spintest_kern.c b/samples/bpf/spintest.bpf.c similarity index 100% rename from samples/bpf/spintest_kern.c rename to samples/bpf/spintest.bpf.c diff --git a/samples/bpf/spintest_user.c b/samples/bpf/spintest_user.c index aadac14f748a..8c77600776fb 100644 --- a/samples/bpf/spintest_user.c +++ b/samples/bpf/spintest_user.c @@ -23,7 +23,7 @@ int main(int ac, char **argv) return 2; } - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); diff --git a/samples/bpf/tracex1_kern.c b/samples/bpf/tracex1.bpf.c similarity index 100% rename from samples/bpf/tracex1_kern.c rename to samples/bpf/tracex1.bpf.c diff --git a/samples/bpf/tracex1_user.c b/samples/bpf/tracex1_user.c index 9d4adb7fd834..8c3d9043a2b6 100644 --- a/samples/bpf/tracex1_user.c +++ b/samples/bpf/tracex1_user.c @@ -12,7 +12,7 @@ int main(int ac, char **argv) char filename[256]; FILE *f; - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); diff --git a/samples/bpf/tracex3_kern.c b/samples/bpf/tracex3.bpf.c similarity index 100% rename from samples/bpf/tracex3_kern.c rename to samples/bpf/tracex3.bpf.c diff --git a/samples/bpf/tracex3_user.c b/samples/bpf/tracex3_user.c index d5eebace31e6..1002eb0323b4 100644 --- a/samples/bpf/tracex3_user.c +++ b/samples/bpf/tracex3_user.c @@ -125,7 +125,7 @@ int main(int ac, char **argv) } } - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); diff --git a/samples/bpf/tracex4_kern.c b/samples/bpf/tracex4.bpf.c similarity index 100% rename from samples/bpf/tracex4_kern.c rename to samples/bpf/tracex4.bpf.c diff --git a/samples/bpf/tracex4_user.c b/samples/bpf/tracex4_user.c index dee8f0a091ba..a5145ad72cbf 100644 --- a/samples/bpf/tracex4_user.c +++ b/samples/bpf/tracex4_user.c @@ -53,7 +53,7 @@ int main(int ac, char **argv) char filename[256]; int map_fd, j = 0; - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); diff --git a/samples/bpf/tracex5_kern.c b/samples/bpf/tracex5.bpf.c similarity index 100% rename from samples/bpf/tracex5_kern.c rename to samples/bpf/tracex5.bpf.c diff --git a/samples/bpf/tracex5_user.c b/samples/bpf/tracex5_user.c index 9d7d79f0d47d..7e2d8397fb98 100644 --- a/samples/bpf/tracex5_user.c +++ b/samples/bpf/tracex5_user.c @@ -42,7 +42,7 @@ int main(int ac, char **argv) char filename[256]; FILE *f; - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); diff --git a/samples/bpf/tracex6_kern.c b/samples/bpf/tracex6.bpf.c similarity index 100% rename from samples/bpf/tracex6_kern.c rename to samples/bpf/tracex6.bpf.c diff --git a/samples/bpf/tracex6_user.c b/samples/bpf/tracex6_user.c index 8e83bf2a84a4..ae811ac83bc2 100644 --- a/samples/bpf/tracex6_user.c +++ b/samples/bpf/tracex6_user.c @@ -180,7 +180,7 @@ int main(int argc, char **argv) char filename[256]; int i = 0; - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); diff --git a/samples/bpf/tracex7_kern.c b/samples/bpf/tracex7.bpf.c similarity index 100% rename from samples/bpf/tracex7_kern.c rename to samples/bpf/tracex7.bpf.c diff --git a/samples/bpf/tracex7_user.c b/samples/bpf/tracex7_user.c index 8be7ce18d3ba..b10b5e03a226 100644 --- a/samples/bpf/tracex7_user.c +++ b/samples/bpf/tracex7_user.c @@ -19,7 +19,7 @@ int main(int argc, char **argv) return 0; } - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); obj = bpf_object__open_file(filename, NULL); if (libbpf_get_error(obj)) { fprintf(stderr, "ERROR: opening BPF object file failed\n"); From patchwork Fri Aug 18 09:01:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357502 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C41E017FE1; Fri, 18 Aug 2023 09:02:08 +0000 (UTC) Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA9F420F; Fri, 18 Aug 2023 02:01:43 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bd9b4f8e0eso5139075ad.1; Fri, 18 Aug 2023 02:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349302; x=1692954102; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ryam0qmIG1JK+wGjTtb7t+L4bft6WGk56DbpSc7Jykc=; b=o9kGXmDMe8yOMoEjbALPHVuwTKxQHp0tCWWDf4k3g8AQNVHB1e+Yn2FqrBq2fNc4XV ESFsPSDxrjuyzGZtDRpWgPw4EO0svRq4wQD9yGR0qNkHpJ+mV7BO1RQ/X3tGBpg21cNN sKr9QuJescl2EBoZI1gA0K1lRMi91rg8uBygYaBjrWkF55qZr2oALisCDbtYDtkzvu3q qxLeDqvzk7bB+Gftj3WDORe5rIRJH1newVSlDQeNwXb5bmIGaYey3YP3VIIsoYw/GfC7 SU0F6cc8gWIBsTOm7VFYfBFSc37Q1wBMjQZeJjO87vUkd3bVYNzRZZLDKfcINf/EAFBn JQmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349302; x=1692954102; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ryam0qmIG1JK+wGjTtb7t+L4bft6WGk56DbpSc7Jykc=; b=RGfVRBwJEE78AS84+B0EJHWrIsM1PICQK0RmHIyI970kflPnBkXG1HDwZaY2uH+8Dh 8s681C1rXEMdD4fbolidX2bYvzxDV9TTtqoSl3Pm3noEpHf7HlgDLe8iqnWFHVlHNHuR GZ0ftTtT/bCKdcbg5/8gf90A/y6nNYSMRCD+1dTlb6UDr0e2cxsztClwJHTTI7Uc3PRr IL96CV53tvOyE5HFDDN2jpWbc+QxHd1RUBJXrxGn18sGw47+kAc3j8lv0drWuyM2FUcU e00QfqSNVksWM6susUFa6JeAayG/buuw2Kjl1JjHBFLUqahLE5nkqHHq0dg4aZpuhe8M 4Cyg== X-Gm-Message-State: AOJu0Yw6pdEBKQL/EYSqXPqE1cMyInzzlu1RDb03tAeUUHGZSekhPFIO 06yxjzJapkeNJsstu0qwJUuDQMrjQ8A/ X-Google-Smtp-Source: AGHT+IFza+NwL4iyK5tpVshvAq23JHXSQZ0E7v+gJK2uQDPegTurAoeGeePeieQfAIG72dIfH39a8A== X-Received: by 2002:a17:902:d386:b0:1b6:bced:1dc2 with SMTP id e6-20020a170902d38600b001b6bced1dc2mr1660587pld.0.1692349302275; Fri, 18 Aug 2023 02:01:42 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:01:42 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 4/9] samples/bpf: fix symbol mismatch by compiler optimization Date: Fri, 18 Aug 2023 18:01:14 +0900 Message-Id: <20230818090119.477441-5-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net Currently, multiple kprobe programs are suffering from symbol mismatch due to compiler optimization. These optimizations might induce additional suffix to the symbol name such as '.isra' or '.constprop'. # egrep ' finish_task_switch| __netif_receive_skb_core' /proc/kallsyms ffffffff81135e50 t finish_task_switch.isra.0 ffffffff81dd36d0 t __netif_receive_skb_core.constprop.0 ffffffff8205cc0e t finish_task_switch.isra.0.cold ffffffff820b1aba t __netif_receive_skb_core.constprop.0.cold To avoid this, this commit replaces the original kprobe section to kprobe.multi in order to match symbol with wildcard characters. Here, asterisk is used for avoiding symbol mismatch. Signed-off-by: Daniel T. Lee --- samples/bpf/offwaketime.bpf.c | 2 +- samples/bpf/tracex1.bpf.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/bpf/offwaketime.bpf.c b/samples/bpf/offwaketime.bpf.c index 8e5105811178..3200a0f44969 100644 --- a/samples/bpf/offwaketime.bpf.c +++ b/samples/bpf/offwaketime.bpf.c @@ -118,7 +118,7 @@ int oncpu(struct trace_event_raw_sched_switch *ctx) /* record previous thread sleep time */ u32 pid = ctx->prev_pid; #else -SEC("kprobe/finish_task_switch") +SEC("kprobe.multi/finish_task_switch*") int oncpu(struct pt_regs *ctx) { struct task_struct *p = (void *) PT_REGS_PARM1(ctx); diff --git a/samples/bpf/tracex1.bpf.c b/samples/bpf/tracex1.bpf.c index bb78bdbffa87..f3be14a03964 100644 --- a/samples/bpf/tracex1.bpf.c +++ b/samples/bpf/tracex1.bpf.c @@ -22,11 +22,12 @@ * Number of arguments and their positions can change, etc. * In such case this bpf+kprobe example will no longer be meaningful */ -SEC("kprobe/__netif_receive_skb_core") +SEC("kprobe.multi/__netif_receive_skb_core*") int bpf_prog1(struct pt_regs *ctx) { /* attaches to kprobe __netif_receive_skb_core, * looks for packets on loobpack device and prints them + * (wildcard is used for avoiding symbol mismatch due to optimization) */ char devname[IFNAMSIZ]; struct net_device *dev; From patchwork Fri Aug 18 09:01:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357503 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7615E17ADD; Fri, 18 Aug 2023 09:02:10 +0000 (UTC) Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B319F3ABB; Fri, 18 Aug 2023 02:01:46 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bf092a16c9so5782695ad.0; Fri, 18 Aug 2023 02:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349306; x=1692954106; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KKKH8lOOWJx5/wwDW5pWYlJrkLRfMTfmu5uoSiIad0c=; b=I2/h1pJ0aV5ha+41pSS7wq1kGNdK00+za19KiMELXEjAi1l5eyFvTZKX3swGbtxxCU qsY5GV9vlvf9H1s2ZGKWA5MESNQmpTzq2FQcdx+dXFsEFKyCoHzIg4cMCsFDsx+E27+b uaVzs3/2bIUslnlb+gcoCNpZ37Lz4f+DYRnc1p2rGRHnhbV9VvsIarAT4Z7a29RPf0Hd Tx7FbgX3iJ8043jK7GYqv8fTZUkVko4BB/VlHZYANePHwKWk8mDlQEov/oKbCNb8KZqv F9ffycIa0q+a4vlPoXx7zPFiO6maYVNhc3z2QFjpYmCqK2/MbPj+e7WagW2KVNDm3TVC 6RVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349306; x=1692954106; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KKKH8lOOWJx5/wwDW5pWYlJrkLRfMTfmu5uoSiIad0c=; b=LmaKtuxDwZUb50YKICkUES9g0SUJkxh0GdCrsu9QRN6UiC8/BZA3k/KafH878h2WfD DyLTkB/Lgm7zghn9yT0wARKKIB5us/i4hPCCo0CRc0a1x4NCwtmIb+EgJ3iMWUCiFekc 8YX2+ZQN0lkydQgbRcj5w4svbGmgwg1cORqA/nONCvtKHOdvUynoPQ+ovtKAGE7Q8ulD ucAyIRcgLdUeNWorLHdzN4bUYj7xzW7VL6YO9Eda+FbDLY+JWYRNI0l6XimB+CRyNwQw 02aUqa6eFrFZBGXKvSljOE8a+1k9UIUYz/3l+PyfDhs4CnkiOOIavdHcmOJrBr7H15ov iikw== X-Gm-Message-State: AOJu0YwxMZWXrwF17IiDv89siIbL19og66nRisDl/DmtjLN6Z7pwZKIE +SQv7fjmVOWz7A1VxRNd2A== X-Google-Smtp-Source: AGHT+IEw/kgz4tTPYWkxWZNPPLXh5DO3suEd+KWXRjF8BGZ1VAgTCgljptPPQpJG09CIEkAGYTlyUg== X-Received: by 2002:a17:903:32c7:b0:1bc:2d43:c747 with SMTP id i7-20020a17090332c700b001bc2d43c747mr2347499plr.38.1692349306057; Fri, 18 Aug 2023 02:01:46 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:01:45 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 5/9] samples/bpf: make tracing programs to be more CO-RE centric Date: Fri, 18 Aug 2023 18:01:15 +0900 Message-Id: <20230818090119.477441-6-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net The existing tracing programs have been developed for a considerable period of time and, as a result, do not properly incorporate the features of the current libbpf, such as CO-RE. This is evident in frequent usage of functions like PT_REGS* and the persistence of "hack" methods using underscore-style bpf_probe_read_kernel from the past. These programs are far behind the current level of libbpf and can potentially confuse users. Therefore, this commit aims to convert the outdated BPF programs to be more CO-RE centric. Signed-off-by: Daniel T. Lee --- samples/bpf/offwaketime.bpf.c | 18 +++++------------- samples/bpf/test_overhead_kprobe.bpf.c | 20 +++++++------------- samples/bpf/tracex1.bpf.c | 17 +++++------------ samples/bpf/tracex5.bpf.c | 5 +++-- 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/samples/bpf/offwaketime.bpf.c b/samples/bpf/offwaketime.bpf.c index 3200a0f44969..5f008f328836 100644 --- a/samples/bpf/offwaketime.bpf.c +++ b/samples/bpf/offwaketime.bpf.c @@ -8,18 +8,12 @@ #include #include #include +#include #ifndef PERF_MAX_STACK_DEPTH #define PERF_MAX_STACK_DEPTH 127 #endif -#define _(P) \ - ({ \ - typeof(P) val; \ - bpf_probe_read_kernel(&val, sizeof(val), &(P)); \ - val; \ - }) - #define MINBLOCK_US 1 #define MAX_ENTRIES 10000 @@ -68,11 +62,9 @@ struct { SEC("kprobe/try_to_wake_up") int waker(struct pt_regs *ctx) { - struct task_struct *p = (void *) PT_REGS_PARM1(ctx); + struct task_struct *p = (void *)PT_REGS_PARM1_CORE(ctx); + u32 pid = BPF_CORE_READ(p, pid); struct wokeby_t woke; - u32 pid; - - pid = _(p->pid); bpf_get_current_comm(&woke.name, sizeof(woke.name)); woke.ret = bpf_get_stackid(ctx, &stackmap, STACKID_FLAGS); @@ -121,9 +113,9 @@ int oncpu(struct trace_event_raw_sched_switch *ctx) SEC("kprobe.multi/finish_task_switch*") int oncpu(struct pt_regs *ctx) { - struct task_struct *p = (void *) PT_REGS_PARM1(ctx); + struct task_struct *p = (void *)PT_REGS_PARM1_CORE(ctx); /* record previous thread sleep time */ - u32 pid = _(p->pid); + u32 pid = BPF_CORE_READ(p, pid); #endif u64 delta, ts, *tsp; diff --git a/samples/bpf/test_overhead_kprobe.bpf.c b/samples/bpf/test_overhead_kprobe.bpf.c index c3528731e0e1..668cf5259c60 100644 --- a/samples/bpf/test_overhead_kprobe.bpf.c +++ b/samples/bpf/test_overhead_kprobe.bpf.c @@ -8,13 +8,7 @@ #include #include #include - -#define _(P) \ - ({ \ - typeof(P) val = 0; \ - bpf_probe_read_kernel(&val, sizeof(val), &(P)); \ - val; \ - }) +#include SEC("kprobe/__set_task_comm") int prog(struct pt_regs *ctx) @@ -26,14 +20,14 @@ int prog(struct pt_regs *ctx) u16 oom_score_adj; u32 pid; - tsk = (void *)PT_REGS_PARM1(ctx); + tsk = (void *)PT_REGS_PARM1_CORE(ctx); - pid = _(tsk->pid); - bpf_probe_read_kernel_str(oldcomm, sizeof(oldcomm), &tsk->comm); - bpf_probe_read_kernel_str(newcomm, sizeof(newcomm), + pid = BPF_CORE_READ(tsk, pid); + bpf_core_read_str(oldcomm, sizeof(oldcomm), &tsk->comm); + bpf_core_read_str(newcomm, sizeof(newcomm), (void *)PT_REGS_PARM2(ctx)); - signal = _(tsk->signal); - oom_score_adj = _(signal->oom_score_adj); + signal = BPF_CORE_READ(tsk, signal); + oom_score_adj = BPF_CORE_READ(signal, oom_score_adj); return 0; } diff --git a/samples/bpf/tracex1.bpf.c b/samples/bpf/tracex1.bpf.c index f3be14a03964..889bed5480ac 100644 --- a/samples/bpf/tracex1.bpf.c +++ b/samples/bpf/tracex1.bpf.c @@ -8,15 +8,9 @@ #include "net_shared.h" #include #include +#include #include -#define _(P) \ - ({ \ - typeof(P) val = 0; \ - bpf_probe_read_kernel(&val, sizeof(val), &(P)); \ - val; \ - }) - /* kprobe is NOT a stable ABI * kernel functions can be removed, renamed or completely change semantics. * Number of arguments and their positions can change, etc. @@ -34,12 +28,11 @@ int bpf_prog1(struct pt_regs *ctx) struct sk_buff *skb; int len; - /* non-portable! works for the given kernel only */ - bpf_probe_read_kernel(&skb, sizeof(skb), (void *)PT_REGS_PARM1(ctx)); - dev = _(skb->dev); - len = _(skb->len); + bpf_core_read(&skb, sizeof(skb), (void *)PT_REGS_PARM1(ctx)); + dev = BPF_CORE_READ(skb, dev); + len = BPF_CORE_READ(skb, len); - bpf_probe_read_kernel(devname, sizeof(devname), dev->name); + BPF_CORE_READ_STR_INTO(&devname, dev, name); if (devname[0] == 'l' && devname[1] == 'o') { char fmt[] = "skb %p len %d\n"; diff --git a/samples/bpf/tracex5.bpf.c b/samples/bpf/tracex5.bpf.c index 8cd697ee7047..4d3d6c9b25fa 100644 --- a/samples/bpf/tracex5.bpf.c +++ b/samples/bpf/tracex5.bpf.c @@ -10,6 +10,7 @@ #include #include #include +#include #define __stringify(x) #x #define PROG(F) SEC("kprobe/"__stringify(F)) int bpf_func_##F @@ -46,7 +47,7 @@ PROG(SYS__NR_write)(struct pt_regs *ctx) { struct seccomp_data sd; - bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx)); + bpf_core_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx)); if (sd.args[2] == 512) { char fmt[] = "write(fd=%d, buf=%p, size=%d)\n"; bpf_trace_printk(fmt, sizeof(fmt), @@ -59,7 +60,7 @@ PROG(SYS__NR_read)(struct pt_regs *ctx) { struct seccomp_data sd; - bpf_probe_read_kernel(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx)); + bpf_core_read(&sd, sizeof(sd), (void *)PT_REGS_PARM2(ctx)); if (sd.args[2] > 128 && sd.args[2] <= 1024) { char fmt[] = "read(fd=%d, buf=%p, size=%d)\n"; bpf_trace_printk(fmt, sizeof(fmt), From patchwork Fri Aug 18 09:01:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357504 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 409EA182BD; Fri, 18 Aug 2023 09:02:13 +0000 (UTC) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AF243C0C; Fri, 18 Aug 2023 02:01:50 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1bc3d94d40fso5587725ad.3; Fri, 18 Aug 2023 02:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349310; x=1692954110; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vEdCdiPpMNFfDPKVrW4rvndg+m3lfoeDTBZC/Rf1A+E=; b=g6I+KP+fbsBxcLLRNdgxN1Yg/swl1XiRKIlNajh8ZcVL8TAigeyYiHFglOoxpAJuGu EdQ74cuS1CVjWpX/b3EY3wvHSbPX6lccnIo4Txp83ySSEyKHPj7FJfgS3gNCMJ3etn0k i4QdPqd/nhsiZRY0q/JRt0QCuvO971Lfdp7WfjLhVp376D/q+h/sMUPQYObsgTeDhUE3 0cLdyxdbZgjycfZe1Jqudy1GNqzY7HCgkTAl2TFtP61Qmm1yvrQxD7AiBOXHL4NkAg9Z uGV9VJ4DmU2SP3iUHY2wUrzEmD1Oegb5gQt24oZHkljnukFKrrlAMx51RLY3Qch7Rp8K 9V3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349310; x=1692954110; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vEdCdiPpMNFfDPKVrW4rvndg+m3lfoeDTBZC/Rf1A+E=; b=LnCH/CotUJFJ3uesogwnyuizv2lAnyGB6sGL+6SVVQ3gaL0IlSXsD8tu74PiRILHDy +ZuXfkNDVQMFq8K9nlup3HaA1VTcd/YlBzYF3TlQ4ga69KUBCwkVUK9ia2xs448fIIXC yXma8y7cLrQTsGTIXJuCHm6XHUTcTUZYeFZjPmtX6o6NUnZ/Wnj2YvHjWAr4GyoVwPZM e1N6fri+HGvgVwNVZKQ6jqbpHEIKDLX7VZ/SJIuotgrL2qSBQQrCPJWb8550CbnokRiw D1ck6Fl/5ZImABlR3LYXefRU5JI/iNhuJrAL7wULiJkA9/tNf6dyLTxLC9wQ/SinTR3f 33eg== X-Gm-Message-State: AOJu0Yz1pWq7Q2ggUOpRoxrcOVflhKDI1igF28sgOgK/MBw1hAfUKam1 l5SqzI325V3obQsX8P/aoA== X-Google-Smtp-Source: AGHT+IFIQLB92lb8IM8DCXjuimWo3DdFYmTPBxeWk0u/kyYHhSrWL07SkLn5G+Sijm7Dhif2f7Dhdw== X-Received: by 2002:a17:902:f545:b0:1bb:7f71:df43 with SMTP id h5-20020a170902f54500b001bb7f71df43mr2325897plf.34.1692349309755; Fri, 18 Aug 2023 02:01:49 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:01:49 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 6/9] samples/bpf: fix bio latency check with tracepoint Date: Fri, 18 Aug 2023 18:01:16 +0900 Message-Id: <20230818090119.477441-7-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net Recently, a new tracepoint for the block layer, specifically the block_io_start/done tracepoints, was introduced in commit 5a80bd075f3b ("block: introduce block_io_start/block_io_done tracepoints"). Previously, the kprobe entry used for this purpose was quite unstable and inherently broke relevant probes [1]. Now that a stable tracepoint is available, this commit replaces the bio latency check with it. One of the changes made during this replacement is the key used for the hash table. Since 'struct request' cannot be used as a hash key, the approach taken follows that which was implemented in bcc/biolatency [2]. (uses dev:sector for the key) [1]: https://github.com/iovisor/bcc/issues/4261 [2]: https://github.com/iovisor/bcc/pull/4691 Fixes: 450b7879e345 ("block: move blk_account_io_{start,done} to blk-mq.c") Signed-off-by: Daniel T. Lee --- samples/bpf/tracex3.bpf.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/samples/bpf/tracex3.bpf.c b/samples/bpf/tracex3.bpf.c index 7cc60f10d2e5..41f37966f5f5 100644 --- a/samples/bpf/tracex3.bpf.c +++ b/samples/bpf/tracex3.bpf.c @@ -9,6 +9,12 @@ #include #include +struct start_key { + dev_t dev; + u32 _pad; + sector_t sector; +}; + struct { __uint(type, BPF_MAP_TYPE_HASH); __type(key, long); @@ -16,16 +22,17 @@ struct { __uint(max_entries, 4096); } my_map SEC(".maps"); -/* kprobe is NOT a stable ABI. If kernel internals change this bpf+kprobe - * example will no longer be meaningful - */ -SEC("kprobe/blk_mq_start_request") -int bpf_prog1(struct pt_regs *ctx) +/* from /sys/kernel/tracing/events/block/block_io_start/format */ +SEC("tracepoint/block/block_io_start") +int bpf_prog1(struct trace_event_raw_block_rq *ctx) { - long rq = PT_REGS_PARM1(ctx); u64 val = bpf_ktime_get_ns(); + struct start_key key = { + .dev = ctx->dev, + .sector = ctx->sector + }; - bpf_map_update_elem(&my_map, &rq, &val, BPF_ANY); + bpf_map_update_elem(&my_map, &key, &val, BPF_ANY); return 0; } @@ -47,21 +54,26 @@ struct { __uint(max_entries, SLOTS); } lat_map SEC(".maps"); -SEC("kprobe/__blk_account_io_done") -int bpf_prog2(struct pt_regs *ctx) +/* from /sys/kernel/tracing/events/block/block_io_done/format */ +SEC("tracepoint/block/block_io_done") +int bpf_prog2(struct trace_event_raw_block_rq *ctx) { - long rq = PT_REGS_PARM1(ctx); + struct start_key key = { + .dev = ctx->dev, + .sector = ctx->sector + }; + u64 *value, l, base; u32 index; - value = bpf_map_lookup_elem(&my_map, &rq); + value = bpf_map_lookup_elem(&my_map, &key); if (!value) return 0; u64 cur_time = bpf_ktime_get_ns(); u64 delta = cur_time - *value; - bpf_map_delete_elem(&my_map, &rq); + bpf_map_delete_elem(&my_map, &key); /* the lines below are computing index = log10(delta)*10 * using integer arithmetic From patchwork Fri Aug 18 09:01:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357505 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DF0F15495; Fri, 18 Aug 2023 09:02:16 +0000 (UTC) Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F1174212; Fri, 18 Aug 2023 02:01:54 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-26b67b38b61so516580a91.0; Fri, 18 Aug 2023 02:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349314; x=1692954114; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4Xh8zEASjOId61d0T5CzTHeLfy4NYBbHm3OIzjsyLyM=; b=garpmHfp1NZCFs/JGbYM/LzyY6xj24XU1oIHsUXC4RWhiqbioDh0610x+iB6nmPMqR xRQdZ9yMIXi2Mf+LIFDH3DbnIYKl0VMpVUr0DNYVrkZoKhhyHCV0Yl4Ew6hN6MjS+UUb 4mW2oaQlb3EzDeJmznB3tcrVA4YQtI6wM0+iEI8ObbsL8Ke1FSK6iyK+EH8lZIGfVAwK JRuOCbTHB0yw/oRkYCc/q9AEQopMh0aJwLBN2eC13dkt5octs92N9zczWc6DMiMXcrTT PVDvCEwDR80mgQzpY4/g8MiB0FSGDJqlfuK15dpPMAt44qDP/z+Uy0NTUUSSJXArijlc bNNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349314; x=1692954114; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Xh8zEASjOId61d0T5CzTHeLfy4NYBbHm3OIzjsyLyM=; b=XsWZ6nBNtOgb4jVpJDkZpKBiAmfNWGx5FR9b/NH7rFqYbcqnJx9H0y/xqOdrcLurXo LLZ9CVyIu6oXX3AsQVld5ptmj4ApiIbGDF/Eq51brV6oTnk94AdEYzFgpkWY8UKjZnpA 7SvR/N7w05RFh6+zUzGPMmVIzucBqpNQQwuV8nlyYVo/+LDcuj26HpMPjWtk4aw6foiO /5hlzUM0K8c/ELavpTeSZhJrizrLr9mKGvb5rQnJGyW4eiN2lNda+WuyQAfspoYjH2v7 7Rh3XjTc4OCfAcjkZj2Ve2utyYfHVf3BwcTNLsf3FVO6i/JNy9FC1Ww5Tae8Gz8P8znj xSZg== X-Gm-Message-State: AOJu0YyMw/JlVgSbegNKzHXgPrbycUGJY8vmXT5BAspsP4Q11p9QTfYM NZ+/PO0jINTbB5p0K7FgYA== X-Google-Smtp-Source: AGHT+IGN+3ucFRLwemRnZTvByU1P9GwVZMCEuN32TdWOIqDNxPrK00ULfaAkPhH/RoFQSU/OVUg0ow== X-Received: by 2002:a17:90a:2e0b:b0:268:3f6d:9751 with SMTP id q11-20020a17090a2e0b00b002683f6d9751mr1804960pjd.23.1692349313682; Fri, 18 Aug 2023 02:01:53 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:01:53 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 7/9] samples/bpf: fix broken map lookup probe Date: Fri, 18 Aug 2023 18:01:17 +0900 Message-Id: <20230818090119.477441-8-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net In the commit 7c4cd051add3 ("bpf: Fix syscall's stackmap lookup potential deadlock"), a potential deadlock issue was addressed, which resulted in *_map_lookup_elem not triggering BPF programs. (prior to lookup, bpf_disable_instrumentation() is used) To resolve the broken map lookup probe using "htab_map_lookup_elem", this commit introduces an alternative approach. Instead, it utilize "bpf_map_copy_value" and apply a filter specifically for the hash table with map_type. Signed-off-by: Daniel T. Lee Fixes: 7c4cd051add3 ("bpf: Fix syscall's stackmap lookup potential deadlock") --- samples/bpf/tracex6.bpf.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/samples/bpf/tracex6.bpf.c b/samples/bpf/tracex6.bpf.c index 6ad82e68f998..9b23b4737cfb 100644 --- a/samples/bpf/tracex6.bpf.c +++ b/samples/bpf/tracex6.bpf.c @@ -1,6 +1,8 @@ #include "vmlinux.h" #include #include +#include +#include struct { __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); @@ -44,13 +46,24 @@ int bpf_prog1(struct pt_regs *ctx) return 0; } -SEC("kprobe/htab_map_lookup_elem") -int bpf_prog2(struct pt_regs *ctx) +/* + * Since *_map_lookup_elem can't be expected to trigger bpf programs + * due to potential deadlocks (bpf_disable_instrumentation), this bpf + * program will be attached to bpf_map_copy_value (which is called + * from map_lookup_elem) and will only filter the hashtable type. + */ +SEC("kprobe/bpf_map_copy_value") +int BPF_KPROBE(bpf_prog2, struct bpf_map *map) { u32 key = bpf_get_smp_processor_id(); struct bpf_perf_event_value *val, buf; + enum bpf_map_type type; int error; + type = BPF_CORE_READ(map, map_type); + if (type != BPF_MAP_TYPE_HASH) + return 0; + error = bpf_perf_event_read_value(&counters, key, &buf, sizeof(buf)); if (error) return 0; From patchwork Fri Aug 18 09:01:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357506 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8C0DEAF1; Fri, 18 Aug 2023 09:02:20 +0000 (UTC) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772333C1F; Fri, 18 Aug 2023 02:01:59 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-688787570ccso544676b3a.2; Fri, 18 Aug 2023 02:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349318; x=1692954118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Irt04AQu1gp3FwbXYU0fkFCp791Xhi8XCApG3i3VWJM=; b=ntuVfYW1LpyPRTB8Xz8BFHsz6wyQaqZRA2IZqtrZ0JbjTrLsdKblRbwd0TGQu6B85l Ph4EomQPkRqZHnBt0MrxWO4siN/BMGqKuJcK+k07QII20aq46hmns6an7ajwWMBFi6aB Ac0nNgYWGuzKnFF8tTk1wazzShGH1ukF8/SyCBvlJzdup9vrSs+9G8yc7DqQ5qPTzKHZ /acU+H5/hApwc5kTHX9xxDpPYrXBjsxnzNXi8PKF3I+SXlZgADGikGyaHCvpb+KPvUNu 9iiuLYMLzqarl8PCbor3unRB8X9oKk8bHxadd1TFuYVaZtjHslefJaqDquX4ICA0ip1a a/UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349318; x=1692954118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Irt04AQu1gp3FwbXYU0fkFCp791Xhi8XCApG3i3VWJM=; b=XS24/aMIn15uzgf7G705PvZb/jgs/WJToYhX8BAEnSNh7ocJUyexK9CaGG0mmgkcW6 xuzTS51jS4/EI3/QqF3HI4wxHh20EZ5vNox8eCxsEicHNI2xt6aMRZTlF2SqjZYULrMN hHXIS+Q2tJnEtAq0TN+RaCrxCMZgotSzzp2NyWVQYsgoKDOgI6SZZaDWv08vgS9YCYVK jTrp8npHU3oq2xUKKpExpvjCCMRYrEMFxlv4CuN4UzNkacimXvB8FKNP25hPPIA3eCHb YU3B1OGW05xFYcZZcdq2c5kpNjmrAkwKna9CbxHmjwBd9WRUQ4R9JEjJUmNDi+PbDr3I uaKw== X-Gm-Message-State: AOJu0YwjgCA1/JvBgv0Fmz92aUmPHwaV8fEkMxLUHdepyCqOyajrY7EF hbwqDqjeEBPxR6vkJHuXPw== X-Google-Smtp-Source: AGHT+IFJ3IQk8E72MQPJUd7OYtCrSA90dWlqDqIzRYy8Pm9Tah1Qn2g43Y1Wsc2NraPcm5r1lBKI8w== X-Received: by 2002:a05:6a20:8f28:b0:11f:4707:7365 with SMTP id b40-20020a056a208f2800b0011f47077365mr2567785pzk.38.1692349317681; Fri, 18 Aug 2023 02:01:57 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:01:57 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 8/9] samples/bpf: refactor syscall tracing programs using BPF_KSYSCALL macro Date: Fri, 18 Aug 2023 18:01:18 +0900 Message-Id: <20230818090119.477441-9-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net This commit refactors the syscall tracing programs by adopting the BPF_KSYSCALL macro. This change aims to enhance the clarity and simplicity of the BPF programs by reducing the complexity of argument parsing from pt_regs. Signed-off-by: Daniel T. Lee --- samples/bpf/test_map_in_map.bpf.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/samples/bpf/test_map_in_map.bpf.c b/samples/bpf/test_map_in_map.bpf.c index 1883559e5977..9f030f9c4e1b 100644 --- a/samples/bpf/test_map_in_map.bpf.c +++ b/samples/bpf/test_map_in_map.bpf.c @@ -103,19 +103,15 @@ static __always_inline int do_inline_hash_lookup(void *inner_map, u32 port) return result ? *result : -ENOENT; } -SEC("kprobe/__sys_connect") -int trace_sys_connect(struct pt_regs *ctx) +SEC("ksyscall/connect") +int BPF_KSYSCALL(trace_sys_connect, unsigned int fd, struct sockaddr_in6 *in6, int addrlen) { - struct sockaddr_in6 *in6; u16 test_case, port, dst6[8]; - int addrlen, ret, inline_ret, ret_key = 0; + int ret, inline_ret, ret_key = 0; u32 port_key; void *outer_map, *inner_map; bool inline_hash = false; - in6 = (struct sockaddr_in6 *)PT_REGS_PARM2_CORE(ctx); - addrlen = (int)PT_REGS_PARM3_CORE(ctx); - if (addrlen != sizeof(*in6)) return 0; From patchwork Fri Aug 18 09:01:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 13357507 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D62C18AFB; Fri, 18 Aug 2023 09:02:28 +0000 (UTC) Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1F8B30E6; Fri, 18 Aug 2023 02:02:05 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bdc8081147so12820445ad.1; Fri, 18 Aug 2023 02:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692349321; x=1692954121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1bdHXPT29PLcOi1vozCQ/EzZC5w7NFhRztdG1ykd4oE=; b=nsCgvHiP+FrG/IK1ExNqDBiNFM+CpDi9hpD3yi8xjmyoW1rIiMgslaR8UHU/UUltyT sEZydwK+IcMh8xII60zHmRnqiGu26aeTEmjrNyyIu9X5sp8YAgPmMLUtXl+TH4YKzE7+ LWn5WFE8jpeSMMdVjj1+LOrMMJcFnVihNCgYnowgeivWDH7L9A4p/FX1FK0kp+bjvKvr DMY/Ic+gX0PA4AI+SxDWxvuyFi+hU3CF7Nx7YGfcmvw9ndFS+p0ICLxfhDdc4k02qGu6 4nGaoKafwTOfG/2KcqnCcWZ+tqz8H5mOZvS5QrUTl1IHNENsZXnQzr2aiWZb8Tdj1jub 9SDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692349321; x=1692954121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1bdHXPT29PLcOi1vozCQ/EzZC5w7NFhRztdG1ykd4oE=; b=V9PxDZsqOQjp3GyoFzpSy15rKPLewwGe2sSmPPfXVCpl/npO8508YSDLKiZsbhKa4p 4YIJYQeB7xoXjNiJvckwkNfPq/nXcP4+RvdSeU/7vRLnHtax6zTvNnVQAdxD9A9l3arb gJv19LbASlfbMG1hRtMPhSqgjp1yA8LcXZSrK3JPbKLBn7oxJrpQRvVYMHxVeFb99MIO oN0cgYzXfHQtod+rhd0sJinNkRTdPmna686Mavwv6jxN3v00brYgQi0+klIz/C7VFMMK fwHIjEqmLFsg6qUgOjNnOBMXwNSeCG7ZvOizFm5pX/lnh3U88V7T+irZiJaInOiv095G bIMA== X-Gm-Message-State: AOJu0YxbiAQm3SxJWFCRIsPO1OIrgMnlG12T00hhcXAEULuipC93OjsB hcB70Z70zb11pFp/AMJ41A== X-Google-Smtp-Source: AGHT+IE5EJZwZG81iNI9tvl+TF4KG5vD6y6dzBIGtxQwwckSkdZXBECEjPKWwnrC/um6iI2PErCx7Q== X-Received: by 2002:a17:902:db05:b0:1be:e851:c076 with SMTP id m5-20020a170902db0500b001bee851c076mr2951149plx.27.1692349321496; Fri, 18 Aug 2023 02:02:01 -0700 (PDT) Received: from dell-sscc.. ([114.71.48.94]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b001b89045ff03sm1217130plb.233.2023.08.18.02.01.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 02:02:01 -0700 (PDT) From: "Daniel T. Lee" To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jens Axboe , Johannes Thumshirn , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [bpf-next 9/9] samples/bpf: simplify spintest with kprobe.multi Date: Fri, 18 Aug 2023 18:01:19 +0900 Message-Id: <20230818090119.477441-10-danieltimlee@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818090119.477441-1-danieltimlee@gmail.com> References: <20230818090119.477441-1-danieltimlee@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net With the introduction of kprobe.multi, it is now possible to attach multiple kprobes to a single BPF program without the need for multiple definitions. Additionally, this method supports wildcard-based matching, allowing for further simplification of BPF programs. In here, an asterisk (*) wildcard is used to map to all symbols relevant to spin_{lock|unlock}. Furthermore, since kprobe.multi handles symbol matching, this commit eliminates the need for the previous logic of reading the ksym table to verify the existence of symbols. Signed-off-by: Daniel T. Lee --- samples/bpf/spintest.bpf.c | 17 +++-------------- samples/bpf/spintest_user.c | 22 +++++++--------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/samples/bpf/spintest.bpf.c b/samples/bpf/spintest.bpf.c index 15740b16a3f7..cba5a9d50783 100644 --- a/samples/bpf/spintest.bpf.c +++ b/samples/bpf/spintest.bpf.c @@ -47,20 +47,9 @@ int foo(struct pt_regs *ctx) \ } /* add kprobes to all possible *spin* functions */ -SEC("kprobe/spin_unlock")PROG(p1) -SEC("kprobe/spin_lock")PROG(p2) -SEC("kprobe/mutex_spin_on_owner")PROG(p3) -SEC("kprobe/rwsem_spin_on_owner")PROG(p4) -SEC("kprobe/spin_unlock_irqrestore")PROG(p5) -SEC("kprobe/_raw_spin_unlock_irqrestore")PROG(p6) -SEC("kprobe/_raw_spin_unlock_bh")PROG(p7) -SEC("kprobe/_raw_spin_unlock")PROG(p8) -SEC("kprobe/_raw_spin_lock_irqsave")PROG(p9) -SEC("kprobe/_raw_spin_trylock_bh")PROG(p10) -SEC("kprobe/_raw_spin_lock_irq")PROG(p11) -SEC("kprobe/_raw_spin_trylock")PROG(p12) -SEC("kprobe/_raw_spin_lock")PROG(p13) -SEC("kprobe/_raw_spin_lock_bh")PROG(p14) +SEC("kprobe.multi/spin_*lock*")PROG(spin_lock) +SEC("kprobe.multi/*_spin_on_owner")PROG(spin_on_owner) +SEC("kprobe.multi/_raw_spin_*lock*")PROG(raw_spin_lock) /* and to inner bpf helpers */ SEC("kprobe/htab_map_update_elem")PROG(p15) diff --git a/samples/bpf/spintest_user.c b/samples/bpf/spintest_user.c index 8c77600776fb..55971edb1088 100644 --- a/samples/bpf/spintest_user.c +++ b/samples/bpf/spintest_user.c @@ -9,13 +9,12 @@ int main(int ac, char **argv) { - char filename[256], symbol[256]; struct bpf_object *obj = NULL; struct bpf_link *links[20]; long key, next_key, value; struct bpf_program *prog; int map_fd, i, j = 0; - const char *section; + char filename[256]; struct ksym *sym; if (load_kallsyms()) { @@ -44,20 +43,13 @@ int main(int ac, char **argv) } bpf_object__for_each_program(prog, obj) { - section = bpf_program__section_name(prog); - if (sscanf(section, "kprobe/%s", symbol) != 1) - continue; - - /* Attach prog only when symbol exists */ - if (ksym_get_addr(symbol)) { - links[j] = bpf_program__attach(prog); - if (libbpf_get_error(links[j])) { - fprintf(stderr, "bpf_program__attach failed\n"); - links[j] = NULL; - goto cleanup; - } - j++; + links[j] = bpf_program__attach(prog); + if (libbpf_get_error(links[j])) { + fprintf(stderr, "bpf_program__attach failed\n"); + links[j] = NULL; + goto cleanup; } + j++; } for (i = 0; i < 5; i++) {