• Ard Biesheuvel's avatar
    ARM: entry: rework stack realignment code in svc_entry · ae5cc07d
    Ard Biesheuvel authored
    The original Thumb-2 enablement patches updated the stack realignment
    code in svc_entry to work around the lack of a STMIB instruction in
    Thumb-2, by subtracting 4 from the frame size, inverting the sense of
    the misaligment check, and changing to a STMIA instruction and a final
    stack push of a 4 byte quantity that results in the stack becoming
    aligned at the end of the sequence. It also pushes and pops R0 to the
    stack in order to have a temp register that Thumb-2 allows in general
    purpose ALU instructions, as TST using SP is not permitted.
    
    Both are a bit problematic for vmap'ed stacks, as using the stack is
    only permitted after we decide that we did not overflow the stack, or
    have already switched to the overflow stack.
    
    As for the alignment check: the current approach creates a corner case
    where, if the initial SUB of SP ends up right at the start of the stack,
    we will end up subtracting another 8 bytes and overflowing it.  This
    means we would need to add the overflow check *after* the SUB that
    deliberately misaligns the stack. However, this would require us to keep
    local state (i.e., whether we performed the subtract or not) across the
    overflow check, but without any GPRs or stack available.
    
    So let's switch to an approach where we don't use the stack, and where
    the alignment check of the stack pointer occurs in the usual way, as
    this is guaranteed not to result in overflow. This means we will be able
    to do the overflow check first.
    
    While at it, switch to R1 so the mode stack pointer in R0 remains
    accessible.
    Acked-by: default avatarNicolas Pitre <nico@fluxnic.net>
    Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
    Tested-by: default avatarMarc Zyngier <maz@kernel.org>
    Tested-by: Vladimir Murzin <vladimir.murzin@arm.com> # ARMv7M
    ae5cc07d
entry-armv.S 30.8 KB