From: Marc Zyngier <maz@kernel.org>
To: Fuad Tabba <tabba@google.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
oliver.upton@linux.dev, will@kernel.org, joey.gouly@arm.com,
suzuki.poulose@arm.com, yuzenghui@huawei.com,
catalin.marinas@arm.com, vdonnefort@google.com,
qperret@google.com, sebastianene@google.com, keirf@google.com,
smostafa@google.com
Subject: Re: [PATCH v1 3/4] KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception
Date: Tue, 05 Aug 2025 19:41:26 +0100 [thread overview]
Message-ID: <86cy99a9wp.wl-maz@kernel.org> (raw)
In-Reply-To: <20250805135617.831971-4-tabba@google.com>
On Tue, 05 Aug 2025 14:56:16 +0100,
Fuad Tabba <tabba@google.com> wrote:
>
> In pKVM, a race condition can occur if a guest updates its VBAR_EL1
> register and, before a vCPU exit synchronizes this change, the
> hypervisor needs to inject an undefined exception into a protected
> guest.
>
> In this scenario, the vCPU still holds the stale VBAR_EL1 value from
> before the guest's update. When pKVM injects the exception, it ends up
> using the stale value.
>
> Explicitly read the live value of VBAR_EL1 from the guest and update the
> vCPU value immediately before pending the exception. This ensures the
> vCPU's value is the same as the guest's and that the exception will be
> handled at the correct address upon resuming the guest.
>
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
> arch/arm64/kvm/hyp/nvhe/sys_regs.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c
> index bbd60013cf9e..b34b10be1ad7 100644
> --- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c
> +++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c
> @@ -253,6 +253,7 @@ static void inject_undef64(struct kvm_vcpu *vcpu)
>
> *vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR);
> *vcpu_cpsr(vcpu) = read_sysreg_el2(SYS_SPSR);
> + vcpu_write_sys_reg(vcpu, read_sysreg_el1(SYS_VBAR), VBAR_EL1);
>
> kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC);
>
There is something I don't understand. vcpu_write_sys_reg() is only
useful if you make use of the SYSREGS_ON_CPU flag. Which is only
driven by the VHE code (in arch/arm64/kvm/hyp/vhe/sysreg-sr.c).
As a consequence, this only writes to memory, since the flag is always
false, and we take the following path:
static inline void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg)
{
u64 (*xlate)(u64) = NULL;
unsigned int el1r;
if (!vcpu_get_flag(vcpu, SYSREGS_ON_CPU))
goto memory_write;
[...]
memory_write:
__vcpu_assign_sys_reg(vcpu, reg, val);
}
My conclusion so far is that you only ever need to write to the shadow
view of the register, and that the previous patch serves no purpose.
Am I missing anything?
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2025-08-05 18:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 13:56 [PATCH v1 0/4] KVM: arm64: Fixes to handling of restricted registers for protected VMs Fuad Tabba
2025-08-05 13:56 ` [PATCH v1 1/4] KVM: arm64: Handle AIDR_EL1 and REVIDR_EL1 in host " Fuad Tabba
2025-08-05 13:56 ` [PATCH v1 2/4] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code Fuad Tabba
2025-08-05 14:38 ` Will Deacon
2025-08-05 15:51 ` Fuad Tabba
2025-08-05 13:56 ` [PATCH v1 3/4] KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception Fuad Tabba
2025-08-05 14:35 ` Will Deacon
2025-08-05 15:25 ` Fuad Tabba
2025-08-05 18:41 ` Marc Zyngier [this message]
2025-08-05 18:43 ` Fuad Tabba
2025-08-05 13:56 ` [PATCH v1 4/4] arm64: vgic-v2: Fix guest endianness check in hVHE mode Fuad Tabba
2025-08-05 14:39 ` [PATCH v1 0/4] KVM: arm64: Fixes to handling of restricted registers for protected VMs Will Deacon
2025-08-05 15:20 ` 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=86cy99a9wp.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=keirf@google.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=sebastianene@google.com \
--cc=smostafa@google.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=vdonnefort@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).