From nobody Thu Apr 9 06:21:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A0E0C4332F for ; Thu, 3 Nov 2022 04:55:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230340AbiKCEzD (ORCPT ); Thu, 3 Nov 2022 00:55:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230324AbiKCEy5 (ORCPT ); Thu, 3 Nov 2022 00:54:57 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8514917E0C for ; Wed, 2 Nov 2022 21:54:56 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id h67-20020a252146000000b006ccc4702068so1115879ybh.12 for ; Wed, 02 Nov 2022 21:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gJ2um6c1slJC7mFKEqkDgLoAnh4NP6kllgPCGRDYU3g=; b=DHyGb7HoSpr040k5uJEFe9wBkt7167do1UmLynLyH7i9mUWinY5NVyCMyuqvQ6OmKV CLT34lD3Qc+ttTZ7chOOm6AemNbVfckUEOf69YpqGwJHWYoe93kMc81jnE+V+Qj8QqYb Op/jfokAzEDmJ0O0W6nxvl8uFLmiFLP+9i/M8tpBMw4ELp/aMj9fVvh2uh31hrFNBPPk PofLimqurLiDI2/PR5lOLinOb8luvpM1Wx+1fx3x3KcfNjBdvTecU73Irv1hINeW7BPf 4BX9pJDUv5OJnKYWOm5tpG8O7ha+CpAA1DlHTpFW50iYnOek9wIPRD1C7Hph1lKkf5T3 ReNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gJ2um6c1slJC7mFKEqkDgLoAnh4NP6kllgPCGRDYU3g=; b=sVe/IUUv1MLwhp3/EjigbPPv8V8bb4+HlDSdD4cexsPCqPweTB8r7EJfvj8riIBXqx GgC/tX84XNa/JGH5ECuQiQUvpU+4oQ0fjK5D2lDR49iAKxvq70jhmqZ94b39mCzhOFGn rPc+92NV/41Ko+0hXRuPYnXCbyA1Il7l7CJMeHFsgFz7qhKg3HUSUK7IdSa3cCAPG+Hy UesOprwJhpZrUvxN3OL29baf7WPFCPSx3qDYwp6z4KRUbwajzNYGLPuielCds54tLhUB BZYQ3XjwvnYwfKTD9kAotLX5XnguBULrJQTmLQdfqpcjiAwOkvhcdrXs9FJcV/DRBe1N w3DQ== X-Gm-Message-State: ACrzQf3aGO2qaEmIHjlbDosHiYSX0A2h6VaIKZ+nRsdPfJBV3bqdxcc+ C/CaLG9JdesImNmxgM281z63DwUGuzkX X-Google-Smtp-Source: AMsMyM41EYdW4Fepyy6eE2wThz3USEHotnrEX8Xm3fBADOLCi7moleXHTwl3G2eXvoHch9hyWyr2Kvrhoog+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:8a9d:7f38:6465:2d7b]) (user=irogers job=sendgmr) by 2002:a0d:f9c2:0:b0:36f:9950:c456 with SMTP id j185-20020a0df9c2000000b0036f9950c456mr180239ywf.338.1667451295275; Wed, 02 Nov 2022 21:54:55 -0700 (PDT) Date: Wed, 2 Nov 2022 21:54:31 -0700 In-Reply-To: <20221103045437.163510-1-irogers@google.com> Message-Id: <20221103045437.163510-2-irogers@google.com> Mime-Version: 1.0 References: <20221103045437.163510-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Subject: [PATCH v1 1/7] perf trace: Raw augmented syscalls fix libbpf 1.0+ compatibility From: Ian Rogers To: Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Don't use deprecated and now broken map style. Avoid use of tools/perf/include/bpf/bpf.h and use the more regular BPF headers. Signed-off-by: Ian Rogers --- .../examples/bpf/augmented_raw_syscalls.c | 75 ++++++++++++++----- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/= examples/bpf/augmented_raw_syscalls.c index a262dcd020f4..13c72fd602c3 100644 --- a/tools/perf/examples/bpf/augmented_raw_syscalls.c +++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c @@ -14,13 +14,19 @@ * code that will combine entry/exit in a strace like way. */ =20 -#include +#include +#include #include -#include -#include +#include +#include =20 /* bpf-output associated map */ -bpf_map(__augmented_syscalls__, PERF_EVENT_ARRAY, int, u32, __NR_CPUS__); +struct __augmented_syscalls__ { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __type(key, int); + __type(value, __u32); + __uint(max_entries, __NR_CPUS__); +} __augmented_syscalls__ SEC(".maps"); =20 /* * string_args_len: one per syscall arg, 0 means not a string or don't cop= y it, @@ -29,24 +35,39 @@ bpf_map(__augmented_syscalls__, PERF_EVENT_ARRAY, int, = u32, __NR_CPUS__); */ struct syscall { bool enabled; - u16 string_args_len[6]; + __u16 string_args_len[6]; }; =20 -bpf_map(syscalls, ARRAY, int, struct syscall, 512); +struct syscalls { + __uint(type, BPF_MAP_TYPE_ARRAY); + __type(key, int); + __type(value, struct syscall); + __uint(max_entries, 512); +} syscalls SEC(".maps"); =20 /* * What to augment at entry? * * Pointer arg payloads (filenames, etc) passed from userspace to the kern= el */ -bpf_map(syscalls_sys_enter, PROG_ARRAY, u32, u32, 512); +struct syscalls_sys_enter { + __uint(type, BPF_MAP_TYPE_PROG_ARRAY); + __type(key, __u32); + __type(value, __u32); + __uint(max_entries, 512); +} syscalls_sys_enter SEC(".maps"); =20 /* * What to augment at exit? * * Pointer arg payloads returned from the kernel (struct stat, etc) to use= rspace. */ -bpf_map(syscalls_sys_exit, PROG_ARRAY, u32, u32, 512); +struct syscalls_sys_exit { + __uint(type, BPF_MAP_TYPE_PROG_ARRAY); + __type(key, __u32); + __type(value, __u32); + __uint(max_entries, 512); +} syscalls_sys_exit SEC(".maps"); =20 struct syscall_enter_args { unsigned long long common_tp_fields; @@ -66,7 +87,12 @@ struct augmented_arg { char value[PATH_MAX]; }; =20 -pid_filter(pids_filtered); +struct pids_filtered { + __uint(type, BPF_MAP_TYPE_HASH); + __type(key, pid_t); + __type(value, bool); + __uint(max_entries, 64); +} pids_filtered SEC(".maps"); =20 struct augmented_args_payload { struct syscall_enter_args args; @@ -79,7 +105,12 @@ struct augmented_args_payload { }; =20 // We need more tmp space than the BPF stack can give us -bpf_map(augmented_args_tmp, PERCPU_ARRAY, int, struct augmented_args_paylo= ad, 1); +struct augmented_args_tmp { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __type(key, int); + __type(value, struct augmented_args_payload); + __uint(max_entries, 1); +} augmented_args_tmp SEC(".maps"); =20 static inline struct augmented_args_payload *augmented_args_payload(void) { @@ -90,14 +121,14 @@ static inline struct augmented_args_payload *augmented= _args_payload(void) static inline int augmented__output(void *ctx, struct augmented_args_paylo= ad *args, int len) { /* If perf_event_output fails, return non-zero so that it gets recorded u= naugmented */ - return perf_event_output(ctx, &__augmented_syscalls__, BPF_F_CURRENT_CPU,= args, len); + return bpf_perf_event_output(ctx, &__augmented_syscalls__, BPF_F_CURRENT_= CPU, args, len); } =20 static inline unsigned int augmented_arg__read_str(struct augmented_arg *augmented_arg, = const void *arg, unsigned int arg_len) { unsigned int augmented_len =3D sizeof(*augmented_arg); - int string_len =3D probe_read_str(&augmented_arg->value, arg_len, arg); + int string_len =3D bpf_probe_read_str(&augmented_arg->value, arg_len, arg= ); =20 augmented_arg->size =3D augmented_arg->err =3D 0; /* @@ -146,7 +177,7 @@ int sys_enter_connect(struct syscall_enter_args *args) if (socklen > sizeof(augmented_args->saddr)) socklen =3D sizeof(augmented_args->saddr); =20 - probe_read(&augmented_args->saddr, socklen, sockaddr_arg); + bpf_probe_read(&augmented_args->saddr, socklen, sockaddr_arg); =20 return augmented__output(args, augmented_args, len + socklen); } @@ -165,7 +196,7 @@ int sys_enter_sendto(struct syscall_enter_args *args) if (socklen > sizeof(augmented_args->saddr)) socklen =3D sizeof(augmented_args->saddr); =20 - probe_read(&augmented_args->saddr, socklen, sockaddr_arg); + bpf_probe_read(&augmented_args->saddr, socklen, sockaddr_arg); =20 return augmented__output(args, augmented_args, len + socklen); } @@ -234,6 +265,16 @@ int sys_enter_renameat(struct syscall_enter_args *args) return augmented__output(args, augmented_args, len); } =20 +static pid_t getpid(void) +{ + return bpf_get_current_pid_tgid(); +} + +static bool pid_filter__has(struct pids_filtered *pids, pid_t pid) +{ + return bpf_map_lookup_elem(pids, &pid) !=3D NULL; +} + SEC("raw_syscalls:sys_enter") int sys_enter(struct syscall_enter_args *args) { @@ -257,7 +298,7 @@ int sys_enter(struct syscall_enter_args *args) if (augmented_args =3D=3D NULL) return 1; =20 - probe_read(&augmented_args->args, sizeof(augmented_args->args), args); + bpf_probe_read(&augmented_args->args, sizeof(augmented_args->args), args); =20 /* * Jump to syscall specific augmenter, even if the default one, @@ -278,7 +319,7 @@ int sys_exit(struct syscall_exit_args *args) if (pid_filter__has(&pids_filtered, getpid())) return 0; =20 - probe_read(&exit_args, sizeof(exit_args), args); + bpf_probe_read(&exit_args, sizeof(exit_args), args); /* * Jump to syscall specific return augmenter, even if the default one, * "!raw_syscalls:unaugmented" that will just return 1 to return the @@ -291,4 +332,4 @@ int sys_exit(struct syscall_exit_args *args) return 0; } =20 -license(GPL); +char _license[] SEC("license") =3D "GPL"; --=20 2.38.1.273.g43a17bfeac-goog From nobody Thu Apr 9 06:21:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F235EC4332F for ; Thu, 3 Nov 2022 04:55:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230481AbiKCEzN (ORCPT ); Thu, 3 Nov 2022 00:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230324AbiKCEzF (ORCPT ); Thu, 3 Nov 2022 00:55:05 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4B8F17ABF for ; Wed, 2 Nov 2022 21:55:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id y65-20020a25c844000000b006bb773548d5so1138983ybf.5 for ; Wed, 02 Nov 2022 21:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NO4EAaPdlCi62iB+M5zDGMRqIBRUtwLFDoXq6ZpSfuw=; b=ZoYo3Un1fIQpifOfk/INmb5tD31LpNepPPNKxroFffZ4XwuFjCmiylh1CpaLi0fMUE ZRTnvSK5Tu2RJsmP79Wx0JqMWvB9BEwZEhUEmGGuV7LGjx3Y9K6EOiYl+fXGtre0vLRM hIHWg1tID6B3vpAftbn9wjCNLXbezQmt3NbfbPcpPXjS10QWHqpMOppzX3I7Lv0qbfB+ XzqwAKx40rlBCIbIrRNixgnvJ5QNVMEBnFywIgfLhqIEyra1MTEHE5nHNwzsB+zwuXMC eOfPLGu1rHP0zjRUGS/JXEUXTAFuhW4pAWj02EH2B+3Hga2MHADSKqFy3NuOlhASOjlu 6l3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NO4EAaPdlCi62iB+M5zDGMRqIBRUtwLFDoXq6ZpSfuw=; b=VpoN3ZZl6sxdLPiMHDGgqAStlTftV+2o0YQFgbX1kCnYWz9MYl3igY8S7w7Axiy+QC KyJtZxPHYwoAZ6mcOD9g2Tl2JHLcbb0CmrhvO8QGIva0aD15ai9zJmCkiE7dYRzGkLVZ DmFcwS4gg9XpnvqtzJbVBJR2JEL2ey+2P8YbH0sXScW7W/YXszWMGx9UWvUJKe8eaEwF itqbg+/EgZOMBBc1gohA/3TbSdz0fCNqAnBO3J0zh9ZKkok2qodvEhK3a3KhzWUypYfy GiCvgejjqocZU46DzNqpnptowswErRpeUM/Vn6SP+npfYyuGd865nutWDNEQUTAWziKI vSog== X-Gm-Message-State: ACrzQf0GTQgf2M80LKSeSSzFnoe3jMuV5n7mUoXB2dKaJE1odxRkJWH5 fz9W8Xohiu+YDL+JGPryxcJpfmpUuJNn X-Google-Smtp-Source: AMsMyM78oSDtfnW3xt5/Y4SvXCBCzuGhCfgfLwau6qa/1+zrjdA//EUcxUaLxEYHCfaMpS07MmHoCpn3Q57+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:8a9d:7f38:6465:2d7b]) (user=irogers job=sendgmr) by 2002:a0d:c501:0:b0:36a:ca92:d207 with SMTP id h1-20020a0dc501000000b0036aca92d207mr189850ywd.429.1667451303556; Wed, 02 Nov 2022 21:55:03 -0700 (PDT) Date: Wed, 2 Nov 2022 21:54:32 -0700 In-Reply-To: <20221103045437.163510-1-irogers@google.com> Message-Id: <20221103045437.163510-3-irogers@google.com> Mime-Version: 1.0 References: <20221103045437.163510-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Subject: [PATCH v1 2/7] perf trace: Etcsnoop fix libbpf 1.0+ compatibility From: Ian Rogers To: Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Don't use deprecated and now broken map style. Avoid use of tools/perf/include/bpf/bpf.h and use the more regular BPF headers. Add "< 0" checks to fix BPF verifier failures about potentially negative values being passed to bpf_perf_event_output. Add a raw_syscalls:sys_enter to avoid the evlist being empty and causing perf trace to exit during argument parsing. Signed-off-by: Ian Rogers --- tools/perf/examples/bpf/etcsnoop.c | 41 ++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/tools/perf/examples/bpf/etcsnoop.c b/tools/perf/examples/bpf/e= tcsnoop.c index e81b535346c0..a04109d9b2b5 100644 --- a/tools/perf/examples/bpf/etcsnoop.c +++ b/tools/perf/examples/bpf/etcsnoop.c @@ -5,7 +5,7 @@ * * Test it with: * - * perf trace -e tools/perf/examples/bpf/augmented_syscalls.c cat /etc/pas= swd > /dev/null + * perf trace -e tools/perf/examples/bpf/etcsnoop.c cat /etc/passwd > /dev= /null * * It'll catch some openat syscalls related to the dynamic linked and * the last one should be the one for '/etc/passwd'. @@ -19,10 +19,17 @@ * tools/perf/include/bpf/stdio.h. */ =20 -#include +#include +#include =20 /* bpf-output associated map */ -bpf_map(__augmented_syscalls__, PERF_EVENT_ARRAY, int, u32, __NR_CPUS__); +struct __augmented_syscalls__ { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __type(key, int); + __type(value, __u32); + __uint(max_entries, __NR_CPUS__); +} __augmented_syscalls__ SEC(".maps"); + =20 struct augmented_filename { int size; @@ -30,6 +37,9 @@ struct augmented_filename { char value[64]; }; =20 +#define syscall_enter(name) \ + SEC("!syscalls:sys_enter_" #name) syscall_enter_ ## name + #define augmented_filename_syscall_enter(syscall) \ struct augmented_enter_##syscall##_args { \ struct syscall_enter_##syscall##_args args; \ @@ -39,17 +49,25 @@ int syscall_enter(syscall)(struct syscall_enter_##sysca= ll##_args *args) \ { \ char etc[6] =3D "/etc/"; \ struct augmented_enter_##syscall##_args augmented_args =3D { .filename.re= served =3D 0, }; \ - probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \ - augmented_args.filename.size =3D probe_read_str(&augmented_args.filename.= value, \ + long size; \ + \ + if (bpf_probe_read(&augmented_args.args, sizeof(augmented_args.args), arg= s) < 0) \ + return -1; \ + \ + size =3D bpf_probe_read_str(&augmented_args.filename.value, \ sizeof(augmented_args.filename.value), \ args->filename_ptr); \ + if (size < 0) \ + return -1; \ + \ + augmented_args.filename.size =3D size; \ if (__builtin_memcmp(augmented_args.filename.value, etc, 4) !=3D 0) \ return 0; \ /* If perf_event_output fails, return non-zero so that it gets recorded u= naugmented */ \ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU= , \ + return bpf_perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT= _CPU, \ &augmented_args, \ (sizeof(augmented_args) - sizeof(augmented_args.filename.value) + \ - augmented_args.filename.size)); \ + size)); \ } =20 struct syscall_enter_openat_args { @@ -73,4 +91,11 @@ struct syscall_enter_open_args { =20 augmented_filename_syscall_enter(open); =20 -license(GPL); +struct syscall_enter_args; + +SEC("raw_syscalls:sys_enter") +int sys_enter(struct syscall_enter_args *args) +{ + return 0; +} +char _license[] SEC("license") =3D "GPL"; --=20 2.38.1.273.g43a17bfeac-goog From nobody Thu Apr 9 06:21:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F27CCC433FE for ; Thu, 3 Nov 2022 04:55:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbiKCEz3 (ORCPT ); Thu, 3 Nov 2022 00:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbiKCEzO (ORCPT ); Thu, 3 Nov 2022 00:55:14 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AE0217E1F for ; Wed, 2 Nov 2022 21:55:12 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-368994f4bc0so8492107b3.14 for ; Wed, 02 Nov 2022 21:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=L+kjIEex1IOYklacrKrannRwY39rvITMzPAwz++9RgI=; b=MbZZjsEj3+nFozyRBV019hV+y7Be8O3uF+CKCcqtsrqy27tDZlQtVy5xGmpuE4sxQr RcWvOZrouGE58XuTg9LRy5Ry96JSoAtsD3bWe+ir4DpZ+CjmF8MQVmYxxNitL0J+8I32 rtYVCyV/H6PsZ8rN4U2y5Wjcxxi8rMElcx3y4uaqv5jZXnbv42X8Zwy8G5D7tMf5+Je5 gG71UwrCBg0wr+C1cvunD6WWaDQxdkGUuODvKNvuVffSEL2MHbpYxMQY1lj6Zp7439nt RP75mbPe86+o4fWsMvIjP4csuuRqXhxHEJz8xH/VSyaqVx/jali+oZEwThtoh9z4B8by n4BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L+kjIEex1IOYklacrKrannRwY39rvITMzPAwz++9RgI=; b=jVbebmOcvn3nEpLMWf0zSSdhihZxH8/R1QfHbB15JbyUHd/pxCnAyXIvVGW/tJyBpj w8lWgxQwVZIiSLoCdM8whMOkufOB6uJe6X4WcfxUiCZax+cBBGDCeXNIr1M1QlCXgxzE O3xeoqM5SAIXjQ6L+Z0BnxuosTiZkeXbSOwDLgmJVWek1h6BoYd9JRqon7emJJzdjEML 3zwi5lp6Faxk3oC+w9yy0L3Z7JN8ObmxePS+jPKkb3q1QUh6W6Wy8DFf8Cno0Oj57Bh2 0fq2XDCMCWeVbUxTby/LDxTYOEnYdsuupqtJTdNYJU/6umqToqDK8UB0m9kVjoQncqbF RsJg== X-Gm-Message-State: ACrzQf0lNKpL7Sq8qmR4/adjta6s5KGgW44GW0NrFCIX8dH3FjNwEOO5 WWd7gdLMH21plmRNf7Iy6XdEDvbWgJ8r X-Google-Smtp-Source: AMsMyM4iIn9a02aMdt6yZsX7DM1HL5tNqHhhuvpC8PkwISePPR39xcxiulhZgC0WZUUsv8vdSfkf2rcek0s5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:8a9d:7f38:6465:2d7b]) (user=irogers job=sendgmr) by 2002:a0d:d84c:0:b0:36b:40f4:7989 with SMTP id a73-20020a0dd84c000000b0036b40f47989mr26806136ywe.432.1667451311498; Wed, 02 Nov 2022 21:55:11 -0700 (PDT) Date: Wed, 2 Nov 2022 21:54:33 -0700 In-Reply-To: <20221103045437.163510-1-irogers@google.com> Message-Id: <20221103045437.163510-4-irogers@google.com> Mime-Version: 1.0 References: <20221103045437.163510-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Subject: [PATCH v1 3/7] perf trace: Augmented syscalls fix libbpf 1.0+ compatibility From: Ian Rogers To: Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Don't use deprecated and now broken map style. Avoid use of tools/perf/include/bpf/bpf.h and use the more regular BPF headers. Add "< 0" checks to fix BPF verifier failures about potentially negative values being passed to bpf_perf_event_output replacing an existing mask. Add a raw_syscalls:sys_enter to avoid the evlist being empty and causing perf trace to exit during argument parsing. Signed-off-by: Ian Rogers --- tools/perf/examples/bpf/augmented_syscalls.c | 58 ++++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/tools/perf/examples/bpf/augmented_syscalls.c b/tools/perf/exam= ples/bpf/augmented_syscalls.c index 524fdb8534b3..a809e1eab95d 100644 --- a/tools/perf/examples/bpf/augmented_syscalls.c +++ b/tools/perf/examples/bpf/augmented_syscalls.c @@ -16,11 +16,17 @@ * contents of pointer arguments. */ =20 -#include -#include +#include +#include +#include =20 /* bpf-output associated map */ -bpf_map(__augmented_syscalls__, PERF_EVENT_ARRAY, int, u32, __NR_CPUS__); +struct __augmented_syscalls__ { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __type(key, int); + __type(value, __u32); + __uint(max_entries, __NR_CPUS__); +} __augmented_syscalls__ SEC(".maps"); =20 struct syscall_exit_args { unsigned long long common_tp_fields; @@ -34,6 +40,12 @@ struct augmented_filename { char value[256]; }; =20 +#define syscall_enter(name) \ + SEC("!syscalls:sys_enter_" #name) syscall_enter_ ## name + +#define syscall_exit(name) \ + SEC("!syscalls:sys_exit_" #name) syscall_exit_ ## name + #define augmented_filename_syscall(syscall) \ struct augmented_enter_##syscall##_args { \ struct syscall_enter_##syscall##_args args; \ @@ -42,18 +54,23 @@ struct augmented_enter_##syscall##_args { \ int syscall_enter(syscall)(struct syscall_enter_##syscall##_args *args) = \ { \ struct augmented_enter_##syscall##_args augmented_args =3D { .filename.re= served =3D 0, }; \ - unsigned int len =3D sizeof(augmented_args); \ - probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \ - augmented_args.filename.size =3D probe_read_str(&augmented_args.filename.= value, \ + long size; \ + \ + if (bpf_probe_read(&augmented_args.args, sizeof(augmented_args.args), arg= s) < 0) \ + return -1; \ + \ + size =3D bpf_probe_read_str(&augmented_args.filename.value, \ sizeof(augmented_args.filename.value), \ args->filename_ptr); \ - if (augmented_args.filename.size < sizeof(augmented_args.filename.value))= { \ - len -=3D sizeof(augmented_args.filename.value) - augmented_args.filename= .size; \ - len &=3D sizeof(augmented_args.filename.value) - 1; \ - } \ + if (size < 0) \ + return -1; \ + \ + augmented_args.filename.size =3D size; \ /* If perf_event_output fails, return non-zero so that it gets recorded u= naugmented */ \ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU= , \ - &augmented_args, len); \ + return bpf_perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT= _CPU, \ + &augmented_args, \ + (sizeof(augmented_args) - sizeof(augmented_args.filename.value) + \ + size)); \ } \ int syscall_exit(syscall)(struct syscall_exit_args *args) \ { \ @@ -106,7 +123,7 @@ augmented_filename_syscall(newstat); #define _K_SS_MAXSIZE 128 #endif =20 -#define augmented_sockaddr_syscall(syscall) \ +#define augmented_sockaddr_syscall(syscall) \ struct augmented_enter_##syscall##_args { \ struct syscall_enter_##syscall##_args args; \ struct sockaddr_storage addr; \ @@ -115,14 +132,14 @@ int syscall_enter(syscall)(struct syscall_enter_##sys= call##_args *args) \ { \ struct augmented_enter_##syscall##_args augmented_args; \ unsigned long addrlen =3D sizeof(augmented_args.addr); \ - probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \ + bpf_probe_read(&augmented_args.args, sizeof(augmented_args.args), args); = \ /* FIXME_CLANG_OPTIMIZATION_THAT_ACCESSES_USER_CONTROLLED_ADDRLEN_DESPITE_= THIS_CHECK */ \ /* if (addrlen > augmented_args.args.addrlen) */ \ /* addrlen =3D augmented_args.args.addrlen; */ \ /* */ \ - probe_read(&augmented_args.addr, addrlen, args->addr_ptr); \ + bpf_probe_read(&augmented_args.addr, addrlen, args->addr_ptr); \ /* If perf_event_output fails, return non-zero so that it gets recorded u= naugmented */ \ - return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU= , \ + return bpf_perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT= _CPU, \ &augmented_args, \ sizeof(augmented_args) - sizeof(augmented_args.addr) + addrlen);\ } \ @@ -166,4 +183,11 @@ struct syscall_enter_sendto_args { =20 augmented_sockaddr_syscall(sendto); =20 -license(GPL); +struct syscall_enter_args; + +SEC("raw_syscalls:sys_enter") +int sys_enter(struct syscall_enter_args *args) +{ + return 0; +} +char _license[] SEC("license") =3D "GPL"; --=20 2.38.1.273.g43a17bfeac-goog From nobody Thu Apr 9 06:21:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1818C43217 for ; Thu, 3 Nov 2022 04:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230300AbiKCEzf (ORCPT ); Thu, 3 Nov 2022 00:55:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230473AbiKCEzW (ORCPT ); Thu, 3 Nov 2022 00:55:22 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6DD417E04 for ; Wed, 2 Nov 2022 21:55:18 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id h9-20020a25e209000000b006cbc4084f2eso1077498ybe.23 for ; Wed, 02 Nov 2022 21:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZRVFGWePvwNmlXm2BOJFvtaMGSMXy8LREl0rrvfBjVA=; b=esd73Ew1HyHI7NYFtpnPAP9jY/cbc550EHnRTY8Ws6yN4OalaXE9EODfDf/NdUi/lS MY37wQkTs7e5rqXiIPuDVqbRrm84uW8eutX7Gp+H/Ao5NSNjHdhovqInJBCiGgQTFfNt rw0bb/XU1WYVN/2ilg5cPKz62ThFN1HUPfv4dwg8iRygeLv7OqzfNApFDDj/v/iQA6eQ uEn4TQfVYd8H/IzkWqefkA00nNq49wdvmVfBzHp5N76GmXQ9H2l9XCofEXtrCqH+hqgg dFgYuqIHPz8aF++8Vg1hlMtPrVxuYfhNxLhgFeu2ECVu/rJzGmm8pDYYFgHrLSDgWEMm RpBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZRVFGWePvwNmlXm2BOJFvtaMGSMXy8LREl0rrvfBjVA=; b=qQC+S1tj3Y0gh8SxGQP/RcBYO9xLiP6VuovRZ7GYdHek6q4a20sCSeK9mrIBfpWznn UvRQnVLbj/4en/glnSAprzh0eHWDA4zs/CA2AO39NHlFg8L+cO7p+xribj7AeVOf8Gm/ Y34IXpq22uMYspH5ZKNwooxf4XBucGCIxYWivFU4+pa8udiOKXVz2/rtdQrYGwzpc2PK SQDDrEtELpKyYnBFRCChZVpAq2oRb0+MrSVFkTaUeMiNOJLF6qNFylCxHS9jD8RhY50K zjoOkyw9xAlJ25do5i70INStIb1bttoYzEaFNG3bqL+h4J+PrRm+YSR00PJjLWIlqtxU kD+A== X-Gm-Message-State: ACrzQf1vR3QRkNK7Ehyn6cQHdrivCAfoBULcMav4FivbCPtAg9/OCLgc kEImjDLLfgVB6kq69T6BVI7O93BB5Dlo X-Google-Smtp-Source: AMsMyM4xeZfFWcIYHW7+VZ8bY5fEr0eMPQ3tVpLlB+nDmZ1z/3e6KwT36FpXWpzSq473i2iaq3+ly/BFyBcw X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:8a9d:7f38:6465:2d7b]) (user=irogers job=sendgmr) by 2002:a05:6902:4d:b0:6cb:9135:29d7 with SMTP id m13-20020a056902004d00b006cb913529d7mr23783827ybh.208.1667451318415; Wed, 02 Nov 2022 21:55:18 -0700 (PDT) Date: Wed, 2 Nov 2022 21:54:34 -0700 In-Reply-To: <20221103045437.163510-1-irogers@google.com> Message-Id: <20221103045437.163510-5-irogers@google.com> Mime-Version: 1.0 References: <20221103045437.163510-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Subject: [PATCH v1 4/7] perf trace: hello fix libbpf 1.0+ compatibility From: Ian Rogers To: Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Don't use deprecated and now broken map style. Avoid use of tools/perf/include/bpf/bpf.h and use the more regular BPF headers. Switch to raw_syscalls:sys_enter to avoid the evlist being empty and fixing generating output. Signed-off-by: Ian Rogers --- tools/perf/examples/bpf/hello.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/perf/examples/bpf/hello.c b/tools/perf/examples/bpf/hell= o.c index cf3c2fdc7f79..e9080b0df158 100644 --- a/tools/perf/examples/bpf/hello.c +++ b/tools/perf/examples/bpf/hello.c @@ -1,9 +1,27 @@ -#include +// SPDX-License-Identifier: GPL-2.0 +#include +#include =20 -int syscall_enter(openat)(void *args) +struct __bpf_stdout__ { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __type(key, int); + __type(value, __u32); + __uint(max_entries, __NR_CPUS__); +} __bpf_stdout__ SEC(".maps"); + +#define puts(from) \ + ({ const int __len =3D sizeof(from); \ + char __from[sizeof(from)] =3D from; \ + bpf_perf_event_output(args, &__bpf_stdout__, BPF_F_CURRENT_CPU, \ + &__from, __len & (sizeof(from) - 1)); }) + +struct syscall_enter_args; + +SEC("raw_syscalls:sys_enter") +int sys_enter(struct syscall_enter_args *args) { puts("Hello, world\n"); return 0; } =20 -license(GPL); +char _license[] SEC("license") =3D "GPL"; --=20 2.38.1.273.g43a17bfeac-goog From nobody Thu Apr 9 06:21:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA8BEC433FE for ; Thu, 3 Nov 2022 04:55:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbiKCEzl (ORCPT ); Thu, 3 Nov 2022 00:55:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230372AbiKCEza (ORCPT ); Thu, 3 Nov 2022 00:55:30 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C93417E1F for ; Wed, 2 Nov 2022 21:55:28 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id t6-20020a25b706000000b006b38040b6f7so1135511ybj.6 for ; Wed, 02 Nov 2022 21:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aytaF9VJiZ59kp8/UqWu1XpON56xoCf/kQCMxXol+VU=; b=kEyteBHALJtRTPCwr3TZEqux/nFBzmqZ8z83EVjNVsVjV8geGkB546cSN8DcWAK3xx /8shHqXyw5Yq7GzzLxX7kaoQiW7lV6WRAAtknxyu4kv6jpU8KPoyUAZSRnCwp6xhn59U G/SKDZ32p4ES1uJKV6NbORrmpTcpfRSLhr/9IO3f8sXFgMAreer+RDjj+YoKp+KSh5CK YkNEXYD2qTEpKqpH/vhU0mvi7Fwl9qJnICFYdyyM8YslYE/Tag2jAJJVd0wDOocFLGQ9 xggyXpeHeV6ZBmx1CXgffPDeVODayjtgvfMrzUpT/6E+JoEWw1HtFv83jLOYakqalFif oJQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aytaF9VJiZ59kp8/UqWu1XpON56xoCf/kQCMxXol+VU=; b=Ff90Sdfwx3Hzre0JdyPxATLOU0SyPNyR8eBydA47WQJ4Eovc3poe8FXFxIUGc1ypBR 3wQ6kHfS8HSlmhy5HHOmeo6JwRwolBOoUmbm/SbgJSSYd7pJhG7Wk9xwjq7XcECkAr7F 5SusXQx3YprsxPyZHlokj5aPEKTfxWX7pWA54VzrPaAW+iSHg1nRCrZHNxNTLD/KMby9 pGXDSNtip0wNF/p/Keb6pxqhkzq4PutNhxDmfRkdhSFrJ6w+a7yNI98NubSbeoei2dLx J9hUZwaX5Yuv5ybE2KenQOMqDDDx9y0BTpfpeSIW/mz2bm/zJ7zJ1TqgmfOpuMYXdu43 iNGQ== X-Gm-Message-State: ACrzQf3hZ0X/ZlV+XTjcQvH6vBwm1rjFAU36geL9fJiMHKUrKzgXBzPc L+sN9OUpHZRBHzYlWgBHwE4pg7gjgqne X-Google-Smtp-Source: AMsMyM7AUCs27q2zSxplxe1yi+Xzo6Vjq3rCThtq/3CxXMtYOH8jSxY5fbFRQ+Je3I9c8ngMwAGpB4AQA9oK X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:8a9d:7f38:6465:2d7b]) (user=irogers job=sendgmr) by 2002:a0d:ddd2:0:b0:367:27b6:db71 with SMTP id g201-20020a0dddd2000000b0036727b6db71mr185334ywe.432.1667451327234; Wed, 02 Nov 2022 21:55:27 -0700 (PDT) Date: Wed, 2 Nov 2022 21:54:35 -0700 In-Reply-To: <20221103045437.163510-1-irogers@google.com> Message-Id: <20221103045437.163510-6-irogers@google.com> Mime-Version: 1.0 References: <20221103045437.163510-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Subject: [PATCH v1 5/7] perf trace: empty fix libbpf 1.0+ compatibility From: Ian Rogers To: Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid use of tools/perf/include/bpf/bpf.h and use the more regular BPF headers. Add raw_syscalls:sys_enter to avoid the evlist being empty. Signed-off-by: Ian Rogers --- tools/perf/examples/bpf/empty.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/perf/examples/bpf/empty.c b/tools/perf/examples/bpf/empt= y.c index 7d7fb0c9fe76..3e296c0c53d7 100644 --- a/tools/perf/examples/bpf/empty.c +++ b/tools/perf/examples/bpf/empty.c @@ -1,3 +1,12 @@ -#include +// SPDX-License-Identifier: GPL-2.0 +#include +#include =20 -license(GPL); +struct syscall_enter_args; + +SEC("raw_syscalls:sys_enter") +int sys_enter(struct syscall_enter_args *args) +{ + return 0; +} +char _license[] SEC("license") =3D "GPL"; --=20 2.38.1.273.g43a17bfeac-goog From nobody Thu Apr 9 06:21:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1003EC4332F for ; Thu, 3 Nov 2022 04:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbiKCEz4 (ORCPT ); Thu, 3 Nov 2022 00:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbiKCEzg (ORCPT ); Thu, 3 Nov 2022 00:55:36 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEDD51834D for ; Wed, 2 Nov 2022 21:55:35 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-373582569edso8830227b3.2 for ; Wed, 02 Nov 2022 21:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EWeuHCyi2W7A7vKA2mK0hGlw9T43n/AucDVWw/mFz6E=; b=P1Jxogm9RvZph3NQWg4N6/h1Y/mZIWrj+g77FotIrZCa8+JenokyCQfQpdHpDLY7Lb VFpPcL8i5orSFxw3pkruzwtE6rdGctGJ1m0ZlcAd+0GBeJzDWX0c0hjxd0wKvCjpkvlf G4v/ezWLfG6VlTd4Pmyu1x6tFgUOR32sNwRC5zAbyRg+1PZOubpiC8w3/XoqxymRg2Ii TSYdvpULIm3Xd0Q0LuLq/uz+MmriAjwvN5woDj3Gt5C/r4eOd98BkabLSVwDECZMV3GB 1Fobn42CcrEo23uNYfOl1UZZ3DLlFR66PJmYRKMXK8RckNB1pTw2XLm9Mg/SkODwA27d aTVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EWeuHCyi2W7A7vKA2mK0hGlw9T43n/AucDVWw/mFz6E=; b=lsrIcTe1nbrwcQgBTmN+STqnSap6D7G3iCDPTVGX0E0lkpwpYiHqiJlPJtcLOtUINu AxIdu3DBK+bCkyyNYYW79j7p0nghsKkAYP1ot+7nYWK/nYK9DfpaYFEojd4pW6Szqdlk hqZFIeAAQQ+Z/3kQhgG6cBtuk6+zSYMamr8YKYhAAKXhzKG+EFsJS3gxQm2v1qTcONQA EFzasrOpvipsjC/jtxh/G/utf2XjRiAdTydsEs67Ano9NOw6XlQIL8G25+Zy0FcNxhy8 1yRoRV4mUqjDOYHXfCYMewTze4SEuvjpxf1tCb9ciBsblHdNyf2MspQ7pcq06CRomEG5 njIA== X-Gm-Message-State: ACrzQf03clTejJKVtu+eR0pojzYW0yXd+rp/H2H+IzX31Lwnboj0pWMV sXKXBZERmBZLVMTZsOfwrsM1YUbWta94 X-Google-Smtp-Source: AMsMyM6e3YYgDcDAJlHUlyP1vHoJhULWU9k7/qIDFNy5Toxr7gPbdwAuaH6iWqfhnYFnmF22uoax4BUak5No X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:8a9d:7f38:6465:2d7b]) (user=irogers job=sendgmr) by 2002:a0d:ccc6:0:b0:369:230:438c with SMTP id o189-20020a0dccc6000000b003690230438cmr26964342ywd.45.1667451335254; Wed, 02 Nov 2022 21:55:35 -0700 (PDT) Date: Wed, 2 Nov 2022 21:54:36 -0700 In-Reply-To: <20221103045437.163510-1-irogers@google.com> Message-Id: <20221103045437.163510-7-irogers@google.com> Mime-Version: 1.0 References: <20221103045437.163510-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Subject: [PATCH v1 6/7] perf trace: 5sec fix libbpf 1.0+ compatibility From: Ian Rogers To: Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid use of tools/perf/include/bpf/bpf.h and use the more regular BPF headers. Note, on testing the probe was unable to attach and the program failed. Signed-off-by: Ian Rogers --- tools/perf/examples/bpf/5sec.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/perf/examples/bpf/5sec.c b/tools/perf/examples/bpf/5sec.c index e6b6181c6dc6..f22312c64713 100644 --- a/tools/perf/examples/bpf/5sec.c +++ b/tools/perf/examples/bpf/5sec.c @@ -39,13 +39,15 @@ Copyright (C) 2018 Red Hat, Inc., Arnaldo Carvalho de Melo */ =20 -#include +#include +#include =20 #define NSEC_PER_SEC 1000000000L =20 -int probe(hrtimer_nanosleep, rqtp)(void *ctx, int err, long long sec) +SEC("hrtimer_nanosleep=3Dhrtimer_nanosleep rqtp") +int hrtimer_nanosleep(void *ctx, int err, long long sec) { return sec / NSEC_PER_SEC =3D=3D 5ULL; } +char _license[] SEC("license") =3D "GPL"; =20 -license(GPL); --=20 2.38.1.273.g43a17bfeac-goog From nobody Thu Apr 9 06:21:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C146C433FE for ; Thu, 3 Nov 2022 04:56:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231201AbiKCE4T (ORCPT ); Thu, 3 Nov 2022 00:56:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbiKCEzt (ORCPT ); Thu, 3 Nov 2022 00:55:49 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D28818E06 for ; Wed, 2 Nov 2022 21:55:44 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id e8-20020a5b0cc8000000b006bca0fa3ab6so1190198ybr.0 for ; Wed, 02 Nov 2022 21:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MUgYFeR5VfNnBAi81qTIwK/qXUSt8bp2iygLv7fkD0I=; b=LeDk8/TRVg8xXxlznJRt+RCwNDDHza+JEdecE94JgWkd3rGy6uwrw8Yl4PaThYu5/+ z9HRGBHP8ToxGpa0HXQxp2QPs/Za8onmkLQ+zdmhIipKdGwVMCBQ+3PeBRYDFLRVsuOp ZphtKT5sO1e7s3qj+sBndvEzn4724j7Z/17Be8qF/nz/HcIX0k+z1MsHxxzVl03i+U5D 5p/j/ttFlA0+J25pxMBFmkkQEyFmyq70sI/rwRTGBxAzZwsrkw2L1Njc3zNo78Ova3iZ mGoc91qD+Q8jtGjU7M+QvzbFRoWNs+w9DpHqOhWjdEM1bJhBTbXskj5df5j5Rr+rXYPL s0rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MUgYFeR5VfNnBAi81qTIwK/qXUSt8bp2iygLv7fkD0I=; b=hnqTRMDaOjZjJiJiaRRS2Xk3Qry0HCPDqo/9e5xyebrqIVlpT5uAub/5BF2GBwCszj z8HydQvF2+I8AZMiBJknymT4ue9zn5gFu+Ci4gaysYD/GesqGkYjPjeXwOXZPZBYuccT eT6y8YWByqwlTMywTVLmxv6MICRA27P/KKE6UyzUnOIRAek3rfCwB1g8g27tHnw96ROt G3S8YQQv3KQ/yQXVGoICVpDNDPpo1GSWYHDjaPAmQK9l6PLO1+8X7/i2SSaRhg+knNAY UhbrBaaqvGCXxetcrhyw6MrJ0mYvmx1BkQK5FuuauZYfiSNRLu2h+govz6xEcZIrjnlG 6mZQ== X-Gm-Message-State: ACrzQf2ayFwmcCQkSrw9Fxlts9piXLNFKboDTba/iFV86P3SbR1Q6fyK mwPZcthsMPTQ9ShpY1sPCl+OzaQut+nF X-Google-Smtp-Source: AMsMyM7Y111fR7xKROa1RHADLVwif/tfIJe5C17IVuQjIhJqnZ3Zpotw2FwXO9aSGAPUssk+c+tONkUubZEg X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:8a9d:7f38:6465:2d7b]) (user=irogers job=sendgmr) by 2002:a25:a08c:0:b0:6cf:e475:2b41 with SMTP id y12-20020a25a08c000000b006cfe4752b41mr7693876ybh.326.1667451343895; Wed, 02 Nov 2022 21:55:43 -0700 (PDT) Date: Wed, 2 Nov 2022 21:54:37 -0700 In-Reply-To: <20221103045437.163510-1-irogers@google.com> Message-Id: <20221103045437.163510-8-irogers@google.com> Mime-Version: 1.0 References: <20221103045437.163510-1-irogers@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Subject: [PATCH v1 7/7] perf bpf: Remove now unused BPF headers From: Ian Rogers To: Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Example code has migrated to use standard BPF header files, remove unnecessary perf equivalents. Update install step to not try to copy these. Signed-off-by: Ian Rogers --- tools/perf/Makefile.perf | 5 -- tools/perf/include/bpf/bpf.h | 70 --------------------------- tools/perf/include/bpf/linux/socket.h | 24 --------- tools/perf/include/bpf/pid_filter.h | 21 -------- tools/perf/include/bpf/stdio.h | 16 ------ tools/perf/include/bpf/unistd.h | 10 ---- 6 files changed, 146 deletions(-) delete mode 100644 tools/perf/include/bpf/bpf.h delete mode 100644 tools/perf/include/bpf/linux/socket.h delete mode 100644 tools/perf/include/bpf/pid_filter.h delete mode 100644 tools/perf/include/bpf/stdio.h delete mode 100644 tools/perf/include/bpf/unistd.h diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index a432e59afc42..67819f905611 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -960,11 +960,6 @@ endif $(call QUIET_INSTALL, libexec) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' ifndef NO_LIBBPF - $(call QUIET_INSTALL, bpf-headers) \ - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'; \ - $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf/linux'= ; \ - $(INSTALL) include/bpf/*.h -m 644 -t '$(DESTDIR_SQ)$(perf_include_instdi= r_SQ)/bpf'; \ - $(INSTALL) include/bpf/linux/*.h -m 644 -t '$(DESTDIR_SQ)$(perf_include_= instdir_SQ)/bpf/linux' $(call QUIET_INSTALL, bpf-examples) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'; \ $(INSTALL) examples/bpf/*.c -m 644 -t '$(DESTDIR_SQ)$(perf_examples_inst= dir_SQ)/bpf' diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h deleted file mode 100644 index b422aeef5339..000000000000 --- a/tools/perf/include/bpf/bpf.h +++ /dev/null @@ -1,70 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#ifndef _PERF_BPF_H -#define _PERF_BPF_H - -#include - -/* - * A helper structure used by eBPF C program to describe map attributes to - * elf_bpf loader, taken from tools/testing/selftests/bpf/bpf_helpers.h: - */ -struct bpf_map { - unsigned int type; - unsigned int key_size; - unsigned int value_size; - unsigned int max_entries; - unsigned int map_flags; - unsigned int inner_map_idx; - unsigned int numa_node; -}; - -#define bpf_map(name, _type, type_key, type_val, _max_entries) \ -struct bpf_map SEC("maps") name =3D { \ - .type =3D BPF_MAP_TYPE_##_type, \ - .key_size =3D sizeof(type_key), \ - .value_size =3D sizeof(type_val), \ - .max_entries =3D _max_entries, \ -}; \ -struct ____btf_map_##name { \ - type_key key; \ - type_val value; \ -}; \ -struct ____btf_map_##name __attribute__((section(".maps." #name), used)) \ - ____btf_map_##name =3D { } - -/* - * FIXME: this should receive .max_entries as a parameter, as careful - * tuning of these limits is needed to avoid hitting limits that - * prevents other BPF constructs, such as tracepoint handlers, - * to get installed, with cryptic messages from libbpf, etc. - * For the current need, 'perf trace --filter-pids', 64 should - * be good enough, but this surely needs to be revisited. - */ -#define pid_map(name, value_type) bpf_map(name, HASH, pid_t, value_type, 6= 4) - -static int (*bpf_map_update_elem)(struct bpf_map *map, void *key, void *va= lue, u64 flags) =3D (void *)BPF_FUNC_map_update_elem; -static void *(*bpf_map_lookup_elem)(struct bpf_map *map, void *key) =3D (v= oid *)BPF_FUNC_map_lookup_elem; - -static void (*bpf_tail_call)(void *ctx, void *map, int index) =3D (void *)= BPF_FUNC_tail_call; - -#define SEC(NAME) __attribute__((section(NAME), used)) - -#define probe(function, vars) \ - SEC(#function "=3D" #function " " #vars) function - -#define syscall_enter(name) \ - SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name - -#define syscall_exit(name) \ - SEC("syscalls:sys_exit_" #name) syscall_exit_ ## name - -#define license(name) \ -char _license[] SEC("license") =3D #name; \ -int _version SEC("version") =3D LINUX_VERSION_CODE; - -static int (*probe_read)(void *dst, int size, const void *unsafe_addr) =3D= (void *)BPF_FUNC_probe_read; -static int (*probe_read_str)(void *dst, int size, const void *unsafe_addr)= =3D (void *)BPF_FUNC_probe_read_str; - -static int (*perf_event_output)(void *, struct bpf_map *, int, void *, uns= igned long) =3D (void *)BPF_FUNC_perf_event_output; - -#endif /* _PERF_BPF_H */ diff --git a/tools/perf/include/bpf/linux/socket.h b/tools/perf/include/bpf= /linux/socket.h deleted file mode 100644 index 7f844568dab8..000000000000 --- a/tools/perf/include/bpf/linux/socket.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _UAPI_LINUX_SOCKET_H -#define _UAPI_LINUX_SOCKET_H - -/* - * Desired design of maximum size and alignment (see RFC2553) - */ -#define _K_SS_MAXSIZE 128 /* Implementation specific max size */ -#define _K_SS_ALIGNSIZE (__alignof__ (struct sockaddr *)) - /* Implementation specific desired alignment */ - -typedef unsigned short __kernel_sa_family_t; - -struct __kernel_sockaddr_storage { - __kernel_sa_family_t ss_family; /* address family */ - /* Following field(s) are implementation specific */ - char __data[_K_SS_MAXSIZE - sizeof(unsigned short)]; - /* space to achieve desired size, */ - /* _SS_MAXSIZE value minus size of ss_family */ -} __attribute__ ((aligned(_K_SS_ALIGNSIZE))); /* force desired alignment */ - -#define sockaddr_storage __kernel_sockaddr_storage - -#endif /* _UAPI_LINUX_SOCKET_H */ diff --git a/tools/perf/include/bpf/pid_filter.h b/tools/perf/include/bpf/p= id_filter.h deleted file mode 100644 index 6e61c4bdf548..000000000000 --- a/tools/perf/include/bpf/pid_filter.h +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-License-Identifier: LGPL-2.1 - -#ifndef _PERF_BPF_PID_FILTER_ -#define _PERF_BPF_PID_FILTER_ - -#include - -#define pid_filter(name) pid_map(name, bool) - -static int pid_filter__add(struct bpf_map *pids, pid_t pid) -{ - bool value =3D true; - return bpf_map_update_elem(pids, &pid, &value, BPF_NOEXIST); -} - -static bool pid_filter__has(struct bpf_map *pids, pid_t pid) -{ - return bpf_map_lookup_elem(pids, &pid) !=3D NULL; -} - -#endif // _PERF_BPF_PID_FILTER_ diff --git a/tools/perf/include/bpf/stdio.h b/tools/perf/include/bpf/stdio.h deleted file mode 100644 index 316af5b2ff35..000000000000 --- a/tools/perf/include/bpf/stdio.h +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#include - -struct bpf_map SEC("maps") __bpf_stdout__ =3D { - .type =3D BPF_MAP_TYPE_PERF_EVENT_ARRAY, - .key_size =3D sizeof(int), - .value_size =3D sizeof(u32), - .max_entries =3D __NR_CPUS__, -}; - -#define puts(from) \ - ({ const int __len =3D sizeof(from); \ - char __from[__len] =3D from; \ - perf_event_output(args, &__bpf_stdout__, BPF_F_CURRENT_CPU, \ - &__from, __len & (sizeof(from) - 1)); }) diff --git a/tools/perf/include/bpf/unistd.h b/tools/perf/include/bpf/unist= d.h deleted file mode 100644 index ca7877f9a976..000000000000 --- a/tools/perf/include/bpf/unistd.h +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: LGPL-2.1 - -#include - -static int (*bpf_get_current_pid_tgid)(void) =3D (void *)BPF_FUNC_get_curr= ent_pid_tgid; - -static pid_t getpid(void) -{ - return bpf_get_current_pid_tgid(); -} --=20 2.38.1.273.g43a17bfeac-goog