Re: [PATCH 0/9] s390: Improve this_cpu operations
From: Peter Zijlstra
Date: Tue Mar 17 2026 - 17:10:23 EST
On Tue, Mar 17, 2026 at 08:54:27PM +0100, Heiko Carstens wrote:
> The idea is that this_cpu operations based on atomic instructions are
> guarded with mvyi instructions:
>
> - The first mvyi instruction writes the register number, which contains
> the percpu address variable to lowcore. This also indicates that a
> percpu code section is executed.
>
> - The first instruction following the mvyi instruction must be the ag
> instruction which adds the percpu offset to the percpu address register.
>
> - Afterwards the atomic percpu operation follows.
>
> - Then a second mvyi instruction writes a zero to lowcore, which indicates
> the end of the percpu code section.
>
> - In case of an interrupt/exception/nmi the register number which was
> written to lowcore is copied to the exception frame (pt_regs), and a zero
> is written to lowcore.
>
> - On return to the previous context it is checked if a percpu code section
> was executed (saved register number not zero), and if the process was
> migrated to a different cpu. If the percpu offset was already added to
> the percpu address register (instruction address does _not_ point to the
> ag instruction) the content of the percpu address register is adjusted so
> it points to percpu variable of the new cpu.
>
> All of this seems to work, but of course it could still be broken since I
> missed some detail.
Right, so this relies on them being single atomic RmW instructions. If
the interrupt/exception happens before the RmW the address is adjusted
and the atomic instruction is executed on the correct CPU. If the
interrupt/exception hits after the atomic but before the second "mvyi"
the address is still adjusted but then goes unused.
I don't immediately see a hole in that scheme. It is neat for not having
retries.