public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Yu-Chine Peter Lin <peter.lin@sifive.com>
To: buenocalvachejoel@gmail.com, opensbi@lists.infradead.org
Cc: anup@brainfault.org
Subject: Re: [PATCH] firmware: fw_base: make stack guard setup conditional on Zkr
Date: Wed, 1 Apr 2026 10:07:53 +0800	[thread overview]
Message-ID: <2c87ff34-ea8a-48be-9b05-9f607700dc66@sifive.com> (raw)
In-Reply-To: <20260331095943.133791-1-buenocalvachejoel@gmail.com>

Hi Joel,

Thanks for the patch,

On 3/31/26 5:59 PM, buenocalvachejoel@gmail.com wrote:
> From: Joel Bueno <buenocalvachejoel@gmail.com>
> 
> Zkr isn't explicitly selected as a mandatory extension to run OpenSBI
> as per: docs/platform_requirements.md
> 
> Since this happens very early on the boot flow of OpenSBI where the
> dynamic extension checks haven't yet happened, we must guard the Zkr
> stack setup behind an ifdef block so that it only gets compiled for
> targets that do actually have the extension.
> 
> Signed-off-by: Joel Bueno <buenocalvachejoel@gmail.com>
> ---
>   firmware/fw_base.S | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
> index 63bb4473..9ea93907 100644
> --- a/firmware/fw_base.S
> +++ b/firmware/fw_base.S
> @@ -107,6 +107,7 @@ _bss_zero:
>   	add	s4, s4, __SIZEOF_POINTER__
>   	blt	s4, s5, _bss_zero
>   
> +#if defined(__riscv_zkr)
>   	/* Trying to initialize the stack guard via the Zkr extension */
>   	lla	t0, __stack_chk_guard_done
>   	csrw	CSR_MTVEC, t0
> @@ -130,6 +131,7 @@ __stack_chk_guard_loop:
>   	j	__stack_chk_guard_done
>   	.align 3
>   __stack_chk_guard_done:
> +#endif

The current trap-based detection mechanism is intentional and works 
correctly
on systems both with and without Zkr.
Using #ifdef guards would break binary portability, e.g. using single 
binary on
heterogeneous systems (e.g., SMP with mixed Zkr/non-Zkr cores)

Regards,
Peter Lin

>   
>   	/* Setup temporary trap handler */
>   	lla	s4, _start_hang


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

      reply	other threads:[~2026-04-01  2:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31  9:59 [PATCH] firmware: fw_base: make stack guard setup conditional on Zkr buenocalvachejoel
2026-04-01  2:07 ` Yu-Chine Peter Lin [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=2c87ff34-ea8a-48be-9b05-9f607700dc66@sifive.com \
    --to=peter.lin@sifive.com \
    --cc=anup@brainfault.org \
    --cc=buenocalvachejoel@gmail.com \
    --cc=opensbi@lists.infradead.org \
    /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