Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp628306lqp; Wed, 22 May 2024 14:58:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOfUjQinCOY7GcuG/42LPuHZd/Ij3R1waxBy+5jYUhDgQEtrgNzmEjDpX+WqFOjJ6EXpqk7yPdN85wOZzoy8w+lWjScHcQwWTXYhEXaQ== X-Google-Smtp-Source: AGHT+IHgMDu05JkNXnjDbMJsy+fz8J6QfJxEWpl1c+EJmVzUZzJflaqBd5/zmTkNBWY2nd92iHHS X-Received: by 2002:a17:902:dace:b0:1f2:fe49:71dd with SMTP id d9443c01a7336-1f339f01c0amr6825395ad.14.1716415117862; Wed, 22 May 2024 14:58:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716415117; cv=pass; d=google.com; s=arc-20160816; b=m9Jz+atIAIFXiEnuhtAV+Pesldb9eRv+rH0qttozZy5u2HGopqxkmn/K4B3wADR0pA BZk3x0u1jOzDmQvsshiHgj19WLLazBX40zY3Bb/MaducHYp5DKUHTkMm06CcuIOW04IO o2A+qafC2W0hw6lccCWjaXHr8kHflDCEiqWj0P7zBSCLLPyPa8ao+vAi1YoMmf1wiPW5 YRv0Tp9rlFlIChDsFTJkSoDYpAeAtcwTi7JoRYDdkmz+ibCZEcp8BEQVW5JVzDFYrQng uFkzgK3OcYnyIYRNqyr0DNr3MS8RSecXbbVsLq/gkMXF6xJr6hSzTZgaamhOY406WOg3 SX4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+6aqIBgYLrxGAfDxEN09j17sczfonDHCWfsfJqUdugI=; fh=+1J0V14dKjMi8h4q7hKoOukbS74/BCx2naK7yok440s=; b=qwMpa2H9JAaAzRS/P9w/M6igK09JXuLd/KN08ZOeMvj3C/443UeMt94E/bT2kNLVj/ buXp+LzZzjMSozX0J8Hw6XHty6laTg2BaI+JwJpZPeJtAY+jJdOuu8faKpYyykuoKEil 7ZkooQ81arpVNRPnMHGfo50pw714Zmh25gyj+BOWFsPowiWwuXTg194TSJqbUYcUT4aq ijx+ytTc9Hci3x1y/70kNqFZhcB2r98oy+khhs81nhLmxPoCfE/cNGweLXap7KD3bpjt Bj1oPTy9eBhzrXRZ8ZiBQ4N/FSqg/flDn8DdsPrrmAZPfyrPdrgf9BY1hGqHg8581Ojs GfvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="KZrQl0R/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-186755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186755-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c039eedsi10815ad.383.2024.05.22.14.58.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 14:58:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="KZrQl0R/"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-186755-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186755-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0C20DB218C2 for ; Wed, 22 May 2024 21:57:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1E2914885A; Wed, 22 May 2024 21:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KZrQl0R/" 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 E50611487E3; Wed, 22 May 2024 21:56:21 +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=1716414982; cv=none; b=X9Gp46fy1UQiPyZ3w/OZVP6p1gevtSlHb5Qa/Wueq395DchIdrD3Nptb9mYlyGhksjzUp8wP4fZ8Ue8PJuPqLiumRCopAh2/yhYvfBt0rpmUcelrFG978suxckF8v3mgC9hcAU6p8Y2phOxaZDhVtB98XANqiPDG/vaUkABZLXg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716414982; c=relaxed/simple; bh=Z4r4Kvmu8bvtpq0F56IFeFFxcPQskBGSqOlqhqZnnvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PnI2HvEELIiXNj9gIZlvRYvR8Z6X6UXSDwVysGVLZQ/8Zf0QyAxTMr5GvL3F8cJbOVc1x1XtJqQoHtWhcWNsMdSxgElbx5B7djmqUhcmIJHHpShGcxXjIruHg9DvmMhzV6t9n45AwSCHfW+lGEm+O6/RL2Ab7Hf7wWCV7ps52Z4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KZrQl0R/; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 190ABC4AF0A; Wed, 22 May 2024 21:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716414981; bh=Z4r4Kvmu8bvtpq0F56IFeFFxcPQskBGSqOlqhqZnnvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZrQl0R/lbG8f4A7szWgDJYqmLYn7KOIeQeMfrtQxitWHeoO/sYd4zuepi/Rp+fCI e4zAfV5f47LS1zMIKgwVOVtSlhSN6mc796VSgUuWO1V/VqEKwiZzHxfklGrRUk2U6r 4PrqUUFqGuC/ZiWBBGnt5Ge70Ff7NVneaTImxXAsmLC4VLZjxAjocOupoa0Zrdqp45 XlYv0cFvjCOL93fJCOTtu/WaCQYDa3c9ihmfNHFjhhYVtfX3tYDoRCDjBHU/DMAxUk /OC/cN+YzUX2/D3D9PWPSUKFvXGy4aZhlLzz6J8lMXJ2QniKoGTumkiGYQ0W5QPJsw 9BIz6HXdxxjew== 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: [PATCH 6/6] perf record: Add --setup-filter option Date: Wed, 22 May 2024 14:56:16 -0700 Message-ID: <20240522215616.762195-7-namhyung@kernel.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240522215616.762195-1-namhyung@kernel.org> References: <20240522215616.762195-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To allow BPF filters for unprivileged users it needs to pin the BPF objects to BPF-fs first. Let's add a new option to pin and unpin the objects easily. $ sudo perf record --setup-filter pin The above command would pin BPF program and maps for the filter when the system has BPF-fs (usually at /sys/fs/bpf/). To unpin the objects, users can run the following command (as root). $ sudo perf record --setup-filter unpin Signed-off-by: Namhyung Kim --- tools/perf/Documentation/perf-record.txt | 5 +++++ tools/perf/builtin-record.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index 6015fdd08fb6..e51a492dc8e0 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt @@ -828,6 +828,11 @@ filtered through the mask provided by -C option. only, as of now. So the applications built without the frame pointer might see bogus addresses. +--setup-filter=:: + Prepare BPF filter to be used by regular users. The action should be + either "pin" or "unpin". The filter can be used after it's pinned. + + include::intel-hybrid.txt[] SEE ALSO diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 3a5a24dec356..4dababd0d338 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -171,6 +171,7 @@ struct record { bool timestamp_filename; bool timestamp_boundary; bool off_cpu; + const char *filter_action; struct switch_output switch_output; unsigned long long samples; unsigned long output_max_size; /* = 0: unlimited */ @@ -3573,6 +3574,8 @@ static struct option __record_options[] = { "write collected trace data into several data files using parallel threads", record__parse_threads), OPT_BOOLEAN(0, "off-cpu", &record.off_cpu, "Enable off-cpu analysis"), + OPT_STRING(0, "setup-filter", &record.filter_action, "pin|unpin", + "BPF filter action"), OPT_END() }; @@ -4102,6 +4105,18 @@ int cmd_record(int argc, const char **argv) pr_warning("WARNING: --timestamp-filename option is not available in parallel streaming mode.\n"); } + if (rec->filter_action) { + if (!strcmp(rec->filter_action, "pin")) + err = perf_bpf_filter__pin(); + else if (!strcmp(rec->filter_action, "unpin")) + err = perf_bpf_filter__unpin(); + else { + pr_warning("Unknown BPF filter action: %s\n", rec->filter_action); + err = -EINVAL; + } + goto out_opts; + } + /* * Allow aliases to facilitate the lookup of symbols for address * filters. Refer to auxtrace_parse_filters(). -- 2.45.1.288.g0e0cd299f1-goog