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 05/16] KVM: arm64: Implement kvm_arch_vcpu_get_ip_gpa()
Date: Tue, 1 Dec 2026 15:21:05 -0800 [thread overview]
Message-ID: <20261201232116.1988791-6-irogers@google.com> (raw)
In-Reply-To: <20261201232116.1988791-1-irogers@google.com>
Implement kvm_arch_vcpu_get_ip_gpa() on arm64 so PERF_SAMPLE_HOST_IP
translates the guest PC to a guest physical address using non-faulting
guest memory reads.
Parameterize the Stage-1 translation walk in at.c with a non-faulting
guest read mode backed by kvm_vcpu_read_guest_nofault() and use
__kvm_translate_va() to translate the guest PC with execute permission
checks (including LPA2, contiguous mappings, S1PIE, and S1POE),
returning INVALID_GPA under pKVM or nested Stage-2.
Signed-off-by: Ian Rogers <irogers@google.com>
---
arch/arm64/include/asm/kvm_nested.h | 2 ++
arch/arm64/kvm/arm.c | 38 ++++++++++++++++++++++++++++
arch/arm64/kvm/at.c | 39 ++++++++++++++++++-----------
3 files changed, 65 insertions(+), 14 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h
index 27ec73da02c6..4e94b57d21e3 100644
--- a/arch/arm64/include/asm/kvm_nested.h
+++ b/arch/arm64/include/asm/kvm_nested.h
@@ -396,6 +396,8 @@ struct s1_walk_info {
bool s2;
bool pa52bit;
bool ha;
+ bool nofault;
+ bool insn_fetch;
};
struct s1_walk_result {
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index a148e80d0aef..98563c3bbec3 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -983,6 +983,44 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu)
{
return *vcpu_pc(vcpu);
}
+
+gpa_t kvm_arch_vcpu_get_ip_gpa(struct kvm_vcpu *vcpu)
+{
+ struct s1_walk_result wr = {};
+ struct s1_walk_info wi = {
+ .nofault = true,
+ .insn_fetch = true,
+ };
+ u64 va = *vcpu_pc(vcpu);
+
+ if (kvm_vm_is_protected(vcpu->kvm))
+ return INVALID_GPA;
+
+ if (vcpu_mode_is_32bit(vcpu)) {
+ if (vcpu_has_nv(vcpu) &&
+ (__vcpu_sys_reg(vcpu, HCR_EL2) &
+ (HCR_EL2_VM | HCR_EL2_DC | HCR_EL2_TGE)))
+ return INVALID_GPA;
+ if (vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_ELx_M)
+ return INVALID_GPA;
+ return va & GENMASK_ULL(31, 0);
+ }
+
+ if (is_hyp_ctxt(vcpu))
+ wi.regime = vcpu_el2_e2h_is_set(vcpu) ? TR_EL20 : TR_EL2;
+ else
+ wi.regime = TR_EL10;
+ wi.as_el0 = !vcpu_mode_priv(vcpu);
+
+ if (__kvm_translate_va(vcpu, &wi, &wr, va))
+ return INVALID_GPA;
+ if (wi.s2)
+ return INVALID_GPA;
+ if (wi.as_el0 ? !wr.ux : !wr.px)
+ return INVALID_GPA;
+
+ return wr.pa;
+}
#endif
static void kvm_init_mpidr_data(struct kvm *kvm)
diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c
index 30d8f062b2c2..f7cfa1793b16 100644
--- a/arch/arm64/kvm/at.c
+++ b/arch/arm64/kvm/at.c
@@ -274,10 +274,13 @@ static int setup_s1_walk(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
goto addrsz;
tbi = (wi->regime == TR_EL2 ?
- FIELD_GET(TCR_EL2_TBI, tcr) :
+ (FIELD_GET(TCR_EL2_TBI, tcr) &&
+ (!wi->insn_fetch || !FIELD_GET(TCR_EL2_TBID, tcr))) :
(va55 ?
- FIELD_GET(TCR_TBI1, tcr) :
- FIELD_GET(TCR_TBI0, tcr)));
+ (FIELD_GET(TCR_TBI1, tcr) &&
+ (!wi->insn_fetch || !(tcr & TCR_TBID1))) :
+ (FIELD_GET(TCR_TBI0, tcr) &&
+ (!wi->insn_fetch || !(tcr & TCR_TBID0)))));
if (!tbi && (u64)sign_extend64(va, 55) != va)
goto addrsz;
@@ -433,7 +436,10 @@ static int kvm_read_s1_desc(struct kvm_vcpu *vcpu, u64 pa, u64 *desc,
u64 val;
int r;
- r = kvm_read_guest(vcpu->kvm, pa, &val, sizeof(val));
+ if (wi->nofault)
+ r = kvm_vcpu_read_guest_nofault(vcpu, pa, &val, sizeof(val));
+ else
+ r = kvm_read_guest(vcpu->kvm, pa, &val, sizeof(val));
if (r)
return r;
@@ -481,6 +487,9 @@ static int walk_s1(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
ipa = baddr | index;
if (wi->s2) {
+ if (wi->nofault)
+ return -EOPNOTSUPP;
+
ret = kvm_walk_nested_s2(vcpu, ipa, &s2_trans);
if (ret == -EAGAIN)
return ret;
@@ -580,17 +589,19 @@ static int walk_s1(struct kvm_vcpu *vcpu, struct s1_walk_info *wi,
new_desc |= PTE_AF;
if (new_desc != desc) {
- if (wi->s2 && !kvm_s2_trans_writable(&s2_trans)) {
- fail_s1_walk(wr, ESR_ELx_FSC_PERM_L(level), true);
- return -EPERM;
- }
+ if (!wi->nofault) {
+ if (wi->s2 && !kvm_s2_trans_writable(&s2_trans)) {
+ fail_s1_walk(wr, ESR_ELx_FSC_PERM_L(level), true);
+ return -EPERM;
+ }
- ret = kvm_swap_s1_desc(vcpu, ipa, desc, new_desc, wi);
- if (ret == -EAGAIN)
- return ret;
- if (ret) {
- fail_s1_walk(wr, ESR_ELx_FSC_SEA_TTW(level), false);
- return ret;
+ ret = kvm_swap_s1_desc(vcpu, ipa, desc, new_desc, wi);
+ if (ret == -EAGAIN)
+ return ret;
+ if (ret) {
+ fail_s1_walk(wr, ESR_ELx_FSC_SEA_TTW(level), false);
+ return ret;
+ }
}
desc = new_desc;
--
2.56.1.915.g69d5ec7298-goog
next prev parent reply other threads:[~2026-12-01 23:21 UTC|newest]
Thread overview: 25+ 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-02 8:29 ` Christian Borntraeger
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 ` Ian Rogers [this message]
2026-12-01 23:41 ` [RFC PATCH 05/16] KVM: arm64: " 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 ` [RFC PATCH 14/16] perf bpf-filter: Support host_ip in BPF sample filters Ian Rogers
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-6-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.