Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	Andrew Donnellan <andrew+kernel@donnellan.id.au>,
	linux-s390@vger.kernel.org, linux-debuggers@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] s390: add CFI directives for call_on_stack
Date: Mon, 30 Nov 2026 11:28:41 -0800	[thread overview]
Message-ID: <87h5gy2k5y.fsf@oracle.com> (raw)
In-Reply-To: <20261124110155.32552B6a-hca@linux.ibm.com>

Hello Heiko,

Thank you very much for the review!

Heiko Carstens <hca@linux.ibm.com> writes:
> Hi Stephen,
>
> again, sorry for taking way too long to look into this!

No, not at all. And my apologies for pinging you just a few days before
I would be out for the Thanksgiving holiday!

> On Fri, Oct 30, 2026 at 04:17:10PM -0700, Stephen Brennan wrote:
>> When debugging s390 on drgn, we experience two issues. First, when a
>> panic is triggered on CPU 0, drgn is unable to unwind past a stack
>> switching event[1,2]. Second, drgn is unable to unwind through an
>> interrupt exception frame.
>> 
>> It turns out that the reason for both is the generated call_on_stack()
>> assembly. It modifies %r15 (the stack pointer) without any CFI
>> directives describing this change. Thus, the compiler-generated CFI is
>> wrong, and drgn tries to unwind using rules based on the wrong SP value.
>> 
>> To resolve this, use %r10 (a callee-saved register) to store the CFA in
>> a temporary register. Then, emit a CFI directive describing the change.
>> So long as DWARF CFI is used to unwind all leaf functions, the value of
>> %r10 should be recoverable, and unwinders will be able to use it to
>> determine the CFA and continue to the new stack.
>> 
>> I've tested this only in a QEMU VM using drgn's vmtest framework.
>> With the patch, drgn is able to unwind through two stack changes: the
>> change to the IRQ stack, and the change to the CPU0 nodat_stack during a
>> panic on CPU 0.
>> 
>> [1]: https://github.com/osandov/drgn/blob/97b613c23bd4d100a61b3b06fb1b5097fcef9f61/vmtest/enter_kdump.py#L69-L74
>> [2]: https://github.com/osandov/drgn/blob/97b613c23bd4d100a61b3b06fb1b5097fcef9f61/tests/linux_kernel/vmcore/test_vmcore.py#L19-L25
>> 
>> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
>> ---
>>  arch/s390/include/asm/stacktrace.h | 18 +++++++++++++++++-
>>  1 file changed, 17 insertions(+), 1 deletion(-)
>
> ...
>
>> +	register unsigned long cfa asm("10") =				\
>> +		frame + STACK_FRAME_OVERHEAD;				\
>
> ...
>
>> @@ -196,15 +208,19 @@ static __always_inline unsigned long get_stack_pointer(struct task_struct *task,
>>  									\
>>  	CALL_TYPECHECK_##nr(__VA_ARGS__);				\
>>  	asm volatile(							\
>> +		CALL_ON_STACK_CFI(".cfi_remember_state\n")		\
>>  		"	lgr	%[_prev],15\n"				\
>> +		CALL_ON_STACK_CFI(".cfi_def_cfa %[_cfa],0\n")	\
>>  		"	lg	15,%[_stack]\n"				\
>>  		"	stg	%[_frame],%[_bc](15)\n"			\
>>  		"	brasl	14,%[_fn]\n"				\
>> -		"	lgr	15,%[_prev]"				\
>> +		"	lgr	15,%[_prev]\n"				\
>> +		CALL_ON_STACK_CFI(".cfi_restore_state\n")		\
>>  		: [_prev] "=&d" (prev), CALL_FMT_##nr			\
>>  		: [_stack] "R" (__stack),				\
>>  		  [_bc] "i" (offsetof(struct stack_frame, back_chain)),	\
>>  		  [_frame] "d" (frame),					\
>> +		  [_cfa] "d" (cfa),					\
>>  		  [_fn] "X" (__fn) : CALL_CLOBBER_##nr);		\
>
> The patch is fine, however this should also work without explicitly specifying
> to use register 10. Any other free register should work as well, since the
> inline assembly is sort of emulating a function call to a different stack -
> and therefore all non-callee saved registers are already clobbered, either
> early clobbered, or explicitly clobbered.
>
> The compiler can only chose between r6 to r13; all of them are callee-saved.

I see what you mean: CALL_CLOBBER_##nr and CALL_FMT_##nr are both
ensuring that the only general-purpose registers available to the
compiler are callee-saved.

> Or in other words: I'd prefer this
>
>> +	register unsigned long cfa asm("10") =				\
>> +		frame + STACK_FRAME_OVERHEAD;				\
>
> to be changed to
>
>> +	unsigned long cfa = frame + STACK_FRAME_OVERHEAD;		\
>
> ..unless I am missing something, but "_prev" also relies on this already.

This is much better than manually specifying a register, thank you. I'll
send a v2 momentarily.

Thank you!
Stephen

      reply	other threads:[~2026-11-30 19:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 23:17 [PATCH] s390: add CFI directives for call_on_stack Stephen Brennan
2026-10-30 23:29 ` sashiko-bot
2026-11-16 18:02 ` Stephen Brennan
2026-11-18 10:13   ` Heiko Carstens
2026-11-24 11:01 ` Heiko Carstens
2026-11-30 19:28   ` Stephen Brennan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h5gy2k5y.fsf@oracle.com \
    --to=stephen.s.brennan@oracle.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andrew+kernel@donnellan.id.au \
    --cc=borntraeger@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=linux-debuggers@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox