Skip to contentSkip to conversation

sbi: add hardware isolation abstraction framework

RFC PATCH In review Raymond Mao 2 participants 3 messages Mar 17 – Apr 7

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 sbi: add hardware isolation abstraction framework

From: Raymond Mao <[email protected]>

Introduce a system-level hardware isolation framework with a registration API and per-domain context tracking.
This establishes an abstraction that allows multiple mechanisms to be composed while keeping core domain data structures independent of any single platform implementation.

---
 include/sbi/sbi_domain.h |   4 +
 include/sbi/sbi_hwiso.h  |  57 +++++++++++
 lib/sbi/objects.mk       |   1 +
 lib/sbi/sbi_hwiso.c      | 215 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 277 insertions(+)
 create mode 100644 include/sbi/sbi_hwiso.h
 create mode 100644 lib/sbi/sbi_hwiso.c
include/sbi/sbi_domain.h +4 -0
index 02765777..fc7330a6 100644
@@ -14,6 +14,7 @@
 #include <sbi/sbi_types.h>
 #include <sbi/sbi_hartmask.h>
 #include <sbi/sbi_domain_context.h>
+#include <sbi/sbi_hwiso.h>
 #include <sbi/sbi_rpxy.h>
 
 struct sbi_scratch;
@@ -199,6 +200,9 @@ struct sbi_domain {
 	bool system_reset_allowed;
 	/** Is domain allowed to suspend the system */
 	bool system_suspend_allowed;
+	/** Hardware isolation contexts for registered mechanisms */
+	struct sbi_hwiso_domain_ctx *hwiso_ctxs;
+	u32 hwiso_ctx_count;
 	/** Identifies whether to include the firmware region */
 	bool fw_region_inited;
 };
include/sbi/sbi_hwiso.h new file +57 -0

57 lines not on this page · raw message

lib/sbi/objects.mk +1 -0
index ca312ee2..6091499a 100644
@@ -72,6 +72,7 @@ libsbi-objs-y += sbi_domain.o
 libsbi-objs-y += sbi_emulate_csr.o
 libsbi-objs-y += sbi_fifo.o
 libsbi-objs-y += sbi_hart.o
+libsbi-objs-y += sbi_hwiso.o
 libsbi-objs-y += sbi_heap.o
 libsbi-objs-y += sbi_math.o
 libsbi-objs-y += sbi_hfence.o
lib/sbi/sbi_hwiso.c new file +215 -0

215 lines not on this page · raw message

Signature · 7 lines
2.25.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#1 lore raw

Hi Raymond,

Quoted 9 lines · Raymond Mao

From: Raymond Mao <[email protected]>

Introduce a system-level hardware isolation framework with a registration API and per-domain context tracking.
This establishes an abstraction that allows multiple mechanisms to be composed while keeping core domain data structures independent of any single platform implementation.

Thank you for the RFC patch on the hardware isolation framework. I'm currently reworking our internal WorldGuard patches and plan to share them for development with Jim's WG QEMU simulation.

I wanted to offer some personal input based on my exploration of an alternative approach which might be useful as we gather community feedback.

The goal is to utilize WorldGuard for system-level protection in static partitioning TEE scenarios (e.g., OP-TEE). To achieve this, we need to work on two components:

1. RISC-V Worlds ISA Extension

The Worlds ISA extension [1] introduces per-hart World ID (WID) management via CSRs like mlwid and mwiddeleg. These concepts should integrate naturally with OpenSBI's domain framework:

- Each domain can be assigned a next_wid (corresponding to mlwid)
- Each domain can be assigned a next_widlist (corresponding to mwiddeleg)

When OpenSBI switches to a target domain, it assigns the domain's next_wid to mlwid, effectively enabling hardware-enforced physical address space isolation for that supervisor domain.

2. WorldGuard Checker Driver

