Update the guest_debug flags from userspace accordingly. Route the breakpoint exceptions to HS mode if the VM is being debugged by userspace, by clearing the corresponding bit in hedeleg CSR. Signed-off-by: Chao Du <duchao@xxxxxxxxxxxxxxxxxx> --- arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index e087c809073c..b8144434ff23 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -473,8 +473,19 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg) { - /* TODO; To be implemented later. */ - return -EINVAL; + if (dbg->control & KVM_GUESTDBG_ENABLE) { + if (vcpu->guest_debug != dbg->control) { + vcpu->guest_debug = dbg->control; + csr_clear(CSR_HEDELEG, BIT(EXC_BREAKPOINT)); + } + } else { + if (vcpu->guest_debug != 0) { + vcpu->guest_debug = 0; + csr_set(CSR_HEDELEG, BIT(EXC_BREAKPOINT)); + } + } + + return 0; } static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu) -- 2.17.1