public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: Bo Gan <ganboing@gmail.com>
Cc: Xiang W <wxjstz@126.com>,
	 opensbi@lists.infradead.org,  Xiang W <wangxiang@iscas.ac.cn>
Subject: Re: [PATCH] lib: sbi: Add runtime stack overrun detection
Date: Tue, 18 Nov 2025 10:25:09 +0100	[thread overview]
Message-ID: <mvmfrab4rre.fsf@suse.de> (raw)
In-Reply-To: <97960cc7-8d37-4105-abe5-681ec5bbe334@gmail.com> (Bo Gan's message of "Tue, 18 Nov 2025 00:43:24 -0800")

On Nov 18 2025, Bo Gan wrote:

> Hi Xiang,
>
> On 11/17/25 20:19, Xiang W wrote:
>> +	if (sp < stack_start || sp > stack_end) {
>> +		/* Reset SP to output error messages */
>> +		asm volatile("mv sp, %0"::"r"(stack_end));
>
> I don't think it's safe to switch stack in C function. I know you want
> to avoid re-entrant, but do it in C function is way too risky. Better
> have an asm wapper over this function and do it before invoking the C
> portion.

The GCC docs makes this explicitly undefined:

     Another restriction is that the clobber list should not contain the
    stack pointer register.  This is because the compiler requires the value
    of the stack pointer to be the same after an 'asm' statement as it was
    on entry to the statement.  However, previous versions of GCC did not
    enforce this rule and allowed the stack pointer to appear in the list,
    with unclear semantics.  This behavior is deprecated and listing the
    stack pointer may become an error in future versions of GCC.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

      reply	other threads:[~2025-11-18  9:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18  4:19 [PATCH] lib: sbi: Add runtime stack overrun detection Xiang W
2025-11-18  4:25 ` Xiang W
2025-11-18  8:43 ` Bo Gan
2025-11-18  9:25   ` Andreas Schwab [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=mvmfrab4rre.fsf@suse.de \
    --to=schwab@suse.de \
    --cc=ganboing@gmail.com \
    --cc=opensbi@lists.infradead.org \
    --cc=wangxiang@iscas.ac.cn \
    --cc=wxjstz@126.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