diff options
author | Yu Chien Peter Lin <peterlin@andestech.com> | 2024-06-07 19:39:28 +0800 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2024-06-13 19:21:27 +0530 |
commit | 3a94a3258039f225d068cb575844062c3f86bc03 (patch) | |
tree | ebdcd5a6e46fc5dc55fe2cf37942b1d6b8f34735 /lib/sbi/sbi_domain_context.c | |
parent | a73ff043e99122be9f50215f04d0a8e93d69a978 (diff) | |
download | opensbi-3a94a3258039f225d068cb575844062c3f86bc03.zip opensbi-3a94a3258039f225d068cb575844062c3f86bc03.tar.gz opensbi-3a94a3258039f225d068cb575844062c3f86bc03.tar.bz2 |
sbi: sbi_domain_context: Fix trap context for domain context switching
Save/restore sbi_trap_context during domain context switching to
ensure proper trap handling and isolation. This maintains correct
domain-specific state, avoiding context corruption.
Fixes: abea949721bc ("lib: sbi: Introduce trap context")
Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
Reviewed-by: Alvin Chang <alvinga@andestech.com>
Tested-by: Alvin Chang <alvinga@andestech.com>
Reviewed-by: Yong Li <yong.li@intel.com>
Tested-by: Yong Li <yong.li@intel.com>
Diffstat (limited to 'lib/sbi/sbi_domain_context.c')
-rwxr-xr-x | lib/sbi/sbi_domain_context.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c index 7528591..49a2f76 100755 --- a/lib/sbi/sbi_domain_context.c +++ b/lib/sbi/sbi_domain_context.c @@ -27,7 +27,7 @@ static void switch_to_next_domain_context(struct sbi_context *ctx, struct sbi_context *dom_ctx) { u32 hartindex = sbi_hartid_to_hartindex(current_hartid()); - struct sbi_trap_regs *trap_regs; + struct sbi_trap_context *trap_ctx; struct sbi_domain *current_dom = ctx->dom; struct sbi_domain *target_dom = dom_ctx->dom; struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); @@ -66,10 +66,9 @@ static void switch_to_next_domain_context(struct sbi_context *ctx, 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) - - SBI_TRAP_REGS_SIZE); - sbi_memcpy(&ctx->regs, trap_regs, sizeof(*trap_regs)); - sbi_memcpy(trap_regs, &dom_ctx->regs, sizeof(*trap_regs)); + trap_ctx = sbi_trap_get_context(scratch); + sbi_memcpy(&ctx->trap_ctx, trap_ctx, sizeof(*trap_ctx)); + sbi_memcpy(trap_ctx, &dom_ctx->trap_ctx, sizeof(*trap_ctx)); /* Mark current context structure initialized because context saved */ ctx->initialized = true; |