The WG checker driver parses device-tree information and programs the WorldGuard checkers to create access control rules associating memory/device regions with allowed World IDs.
(We SiFive will also propose DT formats for this.)

Device Isolation Example:

deviceA: [0x10000000, 0x20000000) WID3
deviceB: [0x20000000, 0x30000000) WID0, WID3 (shared)
deviceC: [0x30000000, 0x40000000) WID0

Memory Partitioning Example:

Given a DRAM range [0x8000_0000, 0x1_0000_0000), we can partition it as follows:

| Mode    | Main User | WID      | Physical Address Range 
                   |
|---------|-----------|----------|----------------------------------------------------------|
| M-mode  | OpenSBI   |       3  | [0x8000_0000, 0x800C_0000) 
                   |
| SU-mode | Linux     | 0, 1, 3  | [0x800C_0000, 0xC000_0000), [0xC100_0000, 0x1_0000_0000) |
| SU-mode | OP-TEE    |    1, 3  | [0xC000_0000, 0xC100_0000) 
                   |

During a domain context switch, OpenSBI assigns the target domain's next_wid to mlwid. This ensures that the hart can only access memory regions associated with the active WID, providing hardware-enforced isolation.

One open question I'm exploring is whether to extend sbi_domain_memregion with WorldGuard-specific fields (flags, permissions, allowed WIDs) as bus checker region descriptor for following considerations:
- WorldGuard checker slots will make use of TOR addressing mode, which PMP does not
- WorldGuard slots do not have execute permission semantics, unlike PMP
- Reusing PMP-style flags directly may cause logic errors in functions like sbi_domain_check_addr()

I haven't fully implemented this yet, so the design may change as I work through the details.

In addition to the RISC-V Worlds ISA specification, I'd like to share resources/ found helpful for understanding WorldGuard and system-level protection:
- [1] RISC-V Worlds ISA Extension:

https://github.com/riscv/riscv-worlds/releases/download/riscv-isa-release-4ae2105-2026-01-09/riscv-privileged.pdf

- [2] RISC-V Secure System Partitioning with Worlds and TrustZone (v0.7.2):
https://github.com/MIPS/riscv-partitioning/releases/tag/v0.7.2

- [3] RISC-V Platform Security Model (v0.5):
https://github.com/riscv/riscv-security-model/releases/tag/v.05

- [4] RISC-V Implementing Application Processor TEEs (Whitepaper):

https://riscv.org/wp-content/uploads/2025/10/RISC-V-Implementing-Application-Processor-TEEs-REV-1.pdf

Again, these are just my quick notes and personal input for this milestone. We should keep talking with the community to ensure our plan is on the right direction.

Looking forward to collaborating on this!

Best regards,
Peter Lin

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#2 lore raw

Hi Peter,

Quoted 110 lines · Yu-Chien Peter Lin

Hi Raymond,

Quoted 9 lines · Raymond Mao

From: Raymond Mao <[email protected]>

Introduce a system-level hardware isolation framework with a registration API and per-domain context tracking.
This establishes an abstraction that allows multiple mechanisms to be composed while keeping core domain data structures independent of any single platform implementation.

Thank you for the RFC patch on the hardware isolation framework. I'm currently
reworking our internal WorldGuard patches and plan to share them for development
with Jim's WG QEMU simulation.

I wanted to offer some personal input based on my exploration of an alternative
approach which might be useful as we gather community feedback.

The goal is to utilize WorldGuard for system-level protection in static partitioning TEE scenarios (e.g., OP-TEE). To achieve this, we need to work on two components:

1. RISC-V Worlds ISA Extension

The Worlds ISA extension [1] introduces per-hart World ID (WID) management via
CSRs like mlwid and mwiddeleg. These concepts should integrate naturally with OpenSBI's domain framework:

- Each domain can be assigned a next_wid (corresponding to mlwid)
- Each domain can be assigned a next_widlist (corresponding to mwiddeleg)

