Re: [RFC PATCH 06/13] arm64: percpu: Add infrastructure for preemptible this_cpu_*() ops
From: Heiko Carstens
Date: Tue Jul 28 2026 - 13:41:58 EST
On Tue, Jul 28, 2026 at 01:38:52PM +0100, Mark Rutland wrote:
> This patch adds infrastructure for a scheme where this_cpu_*() ops do
> not need to transiently disable preemption, avoiding the negative
> impacts described above.
>
> Each operation registers a critical section during which the exception
> return code will adjust the offset and addresses if preemption occurs
> mid-sequence. The critical section is registered/unregistered with a
> small prologue and epilogue which encodes three distinct GPRRs (<pcp>,
> <off>, <addr>) into a new thread_info::pcp_gprs field:
>
> // Prologue. Enable fixups for <off> and <addr>.
> mrs <tsk>, sp_el0
> mov <tmp>, #__VAL_PCPU_GPRS(<pcp>, <off>, <addr>)
> strh <tmp>, [<tsk>, #TSK_TI_PCPU_GPRS]
>
> // Generate cpu-specific address
> mrs <off>, TPIDR_ELx
> add <addr>, <pcp>, <off>
>
> // Perform access sequence
> ldr <val>, [<addr>]
>
> // Epilogue. Disable fixups
> strh wzr, [<tsk>, #TSK_TI_PCPU_GPRS]
>
> If an exception is taken from within the critical section, the exception
> return code will adjust <off> to be the current CPU's offset, and will
> adjust <addr> to be (<pcp> + <off>). Distinct registers are used for
> <pcp>, <off>, and <addr>, so that the fixup can be applied safely at any
> point during the critical section.
This looks indeed better than that what I came up with for s390.
It works without comparing instruction pointers, also works out-of-the-box
with kprobes, and hence the fixup is much simpler. I guess I'll try to change
s390 to a similar mechanism and see what the result will look like. It will
use one more instruction to the current version, as far as I can tell now, but
the simplicity is probably worth it.