When guest triggers async aborts, in most platform, such aborts will be routed to hypervisor. But we don't want the hypervisor to handle such aborts, so we have to route such aborts back to the guest.
This helper is using the HCR_EL2.VSE (HCR.VA for aarch32) bit to route such aborts back to the guest. After updating HCR_EL2.VSE bit in vCPU context, we write the value to HCR_EL2 immediately. In this case we don't need to move the restoration of HCR_EL2 to other place, and it worked regardless of whether we get preempted. If the guest PC had been advanced by SVC/HVC/SMC instructions before we caught the SError in hypervisor, we have to adjust the guest PC to exact address while the SError generated. About HSR_EC_SVC32/64, even thought we don't trap SVC32/64 today, we would like them to be handled here. This would be useful when VM introspection will gain support of SVC32/64 trapping. After updating HCR_EL2.VSE bit of vCPU HCR_EL2, write the value to HCR_EL2 immediately. In this case we don't need to move the restoration of HCR_EL2 to leave_hypervisor_tail, and it worked regardless of whether we get preempted. This helper will be used by the later patches in this series, we use #if 0 to disable it in this patch temporarily to remove the warning message of unused function from compiler. Signed-off-by: Wei Chen <wei.c...@arm.com> Acked-by: Stefano Stabellini <sstabell...@kernel.org> Reviewed-by: Stefano Stabellini <sstabell...@kernel.org> --- v2->v3: 1. After updating HCR_EL2.VSE bit of vCPU HCR_EL2, write the value to HCR_EL2 immediately. 2. Explain in commit message why we write the value to HCR_EL2 after updating the HCR_EL2.VSE bit in vCPU context. 3. Add Stefano's Reviewed-by tag. --- xen/arch/arm/traps.c | 33 +++++++++++++++++++++++++++++++++ xen/include/asm-arm/processor.h | 1 + 2 files changed, 34 insertions(+) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 5f758e1..b15923a 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -618,6 +618,39 @@ static void inject_dabt_exception(struct cpu_user_regs *regs, #endif } +#if 0 +/* Inject a virtual Abort/SError into the guest. */ +static void inject_vabt_exception(struct cpu_user_regs *regs) +{ + const union hsr hsr = { .bits = regs->hsr }; + + /* + * SVC/HVC/SMC already have an adjusted PC (See ARM ARM DDI 0487A.j + * D1.10.1 for more details), which we need to correct in order to + * return to after having injected the SError. + */ + switch ( hsr.ec ) + { + case HSR_EC_SVC32: + case HSR_EC_HVC32: + case HSR_EC_SMC32: +#ifdef CONFIG_ARM_64 + case HSR_EC_SVC64: + case HSR_EC_HVC64: + case HSR_EC_SMC64: +#endif + regs->pc -= hsr.len ? 4 : 2; + break; + + default: + break; + } + + current->arch.hcr_el2 |= HCR_VA; + WRITE_SYSREG(current->arch.hcr_el2, HCR_EL2); +} +#endif + struct reg_ctxt { /* Guest-side state */ uint32_t sctlr_el1; diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h index 4b6338b..d7b0711 100644 --- a/xen/include/asm-arm/processor.h +++ b/xen/include/asm-arm/processor.h @@ -252,6 +252,7 @@ #define HSR_EC_HVC32 0x12 #define HSR_EC_SMC32 0x13 #ifdef CONFIG_ARM_64 +#define HSR_EC_SVC64 0x15 #define HSR_EC_HVC64 0x16 #define HSR_EC_SMC64 0x17 #define HSR_EC_SYSREG 0x18 -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org https://lists.xen.org/xen-devel