From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796167291; b=DKkTxf2q4DvCxtXbOI7Dlm2hAIEWuavmeny77U5+rSg8Gqu7Pvub2rFh4g65NtVTPIyA IPSnDZKei2tcRtSbsn6YtMGMOUk8fNhPvUvjWlx5Wbc5RYqA+xtxO7sDugzhmsD89h5m1 lwl629FhWrMcGrrfHXGp2DAORHoiox/VEYPGMcdxVdVuvucxzN464/jInCMXUHNIEv8+d OF2VbL1/kWxynBKHHbI/2gztqea49ZWmjYfjk8yXgE7y7PEUrp4PVRWHHrCWsw6RrtRKc fJjR8QDy3VjY/n1ym/CsfiFBvuVHI6NVfsFqIQU46Rorf05ti0ZtSF0lqmX93mUyQbQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796167291; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=Nxu0lmrx/WkSzf+rVvyQdTPNS8N3lr0mwF8RgzipvZ8=; b=zAWFhp2tRUP/aqhNEFdqB8sEMQy5G08aj5trq4FVfLi+apI7fCwduunTeSLV1VELstQM Mig2nAIm4WNvXmn/uHB3FfAXWOHGQU0Oxt9j5ApVVLFrakiMZVjmnOWjrmqUAiz0KUTvl T12MzzEZQ0qIZx4xEm4HKLXlmncvnS97HP4ReHvXHQ9PKs1rNEje2E0hr2yBxJ33wJe8Z qTeLeOQd3AA6Tbm+p1nuuKZopFPrw7iqSOlQrWluTpbff4CKViB+sLSvJv1SI+0+r1Ays MKIBWXvLaGeDPet9gk8NZDSZk5d+OA+VtHxGYnB1XatPuVB0J010TKHbnp0qKenZJkQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=N397jMQ8; arc=none smtp.remote-ip=74.125.82.197 Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33B15606A320 for ; Tue, 1 Dec 2026 23:21:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 33B15606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=N397jMQ8 Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-3869865a304so14726873eec.0 for ; Tue, 01 Dec 2026 15:21:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796167289; x=1796772089; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Nxu0lmrx/WkSzf+rVvyQdTPNS8N3lr0mwF8RgzipvZ8=; b=N397jMQ8K1B5NF+xrylLhigeVgZ6zSAjSLoJAD+yAZHmCIR/smZAVi+8A7iphTi85u GPclgO/dYqErMRYuhJ64+aozXJPd1jPKqLci4uCvkw7w6K7b2a6B9oNZAywUmCT4d067 zHXqhMADbPzG7A4JX7xFY5d9DaR8R+tAQ6rIIJCCQD9JbyB+wb7MWr4hSE5urpkwlhn4 Jxl2FcNAzIfgMB0CV+FT4knIsY914lJ+io1tvJawCeuK7lqgJSzti8rLA3IUla9t/mUD xmcDC6MH04zyGicmhSe0AKCHz1jtiTP3ilBqI1cxhkIYnd5PcswfwvmKN0pOhx/OGBmp dbwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796167289; x=1796772089; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Nxu0lmrx/WkSzf+rVvyQdTPNS8N3lr0mwF8RgzipvZ8=; b=Haukc7BOyBQMYN/F8vSYyne/K3C3OFUI7spJv2yavuQU2WkxAzdF4OJseq4utcwwBp Mb0Gy0ZXYtaPjUMCrtdP/oouKtxtukLfmp/pUX3pOEaE5wLndWQjlwo5jxhthdVn/U81 nvDn7wgyzSO92NAN4bAqnu+PLZxRS/2u+XYFvOJ4g2u+d8ouDMFuN/Vc35RwhZZaCKs/ X3SvAaa7u53R3gBBOr/ZjkKxJr6FLfXry8x4VJCAPq2tAVlgwqac/ps0rCVe3roQtGuy ci70s4kqtYf/9oj7eKI4dVHGXckkRJ7S8DmhWoWts4/jaeJ0eDdYUT1gJ30zR9piWxD7 iSMQ== X-Forwarded-Encrypted: i=1; AL+hErGtG62FhHl1Xn5KZIdlAaRp+WwjRpLn9EBGxPUatuA8vTQZxWSUYTHknaYa9O47PLxB5gs=@vger.kernel.org X-Gm-Message-State: APuU4Z9b+d+Wst+S2M9hZrR2PmPIQhfwoo3Aa2CAMeB3nwI2dyPtDBAo E7etBmwVk1C0gBIB3r7xJxE/zB7OxoH/K2X5Jj4CgDS8JlV5YxjlUvI4voOe8cyCvcdxehmwjsc JvESyUcu6Pw== X-Received: from dyw11.prod.google.com ([2002:a05:7300:880b:b0:36a:de0:d28a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:2e32:b0:387:11c7:1ff0 with SMTP id 5a478bee46e88-38711c72693mr6018890eec.15.1796167288829; Tue, 01 Dec 2026 15:21:28 -0800 (PST) Date: Tue, 1 Dec 2026 15:21:00 -0800 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261201232116.1988791-1-irogers@google.com> Subject: [RFC PATCH 00/16] perf, kvm: Add PERF_SAMPLE_HOST_IP for host-side guest symbolization From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Sean Christopherson , Paolo Bonzini Cc: Marc Zyngier , Alexei Starovoitov , linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" This RFC proposes PERF_SAMPLE_HOST_IP along with BPF-filtered mmap_data recording so host-side perf can symbolize KVM guest code directly from host file-backed / DAX mappings without needing guest symbol state. Note: This work is incomplete (for example, guest callchain / stack trace support is missing, as described below). It is being posted early as an RFC because combining host-translated guest IPs with DAX / host-mapped guest binaries is a novel approach, and I would like feedback on the overall idea, UAPI, and kernel/KVM/BPF design before investing further. Motivation: Host IPs + DAX / file-backed guest mappings ======================================================= Profiling KVM guests from the host currently records guest virtual IPs (PERF_SAMPLE_IP), which can only be symbolized if the host copies /proc/kallsyms, /proc/modules, and userspace maps/binaries out of each guest. That is difficult or impossible for opaque, ephemeral, or multi-tenant VMs. When guest executables, shared libraries, or kernel/rootfs images are backed by host files mapped into the hypervisor address space (for example via DAX / virtio-pmem or direct file-backed guest memory), the host already knows which backing file and offset correspond to each guest page. By translating the guest instruction pointer (GVA -> GPA -> HVA in the hypervisor process) at PMI time into PERF_SAMPLE_HOST_IP and recording the hypervisor's non-executable file-backed mappings, host perf report/script can resolve guest samples to host DSOs, symbols, and build-IDs with no guest cooperation. Known gaps & open questions for discussion ========================================== 1. Missing guest callchain support: Perf currently bails out of perf_callchain_{kernel,user}() when perf_guest_state() is active on all architectures, so this RFC only translates the single sampled guest IP. Supporting host-IP translation for guest stack traces (where a per-sample on-stack page translation cache could amortize walks across frames in the same page) is left as future work. 2. No cross-PMI translation caching: Each PMI walks guest page tables fresh. Under hardware TDP (EPT/NPT/Stage-2), guest page-table updates, INVLPG/TLBI, and CR3 loads do not trap to KVM, so caching GVA -> HVA across PMIs risks stale symbol attribution on guest remaps or THP splits. 3. UAPI for host IP sampling (Patch 1): Is PERF_SAMPLE_HOST_IP alongside PERF_SAMPLE_IP (placed before PERF_SAMPLE_AUX so AUX remains last in PERF_RECORD_SAMPLE) the right UAPI, or would maintainers prefer a different representation? 4. Filtering non-executable hypervisor mappings via attr.mmap_bpf (Patch 2): Hypervisors map guest memory without PROT_EXEC, so PERF_RECORD_MMAP misses DAX/file-backed guest images, while enabling attr.mmap_data system-wide floods the ring buffer with anonymous data mappings from every process. Patch 2 adds attr.mmap_bpf to run an attached BPF_PROG_TYPE_PERF_EVENT program (with access to the target vm_area_struct) as a per-event filter in perf_event_mmap_match(). Because it attaches to a non-tracing event's own event->prog and is evaluated per sideband perf_event in perf_iterate_sb(), separate perf commands do not filter each other's mmap records. However, setting attr.mmap_data still incurs system-wide d_path() preparation in perf_event_mmap_event() before per-event filtering, and reusing event->prog means a single perf_event cannot carry both an overflow BPF filter and an mmap_bpf filter (perf record puts mmap_bpf on a dedicated dummy tracking event). Is BPF filtering of mmap_data the right mechanism here? 5. NMI-safe KVM guest-to-host IP translation (Patches 3-7): Patch 3 pairs synchronize_srcu_expedited(&kvm->srcu) with synchronize_rcu_expedited() in kvm_swap_active_memslots() for lockless NMI-safe memslot lookup and adds kvm_vcpu_read_guest_nofault() using copy_from_user_nofault(). Patches 4-7 implement kvm_arch_vcpu_get_ip_gpa() for x86 (including nested EPT/NPT), arm64, riscv, and loongarch. Feedback on the KVM locking/RCU tradeoffs and per-arch walkers is especially welcome. Series overview =============== - Patch 01: Add PERF_SAMPLE_HOST_IP and optional ->get_host_ip() on perf_guest_info_callbacks. - Patch 02: Add attr.mmap_bpf to allow BPF filtering of non-executable mmap_data events. - Patch 03: Add common NMI-safe KVM guest-to-host IP translation infrastructure (kvm_vcpu_read_guest_nofault(), kvm_guest_get_host_ip()). - Patch 04: Implement kvm_arch_vcpu_get_ip_gpa() on x86. - Patch 05: Implement kvm_arch_vcpu_get_ip_gpa() on arm64. - Patch 06: Implement kvm_arch_vcpu_get_ip_gpa() on riscv. - Patch 07: Implement kvm_arch_vcpu_get_ip_gpa() on loongarch. - Patch 08: Sync tools/include/uapi/linux/perf_event.h. - Patch 09: Add PERF_SAMPLE_HOST_IP parsing, synthesis, build-id hit marking, perf record --host-ip, and sample-parsing test updates. - Patch 10: Resolve sample->host_ip against machines->host and fall back to host symbolization for unresolved guest samples. - Patch 11: Add host_ip, host_dso, and host_sym sort keys in perf report and output fields in perf script. - Patch 12: Discover hypervisor processes via /proc and synthesize existing non-executable file-backed data mappings for --host-ip. - Patch 13: Add the kvm_mmap_filter BPF skeleton to filter runtime non-executable hypervisor mappings via attr.mmap_bpf. - Patch 14: Support host_ip in BPF sample filters (--filter) and test. - Patch 15: Anonymize sampled host_ip values in aslr_tool. - Patch 16: Add the host-ip-sym C unit test suite for fallback symbolization, sorting, and ASLR anonymization. Prerequisites ============= This series is based on torvalds/master (19cc08c1a6a6) plus two small pre-existing fix series posted separately: - perf/bpf: Fix BPF program inheritance and overflow races https://lore.kernel.org/linux-perf-users/20261201071653.827828-1-irogers@google.com/ - perf evsel: Add missing bounds checks in __evsel__parse_sample() https://lore.kernel.org/linux-perf-users/20261201071435.824674-1-irogers@google.com/ Development & testing notes =========================== This prototype, tests, and changelogs were developed with an AI coding assistant and reviewed with Sashiko. Tested: - Build-tested kernel/events/core.o and KVM across x86_64, arm64, riscv, loongarch, CONFIG_BPF_SYSCALL=n, and CONFIG_BPF_EVENTS=n. - Build-tested tools/perf across intermediate split commits and at HEAD with BUILD_BPF_SKEL=1 EXTRA_CFLAGS=-DREFCNT_CHECKING=1 and BUILD_BPF_SKEL=0 NO_LIBBPF=1, passing 'perf test "Sample parsing" "PERF_SAMPLE_HOST_IP"'. - Runtime-tested in x86_64 QEMU/KVM (CONFIG_PROVE_LOCKING=y, CONFIG_PROVE_RCU=y): verified 2MB huge-page (797/797) and 4KB 4-level (800/800) guest IP-to-HVA translations, plus end-to-end 'perf record --host-ip' + kvm_mmap_filter capturing a non-executable PROT_READ file-backed guest image and symbolizing guest execution in perf report/script with zero lockdep/RCU splats. - Runtime-tested in arm64 QEMU/KVM (VHE EL2, CONFIG_PROVE_LOCKING=y, CONFIG_PROVE_RCU=y): verified MMU-off (154/154) and non-identity Stage-1 MMU-on (391/391) guest IP-to-HVA translations. Not runtime-tested: - riscv and loongarch KVM guest IP translation (compile-tested only). - x86 nested EPT/NPT guest IP translation (compile-tested only). Ian Rogers (16): perf/core: Add PERF_SAMPLE_HOST_IP sample format perf/core, bpf: Support BPF filtering of mmap_data events KVM: Add NMI-safe guest-to-host IP translation infrastructure KVM: x86: Implement kvm_arch_vcpu_get_ip_gpa() KVM: arm64: Implement kvm_arch_vcpu_get_ip_gpa() KVM: riscv: Implement kvm_arch_vcpu_get_ip_gpa() KVM: loongarch: Implement kvm_arch_vcpu_get_ip_gpa() tools headers UAPI: Sync linux/perf_event.h with the kernel sources perf tools: Add PERF_SAMPLE_HOST_IP parsing, synthesis, and record --host-ip perf symbol: Support host IP resolution and guest fallback symbolization perf report, script: Add host_ip, host_dso, and host_sym fields perf record: Synthesize hypervisor file-backed data mappings for --host-ip perf record: Filter runtime hypervisor data mmaps with BPF for --host-ip perf bpf-filter: Support host_ip in BPF sample filters perf aslr: Anonymize sampled host_ip values perf test: Add PERF_SAMPLE_HOST_IP symbolization, sorting, and ASLR tests arch/arm64/include/asm/kvm_nested.h | 2 + arch/arm64/kvm/arm.c | 38 + arch/arm64/kvm/at.c | 39 +- arch/loongarch/kvm/vcpu.c | 104 +++ arch/riscv/kvm/vcpu.c | 103 +++ arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 7 +- arch/x86/kvm/mmu.h | 14 +- arch/x86/kvm/mmu/mmu.c | 53 +- arch/x86/kvm/mmu/paging_tmpl.h | 86 +++ arch/x86/kvm/svm/nested.c | 17 +- arch/x86/kvm/vmx/main.c | 9 + arch/x86/kvm/vmx/nested.c | 5 +- arch/x86/kvm/vmx/vmx.c | 16 + arch/x86/kvm/vmx/x86_ops.h | 1 + arch/x86/kvm/x86.c | 38 + include/linux/kvm_host.h | 3 + include/linux/perf_event.h | 12 + include/uapi/linux/perf_event.h | 7 +- kernel/events/core.c | 111 ++- tools/include/uapi/linux/perf_event.h | 7 +- tools/perf/Documentation/perf-record.txt | 7 + tools/perf/Documentation/perf-report.txt | 3 + tools/perf/Documentation/perf-script.txt | 4 + tools/perf/builtin-record.c | 25 +- tools/perf/builtin-script.c | 48 ++ tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/host-ip-sym.c | 691 ++++++++++++++++++ tools/perf/tests/sample-parsing.c | 7 +- tools/perf/tests/shell/record_bpf_filter.sh | 8 + tools/perf/tests/tests.h | 1 + tools/perf/util/Build | 3 + tools/perf/util/addr_location.c | 7 + tools/perf/util/addr_location.h | 4 + tools/perf/util/aslr.c | 32 + tools/perf/util/aslr.h | 3 +- tools/perf/util/bpf-filter.c | 3 +- tools/perf/util/bpf-filter.l | 1 + tools/perf/util/bpf_kvm_mmap.c | 120 +++ .../perf/util/bpf_skel/kvm_mmap_filter.bpf.c | 79 ++ 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 | 25 + tools/perf/util/build-id.c | 27 + tools/perf/util/event.c | 58 +- tools/perf/util/evsel.c | 22 + tools/perf/util/evsel.h | 1 + tools/perf/util/hist.c | 48 ++ tools/perf/util/hist.h | 6 + tools/perf/util/kvm-mmap-filter.c | 210 ++++++ tools/perf/util/kvm-mmap-filter.h | 46 ++ tools/perf/util/perf_event_attr_fprintf.c | 3 +- tools/perf/util/record.h | 1 + tools/perf/util/sample.h | 2 + tools/perf/util/session.c | 3 + tools/perf/util/sort.c | 114 +++ tools/perf/util/sort.h | 4 + tools/perf/util/synthetic-events.c | 8 + virt/kvm/kvm_main.c | 64 ++ 60 files changed, 2336 insertions(+), 39 deletions(-) create mode 100644 tools/perf/tests/host-ip-sym.c create mode 100644 tools/perf/util/bpf_kvm_mmap.c create mode 100644 tools/perf/util/bpf_skel/kvm_mmap_filter.bpf.c create mode 100644 tools/perf/util/kvm-mmap-filter.c create mode 100644 tools/perf/util/kvm-mmap-filter.h base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d prerequisite-patch-id: 9d5da60cadbe4821cfe47b4ec47d6e2f11d635f1 prerequisite-patch-id: 974971a9ccbd0a396dcab1c1f587d8b807ef4abb prerequisite-patch-id: 2b50af50ad0619ae3324a7a8932a68561ed55129 -- 2.56.1.915.g69d5ec7298-goog