diff mbox series

[4/5] lib: sbi_trap: Set hypervisor CSRs for HS-mode

Message ID TYYP286MB1439D2AB7CFD5C0E58107ECFC69F9@TYYP286MB1439.JPNP286.PROD.OUTLOOK.COM
State Superseded
Headers show
Series Set hstatus.GVA for traps going to HS-mode | expand

Commit Message

dramforever Aug. 4, 2022, 3:17 a.m. UTC
The hypervisor CSRs hstatus, htval, htinst should always be set if the
trap is to be taken in HS-mode, regardless of which mode it came from.

Signed-off-by: Vivian Wang <dramforever@live.com>
---
 lib/sbi/sbi_trap.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Andrew Jones Aug. 4, 2022, 7:52 a.m. UTC | #1
On Thu, Aug 04, 2022 at 11:17:05AM +0800, Vivian Wang wrote:
> The hypervisor CSRs hstatus, htval, htinst should always be set if the
> trap is to be taken in HS-mode, regardless of which mode it came from.
> 
> Signed-off-by: Vivian Wang <dramforever@live.com>
> ---
>  lib/sbi/sbi_trap.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>

Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
diff mbox series

Patch

diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c
index f782fbf..6e3202b 100644
--- a/lib/sbi/sbi_trap.c
+++ b/lib/sbi/sbi_trap.c
@@ -118,12 +118,14 @@  int sbi_trap_redirect(struct sbi_trap_regs *regs,
 	regs->mstatus |= (next_virt) ? MSTATUS_MPV : 0UL;
 #endif
 
-	/* Update HSTATUS for VS/VU-mode to HS-mode transition */
-	if (misa_extension('H') && prev_virt && !next_virt) {
-		/* Update HSTATUS SPVP and SPV bits */
+	/* Update hypervisor CSRs if going to HS-mode */
+	if (misa_extension('H') && !next_virt) {
 		hstatus = csr_read(CSR_HSTATUS);
-		hstatus &= ~HSTATUS_SPVP;
-		hstatus |= (prev_mode == PRV_S) ? HSTATUS_SPVP : 0;
+		if (prev_virt) {
+			/* hstatus.SPVP is only updated if coming from VS/VU-mode */
+			hstatus &= ~HSTATUS_SPVP;
+			hstatus |= (prev_mode == PRV_S) ? HSTATUS_SPVP : 0;
+		}
 		hstatus &= ~HSTATUS_SPV;
 		hstatus |= (prev_virt) ? HSTATUS_SPV : 0;
 		csr_write(CSR_HSTATUS, hstatus);