Skip to content

Commit

Permalink
sbi: sbi_domain_context: Check privilege spec version before accessin…
Browse files Browse the repository at this point in the history
…g S-mode CSRs

SCOUNTEREN and SENVCFG may not be supported on certain RISC-V core,
so check the existence of these CSRs via privilege spec version to
prevent illegal instructions.

Signed-off-by: Yu Chien Peter Lin <[email protected]>
Signed-off-by: Alvin Chang <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
  • Loading branch information
lyctw authored and avpatel committed Apr 5, 2024
1 parent 7862c24 commit 29ecda9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/sbi/sbi_domain_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ static void switch_to_next_domain_context(struct sbi_context *ctx,
ctx->stval = csr_swap(CSR_STVAL, dom_ctx->stval);
ctx->sip = csr_swap(CSR_SIP, dom_ctx->sip);
ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);

/* Save current trap state and restore target domain's trap state */
trap_regs = (struct sbi_trap_regs *)(csr_read(CSR_MSCRATCH) -
Expand Down

0 comments on commit 29ecda9

Please sign in to comment.