]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception
authorFuad Tabba <tabba@google.com>
Thu, 7 Aug 2025 12:01:32 +0000 (13:01 +0100)
committerOliver Upton <oliver.upton@linux.dev>
Fri, 8 Aug 2025 08:29:32 +0000 (01:29 -0700)
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.

Reported-by: Keir Fraser <keirf@google.com>
Signed-off-by: Fuad Tabba <tabba@google.com>
Link: https://lore.kernel.org/r/20250807120133.871892-3-tabba@google.com
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kvm/hyp/nvhe/sys_regs.c

index bbd60013cf9e98ecb32d20abd3ff6334d3dfa8f8..71d2fc97f0046a777b2e785b5cb2f6c188e183e4 100644 (file)
@@ -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_assign_sys_reg(vcpu, read_sysreg_el1(SYS_VBAR), VBAR_EL1);
 
        kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC);