diff mbox series

KVM: RISC-V: Clear HSTATUS.HU on hypervisor initialization

Message ID 20260817-hstatus_hu-v1-1-28c53cdfb408@sifive.com
State New
Headers show
Series KVM: RISC-V: Clear HSTATUS.HU on hypervisor initialization | expand

Commit Message

Yong-Xuan Wang Aug. 17, 2026, 7:32 a.m. UTC
The RISC-V privileged specification does not mandate HSTATUS reset
values, leaving the HU bit potentially set after hardware reset.
When HU=1, hypervisor instructions (HLV/HLVX/HSV) can execute in
U-mode to access guest memory, which may cause unintended behavior
if not explicitly controlled.

Clear HSTATUS.HU during KVM initialization to ensure hypervisor
instructions are only available in HS-mode, preventing unexpected
guest memory access from U-mode code.

Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
---
 arch/riscv/kvm/main.c | 3 +++
 1 file changed, 3 insertions(+)


---
base-commit: b5060a4aa33d7d78a8c1837ab08ef0c81ea96650
change-id: 20260817-hstatus_hu-a1a88a27c7b1
diff mbox series

Patch

diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c
index 85e772588fad..e80a99e93d56 100644
--- a/arch/riscv/kvm/main.c
+++ b/arch/riscv/kvm/main.c
@@ -47,6 +47,9 @@  static void kvm_riscv_csr_init(void)
 	csr_write(CSR_HCOUNTEREN, 0x02);
 
 	csr_write(CSR_HVIP, 0);
+
+	/* clear HSTATUS.HU */
+	csr_clear(CSR_HSTATUS, HSTATUS_HU);
 }
 
 /* Clear hypervisor CSRs - called during CPU offline and non-retention idle entry */