• Mark Rutland's avatar
    KVM: arm/arm64: Correct AArch32 SPSR on exception entry · 1cfbb484
    Mark Rutland authored
    Confusingly, there are three SPSR layouts that a kernel may need to deal
    with:
    
    (1) An AArch64 SPSR_ELx view of an AArch64 pstate
    (2) An AArch64 SPSR_ELx view of an AArch32 pstate
    (3) An AArch32 SPSR_* view of an AArch32 pstate
    
    When the KVM AArch32 support code deals with SPSR_{EL2,HYP}, it's either
    dealing with #2 or #3 consistently. On arm64 the PSR_AA32_* definitions
    match the AArch64 SPSR_ELx view, and on arm the PSR_AA32_* definitions
    match the AArch32 SPSR_* view.
    
    However, when we inject an exception into an AArch32 guest, we have to
    synthesize the AArch32 SPSR_* that the guest will see. Thus, an AArch64
    host needs to synthesize layout #3 from layout #2.
    
    This patch adds a new host_spsr_to_spsr32() helper for this, and makes
    use of it in the KVM AArch32 support code. For arm64 we need to shuffle
    the DIT bit around, and remove the SS bit, while for arm we can use the
    value as-is.
    
    I've open-coded the bit manipulation for now to avoid having to rework
    the existing PSR_* definitions into PSR64_AA32_* and PSR32_AA32_*
    definitions. I hope to perform a more thorough refactoring in future so
    that we can handle pstate view manipulation more consistently across the
    kernel tree.
    Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
    Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
    Reviewed-by: default avatarAlexandru Elisei <alexandru.elisei@arm.com>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20200108134324.46500-4-mark.rutland@arm.com
    1cfbb484
kvm_emulate.h 8.36 KB