Skip to contentSkip to conversation

Add WorldGuard support with SiFive WG checker

PATCH In review Raymond Mao 3 participants 8 messages Sep 4 – Oct 29 RISC-V

lore
Share & tools
lore
#0 lore raw

v3 cover Add WorldGuard support with SiFive WG checker

From: Raymond Mao <[email protected]>

This series adds WorldGuard support according to the wgchecker2 DT- binding proposal from SiFive [1] with QEMU virt integration.

The implementation:
- reuse sbi_hart_protection for hart-local runtime reconfiguration
- reuse sbi_domain_data for per-domain WorldGuard state
- keep WorldGuard-specific setup and checker programming in platform code

At boot, the generic platform code invokes a QEMU virt WorldGuard setup path which:
- parses wgchecker2 checker instances
- parses provider partition@N entries and programs checker MMIO
- parses per-hart CPU defaults from /cpus
- parses per-domain WorldGuard metadata under hw-isolation

Checker programming is provider-driven. Consumer-side access-controllers references are carried for DT-binding alignment.

During domain transitions, the WorldGuard hart protection implementation reprograms MLWID and, when available, MLWIDLIST, MWIDDELEG, and SLWID.

The series is split as follows:
1. add reusable FDT helpers needed by the WorldGuard parser
2. add WorldGuard CSR definitions and hart extension flags
3. document the current DT layout consumed by the implementation
4. add the wgchecker2 / WorldGuard runtime and QEMU virt integration

Tested with:
- QEMU riscv-wg-v4-260821 [2] with arg 'worlds=on' and the merged WorldGuard test DTB.

[1] dt-bindings: riscv: Add RISC-V Worlds and SiFive WorldGuard DT

    bindings
    https://lore.kernel.org/linux-devicetree/[email protected]/

[2] https://github.com/cwshu/qemu/tree/riscv-wg-v4-260821

Raymond Mao (5):
lib: utils: fdt: add generic domain and property parsing helpers
hart: add WorldGuard CSR IDs and hart extension flags
docs: document WorldGuard DT bindings
platform: generic: add WorldGuard checker support [NOT-FOR-UPSTREAM] platform: virt: add QEMU WorldGuard overlay

 docs/domain_support.md                        | 212 +++++++
 include/sbi/riscv_encoding.h                  |   4 +
 include/sbi/sbi_hart.h                        |  10 +
 include/sbi_utils/fdt/fdt_domain.h            |  13 +
 include/sbi_utils/fdt/fdt_helper.h            |  10 +
 lib/sbi/sbi_hart.c                            |   5 +
 lib/utils/fdt/fdt_domain.c                    |  46 +-
 lib/utils/fdt/fdt_helper.c                    |  76 +++
 .../generic/include/qemu_virt_worldguard.h    |  13 +
 platform/generic/include/wgchecker.h          |  91 +++
 platform/generic/include/worldguard.h         |  36 ++
 platform/generic/objects.mk                   |   3 +
 platform/generic/platform.c                   |  15 +-
 .../generic/virt/qemu-virt-wg-overlay.dts     | 198 +++++++
 platform/generic/virt/qemu_virt_worldguard.c  |  25 +
 platform/generic/wgchecker.c                  | 546 ++++++++++++++++++
 platform/generic/worldguard.c                 | 544 +++++++++++++++++
 17 files changed, 1845 insertions(+), 2 deletions(-)
 create mode 100644 platform/generic/include/qemu_virt_worldguard.h
 create mode 100644 platform/generic/include/wgchecker.h
 create mode 100644 platform/generic/include/worldguard.h
 create mode 100644 platform/generic/virt/qemu-virt-wg-overlay.dts
 create mode 100644 platform/generic/virt/qemu_virt_worldguard.c
 create mode 100644 platform/generic/wgchecker.c
 create mode 100644 platform/generic/worldguard.c
Signature · 6 lines
2.25.1

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

PATCH v3 1/5 lib: utils: fdt: add generic domain and property parsing helpers

From: Raymond Mao <[email protected]>

Add reusable FDT helpers for domain-oriented and other FDT-based consumers.

This adds helpers to:
- find a domain instance DT node by exact name match
- parse a single u32 property
- parse a single u64 property
- parse a u32 property list into a bitmask

Also tighten the internal domain-name matching to use exact node-name matching.

---
 include/sbi_utils/fdt/fdt_domain.h | 13 +++++
 include/sbi_utils/fdt/fdt_helper.h | 10 ++++
 lib/utils/fdt/fdt_domain.c         | 46 +++++++++++++++++-
 lib/utils/fdt/fdt_helper.c         | 76 ++++++++++++++++++++++++++++++
 4 files changed, 144 insertions(+), 1 deletion(-)
include/sbi_utils/fdt/fdt_domain.h +13 -0
index 8c2dee09..60d51d6c 100644
@@ -11,12 +11,18 @@
 #ifndef __FDT_DOMAIN_H__
 #define __FDT_DOMAIN_H__
 
+#include <sbi/sbi_error.h>
 #include <sbi/sbi_types.h>
 
 #ifdef CONFIG_FDT_DOMAIN
 
 struct sbi_domain;
 
