Re: [RFC] in-kernel rseq

From: Heiko Carstens

Date: Tue Feb 24 2026 - 11:16:24 EST


On Tue, Feb 24, 2026 at 05:02:10PM +0100, Heiko Carstens wrote:
> On Tue, Feb 24, 2026 at 04:20:32PM +0100, Peter Zijlstra wrote:
> > > With PREEMPT_LAZY this turns into:
> > >
> > > 0000000000000000 <foo>:
> > > 0: c0 04 00 00 00 00 jgnop 0 <foo>
> > > 6: eb af f0 68 00 24 stmg %r10,%r15,104(%r15)
> > > c: b9 04 00 ef lgr %r14,%r15
> > > 10: b9 04 00 b2 lgr %r11,%r2
> > > 14: e3 f0 ff c8 ff 71 lay %r15,-56(%r15)
> > > 1a: e3 e0 f0 98 00 24 stg %r14,152(%r15) <- up to here: create stack frame
> >
> > So some of that could be elided with that asm call thunk thing we talked
> > about yesterday, right?
>
> Yes, with
> #define __preempt_schedule_notrace() \
> asm volatile("brasl %%r14,preempt_schedule_notrace_thunk" : : : "cc", "memory", "r14")
>
> we would end up with:

...[random junk]...

Sorry, that was an incorrect version, only handling this_cpu_add().

So with

static DEFINE_PER_CPU(long, bar);

long foo(long val)
{
return this_cpu_add_return(bar, val);
}

and the above define the result would be the below (no stack frame -
up to the thunk to handle that, including register save/restore).

0000000000000000 <foo>:
0: c0 04 00 00 00 00 jgnop 0 <foo>
6: eb 01 03 a8 00 6a asi 936,1
c: c0 10 00 00 00 00 larl %r1,c <foo+0xc>
e: R_390_PC32DBL .data..percpu+0x2
12: a7 39 00 00 lghi %r3,0
16: e3 10 33 b8 00 08 ag %r1,952(%r3)
1c: eb 02 10 00 00 e8 laag %r0,%r2,0(%r1)
22: eb ff 03 a8 00 6e alsi 936,-1
28: a7 a4 00 05 jhe 32 <foo+0x32>
2c: b9 08 00 20 agr %r2,%r0
30: 07 fe br %r14
32: e3 e0 f0 88 00 24 stg %r14,136(%r15)
38: c0 e5 00 00 00 00 brasl %r14,38 <foo+0x38>
3a: R_390_PC32DBL preempt_schedule_notrace_thunk+0x2
3e: e3 e0 f0 88 00 04 lg %r14,136(%r15)
44: b9 08 00 20 agr %r2,%r0
48: 07 fe br %r14