[PATCH 19/27] RISC-V: KVM: Redirect nested supervisor ecall and breakpoint traps

Anup Patel anup.patel at oss.qualcomm.com
Tue Jan 20 00:00:05 PST 2026


The supervisor ecall and breakpoint traps from Guest VS/VU-mode
(aka L2/nested guest) should be redirected to Guest HS-mode (aka
L1/guest hypervisor).

Signed-off-by: Anup Patel <anup.patel at oss.qualcomm.com>
---
 arch/riscv/kvm/vcpu_exit.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c
index aeec4c4eee06..6627c2c25a71 100644
--- a/arch/riscv/kvm/vcpu_exit.c
+++ b/arch/riscv/kvm/vcpu_exit.c
@@ -274,12 +274,18 @@ int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
 			ret = gstage_page_fault(vcpu, run, trap);
 		break;
 	case EXC_SUPERVISOR_SYSCALL:
-		if (vcpu->arch.guest_context.hstatus & HSTATUS_SPV)
+		if (kvm_riscv_vcpu_nested_virt(vcpu))
+			ret = vcpu_redirect(vcpu, trap);
+		else if (vcpu->arch.guest_context.hstatus & HSTATUS_SPV)
 			ret = kvm_riscv_vcpu_sbi_ecall(vcpu, run);
 		break;
 	case EXC_BREAKPOINT:
-		run->exit_reason = KVM_EXIT_DEBUG;
-		ret = 0;
+		if (kvm_riscv_vcpu_nested_virt(vcpu)) {
+			ret = vcpu_redirect(vcpu, trap);
+		} else {
+			run->exit_reason = KVM_EXIT_DEBUG;
+			ret = 0;
+		}
 		break;
 	default:
 		break;
-- 
2.43.0




More information about the linux-riscv mailing list