Skip to content

Commit e5d40a5

Browse files
author
Marc Zyngier
committed
KVM: arm64: pkvm: Add a generic synchronous exception injection primitive
Similarly to the "classic" KVM code, pKVM doesn't have an "anything goes" synchronous exception injection primitive. Carve one out of the UNDEF injection code. Link: https://patch.msgid.link/20260108173233.2911955-8-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 70a5ce4 commit e5d40a5

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

arch/arm64/kvm/hyp/nvhe/sys_regs.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,15 @@ static u64 pvm_calc_id_reg(const struct kvm_vcpu *vcpu, u32 id)
243243
}
244244
}
245245

246-
/*
247-
* Inject an unknown/undefined exception to an AArch64 guest while most of its
248-
* sysregs are live.
249-
*/
250-
static void inject_undef64(struct kvm_vcpu *vcpu)
246+
static void inject_sync64(struct kvm_vcpu *vcpu, u64 esr)
251247
{
252-
u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
253-
254248
*vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR);
255249
*vcpu_cpsr(vcpu) = read_sysreg_el2(SYS_SPSR);
250+
251+
/*
252+
* Make sure we have the latest update to VBAR_EL1, as pKVM
253+
* handles traps very early, before sysregs are resync'ed
254+
*/
256255
__vcpu_assign_sys_reg(vcpu, VBAR_EL1, read_sysreg_el1(SYS_VBAR));
257256

258257
kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC);
@@ -265,6 +264,15 @@ static void inject_undef64(struct kvm_vcpu *vcpu)
265264
write_sysreg_el2(*vcpu_cpsr(vcpu), SYS_SPSR);
266265
}
267266

267+
/*
268+
* Inject an unknown/undefined exception to an AArch64 guest while most of its
269+
* sysregs are live.
270+
*/
271+
static void inject_undef64(struct kvm_vcpu *vcpu)
272+
{
273+
inject_sync64(vcpu, (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT));
274+
}
275+
268276
static u64 read_id_reg(const struct kvm_vcpu *vcpu,
269277
struct sys_reg_desc const *r)
270278
{

0 commit comments

Comments
 (0)