From patchwork Thu Nov 3 04:54:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 14643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp321213wru; Wed, 2 Nov 2022 21:58:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6vtJY+441YMRbQTuj3FOYLMnh1IMzgRA/gmiKuJz8d8A+oX9IJPsT9XiBlBxCnQsKqZwUb X-Received: by 2002:a17:903:11cf:b0:178:a8f4:d511 with SMTP id q15-20020a17090311cf00b00178a8f4d511mr28207091plh.72.1667451496241; Wed, 02 Nov 2022 21:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667451496; cv=none; d=google.com; s=arc-20160816; b=ym6Hsjjw07YkqbkWO6l/c5tVxumnwSMV0iuST1c3vI7xAafmFIWUQjG/FfRX15iBVv ah3UEWD00KHcieJebHpLYOL0upmziApYzwbA6IN9U6RZTk4WYmItWQDXvAXiwwIQSUQo ZO2V20sx7QB+p43iHPzKj8z79wAd90g9zCy5gJsi+4udXEqaznyt5jejcsfmq1BcZc8/ s12T+0pq+E/HqMjaWco0yEj0cXRGmTHcx80TDUFYAOy3QW3a3OwS5c3Ja9Et71OnfKN+ Wyog3zidKCpbDhYyFZ32gh7L1IU+5dByNg+HP+62PojThOiuEdBneTNBUVozlU2UP0ZY oL1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=gJ2um6c1slJC7mFKEqkDgLoAnh4NP6kllgPCGRDYU3g=; b=Hx+WpuPy0AQMUP0LQqqmz8GbrAda/yZFvXnSQvNW3aCcW55kmSgJrIlhuuu/Ju+FDF /UFvjb34O0TXNukV78uw9VIODeFPlXDJ7SOmqU9L75LbBUlHzpdf3X8J0Brpjarhyc8B Bj74d62t1vxi33fASejz3mTlmks0TLwllUX5Lvos5JLi718YwvacF0lKF55dobE4hEpN vK5uIlzraNafstMSPsI+xOno9CarpWKe/OqxSjaD0e+VgndqbJK4naFb+aqmZQuxsmm+ QVw9fJVsBBh/KIZSciQymZ0g3Sk8kUu43Fod/P1B3Xd79M0Fssty2pgjOagwaAlcE8Qm 5snQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DHyGb7Ho; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020a1709027d8200b0018659ff71d2si15348827plm.62.2022.11.02.21.58.03; Wed, 02 Nov 2022 21:58:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DHyGb7Ho; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230337AbiKCEzC (ORCPT + 99 others); Thu, 3 Nov 2022 00:55:02 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748449620043828042?= X-GMAIL-MSGID: =?utf-8?q?1748449620043828042?= 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. */ -#include +#include +#include #include -#include -#include +#include +#include /* 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"); /* * string_args_len: one per syscall arg, 0 means not a string or don't copy 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]; }; -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"); /* * What to augment at entry? * * Pointer arg payloads (filenames, etc) passed from userspace to the kernel */ -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"); /* * What to augment at exit? * * Pointer arg payloads returned from the kernel (struct stat, etc) to userspace. */ -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"); struct syscall_enter_args { unsigned long long common_tp_fields; @@ -66,7 +87,12 @@ struct augmented_arg { char value[PATH_MAX]; }; -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"); struct augmented_args_payload { struct syscall_enter_args args; @@ -79,7 +105,12 @@ struct augmented_args_payload { }; // We need more tmp space than the BPF stack can give us -bpf_map(augmented_args_tmp, PERCPU_ARRAY, int, struct augmented_args_payload, 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"); 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_payload *args, int len) { /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ - 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); } static inline unsigned int augmented_arg__read_str(struct augmented_arg *augmented_arg, const void *arg, unsigned int arg_len) { unsigned int augmented_len = sizeof(*augmented_arg); - int string_len = probe_read_str(&augmented_arg->value, arg_len, arg); + int string_len = bpf_probe_read_str(&augmented_arg->value, arg_len, arg); augmented_arg->size = augmented_arg->err = 0; /* @@ -146,7 +177,7 @@ int sys_enter_connect(struct syscall_enter_args *args) if (socklen > sizeof(augmented_args->saddr)) socklen = sizeof(augmented_args->saddr); - probe_read(&augmented_args->saddr, socklen, sockaddr_arg); + bpf_probe_read(&augmented_args->saddr, socklen, sockaddr_arg); 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 = sizeof(augmented_args->saddr); - probe_read(&augmented_args->saddr, socklen, sockaddr_arg); + bpf_probe_read(&augmented_args->saddr, socklen, sockaddr_arg); 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); } +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) != 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 == NULL) return 1; - probe_read(&augmented_args->args, sizeof(augmented_args->args), args); + bpf_probe_read(&augmented_args->args, sizeof(augmented_args->args), args); /* * 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; - 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; } -license(GPL); +char _license[] SEC("license") = "GPL"; From patchwork Thu Nov 3 04:54:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 14644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp321516wru; Wed, 2 Nov 2022 21:59:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5e5RF0NZLPINNHds+NjWzkWyoy0dF9Qwh19TZdwmb2QFLYMJ3a6dzOCHvsPqt/PZQ0nRac X-Received: by 2002:a05:6a00:b47:b0:56d:5266:464c with SMTP id p7-20020a056a000b4700b0056d5266464cmr21656217pfo.2.1667451561601; Wed, 02 Nov 2022 21:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667451561; cv=none; d=google.com; s=arc-20160816; b=ErffX5+8xQ2l/Qrj5rjR5a894WeaCArG0IWMchSM/e6txrkq/JMtF59oW63FDWRXNz Glq+rru3A4QtilSpT+iDsa/Uaex5ZrQVPuYK5s0TEdWBQc8PA+rYGwzvbiYv5axgekVA Q+5lHgLMVwCCC06LNvtXRUdnYdXXij6tSoCqwKkgW8y1fJWUHlr1MAHC1viNTcTbYHjN 8vspV+jTdv06qzOmXtrd1XLhneGmIPMrjxTv2NtNy3mTnT/9uFvoaZCVK+S6dilIZudF lSL3YRMQg0BvWShguNHaOyxcsARUzeLvYBuUKrEFOCVl1o89zrvh2zJt5OcqOygfUsXQ 9lnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=NO4EAaPdlCi62iB+M5zDGMRqIBRUtwLFDoXq6ZpSfuw=; b=c3m4ul7sT45/zRro1L4pHCeiX+zq669OuAbIPbPoM1YIj6IHwcctakX4Ml6QLz20Be 2Uw3BtwT+HFYsuM2L+y7b4aCK86SQUMBNWMkBqQvcb3soI6Hb2lTkNjmpgEFFQbzmeSG 4N+R8cFqP6doc7Fvuv1KwSbNpyet8T2/+XQ+Dl+LEbyHYQtO2gacRgZymseFyw3/Bfyg PNnkGhn1X/AmGMGkITKgOivDSV2n2CcpXF7eIytPPVeXvVV9kL7pRDXQxwA27cvEPU4h LHGJ/Prc7H6QOXNc7Op7zegEwUMnTvYUUCyaP1lEZL+FzIl/ZCCHvX1hZzWNVFOZs3lv 3oNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZoYo3Un1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020a170902e81100b00174c8f14836si19723320plg.237.2022.11.02.21.59.08; Wed, 02 Nov 2022 21:59:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZoYo3Un1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230373AbiKCEzL (ORCPT + 99 others); Thu, 3 Nov 2022 00:55:11 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748449688998174763?= X-GMAIL-MSGID: =?utf-8?q?1748449688998174763?= 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/etcsnoop.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/passwd > /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. */ -#include +#include +#include /* 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"); + struct augmented_filename { int size; @@ -30,6 +37,9 @@ struct augmented_filename { char value[64]; }; +#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_##syscall##_args *args) \ { \ char etc[6] = "/etc/"; \ struct augmented_enter_##syscall##_args augmented_args = { .filename.reserved = 0, }; \ - probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \ - augmented_args.filename.size = probe_read_str(&augmented_args.filename.value, \ + long size; \ + \ + if (bpf_probe_read(&augmented_args.args, sizeof(augmented_args.args), args) < 0) \ + return -1; \ + \ + size = 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 = size; \ if (__builtin_memcmp(augmented_args.filename.value, etc, 4) != 0) \ return 0; \ /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ \ - 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)); \ } struct syscall_enter_openat_args { @@ -73,4 +91,11 @@ struct syscall_enter_open_args { augmented_filename_syscall_enter(open); -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") = "GPL"; From patchwork Thu Nov 3 04:54:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 14645 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp321543wru; Wed, 2 Nov 2022 21:59:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Grhae61bj4e84GNMbGnK4QMG7ax5H0jNJZenqNPEwVtGjj+CQ7nBofHCIYWalF52fAosk X-Received: by 2002:a17:90a:e2c6:b0:214:184f:4009 with SMTP id fr6-20020a17090ae2c600b00214184f4009mr10541672pjb.220.1667451567396; Wed, 02 Nov 2022 21:59:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667451567; cv=none; d=google.com; s=arc-20160816; b=ybOSJPW0vpr3MdvAUiHnYECUXgJ/oGNpbcXQriZ3tQIzxeJPQ4VzT6pdNN66zpi4GJ Mn5nO+30OdW7d9TvHLnJ049fU/X25cRLY3nvaPnumk5OBsYfzAsWvanvhCPO48kVRK9p +7sg/jJ4mzLfqjAYrR9kHriq/Xtgl4WEB32BrAYjpKmzlBQ2un6QQ7yiXCDIZMGuxvja mEaG45OPcC2qlJTGHq/NaJSrlQAsD5pgdn+TNifsQmOp7gWF/ZCNGAQYi7PPWYC+k+eY sa5f6nkJxek36FzJPNprZAnibtKDO39Ag5KouduS61wn/JO2Yy7uRemO2dt9sFgI5n8t O1Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=L+kjIEex1IOYklacrKrannRwY39rvITMzPAwz++9RgI=; b=S1RRkoYewsUnxSkeA9YflPvvbnBbN3B2CjEsTJ+ZC3+QmokII7sqlxjFpHXMUQ1dsZ Sc6Z7kdKF7FMsemD3NEtjE3nFa1A/cFbHDOrvQn423jW5+AEH4Z0Px9SWgzvUi5gtEzX GzidvkF01MRheMF972xkqnbgEE+YlFX8oeIYeQ73AqTIr77Xx5EV76rvDqYtwYEkOkHo 01Vrw8jAXxFqGGC4TUrVptAho0czjsO7uxvx/RmfwjZXsQ0VloTCbARnOcxU6McCtco6 8y+hO01Jhw8WxpOZB9f0Z85jqK9lkNh5q+jiSI64twA1xtsVzLfJNiHfv+XJuOlS5Mvv OE4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MbZZjsEj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a17090301cb00b00174c5fdc8d2si20158747plh.307.2022.11.02.21.59.14; Wed, 02 Nov 2022 21:59:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MbZZjsEj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbiKCEz1 (ORCPT + 99 others); Thu, 3 Nov 2022 00:55:27 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748449694843867966?= X-GMAIL-MSGID: =?utf-8?q?1748449694843867966?= 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/examples/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. */ -#include -#include +#include +#include +#include /* 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"); struct syscall_exit_args { unsigned long long common_tp_fields; @@ -34,6 +40,12 @@ struct augmented_filename { char value[256]; }; +#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 = { .filename.reserved = 0, }; \ - unsigned int len = sizeof(augmented_args); \ - probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \ - augmented_args.filename.size = probe_read_str(&augmented_args.filename.value, \ + long size; \ + \ + if (bpf_probe_read(&augmented_args.args, sizeof(augmented_args.args), args) < 0) \ + return -1; \ + \ + size = 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 -= sizeof(augmented_args.filename.value) - augmented_args.filename.size; \ - len &= sizeof(augmented_args.filename.value) - 1; \ - } \ + if (size < 0) \ + return -1; \ + \ + augmented_args.filename.size = size; \ /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */ \ - 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 -#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_##syscall##_args *args) \ { \ struct augmented_enter_##syscall##_args augmented_args; \ unsigned long addrlen = 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 = 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 unaugmented */ \ - 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 { augmented_sockaddr_syscall(sendto); -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") = "GPL"; From patchwork Thu Nov 3 04:54:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 14649 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp321731wru; Wed, 2 Nov 2022 22:00:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lEb6+LceZPSKqwg295WFPFiAvk/sef8m19B3E3pYFE2znu9H1h9uojOTZpptg0jkuGzaU X-Received: by 2002:a05:6a00:23cc:b0:56c:12c0:aaf7 with SMTP id g12-20020a056a0023cc00b0056c12c0aaf7mr28699475pfc.0.1667451601176; Wed, 02 Nov 2022 22:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667451601; cv=none; d=google.com; s=arc-20160816; b=B1QAuA0qosXK9hQNgPHSB7hh5roTYfl2YHx4LO61EshayrEqkO0M5seV3wJ4lypP91 Dt7mz9EmHJ5DXhCsnv+beSLcNqNn6KYbO3jTzcFrrVz7yaL1lCoYyZQSy9SM0JSR8Tec hAwio0pCLj5Cp7yqZJ1vaixR1hR7JAGXzOtSOd+QsbHf6Y9PdPlqiik3nLflLVfqYlPO zNCKxTmEr13+UFv4uejdbXQIlhc01p1JZvh6VDFuEmS2tovUBtqfmojdR+i9TquoSXwb xxzmtKb+wggBYh/L8S/I7dmJkfCjKPrHPOChLYHNv/Ys6/I3nXuG6WwJIVO4rwePyVcX Plmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=ZRVFGWePvwNmlXm2BOJFvtaMGSMXy8LREl0rrvfBjVA=; b=I1BNa0Tn1L3UXFUmHNepFYul5VvIGdZdaY3D2YUFhngkzyCAJE+fLf6DYq/c+wqmVm 4RfSaloxWXA6v9EzLAtNsOMGnoxndNtM0+IhebIDUFBRDDL6YJSeNh/J+y4O6z6zPDUS PYOl9feQ7lr5X/vcouj0PQ52z3eXOnbib8Ufyxp0zU0N+5w5c8PtXIsE475EkzxsxS7g G2rC1LCSJ08APlfQrue+Cbib7ZwgjEzoT5UlL1hfEiYGumyO5kYsLc0Npkegj6fN5ewf Vgpf8fofTx36C+bS8N2znH7N+bg0gFuUX1pLjwxL/ZByFLpYQJcI9lfFREtNT2oreQcg tErQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=esd73Ew1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j21-20020a170902c3d500b00177f35ce11fsi15413175plj.22.2022.11.02.21.59.48; Wed, 02 Nov 2022 22:00:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=esd73Ew1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbiKCEzd (ORCPT + 99 others); Thu, 3 Nov 2022 00:55:33 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748449730166557778?= X-GMAIL-MSGID: =?utf-8?q?1748449730166557778?= 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/hello.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 -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 = sizeof(from); \ + char __from[sizeof(from)] = 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; } -license(GPL); +char _license[] SEC("license") = "GPL"; From patchwork Thu Nov 3 04:54:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 14646 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp321622wru; Wed, 2 Nov 2022 21:59:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44Enhx4T7vUmxZ3uJjSYXgb0LWcRgGUSzvmDmdG15myAQTE/sSYHKkj/Cl5nStfZnI2jc7 X-Received: by 2002:a17:902:6542:b0:187:27fa:eef1 with SMTP id d2-20020a170902654200b0018727faeef1mr16958973pln.2.1667451582128; Wed, 02 Nov 2022 21:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667451582; cv=none; d=google.com; s=arc-20160816; b=P7c3Nll/EZ/NzH06SKdA6KwTFfXiWnnHMi+LrbiR12LAkiHP1IvnDOd2GGY8AdgoWB QFH9UyaA/erRrH0cpG2oK0LxGvRilmEs9Kk6tuTs0ZYmx2TL/FomWVX8l1paEkkmpJVK bixbIxXl+N+8QdUaSn5re9yDo/7nbMbdXi6HtHe45xH/aruFTJyJs9Z+WotbrU0Lxgn5 u7CnL4AjT81VKpl+ELEUI5/d5uuC5uyPtCqXO6fqqc1lA8wFwZCZJLdt90X9Q4KILGqs H33ndZfUwahaLIGiMVsM6VT3ROi4W0xUcc043kU+F3J34HMy4AryFk03iOFur8xmc/tI Ymkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=aytaF9VJiZ59kp8/UqWu1XpON56xoCf/kQCMxXol+VU=; b=W0to6A5106kAtEwZczTDGWld14e0KLhW/V4F0A/pr6nNdQSl9kkVE5L6+qDnvM/SCB TDntsyna5pQwy95GMUlmFW4mk+Vk0R6OsqbdqonmTzk/Vo4GksKBiAXHr+meTHqyIdbv LtmFpC9Mh7jwBnAZ/0/EYQOn0A+W27aicUSaPtzSeEDigzPz1CxAvdwcr6PI50Itw9kH W9LAc0McEUONXmLFVlPr74ipuFWJEVaZC32g4k3PgrZsxBqxNRRPP+2tsgGdRH+u9Pbr 5JhN6NvY1AiNpOjNjnCb4C1C9BZzpEV6WIVxk00KphFL2jEayeKqpE6ajvDSvohItict AdTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kEyteBHA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a1709026bc800b0018537cc29f9si17318098plt.15.2022.11.02.21.59.29; Wed, 02 Nov 2022 21:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kEyteBHA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbiKCEzj (ORCPT + 99 others); Thu, 3 Nov 2022 00:55:39 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748449710446346261?= X-GMAIL-MSGID: =?utf-8?q?1748449710446346261?= 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/empty.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 -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") = "GPL"; From patchwork Thu Nov 3 04:54:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 14647 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp321626wru; Wed, 2 Nov 2022 21:59:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59fteLPGNfjj1YP1l5e2MT8qvI+y27v+m25bQ3LJ/H2ZLq6l8YdpIu4O+c5/ID8bbBTfB8 X-Received: by 2002:a05:6a00:340f:b0:56d:b039:202 with SMTP id cn15-20020a056a00340f00b0056db0390202mr14823040pfb.2.1667451582622; Wed, 02 Nov 2022 21:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667451582; cv=none; d=google.com; s=arc-20160816; b=YUc/fIC5kpK5Krhor4aD3CJYYzH1xZPE6DCXf4QasFaBTTrRsO7fTFVMSOIclBt6ui N+YuAqk8d8au3RrhY7KXK+v+CuB/846qpJFzcRR69MXgEwmCeTUa67g8zU86adwx1s9X pLx1SfR3Z10Etw8q79ff87c/zoi9O+LKu0zCAvp7FOnUC6fNy7E3b+ptfr/mKdGtSvNY Y5H2KPlPgOVvYgyrP2DuquFjQQRG6H4jp8MN5rUnHb09pDdCFGajg6FBrv1wEKNBXFEo kltY5c+9bxdlqGOjJaAZKgFLG1sdlwPa8Cypy244VH8+qgH2vqYPorwMVvKRCgqgLXap YnHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=EWeuHCyi2W7A7vKA2mK0hGlw9T43n/AucDVWw/mFz6E=; b=y+eFFc+9pcwS3R1eXtzyZ8N/YacH9uif2Cu7Gvf8llWf9fRIrd5VGgkDLb+NGz7wH3 lyGybkhN7+ubtMVurGAnEKSZRcvNM3K8l7azU78Xs7NKIRLbncwaj+OX6ygB37e5QIsB XpVFvS28mr3EAHMYtDt++IUK0IjkGba7sKFercSoWgNJhTq3ChJgeXT/2zpwNrWtTVpT kjrnWhsNVPcdsX2aBXj9xShdDKtmmnvJJdEtXlv+rblmVc8Avq/rgq5ojkI9BmFq/ZGu 3XyZYAXShEtfrCjvHQBSHeVhgaeE41DOCa1iDg3J8wmnAIRI7woyRLg+hxeTm4vdbZhf /gOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=P1Jxogm9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 21-20020a631355000000b0047009247402si4582532pgt.414.2022.11.02.21.59.29; Wed, 02 Nov 2022 21:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=P1Jxogm9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231221AbiKCEzx (ORCPT + 99 others); Thu, 3 Nov 2022 00:55:53 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748449711054157790?= X-GMAIL-MSGID: =?utf-8?q?1748449711054157790?= 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 */ -#include +#include +#include #define NSEC_PER_SEC 1000000000L -int probe(hrtimer_nanosleep, rqtp)(void *ctx, int err, long long sec) +SEC("hrtimer_nanosleep=hrtimer_nanosleep rqtp") +int hrtimer_nanosleep(void *ctx, int err, long long sec) { return sec / NSEC_PER_SEC == 5ULL; } +char _license[] SEC("license") = "GPL"; -license(GPL); From patchwork Thu Nov 3 04:54:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 14648 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp321637wru; Wed, 2 Nov 2022 21:59:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7lFJ3rSIfnqwtaeWTWrmLbtDz2hhCsDJ/RsUzx5daJBxu+j9wgITqECp0gKLfprQ48gnfY X-Received: by 2002:a17:90b:378f:b0:213:acf2:13ba with SMTP id mz15-20020a17090b378f00b00213acf213bamr27913628pjb.25.1667451584779; Wed, 02 Nov 2022 21:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667451584; cv=none; d=google.com; s=arc-20160816; b=GyNi9bf7m23/crWaI/n6w39CpfrbbNyPOQnBqIyRj/25T0bKAAyLEej572q1mBNqy/ WHcbYw/wF7+a+cmA8pMSEev4AWT9c4k2md3RpErXpExmumEQH99pPlJZptzuvNi+7kLb GoSleSiBF3K1JZEVCMscTiYCj1o11EytvC4lW4S3J3luZQ12BHCo+h1GrSFdGQ8juwi9 FGDWXDBepxlt4GfDBrybWM8ihsEEaHDcXdzk/eP/3Wc8DTO6lNRjHBr0Oltn68BonhaU 3FVluVZy3DpbrPPAi+PiN7rhCqXuFAyez+Fjm6AtWf66SJtB5Jo/78eKOWGSp/C+QaxV FiPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=MUgYFeR5VfNnBAi81qTIwK/qXUSt8bp2iygLv7fkD0I=; b=SK2kPPs+VObbf63pfkSZmYGAJmjXhPBQ4DgrJWpVXwh3ojL+g/ricxCpl1eBBdirpW ex6tXPjzTnBSUFQfvIO5wAC/zzwSvFrlnlU85gCoDiK7O+sG7RqueiUGtTY+hjfYj+fw K+ckrhWdmPGvbOIWtspBIKn8x5vXn5kHDDVy139w3Y1pm2fhmJbCm9NULjo/KY9HwDFk +PdLDCKiIbOphORc0EIzdSpFvp7RnWQSaP+CpKGT9lPUaK2zbkuamaPPENB9izgk5Rt1 0W+py2Ojbu4ii6gaxCUYWYBnc80Evt4wmec7CfKS9XJMmv+IHcHGAdNVYmAJgPGeN9Yn 8W4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="LeDk8/TR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u14-20020a63790e000000b0042adcc66b1asi19577643pgc.22.2022.11.02.21.59.32; Wed, 02 Nov 2022 21:59:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="LeDk8/TR"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbiKCE4S (ORCPT + 99 others); Thu, 3 Nov 2022 00:56:18 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748449712891234495?= X-GMAIL-MSGID: =?utf-8?q?1748449712891234495?= 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_instdir_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_instdir_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 = { \ - .type = BPF_MAP_TYPE_##_type, \ - .key_size = sizeof(type_key), \ - .value_size = sizeof(type_val), \ - .max_entries = _max_entries, \ -}; \ -struct ____btf_map_##name { \ - type_key key; \ - type_val value; \ -}; \ -struct ____btf_map_##name __attribute__((section(".maps." #name), used)) \ - ____btf_map_##name = { } - -/* - * 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, 64) - -static int (*bpf_map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags) = (void *)BPF_FUNC_map_update_elem; -static void *(*bpf_map_lookup_elem)(struct bpf_map *map, void *key) = (void *)BPF_FUNC_map_lookup_elem; - -static void (*bpf_tail_call)(void *ctx, void *map, int index) = (void *)BPF_FUNC_tail_call; - -#define SEC(NAME) __attribute__((section(NAME), used)) - -#define probe(function, vars) \ - SEC(#function "=" #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") = #name; \ -int _version SEC("version") = LINUX_VERSION_CODE; - -static int (*probe_read)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read; -static int (*probe_read_str)(void *dst, int size, const void *unsafe_addr) = (void *)BPF_FUNC_probe_read_str; - -static int (*perf_event_output)(void *, struct bpf_map *, int, void *, unsigned long) = (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/pid_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 = 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) != 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__ = { - .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, - .key_size = sizeof(int), - .value_size = sizeof(u32), - .max_entries = __NR_CPUS__, -}; - -#define puts(from) \ - ({ const int __len = sizeof(from); \ - char __from[__len] = 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/unistd.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) = (void *)BPF_FUNC_get_current_pid_tgid; - -static pid_t getpid(void) -{ - return bpf_get_current_pid_tgid(); -}