[PATCH v3 0/3] lib: sbi: Fix Smrnmi resume init and optional platform callback

Anup Patel anup at brainfault.org
Mon Nov 2 23:53:36 PST 2026


On Wed, Sep 16, 2026 at 11:26 AM Nia Su <nia.su at sifive.com> wrote:
>
> On non-retentive suspend resume, the hart never initializes the
> Smrnmi CSRs the way hart_detect_features() does at boot, so a hart
> waking from non-retentive suspend resumes with NMIs disabled and no
> RNMI handler installed.
>
> Patch 1 extracts the setup into sbi_smrnmi_hart_init() and calls it
> from both hart_detect_features() and sbi_hart_reinit().
>
> Patch 2 changes smrnmi_handlers_init to return int, so a failed
> callback no longer gets ignored before NMIE is enabled anyway. It
> also documents the SBI_OK/error return convention and aligns the
> neighboring rnmi_handler comment to use SBI_OK as well.
>
> Patch 3 allows a NULL smrnmi_handlers_init only when the platform
> sets the new SBI_PLATFORM_HAS_FIXED_SMRNMI_VECTOR feature flag, so a
> platform with a fixed or mtvec-based NMI vector can say so
> explicitly instead of a bare NULL being indistinguishable from a
> callback the platform simply forgot to set. It also reports the init
> mode ("Platform" or "Default") in the boot HART banner.
>
> Signed-off-by: Nia Su <nia.su at sifive.com>
> ---
> Changes in v3:
> - Patch 1: call sbi_smrnmi_hart_init() early in sbi_hart_reinit();
>   document that smrnmi_handlers_init may run twice on cold boot.
> - Patch 2: document SBI_OK/error return convention on
>   smrnmi_handlers_init; align rnmi_handler comment to use SBI_OK too.
> - Patch 3: gate NULL smrnmi_handlers_init behind new
>   SBI_PLATFORM_HAS_FIXED_SMRNMI_VECTOR flag instead of accepting it
>   unconditionally.
> - Link to v2: https://lore.kernel.org/r/20260903-smrnmi-context-restore-v2-0-10b17506d257@sifive.com
>
> Changes in v2:
> - Break v1's patch 1 into three smaller, self-contained patches for
>   a clearer structure.
> - Dropped v1's patch 2, which is unrelated to this fix and will be
>   sent separately.
> - Link to v1: https://lore.kernel.org/opensbi/20260827-rnmi-trap-fixes-v1-0-df371cf92301@sifive.com/
>
> ---
> Nia Su (3):
>       lib: sbi: extract sbi_smrnmi_hart_init() and call on non-retentive resume
>       lib: sbi: report smrnmi_handlers_init failures instead of ignoring them
>       lib: sbi: allow NULL smrnmi_handlers_init and report init mode at boot

I have renamed sbi_smrnmi_hart_init() to smrnmi_hart_init() at the time
of merging. Otherwise, LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Applied this series to the riscv/opensbi repo.

Thanks,
Anup



More information about the opensbi mailing list