SSE event injection across domains: privilege mismatch when injecting into root domain from a non-root domain
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- c
調査の方向性
Start by reading sse_event_inject() and the SBI SSE context rules; the issue does not name source files or tests. Then review the referenced per-domain context and VIRQ work to understand how events reach a target domain. Done means the intended behavior for cross-domain injection, including M-mode interrupt events, is clarified with a recommended approach or pointers to existing design work.
索引モデルが issue の本文から書いたものです。
説明
Summary
sse_event_inject() constructs a synthetic S-mode entry context by deriving mstatus/hstatus fields from the currently visible processor state, then forces MSTATUS_MPP = PRV_S and clears MPV. In a multi-domain system (Smsd/Smmpt), if the HART is executing in a non-root domain (e.g., a TEE domain) when an SSE event destined for the root domain is injected, the resulting entry context reflects the non-root domain's privilege/virtualization view while targeting the root domain's handler. This can cause a privilege mismatch. Because the event may be triggered by an M-mode interrupt (e.g., RAS), supervisor software is passively interrupted and cannot perform any domain-context switch beforehand.
Background
- OpenSBI supports multiple S-mode domains via Smsd/Smmpt, and the root domain may host a general OS while another domain hosts TEE-OS.
- SSE is used as the notification/entry mechanism for events, and RAS handling is expected to rely on SSE injection for firmware-first error notification.
sse_event_inject()currently derives context as follows (simplified):
i_ctx->flags = sse_interrupted_flags(regs->mstatus);
i_ctx->sepc = csr_read(CSR_SEPC);
regs->mstatus &= ~(MSTATUS_SPP | SSTATUS_SPIE);
if (regs->mstatus & MSTATUS_MPP)
regs->mstatus |= MSTATUS_SPP;
if (regs->mstatus & MSTATUS_SIE)
regs->mstatus |= MSTATUS_SPIE;
if (misa_extension('H')) {
unsigned long hstatus = csr_read(CSR_HSTATUS);
if (sbi_regs_from_virt(regs))
hstatus |= HSTATUS_SPV;
else
hstatus &= ~HSTATUS_SPV;
...
}
regs->mstatus &= ~(MSTATUS_MPP | MSTATUS_SIE | MSTATUS_SPELP);
regs->mstatus |= (PRV_S << MSTATUS_MPP_SHIFT);
All of these values are computed from the current HART state, not from any saved per-domain context.
Problem
Scenario:
- HART is running in a TEE domain (non-root).
- An M-mode interrupt arrives (e.g., a RAS error interrupt).
- Firmware decides the event should be delivered to the root domain's SSE handler.
sse_event_inject()runs while the HART is still in the TEE domain context.- The synthetic S-mode context is built from the TEE domain's
mstatus/hstatus, butMEPC/entry point target the root domain's handler.
Because hstatus.SPV/SPVP, sstatus.SPP/SPIE/SPELP, and MPV are derived from the interrupted (non-root) context, the root domain's handler may resume with a privilege/virtualization view that does not match its own expected state.
For an M-mode interrupt, supervisor software cannot save or switch its own domain context before injection, so a "supervisor does it" workaround is not applicable at the injection instant.
Prior discussion
- In the SSE context-corruption patch discussion, the maintainer noted that OpenSBI's SSE implementation saves/restores the minimal state defined by the SBI SSE spec, and that updating supervisor state (including HS-mode) is the supervisor software's responsibility. That leaves cross-domain state alignment outside the SSE injection path.
- The lack of per-domain SSE context was also acknowledged earlier, with per-domain context infrastructure and the VIRQ framework being developed to route interrupts to a target domain and switch domain context before delivery.
Question
Could the community clarify the intended design for the following?
- Is
sse_event_inject()intentionally agnostic to domain identity, i.e., is the caller (M-mode event dispatch) responsible for ensuring the HART is already in the target domain's context before injection? - Is the in-progress VIRQ / per-domain context work expected to cover the "target domain != current domain" case for SSE injection, including events originating from M-mode interrupts?
- Until that infrastructure lands in mainline, what is the recommended approach for firmware that needs to inject an SSE event into the root domain while a non-root domain is active? Should the event be queued and injected only after the HART returns to the root domain, or should the dispatch path perform an explicit domain context switch before calling
sse_event_inject()?
Any pointers to existing patches, RFCs, or design notes would be appreciated.
- 主要言語
- C
- スター
- 1.6k
- フォーク
- 734
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
riscv-software-src/opensbi のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
riscv-software-src/opensbi#425 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
riscv-software-src/opensbi#424 · コメント 1 件 ·
-
sbi_trap_redirect() does not clear SPELP when the interrupted context had no landing pad expectedオープン
難易度 3/5 1〜2日 初心者へのやさしさ 67/100
riscv-software-src/opensbi#438 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
riscv-software-src/opensbi#436 · コメント 3 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
riscv-software-src/opensbi#435 ·
riscv-software-src/opensbi の issue をすべて見る
似ている issue
-
area/docdb kind/failing-test priority/medium status/awaiting-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
yugabyte/yugabyte-db#39462 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
libreswan/libreswan#3185 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
category:port-update
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信