+struct fdt_find_domain_offset_info {
+	const char *name;
+	int domain_offset;
+};
+
 /**
  * Iterate over each domains in device tree
  *
@@ -45,6 +51,8 @@ int fdt_iterate_each_memregion(void *fdt, int domain_offset, void *opaque,
 					 int region_offset, u32 region_access,
 					 void *opaque));
 
+int fdt_find_domain_offset(const void *fdt, const struct sbi_domain *dom);
+
 /**
  * Fix up the domain configuration in the device tree
  *
@@ -76,6 +84,11 @@ int fdt_domains_populate(const void *fdt);
 
 static inline void fdt_domain_fixup(void *fdt) { }
 static inline int fdt_domains_populate(const void *fdt) { return 0; }
+static inline int fdt_find_domain_offset(const void *fdt,
+					 const struct sbi_domain *dom)
+{
+	return SBI_ENOENT;
+}
 
 #endif
 
include/sbi_utils/fdt/fdt_helper.h +10 -0
index 75a564d1..05ca9f79 100644
@@ -50,6 +50,16 @@ int fdt_parse_hart_id(const void *fdt, int cpu_offset, u32 *hartid);
 
 int fdt_parse_max_enabled_hart_id(const void *fdt, u32 *max_hartid);
 
+int fdt_parse_u32(const void *fdt, int nodeoff, const char *prop_name,
+		  u32 *out_val);
+
+int fdt_parse_u64(const void *fdt, int nodeoff, const char *prop_name,
+		  u64 *out_val);
+
+int fdt_parse_u32_array_bitmask(const void *fdt, int nodeoff,
+				const char *prop_name, u32 max_bits,
+				u32 *out_mask);
+
 int fdt_parse_cbom_block_size(const void *fdt, int cpu_offset, unsigned long  *cbom_block_size);
 
 int fdt_parse_timebase_frequency(const void *fdt, unsigned long *freq);
lib/utils/fdt/fdt_domain.c +45 -1

59 lines not on this page · raw message

lib/utils/fdt/fdt_helper.c +76 -0

82 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
#2 lore raw

PATCH v3 2/5 hart: add WorldGuard CSR IDs and hart extension flags

In reply to Raymond Mao

From: Raymond Mao <[email protected]>

Define the WorldGuard-related CSR numbers and advertise the Worlds ISA extensions: smlwid, smlwidlist, smwid, smwiddeleg, and sswid. This lets platform code probe support before programming MLWID, MLWIDLIST, MWIDDELEG, and SLWID.

---
 include/sbi/riscv_encoding.h |  4 ++++
 include/sbi/sbi_hart.h       | 10 ++++++++++
 lib/sbi/sbi_hart.c           |  5 +++++
 3 files changed, 19 insertions(+)
include/sbi/riscv_encoding.h +4 -0
index ffe7666c..5aca57a5 100644
@@ -373,6 +373,7 @@
 
 /* Supervisor Protection and Translation */
 #define CSR_SATP			0x180
+#define CSR_SLWID			0x190
 
 /* Supervisor Indirect Register Alias */
 #define CSR_SISELECT			0x150
@@ -510,6 +511,7 @@
 /* Machine Configuration */
 #define CSR_MENVCFG			0x30a
 #define CSR_MENVCFGH			0x31a
+#define CSR_MLWID			0x390
 
 /* Machine Trap Handling */
 #define CSR_MSCRATCH			0x340
@@ -736,6 +738,8 @@
 /* Machine Security Configuration CSR (mseccfg) */
 #define CSR_MSECCFG			0x747
 #define CSR_MSECCFGH			0x757
+#define CSR_MWIDDELEG			0x748
+#define CSR_MLWIDLIST			0x74a
 
 #define MSECCFG_MML_SHIFT		(0)
 #define MSECCFG_MML			(_UL(1) << MSECCFG_MML_SHIFT)
include/sbi/sbi_hart.h +10 -0
index 543393bb..67362ec3 100644
@@ -63,6 +63,16 @@ enum sbi_hart_extensions {
 	SBI_HART_EXT_SSCSRIND,
 	/** Hart has Ssccfg extension */
 	SBI_HART_EXT_SSCCFG,
+	/** Hart has Smlwid extension */
+	SBI_HART_EXT_SMLWID,
+	/** Hart has Smlwidlist extension */
+	SBI_HART_EXT_SMLWIDLIST,
+	/** Hart has Smwid extension */
+	SBI_HART_EXT_SMWID,
+	/** Hart has Smwiddeleg extension */
+	SBI_HART_EXT_SMWIDDELEG,
+	/** Hart has Sswid extension */
+	SBI_HART_EXT_SSWID,
 	/** Hart has Svade extension */
 	SBI_HART_EXT_SVADE,
 	/** Hart has Svadu extension */
lib/sbi/sbi_hart.c +5 -0
index bee88557..aeafb51a 100644
@@ -344,6 +344,11 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {
 	__SBI_HART_EXT_DATA(smcdeleg, SBI_HART_EXT_SMCDELEG),
 	__SBI_HART_EXT_DATA(sscsrind, SBI_HART_EXT_SSCSRIND),
 	__SBI_HART_EXT_DATA(ssccfg, SBI_HART_EXT_SSCCFG),
+	__SBI_HART_EXT_DATA(smlwid, SBI_HART_EXT_SMLWID),
+	__SBI_HART_EXT_DATA(smlwidlist, SBI_HART_EXT_SMLWIDLIST),
+	__SBI_HART_EXT_DATA(smwid, SBI_HART_EXT_SMWID),
+	__SBI_HART_EXT_DATA(smwiddeleg, SBI_HART_EXT_SMWIDDELEG),
+	__SBI_HART_EXT_DATA(sswid, SBI_HART_EXT_SSWID),
 	__SBI_HART_EXT_DATA(svade, SBI_HART_EXT_SVADE),
 	__SBI_HART_EXT_DATA(svadu, SBI_HART_EXT_SVADU),
 	__SBI_HART_EXT_DATA(smnpm, SBI_HART_EXT_SMNPM),
Signature · 7 lines
2.25.1


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

PATCH v3 3/5 docs: document WorldGuard DT bindings

In reply to Raymond Mao

From: Raymond Mao <[email protected]>

Document the WorldGuard device-tree metadata used by the current hart protection runtime flow on WorldGuard-enabled platforms.

---
 docs/domain_support.md | 212 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 212 insertions(+)
docs/domain_support.md +212 -0
index e267a9f7..de413a41 100644
@@ -204,6 +204,218 @@ 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 used by platform-specific
+  isolation mechanisms. The current OpenSBI WorldGuard implementation uses
+  this node only as a container for per-domain WorldGuard execution metadata.
+
+WorldGuard Device Tree Binding
+------------------------------
+
+The current OpenSBI WorldGuard support is built from:
+
+* **sbi_hart_protection** for hart-local runtime reconfiguration during
+  domain transitions
+* **sbi_domain_data** for per-domain WorldGuard state
+* platform-specific setup code that parses and programs WorldGuard checkers
+  before domains are populated
+
+The WorldGuard-specific DT state is split across two places:
+
+* under a domain instance node, for per-domain execution metadata
+* in the normal system DT topology, for CPU defaults and checker policy
+
+### Domain-local WorldGuard Metadata
+
+The optional **hw-isolation** child node under a domain instance may contain
+one WorldGuard child node:
+
+* **compatible = "sifive,wgchecker2"**
+* **worldguard,wid** - Machine world ID selected when entering the domain
+* **worldguard,widlist** - List of world IDs delegated to the domain
+
+The current implementation looks up the domain node in the FDT, finds its
+**hw-isolation** child, and parses the first child node compatible with
+**sifive,wgchecker2**.
+
+### System-level WorldGuard Metadata
+
+The current implementation also parses the following system-level DT state:
+
+* **/cpus/cpu@X**
+  * **riscv,pmwid** - Default machine world ID for the hart
+  * **riscv,pmwidlist** - Optional M-mode WID bitmap for the hart
+  * **riscv,pmlwidlist** - Optional delegated lower-privilege WID bitmap
+* **sifive,wgchecker2** nodes
+  * **reg** - Checker MMIO base/size
+  * **#address-cells = <1>**
+  * **#size-cells = <0>**
+  * **#access-controller-cells = <1>**
+  * **partition@N** child nodes with:
+    * **reg** - Partition identifier
+    * **sifive,wg-region** - Protected base/size pair
+    * **sifive,slot-permissions** - 64-bit WID permission bitmap
+    * **sifive,slot-config** - DT-visible **ER/EW/IR/IW/LOCK** policy bits
+* protected resource nodes with **access-controllers** properties that point
+  to a checker and reference one or more partition IDs
+
+For the current implementation, checker policy is parsed from **partition@N**
+children under each checker node. Consumer-side **access-controllers**
+references are carried for DT-binding alignment, but the OpenSBI platform code
+programs the checker from provider-local partition metadata.
+OpenSBI validates that each checker has exactly one cell for each required
+provider property and that their values are **#address-cells = <1>**,
+**#size-cells = <0>**, and **#access-controller-cells = <1>**.
+
+### Runtime Behavior
+
+At boot:
+
+* platform setup detects whether checker programming and/or runtime WID
+  switching are present in the DT
+* if runtime WID support is present, OpenSBI registers a WorldGuard
+  **sbi_hart_protection** mechanism and a **sbi_domain_data** provider
+* per-hart default WID state is parsed from **/cpus**
+* checker instances are parsed, validated, and programmed before domain
+  population completes
+
+During a domain transition:
+
+* the WorldGuard **sbi_domain_data** provider supplies per-domain
+  **worldguard,wid** and **worldguard,widlist** state
+* the WorldGuard **sbi_hart_protection** implementation reprograms
+  **MLWID**
+* when **smlwidlist** is present, it also reprograms **MLWIDLIST**
+* when **smwiddeleg** and **sswid** are present, it also reprograms
+  **MWIDDELEG** and **SLWID**
+* when a domain is quiesced, the hart is returned to its per-hart fallback
+  machine world state
+
+**MLWIDLIST** is restored from the hart's **riscv,pmwidlist** value. Domain
+**worldguard,widlist** metadata controls lower-privilege delegation through
+**MWIDDELEG** and is constrained by **riscv,pmlwidlist**.
+
+Runtime WID switching is enabled only when the CPU runtime properties are
+present. A DT that only describes checker hardware does not, by itself,
+enable hart-local WorldGuard reconfiguration.
+
+WorldGuard Examples
+-------------------
+
+Domain instance with WorldGuard 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 = <0x1>;
+                        worldguard,widlist = <1 3>;
+                    };
+                };
+            };
+        };
+    };
+```
+
+CPU default state, checker, and protected resource example:
+
+```text
+    memory0: memory@80000000 {
+        reg = <0x0 0x80000000 0x0 0x80000000>;
+        access-controllers = <&wgchecker0 0>, <&wgchecker0 1>, <&wgchecker0 2>;
+    };
+
+    flash0: flash@20000000 {
+        reg = <0x0 0x20000000 0x0 0x04000000>;
+        access-controllers = <&wgchecker1 0>;
+    };
+
+    uart0: serial@10000000 {
+        reg = <0x0 0x10000000 0x0 0x00001000>;
+        access-controllers = <&wgchecker2 0>;
+    };
+
+    wgchecker0: wgchecker@6000000 {
+        compatible = "qemu,wgchecker2", "sifive,wgchecker2";
+        reg = <0x0 0x06000000 0x0 0x1000>;
+        #access-controller-cells = <1>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+        phandle = <0x100>;
+
+        partition@0 {
+            reg = <0>;
+            sifive,wg-region = <0x0 0x80000000 0x0 0x40000000>;
+            sifive,slot-permissions = <0x0 0x000000cf>;
+            sifive,slot-config = <0x0f>;
+        };
+
+        partition@1 {
+            reg = <1>;
+            sifive,wg-region = <0x0 0xc0000000 0x0 0x01000000>;
+            sifive,slot-permissions = <0x0 0x000000cc>;
+            sifive,slot-config = <0x0f>;
+        };
+
+        partition@2 {
+            reg = <2>;
+            sifive,wg-region = <0x0 0xc1000000 0x0 0x3f000000>;
+            sifive,slot-permissions = <0x0 0x000000cf>;
+            sifive,slot-config = <0x0f>;
+        };
+    };
+
+    wgchecker1: wgchecker@6001000 {
+        compatible = "qemu,wgchecker2", "sifive,wgchecker2";
+        reg = <0x0 0x06001000 0x0 0x1000>;
+        #access-controller-cells = <1>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+        phandle = <0x101>;
+
+        partition@0 {
+            reg = <0>;
+            sifive,wg-region = <0x0 0x20000000 0x0 0x04000000>;
+            sifive,slot-permissions = <0x0 0x000000c3>;
+            sifive,slot-config = <0x0f>;
+        };
+    };
+
+    wgchecker2: wgchecker@6002000 {
+        compatible = "qemu,wgchecker2", "sifive,wgchecker2";
+        reg = <0x0 0x06002000 0x0 0x1000>;
+        #access-controller-cells = <1>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+        phandle = <0x102>;
+
+        partition@0 {
+            reg = <0>;
+            sifive,wg-region = <0x0 0x10000000 0x0 0x00001000>;
+            sifive,slot-permissions = <0x0 0x000000c0>;
+            sifive,slot-config = <0x0f>;
+        };
+    };
+```
+
+The test overlay used in this tree is at:
+
+* **platform/generic/virt/qemu-virt-wg-overlay.dts**
+
+That overlay supplies the current QEMU virt test metadata for OpenSBI
+domains and protected resources. The base DTB must still provide the checker
+nodes and the CPU-level WorldGuard properties consumed by the runtime code.
 
 ### Assigning HART To Domain Instance
 
Signature · 7 lines
2.25.1


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

PATCH v3 4/5 platform: generic: add WorldGuard checker support

In reply to Raymond Mao

From: Raymond Mao <[email protected]>

Add WorldGuard support for the hart protection runtime on the generic platform.

Parse checker provider nodes compatible with qemu,wgchecker2 or sifive,wgchecker2 and their partition@N children, then program checker MMIO state from the described protected ranges, permissions, and DT-visible slot policy bits.

Add WorldGuard runtime support to parse per-hart CPU defaults from /cpus and per-domain WorldGuard metadata under domain hw-isolation nodes, and use that state to reprogram MLWID, MLWIDLIST, MWIDDELEG, SLWID during domain transitions.

Keep the QEMU virt platform code as the integration layer that invokes WorldGuard setup for the virt platform.

---
 .../generic/include/qemu_virt_worldguard.h    |  13 +
 platform/generic/include/wgchecker.h          |  91 +++
 platform/generic/include/worldguard.h         |  36 ++
 platform/generic/objects.mk                   |   3 +
 platform/generic/platform.c                   |  15 +-
 platform/generic/virt/qemu_virt_worldguard.c  |  25 +
 platform/generic/wgchecker.c                  | 546 ++++++++++++++++++
 platform/generic/worldguard.c                 | 544 +++++++++++++++++
 8 files changed, 1272 insertions(+), 1 deletion(-)
 create mode 100644 platform/generic/include/qemu_virt_worldguard.h
 create mode 100644 platform/generic/include/wgchecker.h
 create mode 100644 platform/generic/include/worldguard.h
 create mode 100644 platform/generic/virt/qemu_virt_worldguard.c
 create mode 100644 platform/generic/wgchecker.c
 create mode 100644 platform/generic/worldguard.c
platform/generic/include/qemu_virt_worldguard.h new file +13 -0
new file mode 100644
index 00000000..8db30a24
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright (c) 2026 RISCstar Solutions Corporation.
+ *
+ * Author: Raymond Mao <[email protected]>
+ */
+
+#ifndef __PLATFORM_GENERIC_QEMU_VIRT_WORLDGUARD_H__
+#define __PLATFORM_GENERIC_QEMU_VIRT_WORLDGUARD_H__
+
+int qemu_virt_worldguard_setup(const void *fdt);
+
+#endif
platform/generic/include/wgchecker.h new file +91 -0

91 lines not on this page · raw message

platform/generic/include/worldguard.h new file +36 -0
new file mode 100644
index 00000000..dc77458d
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright (c) 2026 RISCstar Solutions Corporation.
+ *
+ * Author: Raymond Mao <[email protected]>
+ */
+
+#ifndef __PLATFORM_GENERIC_WORLDGUARD_H__
+#define __PLATFORM_GENERIC_WORLDGUARD_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi/sbi_domain.h>
+
+#define WORLDGUARD_PROP_WID		"worldguard,wid"
+#define WORLDGUARD_PROP_WIDLIST		"worldguard,widlist"
+#define WORLDGUARD_CPU_PROP_PMWID	"riscv,pmwid"
+#define WORLDGUARD_CPU_PROP_PMWIDLIST	"riscv,pmwidlist"
+#define WORLDGUARD_CPU_PROP_PMLWIDLIST	"riscv,pmlwidlist"
+#define WORLDGUARD_MAX_WIDS		64
+
+struct wg_cpu_defaults {
+	u32 pmwid;
+	u64 pmwidlist_mask;
+	u64 pmlwidlist_mask;
+};
+
+struct worldguard_domain_state {
+	bool has_wid;
+	u32 wid;
+	u64 widlist_mask;
+};
+
+int worldguard_setup(const void *fdt);
+bool worldguard_is_enabled(void);
+
+#endif
platform/generic/objects.mk +3 -0
index ca7fb8b7..0e400809 100644
@@ -20,6 +20,9 @@ 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.carray.o
+platform-objs-y += worldguard.o
+platform-objs-y += wgchecker.o
+platform-objs-y += virt/qemu_virt_worldguard.o
 
 # Blobs to build
 FW_DYNAMIC=y
platform/generic/platform.c +14 -1
index 1df0280d..ed56ab0b 100644
@@ -11,6 +11,8 @@
 #include <platform_override.h>
 #include <sbi/riscv_asm.h>
 #include <sbi/sbi_bitops.h>
+#include <sbi/sbi_console.h>
+#include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
 #include <sbi/sbi_heap.h>
 #include <sbi/sbi_platform.h>
@@ -29,6 +31,7 @@
 #include <sbi_utils/serial/fdt_serial.h>
 #include <sbi_utils/serial/semihosting.h>
 #include <sbi_utils/timer/fdt_timer.h>
+#include <qemu_virt_worldguard.h>
 
 /* List of platform override modules generated at compile time */
 extern const struct fdt_driver *const platform_override_modules[];
@@ -267,9 +270,19 @@ int generic_domains_init(void)
 	const void *fdt = fdt_get_address();
 	int offset, ret;
 
+	ret = qemu_virt_worldguard_setup(fdt);
+	if (ret < 0) {
+		sbi_printf("%s: qemu_virt_worldguard_setup failed (error %d)\n",
+			   __func__, ret);
+		return ret;
+	}
+
 	ret = fdt_domains_populate(fdt);
-	if (ret < 0)
+	if (ret < 0) {
+		sbi_printf("%s: fdt_domains_populate failed (error %d)\n",
+			   __func__, ret);
 		return ret;
+	}
 
 	offset = fdt_path_offset(fdt, "/chosen");
 
platform/generic/virt/qemu_virt_worldguard.c new file +25 -0
new file mode 100644
index 00000000..f376d5a2
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * QEMU virt WorldGuard registration shim
+ *
+ * Copyright (c) 2026 RISCstar Solutions Corporation.
+ *
+ * Author: Raymond Mao <[email protected]>
+ */
+
+#include <libfdt.h>
+#include <qemu_virt_worldguard.h>
+#include <sbi/sbi_error.h>
+#include <worldguard.h>
+
+int qemu_virt_worldguard_setup(const void *fdt)
+{
+	if (!fdt)
+		return 0;
+
+	if (fdt_node_check_compatible(fdt, 0, "riscv-virtio") &&
+	    fdt_node_check_compatible(fdt, 0, "qemu,virt"))
+		return 0;
+
+	return worldguard_setup(fdt);
+}
platform/generic/wgchecker.c new file +546 -0

546 lines not on this page · raw message

platform/generic/worldguard.c new file +544 -0

544 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
#5 lore raw

PATCH v3 5/5 platform: virt: add QEMU WorldGuard overlay

In reply to Raymond Mao

From: Raymond Mao <[email protected]>

Add a QEMU virt device-tree overlay that describes OpenSBI domain WorldGuard metadata and checker permission policy for the current test and demo flow.

---
 .../generic/virt/qemu-virt-wg-overlay.dts     | 198 ++++++++++++++++++
 1 file changed, 198 insertions(+)
 create mode 100644 platform/generic/virt/qemu-virt-wg-overlay.dts
platform/generic/virt/qemu-virt-wg-overlay.dts new file +198 -0
new file mode 100644
index 00000000..e629df89
@@ -0,0 +1,198 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/dts-v1/;
+/plugin/;
+
+/*
+ * Test-only overlay for exercising WorldGuard domain metadata and
+ * WorldGuard checker access-controller rules.
+ *
+ * This overlay adds:
+ * 1. OpenSBI domain metadata for domain-local WID policy
+ * 2. access-controllers partition metadata and consumer references
+ *
+ * The base DTB is expected to already provide:
+ * - WorldGuard checker nodes
+ * - /cpus worlds properties
+ * - per-hart worlds properties
+ *
+ * Usage:
+ * Domain hart phandles are filled in after merge because fdtoverlay does not
+ * reliably resolve CPU-node references against QEMU dumpdtb output here.
+ * See below steps for filling the domain hart phandles (assume the dumped dtb
+ * and merged dtb are represented by 'qemu.dtb' and 'qemu-merged.dtb'
+ * respectively):
+ *   cpu0_phandle=$(fdtget -t x qemu.dtb /cpus/cpu@0 phandle)
+ *   cpu1_phandle=$(fdtget -t x qemu.dtb /cpus/cpu@1 phandle)
+ *   fdtput -t x qemu-merged.dtb /chosen/opensbi-domains/domain@0 \
+ *     possible-harts "$cpu0_phandle" "$cpu1_phandle"
+ *   fdtput -t x qemu-merged.dtb /chosen/opensbi-domains/domain@0 \
+ *     boot-hart "$cpu0_phandle"
+ *   fdtput -t x qemu-merged.dtb /chosen/opensbi-domains/domain@1 \
+ *     possible-harts "$cpu1_phandle"
+ *   fdtput -t x qemu-merged.dtb /chosen/opensbi-domains/domain@1 \
+ *     boot-hart "$cpu1_phandle"
+ */
+/ {
+	fragment@0 {
+		target-path = "/chosen";
+		__overlay__ {
+			opensbi,worldguard-sbiunit;
+			opensbi-domains {
+				compatible = "opensbi,domain,config";
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				memregion0: memregion@0 {
+					compatible = "opensbi,domain,memregion";
+					base = <0x00000000 0x80000000>;
+					order = <0x1f>;
+				};
+
+				guest0: domain@0 {
+					compatible = "opensbi,domain,instance";
+					regions = <&memregion0 0x3f>;
+					next-addr = <0x00000000 0x80200000>;
+					next-arg1 = <0x00000000 0x82200000>;
+					next-mode = <0x1>;
+
+					hw-isolation {
+						worldguard {
+							compatible = "sifive,wgchecker2";
+							worldguard,wid = <0>;
+							worldguard,widlist = <0 1 3>;
+						};
+					};
+				};
+
+				guest1: domain@1 {
+					compatible = "opensbi,domain,instance";
+					regions = <&memregion0 0x3f>;
+					next-addr = <0x00000000 0x80200000>;
+					next-mode = <0x1>;
+
+					hw-isolation {
+						worldguard {
+							compatible = "sifive,wgchecker2";
+							worldguard,wid = <1>;
+							worldguard,widlist = <1 3>;
+						};
+					};
+				};
+			};
+		};
+	};
+
+	fragment@1 {
+		target-path = "/cpus/cpu@0";
+		__overlay__ {
+			opensbi-domain = <&guest0>;
+		};
+	};
+
+	fragment@2 {
+		target-path = "/cpus/cpu@1";
+		__overlay__ {
+			opensbi-domain = <&guest0>;
+		};
+	};
+
+	fragment@3 {
+		target-path = "/memory@80000000";
+		__overlay__ {
+			access-controllers =
+				<0x100 0x0>,
+				<0x100 0x1>,
+				<0x100 0x2>;
+		};
+	};
+
+	fragment@4 {
+		target-path = "/flash@20000000";
+		__overlay__ {
+			access-controllers = <0x101 0x0>;
+		};
+	};
+
+	fragment@5 {
+		target-path = "/soc/serial@10000000";
+		__overlay__ {
+			access-controllers = <0x102 0x0>;
+		};
+	};
+
+	fragment@6 {
+		target-path = "/soc/wgchecker@6000000";
+		__overlay__ {
+			compatible = "qemu,wgchecker2", "sifive,wgchecker2";
+			#access-controller-cells = <1>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			phandle = <0x100>;
+			linux,phandle = <0x100>;
+
+			partition@0 {
+				reg = <0>;
+				sifive,wg-region =
+					<0x00000000 0x80000000 0x00000000 0x40000000>;
+				sifive,slot-permissions = <0x00000000 0x000000cf>;
+				sifive,slot-config = <0x0f>;
+			};
+
+			partition@1 {
+				reg = <1>;
+				sifive,wg-region =
+					<0x00000000 0xc0000000 0x00000000 0x01000000>;
+				sifive,slot-permissions = <0x00000000 0x000000cc>;
+				sifive,slot-config = <0x0f>;
+			};
+
+			partition@2 {
+				reg = <2>;
+				sifive,wg-region =
+					<0x00000000 0xc1000000 0x00000000 0x3f000000>;
+				sifive,slot-permissions = <0x00000000 0x000000cf>;
+				sifive,slot-config = <0x0f>;
+			};
+		};
+	};
+
+	fragment@7 {
+		target-path = "/soc/wgchecker@6001000";
+		__overlay__ {
+			compatible = "qemu,wgchecker2", "sifive,wgchecker2";
+			#access-controller-cells = <1>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			phandle = <0x101>;
+			linux,phandle = <0x101>;
+
+			partition@0 {
+				reg = <0>;
+				sifive,wg-region =
+					<0x00000000 0x20000000 0x00000000 0x04000000>;
+				sifive,slot-permissions = <0x00000000 0x000000c3>;
+				sifive,slot-config = <0x0f>;
+			};
+		};
+	};
+
+	fragment@8 {
+		target-path = "/soc/wgchecker@6002000";
+		__overlay__ {
+			compatible = "qemu,wgchecker2", "sifive,wgchecker2";
+			#access-controller-cells = <1>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			phandle = <0x102>;
+			linux,phandle = <0x102>;
+
+			partition@0 {
+				reg = <0>;
+				sifive,wg-region =
+					<0x00000000 0x10000000 0x00000000 0x00001000>;
+				sifive,slot-permissions = <0x00000000 0x000000c0>;
+				sifive,slot-config = <0x0f>;
+			};
+		};
+	};
+};
Signature · 7 lines
2.25.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#6 lore raw
In reply to Raymond Mao

Hi Raymond,

Quoted 31 lines · Raymond Mao

From: Raymond Mao <[email protected]>

This series adds WorldGuard support according to the wgchecker2 DT- binding proposal from SiFive [1] with QEMU virt integration.

The implementation:
- reuse sbi_hart_protection for hart-local runtime reconfiguration
- reuse sbi_domain_data for per-domain WorldGuard state
- keep WorldGuard-specific setup and checker programming in platform code

At boot, the generic platform code invokes a QEMU virt WorldGuard setup path which:
- parses wgchecker2 checker instances
- parses provider partition@N entries and programs checker MMIO
- parses per-hart CPU defaults from /cpus
- parses per-domain WorldGuard metadata under hw-isolation

Checker programming is provider-driven. Consumer-side access-controllers references are carried for DT-binding alignment.

During domain transitions, the WorldGuard hart protection implementation reprograms MLWID and, when available, MLWIDLIST, MWIDDELEG, and SLWID.

The series is split as follows:
1. add reusable FDT helpers needed by the WorldGuard parser
2. add WorldGuard CSR definitions and hart extension flags
3. document the current DT layout consumed by the implementation
4. add the wgchecker2 / WorldGuard runtime and QEMU virt integration

Quoted 8 lines

Tested with:
- QEMU riscv-wg-v4-260821 [2] with arg 'worlds=on' and the merged WorldGuard test DTB.

[1] dt-bindings: riscv: Add RISC-V Worlds and SiFive WorldGuard DT

    bindings
    https://lore.kernel.org/linux-devicetree/[email protected]/

[2] https://github.com/cwshu/qemu/tree/riscv-wg-v4-260821

Thanks for working on this series. Could we align the implementation with the DT proposal on a few key points?

1. Domain WIDs should use wid / widdeleg directly under domain nodes, not hw-isolation with sifive,wgchecker2.
My patches already handle the WID assignment and switching.
https://patchwork.ozlabs.org/project/opensbi/patch/[email protected]/
2. wgChecker is a static firewall configured once at boot; by design it does not support efficient dynamic reconfiguration.
3. Unlike sequential first-match PMP, wgChecker slots are strictly accretive (parallel OR), so overlapping rules cannot restrict access. i.e.

   /* PMP (Priority-based, sequential): */
   for (i = N-1; i >= 0; i--) {
       if (pmp[i].matches(addr))
           return pmp[i].perm;      // FIRST match wins
   }
   
   /* wgChecker (Strictly accretive, parallel): */
   perm = NO_ACCESS;
   for (i = 0; i < nslots; i++) {
       if (slot[i].matches(addr))
           perm |= slot[i].perm[wid]; // OR all matches
   }
   if (perm allows access)
       grant_access();

The wgChecker driver should automatically select between NAPOT and TOR encoding to minimize slot usage.

4. OpenSBI should support use cases below and dump the wgChecker slot info at boot:

========================================================================
Use Case 1: Single-Slot Peripheral Protection (Full Subordinate Range)
========================================================================

0x001c_1000 +---------------------------------------------------+

            | partition@0 : [0x001c_1000, 0x001c_2000)          |
            | serial@1c1000 | WID 0,3 RW (perm 0xc3, cfg 0x1f)  |
            | Slot00..01  : A=TOR (Slot00 base, Slot01 top)     |

0x001c_2000 +---------------------------------------------------+

uart: serial@1c1000 {
    reg = <0x001c1000 0x1000>;
    access-controllers = <&wgc0 0>;
};
wgc0: access-controller@1c2000 {
    compatible = "qemu,wgchecker2", "sifive,wgchecker2";
    reg = <0x0 0x001c2000 0x0 0x1000>;
    #access-controller-cells = <1>;
    #address-cells = <1>;
    #size-cells = <0>;

    partition@0 {
        reg = <0>;
        sifive,wg-region = <0x0 0x001c1000 0x0 0x00001000>;
        sifive,slot-permissions = <0x0 0x000000c3>;
        sifive,slot-config = <0x1f>;
    };
};

Expected OpenSBI boot dump:
wgChecker Base : 0x1c2000
wgChecker Slot00 : 0x00000000001c1000-.................. 00: A:0 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot01 : ..................-0x00000000001c2000 c3: A:1 ER:1 EW:1 IR:1 IW:1 L:1
wgChecker Slot Usage : 1 (total), 1 (used), 0 (free)

========================================================================
Use Case 2: Multi-Region Peripheral Protection (Disjoint Register Groups)
========================================================================

0x0001_0000 +---------------------------------------------------+

            | partition@0 : [0x0001_0000, 0x0001_8000) (32 KiB) |
            | reg[0] m_mode | WID 3 RW   (perm 0xc0) | Slot01   |
0x0001_8000 +---------------------------------------------------+
            :                  (unreferenced)                   :
0x00a0_0000 +---------------------------------------------------+
            | partition@1 : [0x00a0_0000, 0x00a0_4000) (16 KiB) |
            | reg[1] s_mode | WID 0,3 RW (perm 0xc3) | Slot02   |

0x00a0_4000 +---------------------------------------------------+

device@10000 {
    reg = <0x0 0x00010000 0x0 0x8000>,
          <0x0 0x00a00000 0x0 0x4000>;
    reg-names = "m_mode", "s_mode";
    access-controllers = <&wgc1 0>, <&wgc1 1>;
};
wgc1: access-controller@35000 {
    compatible = "qemu,wgchecker2", "sifive,wgchecker2";
    reg = <0x0 0x00035000 0x0 0x1000>;
    #access-controller-cells = <1>;
    #address-cells = <1>;
    #size-cells = <0>;

    partition@0 {
        reg = <0>;
        sifive,wg-region = <0x0 0x00010000 0x0 0x00008000>;
        sifive,slot-permissions = <0x0 0x000000c0>;
        sifive,slot-config = <0x0f>;
    };
    partition@1 {
        reg = <1>;
        sifive,wg-region = <0x0 0x00a00000 0x0 0x00004000>;
        sifive,slot-permissions = <0x0 0x000000c3>;
        sifive,slot-config = <0x0f>;
    };
};

Expected OpenSBI boot dump:
wgChecker Base : 0x35000
wgChecker Slot00 : 0x0000000000000000-.................. 00: A:0 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot01 : 0x0000000000010000-0x0000000000018000 c0: A:3 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot02 : 0x0000000000a00000-0x0000000000a04000 c3: A:3 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot04 : ..................-0x0000000001000000 00: A:0 ER:0 EW:0 IR:0 IW:0 L:0
wgChecker Slot Usage : 4 (total), 2 (used), 2 (free)

========================================================================
Use Case 3: Multi-Domain DRAM Spatial Partitioning (Hybrid NAPOT + TOR)
========================================================================

OpenSBI: WID3
Linux : WID0
OP-TEE : WID1

0x8000_0000 +---------------------------------------------------+

              | partition@0 : [0x8000_0000, 0xC000_0000) (1024M)  |
              | Linux / OpenSBI | WID 0,1,3 RW (0xcf) | Slot01 A:3|
  0xC000_0000 +---------------------------------------------------+
              | partition@1 : [0xC000_0000, 0xC100_0000) (16M)    |
              | OP-TEE / OpenSBI| WID 1,3 RW   (0xcc) | Slot02 A:3|
  0xC100_0000 +---------------------------------------------------+
              | partition@2 : [0xC100_0000, 0x1_0000_0000) (1008M)|
              | Linux / OpenSBI | WID 0,1,3 RW (0xcf) | Slot03..04|

0x1_0000_0000 +-------------------------------------------------+

memory: memory@80000000 {
    reg = <0x0 0x80000000 0x0 0x80000000>;
    access-controllers = <&wgc2 0>, <&wgc2 1>, <&wgc2 2>;
};
wgc2: access-controller@50000000 {
    compatible = "qemu,wgchecker2", "sifive,wgchecker2";
    reg = <0x0 0x50000000 0x0 0x1000>;
    #access-controller-cells = <1>;
    #address-cells = <1>;
    #size-cells = <0>;

    partition@0 {
        reg = <0>;
        sifive,wg-region = <0x0 0x80000000 0x0 0x40000000>;
        sifive,slot-permissions = <0x0 0x000000cf>;
        sifive,slot-config = <0x0f>;
    };
    partition@1 {
        reg = <1>;
        sifive,wg-region = <0x0 0xc0000000 0x0 0x01000000>;
        sifive,slot-permissions = <0x0 0x000000cc>;
        sifive,slot-config = <0x0f>;
    };
    partition@2 {
        reg = <2>;
        sifive,wg-region = <0x0 0xc1000000 0x0 0x3f000000>;
        sifive,slot-permissions = <0x0 0x000000cf>;
        sifive,slot-config = <0x0f>;
    };
};

Expected OpenSBI boot dump:
wgChecker Base : 0x50000000
wgChecker Slot00 : 0x0000000000000000-.................. 00: A:0 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot01 : 0x0000000080000000-0x00000000c0000000 cf: A:3 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot02 : 0x00000000c0000000-0x00000000c1000000 cc: A:3 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot03 : 0x00000000c1000000-.................. 00: A:0
wgChecker Slot04 : ..................-0x0000000100000000 cf: A:1 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot16 : ..................-0x0000000100000000 00: A:0 ER:0 EW:0 IR:0 IW:0 L:0
wgChecker Slot Usage : 16 (total), 4 (used), 12 (free)

Best regards,
Peter Lin

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

Hi Peter,

Quoted 213 lines · Yu-Chien Peter Lin

Hi Raymond,

Quoted 31 lines · Raymond Mao

From: Raymond Mao <[email protected]>

This series adds WorldGuard support according to the wgchecker2 DT- binding proposal from SiFive [1] with QEMU virt integration.

The implementation:
- reuse sbi_hart_protection for hart-local runtime reconfiguration
- reuse sbi_domain_data for per-domain WorldGuard state
- keep WorldGuard-specific setup and checker programming in platform code

At boot, the generic platform code invokes a QEMU virt WorldGuard setup path which:
- parses wgchecker2 checker instances
- parses provider partition@N entries and programs checker MMIO
- parses per-hart CPU defaults from /cpus
- parses per-domain WorldGuard metadata under hw-isolation

Checker programming is provider-driven. Consumer-side access-controllers references are carried for DT-binding alignment.

During domain transitions, the WorldGuard hart protection implementation reprograms MLWID and, when available, MLWIDLIST, MWIDDELEG, and SLWID.

The series is split as follows:
1. add reusable FDT helpers needed by the WorldGuard parser
2. add WorldGuard CSR definitions and hart extension flags
3. document the current DT layout consumed by the implementation
4. add the wgchecker2 / WorldGuard runtime and QEMU virt integration

Quoted 8 lines

Tested with:
- QEMU riscv-wg-v4-260821 [2] with arg 'worlds=on' and the merged WorldGuard test DTB.

[1] dt-bindings: riscv: Add RISC-V Worlds and SiFive WorldGuard DT

    bindings
    https://lore.kernel.org/linux-devicetree/[email protected]/

[2] https://github.com/cwshu/qemu/tree/riscv-wg-v4-260821

Thanks for working on this series. Could we align the implementation with the DT proposal on a few key points?

1. Domain WIDs should use wid / widdeleg directly under domain nodes, not hw-isolation with sifive,wgchecker2.
My patches already handle the WID assignment and switching.
https://patchwork.ozlabs.org/project/opensbi/patch/[email protected]/
2. wgChecker is a static firewall configured once at boot; by design it does not support efficient dynamic reconfiguration.
3. Unlike sequential first-match PMP, wgChecker slots are strictly accretive (parallel OR), so overlapping rules cannot restrict access. i.e.

   /* PMP (Priority-based, sequential): */
   for (i = N-1; i >= 0; i--) {
       if (pmp[i].matches(addr))
           return pmp[i].perm;      // FIRST match wins
   }

   /* wgChecker (Strictly accretive, parallel): */
   perm = NO_ACCESS;
   for (i = 0; i < nslots; i++) {
       if (slot[i].matches(addr))
           perm |= slot[i].perm[wid]; // OR all matches
   }
   if (perm allows access)
       grant_access();

The wgChecker driver should automatically select between NAPOT and TOR encoding to minimize slot usage.

4. OpenSBI should support use cases below and dump the wgChecker slot info at boot:

========================================================================
Use Case 1: Single-Slot Peripheral Protection (Full Subordinate Range)
========================================================================

0x001c_1000 +---------------------------------------------------+

            | partition@0 : [0x001c_1000, 0x001c_2000)          |
            | serial@1c1000 | WID 0,3 RW (perm 0xc3, cfg 0x1f)  |
            | Slot00..01  : A=TOR (Slot00 base, Slot01 top)     |

0x001c_2000 +---------------------------------------------------+

uart: serial@1c1000 {
    reg = <0x001c1000 0x1000>;
    access-controllers = <&wgc0 0>;
};
wgc0: access-controller@1c2000 {
    compatible = "qemu,wgchecker2", "sifive,wgchecker2";
    reg = <0x0 0x001c2000 0x0 0x1000>;
    #access-controller-cells = <1>;
    #address-cells = <1>;
    #size-cells = <0>;

    partition@0 {
        reg = <0>;
        sifive,wg-region = <0x0 0x001c1000 0x0 0x00001000>;
        sifive,slot-permissions = <0x0 0x000000c3>;
        sifive,slot-config = <0x1f>;
    };
};

Expected OpenSBI boot dump:
wgChecker Base : 0x1c2000
wgChecker Slot00 : 0x00000000001c1000-.................. 00: A:0 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot01 : ..................-0x00000000001c2000 c3: A:1 ER:1 EW:1 IR:1 IW:1 L:1
wgChecker Slot Usage : 1 (total), 1 (used), 0 (free)

========================================================================
Use Case 2: Multi-Region Peripheral Protection (Disjoint Register Groups)
========================================================================

0x0001_0000 +---------------------------------------------------+

            | partition@0 : [0x0001_0000, 0x0001_8000) (32 KiB) |
            | reg[0] m_mode | WID 3 RW   (perm 0xc0) | Slot01   |
0x0001_8000 +---------------------------------------------------+
            :                  (unreferenced)                   :
0x00a0_0000 +---------------------------------------------------+
            | partition@1 : [0x00a0_0000, 0x00a0_4000) (16 KiB) |
            | reg[1] s_mode | WID 0,3 RW (perm 0xc3) | Slot02   |

0x00a0_4000 +---------------------------------------------------+

device@10000 {
    reg = <0x0 0x00010000 0x0 0x8000>,
          <0x0 0x00a00000 0x0 0x4000>;
    reg-names = "m_mode", "s_mode";
    access-controllers = <&wgc1 0>, <&wgc1 1>;
};
wgc1: access-controller@35000 {
    compatible = "qemu,wgchecker2", "sifive,wgchecker2";
    reg = <0x0 0x00035000 0x0 0x1000>;
    #access-controller-cells = <1>;
    #address-cells = <1>;
    #size-cells = <0>;

    partition@0 {
        reg = <0>;
        sifive,wg-region = <0x0 0x00010000 0x0 0x00008000>;
        sifive,slot-permissions = <0x0 0x000000c0>;
        sifive,slot-config = <0x0f>;
    };
    partition@1 {
        reg = <1>;
        sifive,wg-region = <0x0 0x00a00000 0x0 0x00004000>;
        sifive,slot-permissions = <0x0 0x000000c3>;
        sifive,slot-config = <0x0f>;
    };
};

Expected OpenSBI boot dump:
wgChecker Base : 0x35000
wgChecker Slot00 : 0x0000000000000000-.................. 00: A:0 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot01 : 0x0000000000010000-0x0000000000018000 c0: A:3 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot02 : 0x0000000000a00000-0x0000000000a04000 c3: A:3 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot04 : ..................-0x0000000001000000 00: A:0 ER:0 EW:0 IR:0 IW:0 L:0
wgChecker Slot Usage : 4 (total), 2 (used), 2 (free)

========================================================================
Use Case 3: Multi-Domain DRAM Spatial Partitioning (Hybrid NAPOT + TOR)
========================================================================

OpenSBI: WID3
Linux : WID0
OP-TEE : WID1

0x8000_0000 +---------------------------------------------------+

              | partition@0 : [0x8000_0000, 0xC000_0000) (1024M)  |
              | Linux / OpenSBI | WID 0,1,3 RW (0xcf) | Slot01 A:3|
  0xC000_0000 +---------------------------------------------------+
              | partition@1 : [0xC000_0000, 0xC100_0000) (16M)    |
              | OP-TEE / OpenSBI| WID 1,3 RW   (0xcc) | Slot02 A:3|
  0xC100_0000 +---------------------------------------------------+
              | partition@2 : [0xC100_0000, 0x1_0000_0000) (1008M)|
              | Linux / OpenSBI | WID 0,1,3 RW (0xcf) | Slot03..04|

0x1_0000_0000 +-------------------------------------------------+

memory: memory@80000000 {
    reg = <0x0 0x80000000 0x0 0x80000000>;
    access-controllers = <&wgc2 0>, <&wgc2 1>, <&wgc2 2>;
};
wgc2: access-controller@50000000 {
    compatible = "qemu,wgchecker2", "sifive,wgchecker2";
    reg = <0x0 0x50000000 0x0 0x1000>;
    #access-controller-cells = <1>;
    #address-cells = <1>;
    #size-cells = <0>;

    partition@0 {
        reg = <0>;
        sifive,wg-region = <0x0 0x80000000 0x0 0x40000000>;
        sifive,slot-permissions = <0x0 0x000000cf>;
        sifive,slot-config = <0x0f>;
    };
    partition@1 {
        reg = <1>;
        sifive,wg-region = <0x0 0xc0000000 0x0 0x01000000>;
        sifive,slot-permissions = <0x0 0x000000cc>;
        sifive,slot-config = <0x0f>;
    };
    partition@2 {
        reg = <2>;
        sifive,wg-region = <0x0 0xc1000000 0x0 0x3f000000>;
        sifive,slot-permissions = <0x0 0x000000cf>;
        sifive,slot-config = <0x0f>;
    };
};
Quoted 10 lines

Expected OpenSBI boot dump:
wgChecker Base : 0x50000000
wgChecker Slot00 : 0x0000000000000000-.................. 00: A:0 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot01 : 0x0000000080000000-0x00000000c0000000 cf: A:3 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot02 : 0x00000000c0000000-0x00000000c1000000 cc: A:3 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot03 : 0x00000000c1000000-.................. 00: A:0
wgChecker Slot04 : ..................-0x0000000100000000 cf: A:1 ER:1 EW:1 IR:1 IW:1 L:0
wgChecker Slot16 : ..................-0x0000000100000000 00: A:0 ER:0 EW:0 IR:0 IW:0 L:0
wgChecker Slot Usage : 16 (total), 4 (used), 12 (free)

Thanks for these comments. In v4, I will address them and rebase on your series [1].
Hopefully I will post v4 after [1] is merged into the mainline.

Regards,
Raymond

[1] https://lore.kernel.org/opensbi/[email protected]/

Quoted 2 lines

Best regards,
Peter Lin

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