diff mbox series

[v2,6/9] lib: sbi_domain_context: add slwid to per-domain S-mode context

Message ID 20260817090503.2104998-7-peter.lin@sifive.com
State New
Headers show
Series Add RISC-V Worlds ISA support to OpenSBI | expand

Commit Message

Yu-Chien Peter Lin Aug. 17, 2026, 9:05 a.m. UTC
slwid is the S-mode CSR that controls U-mode's World ID. Since
each domain may run different U-mode workloads with different
WID isolation requirements, slwid must be part of the per-domain
S-mode context.

Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
---
 lib/sbi/sbi_domain_context.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Pawandeep Oza Sept. 3, 2026, 9:59 p.m. UTC | #1
On Mon, Aug 17, 2026 at 2:05 AM Yu-Chien Peter Lin <peter.lin@sifive.com> wrote:
>
> slwid is the S-mode CSR that controls U-mode's World ID. Since
> each domain may run different U-mode workloads with different
> WID isolation requirements, slwid must be part of the per-domain
> S-mode context.
>
> Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
> ---
>  lib/sbi/sbi_domain_context.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
> index 0861d541..0b45c0fd 100644
> --- a/lib/sbi/sbi_domain_context.c
> +++ b/lib/sbi/sbi_domain_context.c
> @@ -50,6 +50,8 @@ struct hart_context {
>         unsigned long senvcfg;
>         /** Supervisor resource management configuration register */
>         unsigned long srmcfg;
> +       /** Supervisor lower-privilege mode World ID register */
> +       unsigned long slwid;
>
>         /** Float context state */
>         struct sbi_fp_context fp_ctx;
> @@ -145,6 +147,17 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
>                 ctx->senvcfg    = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
>         if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
>                 ctx->srmcfg     = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
> +       if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSWID)) {
> +               /*
> +                * Temporarily enable Sswid so slwid is accessible for
> +                * swap. The target domain's mwiddeleg is restored by
> +                * sbi_hart_protection_reconfigure() below.
> +                */
> +               csr_write(CSR_MWIDDELEG, ~0UL);
> +               if (csr_read(CSR_MWIDDELEG))
> +                       ctx->slwid = csr_swap(CSR_SLWID, dom_ctx->slwid);
> +               csr_write(CSR_MWIDDELEG, 0);
> +       }
>
>         /* Eager context switch for float */
>         if (sbi_hart_has_extension(scratch, SBI_HART_EXT_F) ||
> --
> 2.43.7
>

Reviewed-by: Pawandeep Oza <pawandeep.oza@oss.qualcomm.com>
diff mbox series

Patch

diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index 0861d541..0b45c0fd 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -50,6 +50,8 @@  struct hart_context {
 	unsigned long senvcfg;
 	/** Supervisor resource management configuration register */
 	unsigned long srmcfg;
+	/** Supervisor lower-privilege mode World ID register */
+	unsigned long slwid;
 
 	/** Float context state */
 	struct sbi_fp_context fp_ctx;
@@ -145,6 +147,17 @@  static int switch_to_next_domain_context(struct hart_context *ctx,
 		ctx->senvcfg	= csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
 	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
 		ctx->srmcfg	= csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSWID)) {
+		/*
+		 * Temporarily enable Sswid so slwid is accessible for
+		 * swap. The target domain's mwiddeleg is restored by
+		 * sbi_hart_protection_reconfigure() below.
+		 */
+		csr_write(CSR_MWIDDELEG, ~0UL);
+		if (csr_read(CSR_MWIDDELEG))
+			ctx->slwid = csr_swap(CSR_SLWID, dom_ctx->slwid);
+		csr_write(CSR_MWIDDELEG, 0);
+	}
 
 	/* Eager context switch for float */
 	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_F) ||