Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp627656lqp; Wed, 22 May 2024 14:56:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYAWKWVsBkaqnF/AXr+SGo7LLHXpP/xDkMsf61OmInQqUiu+Wt/FHEn81oLlEJU9ZQ9F537+skybj3mTv1MO5pJ+FUvkScYavjKjmJIA== X-Google-Smtp-Source: AGHT+IGcY1VTtjVckB0MlV5Nq08IjPZfuF7sYeGHxbHXZBlpy3u8wfbh3U5zBy5KW5w64Xi1Q2sH X-Received: by 2002:a17:90a:ead1:b0:2bd:92d9:e44b with SMTP id 98e67ed59e1d1-2bddce7bbb5mr675854a91.8.1716414992408; Wed, 22 May 2024 14:56:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716414992; cv=pass; d=google.com; s=arc-20160816; b=vHWfnQ6un3XircspYtgo46NQI2yEzywKbEnogZfkkYM6AT2y9VoxDEq2EvVhhZPM0u xnMITGxAUE6NZ/Nr5gbUNk1ATgGbNqww51rAl83RVL/OeNzUWL8hhSCGBQTTcsCPPpE0 rlxTMB7lErD/jhN+LCxzlXASM0Il3/IwNXB7ix+8rJSNlVT4NppttPpQjTfMdHY7g18k wDEkPOQsmZxDKlslkPVuvSFBF6R+C4yNXuVfKk3ygWtZ+6irVXlajOnw1z/n1jBMB1Gb ErimTMZmVm6nWyE3YkmPjDAuJplEJEEthevL1hclFdHz5L9huEgt5+aIRnFt9TEathaQ gfBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Rm8yC5HOFcbYmudAEjetbmUmi161ePkpNq738/CgPQk=; fh=+1J0V14dKjMi8h4q7hKoOukbS74/BCx2naK7yok440s=; b=TnuU5Q26Dr6ZLgYVevVj2zi8LtOE0nUY3eWa1RCNtkiPW/CuUOLsH8FooLD30dDmTW e42WkCY5cDFVvo6Y7omxiI2zHHjaro3slYuNv1PMPrT++gLvVJv2b9k+zjCZoDjtgjMv cie2/pZMVdyq++rEUSxa8WaXGTZDstz2JTfP+ReejH9JmoLqtsJFAiYVVM/WXpBH7SXo 6QDBI39HU8x+6ZwxTYK9JVYhfMv+76o26MTtpLeas8qWekgWbG304mKai8astOBWxxEs VxfmDBeV2t2e+R7oVfdQaEw1NDyAzk+r9Ry2ZOkd/nOlEfHjaykeFueJc2aFOOmfu/rw REDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="b7/kSKMT"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-186749-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186749-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2a72d8asi7598608b3a.27.2024.05.22.14.56.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 14:56:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186749-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="b7/kSKMT"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-186749-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186749-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 09BBE281F9E for ; Wed, 22 May 2024 21:56:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E2AD146D4F; Wed, 22 May 2024 21:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b7/kSKMT" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 694551BF2A; Wed, 22 May 2024 21:56:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716414978; cv=none; b=j1JbZ3g8MHLk2qcMLtpiCFUo8kPUr4bSc556w6tgB+LdNuuvnk+CSq5abBVBYqbgugmlpGN+R7ZiQ5MpjG5RvbwsKX2aMz/yPR+dyKafxoMDK9Q3r1lWQk/OIbKt3IRAGTSA/l91HN7xScaDx+cWN4QVFZHcduVV2bzyFrYcSqU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716414978; c=relaxed/simple; bh=1vIOH6m5r66YlxdDfT/tB9LNZ0Lyw5wBqQXHVST2wCE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MB8qf5YMxaQj7dEu4oqqR17Cf8Bf6MlloaVCtf3M6JePB5y60w4FFzJRkJLeZt26ZfiKv2a81MclF9oPjclv6oMkPklm7GZmraPbktf1e2BukdB5zZf6yWmmwBYBnCCwsLLO+trl38tjFKDGmpCpkpEPNi+jJA3VSwZ1s/4wWAQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b7/kSKMT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C9EDC2BBFC; Wed, 22 May 2024 21:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716414977; bh=1vIOH6m5r66YlxdDfT/tB9LNZ0Lyw5wBqQXHVST2wCE=; h=From:To:Cc:Subject:Date:From; b=b7/kSKMTKaLJ79zb0GDtrhYJiH5qxIKxWy0FQP0FlJtPgt7AZZlHWvaJdWxjIzoS8 zAfIRxExSSVcjPSwrMzJHR+YapZkmwQe3usN2JzAh1ms5E+zbmfuVcDIS3DoBzQHxD WQSUM31I2cmn6mS77XUvrQmbZp8BS42PhrQk2SfpDRlbw/lBGA0035xXf3d2d4G7HE pljJ6df7fspy9jxTYUYrvX4AxBboiYar1hI23beXg75V79ImzogBzpQR6vdpnZ+2dL 4jsjEQnVAw6pVm31FrLrGxOFktWVT1WXQPqdX7yskWagiQyciYyqCZhULdsc2T+xak dO45PQ3Sq2tXA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, KP Singh , Stephane Eranian , Song Liu , bpf@vger.kernel.org Subject: [RFC 0/6] perf record: Use pinned BPF program for filter (v1) Date: Wed, 22 May 2024 14:56:10 -0700 Message-ID: <20240522215616.762195-1-namhyung@kernel.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hello, This is to support the unprivileged BPF filter for profiling per-task events. Until now only root (or any user with CAP_BPF) can use the filter and we cannot add a new unprivileged BPF program types. After talking with the BPF folks at LSF/MM/BPF 2024, I was told that this is the way to go. Finally I managed to make it working with pinned BPF objects. :) But it requires the one-time setup (by root) before using it like below. # perf record --setup-filter pin This will load the BPF program and maps and pin them in the BPF-fs. Then normal users can use the filter. $ perf record -o- -e cycles:u --filter 'period < 10000' perf test -w noploop | perf script -i- [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.011 MB - ] perf 759982 448227.214189: 1 cycles:u: 7f153719f4d0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) perf 759982 448227.214195: 1 cycles:u: 7f153719f4d0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) perf 759982 448227.214196: 7 cycles:u: 7f153719f4d0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) perf 759982 448227.214196: 223 cycles:u: 7f153719f4d0 _start+0x0 (/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) perf 759982 448227.214198: 9475 cycles:u: ffffffff8ee012a0 [unknown] ([unknown]) perf 759982 448227.548608: 1 cycles:u: 559a9f03c81c noploop+0x5c (/home/namhyung/linux/tools/perf/perf) perf 759982 448227.548611: 1 cycles:u: 559a9f03c81c noploop+0x5c (/home/namhyung/linux/tools/perf/perf) perf 759982 448227.548612: 12 cycles:u: 559a9f03c81c noploop+0x5c (/home/namhyung/linux/tools/perf/perf) perf 759982 448227.548613: 466 cycles:u: 559a9f03c81c noploop+0x5c (/home/namhyung/linux/tools/perf/perf) It's also possible to unload (and unpin, of course) using this command: # perf record --setup-filter unpin The code is avaiable in 'perf/pinned-filter-v1' branch at git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git Thanks, Namhyung Namhyung Kim (6): perf bpf-filter: Make filters map a single entry hashmap perf bpf-filter: Pass 'target' to perf_bpf_filter__prepare() perf bpf-filter: Split per-task filter use case perf bpf-filter: Support pin/unpin BPF object perf record: Fix a potential error handling issue perf record: Add --setup-filter option tools/perf/Documentation/perf-record.txt | 5 + tools/perf/builtin-record.c | 23 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/bpf-filter.c | 369 +++++++++++++++++-- tools/perf/util/bpf-filter.h | 19 +- tools/perf/util/bpf_skel/sample-filter.h | 4 +- tools/perf/util/bpf_skel/sample_filter.bpf.c | 58 ++- tools/perf/util/evlist.c | 5 +- tools/perf/util/evlist.h | 4 +- tools/perf/util/python.c | 3 +- 11 files changed, 428 insertions(+), 66 deletions(-) base-commit: ea558c86248b4955e5c5f3c0c921df450880605e -- 2.45.1.288.g0e0cd299f1-goog