[RFC PATCH v3 4/6] lib: sbi: Preserve S/VS indirect CSR selectors

Samuel Holland samuel.holland at sifive.com
Thu Nov 5 07:04:21 PST 2026


On 2026-11-04 10:43 PM, Theodorus Wensan Februanto wrote:
> Preserve siselect when either Sscsrind or Smaia is available.
> 
> When H is implemented, also preserve vsiselect.
> 
> This change preserves the selectors only. It does not save
> the indirectly selected backing state or IMSIC files.
> 
> Link: https://github.com/riscv-software-src/opensbi/issues/433
> 
> Signed-off-by: Theodorus Wensan Februanto <theodoruswensanfebruanto025 at gmail.com>
> ---
>  lib/sbi/sbi_domain_context.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
> index 89fd1647..fe7d98af 100644
> --- a/lib/sbi/sbi_domain_context.c
> +++ b/lib/sbi/sbi_domain_context.c
> @@ -96,6 +96,10 @@ struct hart_context {
>  	struct hart_context_sstc sstc;
>  	/** Supervisor counter inhibit configuration */
>  	unsigned long scountinhibit;
> +	/** Supervisor indirect CSR selector */
> +	unsigned long siselect;
> +	/** Virtual supervisor indirect CSR selector */
> +	unsigned long vsiselect;

Should this go inside struct hart_context_hext?

Regards,
Samuel

>  
>  	/** Float context state */
>  	struct sbi_fp_context fp_ctx;
> @@ -277,6 +281,13 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
>  	    (csr_read64(CSR_MENVCFG) & ENVCFG_CDE))
>  		ctx->scountinhibit = csr_swap(CSR_SCOUNTINHIBIT,
>  						 dom_ctx->scountinhibit);
> +	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCSRIND) ||
> +	    sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA)) {
> +		ctx->siselect = csr_swap(CSR_SISELECT, dom_ctx->siselect);
> +		if (misa_extension('H'))
> +			ctx->vsiselect = csr_swap(CSR_VSISELECT,
> +						 dom_ctx->vsiselect);
> +	}
>  
>  	/* Eager context switch for float */
>  	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_F) ||




More information about the opensbi mailing list