[PATCH v2 6/9] lib: sbi_domain_context: add slwid to per-domain S-mode context
Pawandeep Oza
pawandeep.oza at oss.qualcomm.com
Thu Sep 3 14:59:21 PDT 2026
On Mon, Aug 17, 2026 at 2:05 AM Yu-Chien Peter Lin <peter.lin at 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 at 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 at oss.qualcomm.com>
More information about the opensbi
mailing list