From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796168471; b=UtQIocrXKV0VA67XOdKZ7kg0aeTHbxs2X0rTnx0zcZh+VUaAyDTab8gjueUie05kvOTG huUw5XqLFNH3W+Os2iNprjhlNiEDOoP66kzlzpAzhO5gYqttENnu4D1o+Vy8OvMGMtEtq LTGUA0rLg16kK4Su6FVExTiQBZ+PZjfAoc7keVlGJs5LuGe5O4u3/lQer/lZsCb/EltM+ 5eA4iT5ClpcfpNkX34AnDwo51bI4qtq4afWKEGvNmXV3uHeab+CWp0RqaoV9uW7IozwrB rvXcMc2KDfslWOsKGLZ5ri0JyBT/Hq/+yKYFiD0mISD2NJlytmxFUvc6R+SAWPi4xbA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796168471; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Fl/F6Ov8WM2CV88EYv81GP0Wky0dU4rcM3O6EoI8R0I=; b=BvAUvTcKizCBKNwTc3iqAgnYODms56cHH7ctJytv/bFX06Xet3AlfkL2FCARmAsJYQbq z81VFJjM3ORW+B/4WlYEFwjbSNqdaX+gLKZzvEB9IjATvrdeHYPb+It1kf+fnPyjmj4X3 phiEcDxYNI3fe1FW3kixfyJA8SeXpij1UdNTZe1bFJoElaJOEDwP1ZgjgEA5b9Qjfa9Z6 NsDJfw/D9L1rc9igSaQGkBK8V7BCXNu7lLAwAYtk//yO/hXwMN3JhYRWfNhgseUK9fD1z OX3mJ39yCeoCs2mIemwSQ9XeF3QHY+kkPVkYK8+QFyowbbs3mjSGNUYd8Qt/j14MIiw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LtnPVFad; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C8B6606A320; Tue, 1 Dec 2026 23:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LtnPVFad Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1163A1F00897; Tue, 1 Dec 2026 23:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796168471; bh=Fl/F6Ov8WM2CV88EYv81GP0Wky0dU4rcM3O6EoI8R0I=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=LtnPVFad7X+UBrqhz+q6TIHLlEcnJTLU1vQ0qJiu1NAviIduwBLGDRj1k5jOa023m Cf5+XqG4jTPOM8AuBYu/gOSqYOxOXIHHPDKKwzhKgoo7d9zqITCZTANEYK3vh18/S9 6hfU3BlBKCuoKPCJHhbJrd5KTINaLl4bnVl7BjqvZ2e8Z3ZJO3yenx2n/OCvAa24I0 s6zc/lKPj7wjQUj5t1pvUU64MDcap3mY3sTu0XCWQxGM+8/b9mX7MyBA3M3JyMgWuy zvHuRyI/pLjfEYOIbaYdOnduNw6jmuUgbSCLyazPpHbhLFAAcmY4dxKZmAKE7u6GU5 d/ebyXKKkRWrQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH 05/16] KVM: arm64: Implement kvm_arch_vcpu_get_ip_gpa() Reply-To: sashiko-reviews@lists.linux.dev To: "Ian Rogers" Cc: linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, bpf@vger.kernel.org In-Reply-To: <20261201232116.1988791-6-irogers@google.com> References: <20261201232116.1988791-1-irogers@google.com> <20261201232116.1988791-6-irogers@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 23:41:10 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D {}; > + struct s1_walk_info wi =3D { > + .nofault =3D true, > + .insn_fetch =3D true, > + }; > + u64 va =3D *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 =3D hyp_vcpu->vcpu.arch.fault; host_vcpu->arch.iflags =3D hyp_vcpu->vcpu.arch.iflags; ... host_vcpu->arch.ctxt.regs.pc =3D hyp_vcpu->vcpu.arch.ctxt.regs.pc; host_vcpu->arch.ctxt.regs.pstate =3D 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 =3D vcpu_el2_e2h_is_set(vcpu) ? TR_EL20 : TR_EL2; > + else > + wi.regime =3D TR_EL10; > + wi.as_el0 =3D !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 &=3D pov_perms & POE_R; wr->pw &=3D pov_perms & POE_W; wr->px &=3D pov_perms & POE_X; } if (wr->uov) { ... wr->ur &=3D uov_perms & POE_R; wr->uw &=3D uov_perms & POE_W; wr->ux &=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201232116.1988= 791-1-irogers@google.com?part=3D5