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

Nia Su nia.su at sifive.com
Tue Sep 15 22:56:42 PDT 2026


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

 include/sbi/sbi_platform.h | 19 ++++++++++---
 lib/sbi/sbi_hart.c         | 68 ++++++++++++++++++++++++++++++----------------
 lib/sbi/sbi_init.c         |  9 ++++++
 3 files changed, 69 insertions(+), 27 deletions(-)
---
base-commit: 35511bc6ee1c9c17b6a89b44c52e2044bb51b979
change-id: 20260901-smrnmi-context-restore-b3b1f23bec28

--




More information about the opensbi mailing list