From: sashiko-bot@kernel.org
To: "Fuad Tabba" <fuad.tabba@linux.dev>
Cc: "Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>,
kvmarm@lists.linux.dev
Subject: Re: [PATCH v4 2/8] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code
Date: Mon, 06 Jul 2026 10:25:02 +0000 [thread overview]
Message-ID: <20260706102503.63AD01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706095927.560795-3-fuad.tabba@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] `kvm_vcpu_read_sys_reg()` and `kvm_vcpu_write_sys_reg()` are fundamentally unsafe for nVHE EL2 emulation (e.g., during `fixup_guest_exit`), despite the commit claiming they are "valid in any context".
--
commit 61ee8756572b776a9170ae13bb7ede91ed5afb18
Author: Fuad Tabba <fuad.tabba@linux.dev>
KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code
This commit moves the wrappers for vcpu_read_sys_reg and vcpu_write_sys_reg
from exception.c to kvm_emulate.h as kvm_vcpu_read_sys_reg and
kvm_vcpu_write_sys_reg. This makes them available to all hyp code so that
emulation logic can be shared at EL2.
> diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> index 5bf3d7e1d92c7..80b30fead3d16 100644
> --- a/arch/arm64/include/asm/kvm_emulate.h
> +++ b/arch/arm64/include/asm/kvm_emulate.h
> @@ -506,6 +506,22 @@ static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
> return __vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;
> }
>
> +static inline u64 kvm_vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg)
> +{
> + if (has_vhe())
> + return vcpu_read_sys_reg(vcpu, reg);
> +
> + return __vcpu_sys_reg(vcpu, reg);
> +}
[Severity: High]
This is a pre-existing issue, but are these accessors actually safe for nVHE
EL2 emulation? The commit message claims they are valid in any context, but
during early exit handling (like fixup_guest_exit), the live guest state is
still in hardware registers.
Because has_vhe() evaluates to false in nVHE EL2, kvm_vcpu_read_sys_reg() falls
back to reading the memory context via __vcpu_sys_reg(). This means it reads
stale state until __sysreg_save_state_nvhe() runs.
For example, when an exception is injected into a protected guest via
inject_sync64(), enter_exception64() uses this helper to read SCTLR_EL1 and
computes the new PSTATE from it. This reads a stale SCTLR_EL1, potentially
corrupting the injected PSTATE.SPAN and PSTATE.SSBS bits.
Could exposing these as generic helpers lead to more traps where EL2 code
accidentally reads stale memory-backed sysregs before they are synced?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260706095927.560795-1-fuad.tabba@linux.dev?part=2
next prev parent reply other threads:[~2026-07-06 10:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 9:59 [PATCH v4 0/8] KVM: arm64: pKVM vCPU state management at EL2 (series A) Fuad Tabba
2026-07-06 9:59 ` [PATCH v4 1/8] KVM: arm64: Extract MPIDR computation into a shared header Fuad Tabba
2026-07-06 9:59 ` [PATCH v4 2/8] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code Fuad Tabba
2026-07-06 10:25 ` sashiko-bot [this message]
2026-07-06 11:48 ` Fuad Tabba
2026-07-14 0:30 ` Oliver Upton
2026-07-14 6:41 ` Fuad Tabba
2026-07-06 9:59 ` [PATCH v4 3/8] KVM: arm64: Factor out reusable vCPU reset helpers Fuad Tabba
2026-07-06 9:59 ` [PATCH v4 4/8] KVM: arm64: Move PSCI helper functions to a shared header Fuad Tabba
2026-07-06 9:59 ` [PATCH v4 5/8] KVM: arm64: Add host and hypervisor vCPU lookup primitives Fuad Tabba
2026-07-06 9:59 ` [PATCH v4 6/8] KVM: arm64: Minimise EL2's exposure of host VGIC state during world switch Fuad Tabba
2026-07-06 10:28 ` sashiko-bot
2026-07-06 11:53 ` Fuad Tabba
2026-07-06 9:59 ` [PATCH v4 7/8] KVM: arm64: Add primitives to flush/sync the VGIC state at EL2 Fuad Tabba
2026-07-06 9:59 ` [PATCH v4 8/8] KVM: arm64: Implement lazy vCPU state sync for non-protected guests Fuad Tabba
2026-07-06 10:36 ` sashiko-bot
2026-07-06 11:59 ` Fuad Tabba
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=20260706102503.63AD01F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fuad.tabba@linux.dev \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@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