| Message ID | 20261023070925.241680-3-theodoruswensanfebruanto025@gmail.com |
|---|---|
| State | New |
| Headers | show |
| Series | Preserve more architectural state across domain switches | expand |
Btw. you're adding optional state in [1/8] as well, so why not squash at least the interrupt parts? 2026-10-23T00:09:19-07:00, Theodorus Wensan Februanto <theodoruswensanfebruanto025@gmail.com>: > Preserve hypervisor interrupt enable state provided by Smaia and > hypervisor state-enable CSRs provided by Smstateen. > > Use extension checks so systems without these CSRs are unaffected. > The 64-bit helper preserves the corresponding high-half CSRs on RV32. > > Link: https://github.com/riscv-software-src/opensbi/issues/433 > Signed-off-by: Theodorus Wensan Februanto <theodoruswensanfebruanto025@gmail.com> > --- > diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c > @@ -208,6 +211,19 @@ static int switch_to_next_domain_context(struct hart_context *ctx, > ctx->hext.hviph = csr_swap(CSR_HVIPH, dom_ctx->hext.hviph); > } > #endif > + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA)) > + ctx->hext.hvien = csr_swap64(CSR_HVIEN, dom_ctx->hext.hvien); hvien also needs to be carefully ordered because it has an effect on vsip and vsie. (hvictl, hviprio1, and hviprio2 are missing.) Thanks.
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c index 4bafda5b..79419edc 100644 --- a/lib/sbi/sbi_domain_context.c +++ b/lib/sbi/sbi_domain_context.c @@ -32,6 +32,9 @@ struct hart_context_hext { unsigned long htinst; unsigned long hvip; unsigned long hgatp; + /** Optional hypervisor state */ + u64 hvien; + u64 hstateen[4]; #if __riscv_xlen == 32 unsigned long hidelegh; unsigned long hviph; @@ -208,6 +211,19 @@ static int switch_to_next_domain_context(struct hart_context *ctx, ctx->hext.hviph = csr_swap(CSR_HVIPH, dom_ctx->hext.hviph); } #endif + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA)) + ctx->hext.hvien = csr_swap64(CSR_HVIEN, dom_ctx->hext.hvien); + + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMSTATEEN)) { + ctx->hext.hstateen[0] = csr_swap64(CSR_HSTATEEN0, + dom_ctx->hext.hstateen[0]); + ctx->hext.hstateen[1] = csr_swap64(CSR_HSTATEEN1, + dom_ctx->hext.hstateen[1]); + ctx->hext.hstateen[2] = csr_swap64(CSR_HSTATEEN2, + dom_ctx->hext.hstateen[2]); + ctx->hext.hstateen[3] = csr_swap64(CSR_HSTATEEN3, + dom_ctx->hext.hstateen[3]); + } } if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
Preserve hypervisor interrupt enable state provided by Smaia and hypervisor state-enable CSRs provided by Smstateen. Use extension checks so systems without these CSRs are unaffected. The 64-bit helper preserves the corresponding high-half CSRs on RV32. Link: https://github.com/riscv-software-src/opensbi/issues/433 Signed-off-by: Theodorus Wensan Februanto <theodoruswensanfebruanto025@gmail.com> --- lib/sbi/sbi_domain_context.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)