When OpenSBI switches to a target domain, it assigns the domain's next_wid to
mlwid, effectively enabling hardware-enforced physical address space isolation
for that supervisor domain.

2. WorldGuard Checker Driver

The WG checker driver parses device-tree information and programs the WorldGuard
checkers to create access control rules associating memory/device regions with
allowed World IDs.
(We SiFive will also propose DT formats for this.)

Device Isolation Example:

deviceA: [0x10000000, 0x20000000) WID3
deviceB: [0x20000000, 0x30000000) WID0, WID3 (shared)
deviceC: [0x30000000, 0x40000000) WID0

Memory Partitioning Example:

Given a DRAM range [0x8000_0000, 0x1_0000_0000), we can partition it as follows:

| Mode    | Main User | WID      | Physical Address Range
                    |
|---------|-----------|----------|----------------------------------------------------------|
| M-mode  | OpenSBI   |       3  | [0x8000_0000, 0x800C_0000)
                    |
| SU-mode | Linux     | 0, 1, 3  | [0x800C_0000, 0xC000_0000),
[0xC100_0000, 0x1_0000_0000) |
| SU-mode | OP-TEE    |    1, 3  | [0xC000_0000, 0xC100_0000)
                    |

During a domain context switch, OpenSBI assigns the target domain's next_wid
to mlwid. This ensures that the hart can only access memory regions associated
with the active WID, providing hardware-enforced isolation.

One open question I'm exploring is whether to extend sbi_domain_memregion with
WorldGuard-specific fields (flags, permissions, allowed WIDs) as bus checker region descriptor for following considerations:
- WorldGuard checker slots will make use of TOR addressing mode, which PMP does not
- WorldGuard slots do not have execute permission semantics, unlike PMP
- Reusing PMP-style flags directly may cause logic errors in functions like sbi_domain_check_addr()

I haven't fully implemented this yet, so the design may change as I work through
the details.

In addition to the RISC-V Worlds ISA specification, I'd like to share resources/
found helpful for understanding WorldGuard and system-level protection:
- [1] RISC-V Worlds ISA Extension:

https://github.com/riscv/riscv-worlds/releases/download/riscv-isa-release-4ae2105-2026-01-09/riscv-privileged.pdf

- [2] RISC-V Secure System Partitioning with Worlds and TrustZone (v0.7.2):
https://github.com/MIPS/riscv-partitioning/releases/tag/v0.7.2

- [3] RISC-V Platform Security Model (v0.5):
https://github.com/riscv/riscv-security-model/releases/tag/v.05

- [4] RISC-V Implementing Application Processor TEEs (Whitepaper):

Quoted 8 lines

https://riscv.org/wp-content/uploads/2025/10/RISC-V-Implementing-Application-Processor-TEEs-REV-1.pdf

Again, these are just my quick notes and personal input for this milestone. We should keep talking with the community to ensure our plan is on the right direction.

Looking forward to collaborating on this!

Thanks for the detailed feedback and the WG/Worlds context — very helpful.

The proposed HWISO is meant to be a generic framework for isolation management across domain lifecycle phases (boot, domain_init, domain exit/enter). The intent is to keep this layer mechanism‑agnostic, and have specific technologies (like WG/Worlds) plug in as one of the registered mechanisms.

From your description, WG fits well: a WG mechanism can parse its own DT binding, keep per‑domain context (next_wid/next_widlist, checker config), and program hardware on domain enter/exit. This avoids forcing WG into PMP semantics or sbi_domain_memregion.

So for this phase I plan to keep the HWISO abstraction minimal and mechanism-driven. When you share the WG DT format and implementation, we can integrate it as another registered mechanism under HWISO without refactoring the framework itself. If we discover we need multi‑instance support or richer matching at the framework level, we can evolve it then.

Looking forward to continuing the discussion.

Thanks and regards,
Raymond

Quoted 2 lines

Best regards,
Peter Lin

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi