From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: Marc Zyngier <maz@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
linux-perf-users@vger.kernel.org, kvm@vger.kernel.org,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
Ian Rogers <irogers@google.com>
Subject: [RFC PATCH 14/16] perf bpf-filter: Support host_ip in BPF sample filters
Date: Tue, 1 Dec 2026 15:21:14 -0800 [thread overview]
Message-ID: <20261201232116.1988791-15-irogers@google.com> (raw)
In-Reply-To: <20261201232116.1988791-1-irogers@google.com>
Add the host_ip term to the BPF sample filter lexer, sample flag
validation, sample-filter.h / sample_filter.bpf.c (using 1ULL shifts
for sample bit checks), and vmlinux.h, and extend record_bpf_filter.sh
to verify host_ip filter sample-flag validation.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/tests/shell/record_bpf_filter.sh | 8 ++++++++
tools/perf/util/bpf-filter.c | 3 ++-
tools/perf/util/bpf-filter.l | 1 +
tools/perf/util/bpf_skel/sample-filter.h | 3 ++-
tools/perf/util/bpf_skel/sample_filter.bpf.c | 9 +++++++--
tools/perf/util/bpf_skel/vmlinux/vmlinux.h | 1 +
6 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/tools/perf/tests/shell/record_bpf_filter.sh b/tools/perf/tests/shell/record_bpf_filter.sh
index 383574cb3bd3..5c898b52b263 100755
--- a/tools/perf/tests/shell/record_bpf_filter.sh
+++ b/tools/perf/tests/shell/record_bpf_filter.sh
@@ -113,6 +113,14 @@ test_bpf_filter_group() {
return
fi
+ if ! perf record -e task-clock --filter 'period > 0 || host_ip > 0' \
+ -o /dev/null true 2>&1 | grep -q PERF_SAMPLE_HOST_IP
+ then
+ echo "Group bpf-filter test [Failed forbidden HOST_IP]"
+ err=1
+ return
+ fi
+
echo "Group bpf-filter test [Success]"
}
diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c
index 72e83ac1d6a4..698fcd7c2d09 100644
--- a/tools/perf/util/bpf-filter.c
+++ b/tools/perf/util/bpf-filter.c
@@ -104,6 +104,7 @@ static const struct perf_sample_info {
PERF_SAMPLE_TYPE(CODE_PAGE_SIZE, "--code-page-size"),
PERF_SAMPLE_TYPE(DATA_PAGE_SIZE, "--data-page-size"),
PERF_SAMPLE_TYPE(CGROUP, "--all-cgroups"),
+ PERF_SAMPLE_TYPE(HOST_IP, "--host-ip"),
};
static int get_pinned_fd(const char *name);
@@ -124,7 +125,7 @@ static int check_sample_flags(struct evsel *evsel, struct perf_bpf_filter_expr *
const struct perf_sample_info *info;
if (expr->term >= PBF_TERM_SAMPLE_START && expr->term <= PBF_TERM_SAMPLE_END &&
- (evsel->core.attr.sample_type & (1 << (expr->term - PBF_TERM_SAMPLE_START))))
+ (evsel->core.attr.sample_type & (1ULL << (expr->term - PBF_TERM_SAMPLE_START))))
return 0;
if (expr->term == PBF_TERM_UID || expr->term == PBF_TERM_GID) {
diff --git a/tools/perf/util/bpf-filter.l b/tools/perf/util/bpf-filter.l
index 1be9df6550fc..ade6d88bb964 100644
--- a/tools/perf/util/bpf-filter.l
+++ b/tools/perf/util/bpf-filter.l
@@ -86,6 +86,7 @@ ident [_a-zA-Z][_a-zA-Z0-9]+
{space} { }
ip { return sample(PBF_TERM_IP); }
+host_ip { return sample(PBF_TERM_HOST_IP); }
id { return sample(PBF_TERM_ID); }
tid { return sample(PBF_TERM_TID); }
pid { return sample_part(PBF_TERM_TID, 1); }
diff --git a/tools/perf/util/bpf_skel/sample-filter.h b/tools/perf/util/bpf_skel/sample-filter.h
index 683fec85e71e..04d0314e8f53 100644
--- a/tools/perf/util/bpf_skel/sample-filter.h
+++ b/tools/perf/util/bpf_skel/sample-filter.h
@@ -49,7 +49,8 @@ enum perf_bpf_filter_term {
PBF_TERM_DATA_PAGE_SIZE = PBF_TERM_SAMPLE_START + 22, /* SAMPLE_DATA_PAGE_SIZE = 1U << 22 */
PBF_TERM_CODE_PAGE_SIZE = PBF_TERM_SAMPLE_START + 23, /* SAMPLE_CODE_PAGE_SIZE = 1U << 23 */
PBF_TERM_WEIGHT_STRUCT = PBF_TERM_SAMPLE_START + 24, /* SAMPLE_WEIGHT_STRUCT = 1U << 24 */
- PBF_TERM_SAMPLE_END = PBF_TERM_WEIGHT_STRUCT,
+ PBF_TERM_HOST_IP = PBF_TERM_SAMPLE_START + 25, /* SAMPLE_HOST_IP = 1U << 25 */
+ PBF_TERM_SAMPLE_END = PBF_TERM_HOST_IP,
/* Terms computed from BPF helpers. */
PBF_TERM_UID,
PBF_TERM_GID,
diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c b/tools/perf/util/bpf_skel/sample_filter.bpf.c
index e5666d4c1722..c22d9c867c7e 100644
--- a/tools/perf/util/bpf_skel/sample_filter.bpf.c
+++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c
@@ -80,7 +80,7 @@ static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
return 0;
#define BUILD_CHECK_SAMPLE(x) \
- _Static_assert((1 << (PBF_TERM_##x - PBF_TERM_SAMPLE_START)) == PERF_SAMPLE_##x, \
+ _Static_assert((1ULL << (PBF_TERM_##x - PBF_TERM_SAMPLE_START)) == PERF_SAMPLE_##x, \
"Mismatched PBF term to sample bit " #x)
BUILD_CHECK_SAMPLE(IP);
BUILD_CHECK_SAMPLE(TID);
@@ -97,16 +97,21 @@ static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
BUILD_CHECK_SAMPLE(DATA_PAGE_SIZE);
BUILD_CHECK_SAMPLE(CODE_PAGE_SIZE);
BUILD_CHECK_SAMPLE(WEIGHT_STRUCT);
+ BUILD_CHECK_SAMPLE(HOST_IP);
#undef BUILD_CHECK_SAMPLE
/* For sample terms check the sample bit is set. */
if (entry->term >= PBF_TERM_SAMPLE_START && entry->term <= PBF_TERM_SAMPLE_END &&
- (data->sample_flags & (1 << (entry->term - PBF_TERM_SAMPLE_START))) == 0)
+ (data->sample_flags & (1ULL << (entry->term - PBF_TERM_SAMPLE_START))) == 0)
return 0;
switch (entry->term) {
case PBF_TERM_IP:
return kctx->data->ip;
+ case PBF_TERM_HOST_IP:
+ if (bpf_core_field_exists(kctx->data->host_ip))
+ return kctx->data->host_ip;
+ return 0;
case PBF_TERM_ID:
return kctx->data->id;
case PBF_TERM_TID:
diff --git a/tools/perf/util/bpf_skel/vmlinux/vmlinux.h b/tools/perf/util/bpf_skel/vmlinux/vmlinux.h
index 7d07c565762c..2d7659d4cb7e 100644
--- a/tools/perf/util/bpf_skel/vmlinux/vmlinux.h
+++ b/tools/perf/util/bpf_skel/vmlinux/vmlinux.h
@@ -206,6 +206,7 @@ struct perf_sample_data {
u64 cgroup;
u64 data_page_size;
u64 code_page_size;
+ u64 host_ip;
} __attribute__((__aligned__(64))) __attribute__((preserve_access_index));
struct perf_event {
--
2.56.1.915.g69d5ec7298-goog
next prev parent reply other threads:[~2026-12-01 23:21 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 23:21 [RFC PATCH 00/16] perf, kvm: Add PERF_SAMPLE_HOST_IP for host-side guest symbolization Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 01/16] perf/core: Add PERF_SAMPLE_HOST_IP sample format Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 02/16] perf/core, bpf: Support BPF filtering of mmap_data events Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 03/16] KVM: Add NMI-safe guest-to-host IP translation infrastructure Ian Rogers
2026-12-01 23:40 ` sashiko-bot
2026-12-01 23:21 ` [RFC PATCH 04/16] KVM: x86: Implement kvm_arch_vcpu_get_ip_gpa() Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 05/16] KVM: arm64: " Ian Rogers
2026-12-01 23:41 ` sashiko-bot
2026-12-01 23:21 ` [RFC PATCH 06/16] KVM: riscv: " Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 07/16] KVM: loongarch: " Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 08/16] tools headers UAPI: Sync linux/perf_event.h with the kernel sources Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 09/16] perf tools: Add PERF_SAMPLE_HOST_IP parsing, synthesis, and record --host-ip Ian Rogers
2026-12-01 23:36 ` sashiko-bot
2026-12-01 23:21 ` [RFC PATCH 10/16] perf symbol: Support host IP resolution and guest fallback symbolization Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 11/16] perf report, script: Add host_ip, host_dso, and host_sym fields Ian Rogers
2026-12-01 23:41 ` sashiko-bot
2026-12-01 23:21 ` [RFC PATCH 12/16] perf record: Synthesize hypervisor file-backed data mappings for --host-ip Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 13/16] perf record: Filter runtime hypervisor data mmaps with BPF " Ian Rogers
2026-12-01 23:43 ` sashiko-bot
2026-12-01 23:21 ` Ian Rogers [this message]
2026-12-01 23:21 ` [RFC PATCH 15/16] perf aslr: Anonymize sampled host_ip values Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 16/16] perf test: Add PERF_SAMPLE_HOST_IP symbolization, sorting, and ASLR tests Ian Rogers
2026-12-01 23:40 ` sashiko-bot
2026-12-01 23:43 ` [RFC PATCH 00/16] perf, kvm: Add PERF_SAMPLE_HOST_IP for host-side guest symbolization sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201232116.1988791-15-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox