Add QEMU virt WorldGuard support on top of HWISO
cover Add QEMU virt WorldGuard support on top of HWISO
From: Raymond Mao <[email protected]>
This series adds an WorldGuard implementation for OpenSBI on top of previous hardware-isolation framework (HWISO) RFC [1].
The goal is to let OpenSBI program platform WorldGuard checker state at boot and reprogram WorldGuard hart state during domain transitions. The current RFC targets the QEMU virt WorldGuard model on top of the proposed generic HWISO hooks.
This series does the following:
1. Add the WorldGuard CSR definitions and hart extension flags needed to detect support for MLWID, MWIDDELEG, and SLWID.
2. Document the HWISO/WorldGuard DT bindings and add a QEMU virt overlay example for domain WID/WID list assignment and checker permissions.
3. Add a QEMU virt WorldGuard HWISO mechanism that:
- parses checker topology and protected resource permissions from DT
- programs wgChecker MMIO state at boot
- parses per-hart default WorldGuard execution state
- parses per-domain WorldGuard metadata
- reprograms MLWID, MWIDDELEG, and SLWID on domain transitions
[1] [RFC PATCH] sbi: add hardware isolation abstraction framework
https://lore.kernel.org/opensbi/[email protected]/
Raymond Mao (3):
hart: add WorldGuard CSR IDs and hart extension flags
docs: document hwiso WorldGuard DT bindings and add QEMU overlay
example
platform: virt: add QEMU virt WorldGuard hwiso mechanism
docs/domain_support.md | 159 +++ include/sbi/riscv_encoding.h | 3 + include/sbi/sbi_hart.h | 4 + lib/sbi/sbi_hart.c | 2 + platform/generic/include/qemu_virt_wg.h | 60 + platform/generic/objects.mk | 1 + platform/generic/platform.c | 11 + .../generic/virt/qemu-virt-hwiso-overlay.dts | 120 ++ platform/generic/virt/qemu_virt_wgchecker.c | 1050 +++++++++++++++++ 9 files changed, 1410 insertions(+) create mode 100644 platform/generic/include/qemu_virt_wg.h create mode 100644 platform/generic/virt/qemu-virt-hwiso-overlay.dts create mode 100644 platform/generic/virt/qemu_virt_wgchecker.c
Signature · 7 lines
2.25.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
RFC PATCH 1/3 hart: add WorldGuard CSR IDs and hart extension flags
From: Raymond Mao <[email protected]>
Define the WorldGuard-related CSR numbers and claim smwg / sswg hart extensions so platform code can probe support before programming MLWID, MWIDDELEG and SLWID.
--- include/sbi/riscv_encoding.h | 3 +++ include/sbi/sbi_hart.h | 4 ++++ lib/sbi/sbi_hart.c | 2 ++ 3 files changed, 9 insertions(+)
include/sbi/riscv_encoding.h +3 -0
@@ -331,6 +331,7 @@/* Supervisor Protection and Translation */ #define CSR_SATP 0x180 +#define CSR_SLWID 0x190/* Supervisor Indirect Register Alias */ #define CSR_SISELECT 0x150
@@ -454,6 +455,7 @@/* Machine Configuration */ #define CSR_MENVCFG 0x30a#define CSR_MENVCFGH 0x31a +#define CSR_MLWID 0x390/* Machine Trap Handling */ #define CSR_MSCRATCH 0x340
@@ -680,6 +682,7 @@/* Machine Security Configuration CSR (mseccfg) */ #define CSR_MSECCFG 0x747#define CSR_MSECCFGH 0x757 +#define CSR_MWIDDELEG 0x748#define MSECCFG_MML_SHIFT (0)#define MSECCFG_MML (_UL(1) << MSECCFG_MML_SHIFT)
include/sbi/sbi_hart.h +4 -0
@@ -63,6 +63,10 @@ enum sbi_hart_extensions {SBI_HART_EXT_SSCSRIND ,/** Hart has Ssccfg extension */ SBI_HART_EXT_SSCCFG , +/** Hart has Smwg extension */ +SBI_HART_EXT_SMWG , +/** Hart has Sswg extension */ +SBI_HART_EXT_SSWG ,/** Maximum index of Hart extension */ SBI_HART_EXT_MAX,
lib/sbi/sbi_hart.c +2 -0
@@ -666,6 +666,8 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {__SBI_HART_EXT_DATA (sdtrig,SBI_HART_EXT_SDTRIG ),__SBI_HART_EXT_DATA (smcsrind,SBI_HART_EXT_SMCSRIND ),__SBI_HART_EXT_DATA (smcdeleg,SBI_HART_EXT_SMCDELEG ), +__SBI_HART_EXT_DATA (smwg,SBI_HART_EXT_SMWG ), + __SBI_HART_EXT_DATA(sswg, SBI_HART_EXT_SSWG), };/**
Signature · 7 lines
2.25.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
RFC PATCH 2/3 docs: document hwiso WorldGuard DT bindings and add QEMU overlay example
In reply to Raymond MaoFrom: Raymond Mao <[email protected]>
Document the hw-isolation and worldguard_cfg device-tree metadata used by the HWISO framework, and provide a QEMU virt overlay example showing domain WID/WID list assignment and checker permission policy.
--- docs/domain_support.md | 159 ++++++++++++++++++ .../generic/virt/qemu-virt-hwiso-overlay.dts | 120 +++++++++++++ 2 files changed, 279 insertions(+) create mode 100644 platform/generic/virt/qemu-virt-hwiso-overlay.dts
docs/domain_support.md +159 -0
@@ -201,6 +201,165 @@ The DT properties of a domain instance DT node are as follows: whether the domain instance is allowed to do system reset. * **system-suspend-allowed** (Optional) - A boolean flag representing whether the domain instance is allowed to do system suspend. +* **hw-isolation** (Optional) - A child node acting as a container for + system-level hardware isolation mechanisms. Each child node represents a + single mechanism configured via its compatible string and properties. + +Hardware Isolation Hooks +------------------------ + +OpenSBI provides a system-level hardware isolation framework that dispatches +all registered mechanisms in the following phases: + +* **init** - Runs at boot to configure system-level isolation features. +* **domain_init** - Parses per-domain isolation configuration. +* **domain_exit** - Runs before switching out of a domain. +* **domain_enter** - Runs after switching into a domain. + +Hardware Isolation Device Tree Binding +-------------------------------------- + +The hardware isolation configuration is specified as an optional child node +named **hw-isolation** under a domain instance node. The **hw-isolation** +node is a container for one or more mechanism nodes. + +The DT properties of a hardware isolation container node are as follows: + +* **#address-cells** / **#size-cells** (Optional) - Standard container node + properties. They are not interpreted by OpenSBI. + +Each hardware isolation mechanism has its own properties and compatible +string. A mechanism can either use per-domain properties below the domain +instance node, or parse system-level DT nodes describing isolation hardware. + +For the WorldGuard support on QEMU virt, OpenSBI parses the +following WG-style system nodes: + +* **sifive,wgchecker2** - WorldGuard checker node. +* **reg** - Checker MMIO base/size. +* **sifive,slot-count** - Number of hardware checker slots. +* **sifive,subordinates** - List of protected resource phandles owned by the + checker. +* **worldguard_cfg** - Child node of a protected memory or device node + describing WorldGuard policy for that resource. +* **perms** - 64-bit permission bitmap values encoded as **<hi lo>** cell + pairs, with either one value for the whole resource or one value per + protected range. +* **reg** - Optional protected address ranges inside a **worldguard_cfg** + child. If omitted, the resource node's own **reg** is used. A single + subordinate with one **perms** entry and no explicit **worldguard_cfg/reg** + is treated as a full-checker rule. +* **worldguard** - Optional CPU child node compatible with **riscv,wgcpu** + providing default WG execution state. +* **mwid** - Default machine world ID for a hart. +* **mwidlist** - Valid/delegable world IDs for that hart. + +Domain nodes can optionally provide WG execution metadata under the +**hw-isolation** container: + +* **worldguard,wid** - Machine world ID selected when entering the domain. +* **worldguard,widlist** - World IDs delegated to the domain. + +At runtime the WorldGuard implementation uses the hooks as follows: + +* **init** - Parses all WG checker nodes, validates the protected ranges, and + programs checker MMIO slots at boot when platform checker nodes are + present. Runtime WID/WID list support is enabled only when per-CPU WG + runtime nodes are present; checker-only DTs do not force runtime + switching on. +* **domain_init** - Parses per-domain **worldguard,wid** and + **worldguard,widlist** metadata. +* **domain_exit** - Quiesces the current hart back to its per-hart default + machine WID and clears **MWIDDELEG** before the handoff. +* **domain_enter** - Reprograms **MLWID**, **MWIDDELEG**, and, when + delegation is active, **SLWID** for the destination domain when the hart + supports **smwg** / **sswg**. + +The CPU **worldguard** defaults are parsed per hart from **/cpus/<cpu>**, so +platforms may provide different default **mwid** / **mwidlist** values on +different harts. + +Hardware Isolation Examples +--------------------------- + +Domain instance with WG execution metadata: + +```text + chosen { + opensbi-domains { + compatible = "opensbi,domain,config"; + + example_domain: domain@1 { + compatible = "opensbi,domain,instance"; + possible-harts = <&cpu2>; + regions = <&mem0 0x3f>; + boot-hart = <&cpu2>; + next-addr = <0x00000000 0x80200000>; + next-mode = <0x1>; + + hw-isolation { + worldguard { + compatible = "sifive,wgchecker2"; + worldguard,wid = <1>; + worldguard,widlist = <1 3>; + }; + }; + }; + }; + }; +``` + +WG checker, CPU default state, and protected resource example. These nodes +remain in the normal system DT topology because they describe isolation +hardware and protected resources, not OpenSBI domain instances: + +```text + cpu0: cpu@0 { + worldguard { + compatible = "riscv,wgcpu"; + mwid = <0>; + mwidlist = <0 1 3>; + }; + }; + + flash0: flash@20000000 { + reg = <0x0 0x20000000 0x0 0x2000000>; + worldguard_cfg { + perms = <0x0 0xc3>; + }; + }; + + uart0: serial@10000000 { + reg = <0x0 0x10000000 0x0 0x100>; + worldguard_cfg { + perms = <0x0 0xc0>; + }; + }; + + memory0: memory@80000000 { + reg = <0x0 0x80000000 0x0 0x80000000>; + worldguard_cfg { + reg = <0x0 0x80000000 0x0 0x40000000 + 0x0 0xc0000000 0x0 0x01000000 + 0x0 0xc1000000 0x0 0x3f000000>; + perms = <0x0 0xcf 0x0 0xcc 0x0 0xcf>; + }; + }; + + wgchecker0: wgchecker@10100000 { + compatible = "sifive,wgchecker2"; + reg = <0x0 0x10100000 0x0 0x1000>; + sifive,slot-count = <8>; + sifive,subordinates = <&memory0 &flash0 &uart0>; + }; +``` + +The test overlay used in this tree is at: + +* **platform/generic/virt/qemu-virt-hwiso-overlay.dts** + +That overlay only adds per-domain and per-resource metadata. The base DTB +must still provide the WG checker nodes and per-CPU **worldguard** nodes. ### Assigning HART To Domain Instance
platform/generic/virt/qemu-virt-hwiso-overlay.dts new file +120 -0
120 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
RFC PATCH 3/3 platform: virt: add QEMU virt WorldGuard hwiso mechanism
In reply to Raymond MaoFrom: Raymond Mao <[email protected]>
Implement the QEMU virt WorldGuard HWISO mechanism. Parse checker subordinates and resource permissions from the FDT, program wgChecker MMIO state at boot, parse per-hart CPU defaults plus per-domain WorldGuard metadata, and switch MLWID, MWIDDELEG and SLWID on domain transitions.
--- platform/generic/include/qemu_virt_wg.h | 60 ++ platform/generic/objects.mk | 1 + platform/generic/platform.c | 11 + platform/generic/virt/qemu_virt_wgchecker.c | 1050 +++++++++++++++++++ 4 files changed, 1122 insertions(+) create mode 100644 platform/generic/include/qemu_virt_wg.h create mode 100644 platform/generic/virt/qemu_virt_wgchecker.c
platform/generic/include/qemu_virt_wg.h new file +60 -0
@@ -0,0 +1,60 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2026 RISCstar Solutions Corporation. +* +* Author: Raymond Mao <[email protected]> +*/ + +#ifndef __QEMU_VIRT_WG_H__ +#define __QEMU_VIRT_WG_H__ + +#include <sbi/sbi_types.h> + +/* +* QEMU virt WorldGuard model definitions +*/ +#define QEMU_VIRT_WG_COMPAT "sifive,wgchecker2" +#define QEMU_VIRT_WG_CPU_COMPAT "riscv,wgcpu" +#define QEMU_VIRT_WG_CPU_NODE "worldguard" +#define QEMU_VIRT_WG_CFG_NODE "worldguard_cfg" + +#define QEMU_VIRT_WG_PROP_SLOT_COUNT "sifive,slot-count" +#define QEMU_VIRT_WG_PROP_SUBORDINATES "sifive,subordinates" +#define QEMU_VIRT_WG_PROP_WID "worldguard,wid" +#define QEMU_VIRT_WG_PROP_WIDLIST "worldguard,widlist" +#define QEMU_VIRT_WG_PROP_MWID "mwid" +#define QEMU_VIRT_WG_PROP_MWIDLIST "mwidlist" +#define QEMU_VIRT_WG_PROP_PERMS "perms" + +/* +* The current QEMU wgChecker model uses a 64-bit permission register with +* 2 bits per world, so the current software model tracks at most 32 WIDs. +*/ +#define QEMU_VIRT_WG_MAX_WIDS 32 + +/* The current QEMU wgChecker model requires 4 KiB slot alignment. */ +#define QEMU_VIRT_WG_MIN_ALIGN 0x1000ULL + +/* Current QEMU wgChecker MMIO register layout. */ +#define QEMU_VIRT_WG_MMIO_NSLOTS 0x008 +#define QEMU_VIRT_WG_MMIO_ERRCAUSE 0x010 +#define QEMU_VIRT_WG_MMIO_ERRADDR 0x018 +#define QEMU_VIRT_WG_MMIO_SLOT_BASE 0x020 +#define QEMU_VIRT_WG_MMIO_SLOT_STRIDE 0x020 +#define QEMU_VIRT_WG_MMIO_SLOT_ADDR 0x000 +#define QEMU_VIRT_WG_MMIO_SLOT_PERM 0x008 +#define QEMU_VIRT_WG_MMIO_SLOT_CFG 0x010 + +/* Current QEMU wgChecker slot cfg.A[1:0] encoding. */ +#define QEMU_VIRT_WG_SLOT_CFG_A_MASK 0x3 +#define QEMU_VIRT_WG_SLOT_CFG_A_OFF 0x0 +#define QEMU_VIRT_WG_SLOT_CFG_A_TOR 0x1 + +struct qemu_virt_wg_range { +u64 base; +u64 size; +u64 perm; +}; + +#endif
platform/generic/objects.mk +1 -0
@@ -20,6 +20,7 @@ platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \ # Objects to build platform-objs-y += platform.o platform-objs-y += platform_override_modules.o +platform-objs-y += virt/qemu_virt_wgchecker.o # Blobs to build FW_TEXT_START=0x80000000
platform/generic/platform.c +11 -0
@@ -11,6 +11,7 @@#include <platform_override.h> #include <sbi/riscv_asm.h> #include <sbi/sbi_bitops.h> +#include <sbi/sbi_error.h> #include <sbi/sbi_hartmask.h> #include <sbi/sbi_heap.h> #include <sbi/sbi_platform.h>
@@ -30,6 +31,8 @@#include <sbi_utils/rpxy/fdt_rpxy.h> #include <sbi_utils/serial/semihosting.h> +extern int qemu_virt_hwiso_register (void *fdt); +/* List of platform override modules generated at compile time */ extern const struct platform_override *platform_override_modules[];extern unsigned long platform_override_modules_size;
@@ -222,9 +225,17 @@ static int generic_nascent_init(void)static int generic_early_init (bool cold_boot) { +int rc; +if (cold_boot)fdt_reset_init (); +if (cold_boot) { + rc =qemu_virt_hwiso_register (fdt_get_address ()); +if (rc && rc !=SBI_EALREADY ) +return rc; + } +if (!generic_plat || !generic_plat->early_init)return 0 ;
platform/generic/virt/qemu_virt_wgchecker.c new file +1050 -0
1,050 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