[PATCH v2 5/7] ARM: switch_to: clean up Thumb2 code path

Nicolas Pitre nico at fluxnic.net
Mon Oct 18 08:37:43 PDT 2021


On Mon, 18 Oct 2021, Ard Biesheuvel wrote:

> The load-multiple instruction that essentially performs the switch_to
> operation in ARM mode, by loading all callee save registers as well the
> stack pointer and the program counter, is split into 3 separate loads
> for Thumb-2, with the IP register used as a temporary to capture the
> value of R4 before it gets overwritten.
> 
> We can clean this up a bit, by sticking with a single LDMIA instruction,
> but one that pops SP and PC into IP and LR, respectively, and by using
> ordinary move register and branch instructions to get those values into
> SP and PC. This also allows us to move the set_current call closer to
> the assignment of SP, reducing the window where those are mutually out
> of sync. This is especially relevant for CONFIG_VMAP_STACK, which is
> being introduced in a subsequent patch, where we need to issue a load
> that might fault from the new stack while running from the old one, to
> ensure that stale PMD entries in the VMALLOC space are synced up.

What could happen if they are of sync? The window is small but still.


Nicolas



More information about the linux-arm-kernel mailing list