[PATCH] lib: sbi: Preserve hcounteren and htimedelta across domain switches
Anup Patel
anup at brainfault.org
Thu Oct 22 23:08:51 PDT 2026
On Fri, Oct 23, 2026 at 5:32 AM whensun
<theodoruswensanfebruanto025 at gmail.com> wrote:
>
> Save and restore hcounteren and htimedelta when switching between
> domains on harts supporting the Hypervisor extension.
>
> Without this preservation, a resumed domain can observe the register
> values left by another domain.
>
> Link: https://github.com/riscv-software-src/opensbi/issues/433
> Signed-off-by: whensun <theodoruswensanfebruanto025 at gmail.com>
Squash this in appropriate patch of your other series "Preserve more
S/HS architectural state across domain switches"
Regards,
Anup
> ---
> lib/sbi/sbi_domain_context.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
> index 0861d541..31fa5afc 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;
> + unsigned long hcounteren;
> + u64 htimedelta;
>
> /** Float context state */
> struct sbi_fp_context fp_ctx;
> @@ -145,6 +147,10 @@ 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 (misa_extension('H')) {
> + ctx->hcounteren = csr_swap(CSR_HCOUNTEREN, dom_ctx->hcounteren);
> + ctx->htimedelta = csr_swap64(CSR_HTIMEDELTA, dom_ctx->htimedelta);
> + }
>
> /* Eager context switch for float */
> if (sbi_hart_has_extension(scratch, SBI_HART_EXT_F) ||
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
More information about the opensbi
mailing list