From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org, kvm@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [RFC PATCH 05/16] KVM: arm64: Implement kvm_arch_vcpu_get_ip_gpa()
Date: Tue, 01 Dec 2026 23:41:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-244427@kernel.org> (raw)
In-Reply-To: <20261201232116.1988791-6-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] KVM: arm64: S1POE bitwise-AND on bool clears execute perms in
at.c
- [Medium] KVM: arm64: vcpu_mode_is_32bit() check breaks 32-bit EL0 IP
translation
- [Medium] KVM: arm64: kvm_vm_is_protected() misses non-protected pKVM
guests
--
commit 3cc4c3ee57836b5df873d0dbeffedcd751a7a24c
Author: Ian Rogers <irogers@google.com>
KVM: arm64: Implement kvm_arch_vcpu_get_ip_gpa()
This commit implements kvm_arch_vcpu_get_ip_gpa() on arm64 by extending
the Stage-1 translation walk in at.c with a non-faulting guest memory
read mode and using __kvm_translate_va() to translate the guest PC.
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index a148e80d0aef7..98563c3bbec3f 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;
[Severity: Medium]
Should this check is_protected_kvm_enabled() (or
kvm_vm_hyp_is_distrusting(vcpu->kvm)) instead of
kvm_vm_is_protected(vcpu->kvm)?
kvm_vm_is_protected() only matches protected VMs (VM_PROTECTED_PKVM) and
is false for normal non-protected guests running under pKVM (VM_PKVM).
For VM_PKVM guests, EL2 owns the live system registers and does not sync
them to host_vcpu->arch.ctxt.sys_regs on IRQ exits:
arch/arm64/kvm/hyp/nvhe/hyp-main.c:sync_hyp_vcpu() {
...
} else {
/* Non-protected: the host gets the full fault. */
host_vcpu->arch.fault = hyp_vcpu->vcpu.arch.fault;
host_vcpu->arch.iflags = hyp_vcpu->vcpu.arch.iflags;
...
host_vcpu->arch.ctxt.regs.pc = hyp_vcpu->vcpu.arch.ctxt.regs.pc;
host_vcpu->arch.ctxt.regs.pstate = hyp_vcpu->vcpu.arch.ctxt.regs.pstate;
}
}
On a PMU interrupt exit for a non-protected pKVM guest,
__kvm_translate_va() will walk the guest Stage-1 page tables using stale
host-side SCTLR_EL1, TCR_EL1, and TTBRx_EL1 values instead of returning
INVALID_GPA as described in the commit message.
> +
> + 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);
> + }
[Severity: Medium]
Does checking vcpu_mode_is_32bit(vcpu) here break IP translation for
32-bit compat EL0 tasks running under a 64-bit guest kernel?
vcpu_mode_is_32bit() checks PSR_MODE32_BIT in PSTATE, which is also set
when a 64-bit EL1 kernel (!vcpu_el1_is_32bit(vcpu)) runs a 32-bit EL0
userspace task with SCTLR_EL1.M enabled. In that case the EL1&0 regime
still uses standard AArch64 Stage-1 page tables, so masking va to 32 bits
and translating it through __kvm_translate_va() works, whereas rejecting
SCTLR_ELx_M here causes every 32-bit compat EL0 sample to return
INVALID_GPA. Also, for nested virtualization vCPUs (or when
!kvm_supports_32bit_el0()), any 32-bit mode is illegal
(vcpu_mode_is_bad_32bit()), yet this block returns va & GENMASK_ULL(31, 0)
when HCR_EL2.{VM,DC,TGE} and SCTLR_EL1.M are clear.
> +
> + 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;
[Severity: Medium]
Will this execute permission check always fail and return INVALID_GPA
whenever the guest has S1POE enabled?
In struct s1_walk_result, wr.px, wr.ux, wr.pw, and wr.uw are bool fields
(0 or 1), while POE_X is UL(0x2) and POE_W is UL(0x4). In
compute_s1_overlay_permissions(), the compound bitwise-ANDs do not
normalize the bitmask tests to booleans:
arch/arm64/kvm/at.c:compute_s1_overlay_permissions() {
...
if (wr->pov) {
...
wr->pr &= pov_perms & POE_R;
wr->pw &= pov_perms & POE_W;
wr->px &= pov_perms & POE_X;
}
if (wr->uov) {
...
wr->ur &= uov_perms & POE_R;
wr->uw &= uov_perms & POE_W;
wr->ux &= uov_perms & POE_X;
}
}
Because 1UL & 2UL is 0, wr->px and wr->ux (as well as wr->pw and wr->uw)
are unconditionally cleared to false whenever S1POE is active.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201232116.1988791-1-irogers@google.com?part=5
next prev parent reply other threads:[~2026-12-01 23:41 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 [this message]
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=sashiko-outbox-244427@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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