RISC-V: KVM: Guest Debug Support
Subsystems (3)
cover RISC-V: KVM: Guest Debug Support
This series implements KVM Guest Debug on RISC-V. Currently, we can debug RISC-V KVM guest from the host side, with software breakpoints.
A brief test was done on QEMU RISC-V hypervisor emulator.
A TODO list which will be added later:
1. HW breakpoints support
2. Test cases
This series is based on Linux 6.7-rc6 and is also available at:
https://github.com/Du-Chao/linux/tree/riscv_gd_sw
The matched QEMU is available at:
https://github.com/Du-Chao/qemu/tree/riscv_gd_sw
Chao Du (3):
RISC-V: KVM: Enable the KVM_CAP_SET_GUEST_DEBUG capability
RISC-V: KVM: Implement kvm_arch_vcpu_ioctl_set_guest_debug()
RISC-V: KVM: Handle breakpoint exits for VCPU
arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- arch/riscv/kvm/vcpu_exit.c | 4 ++++ arch/riscv/kvm/vm.c | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)
--
2.17.1
RFC PATCH 1/3 RISC-V: KVM: Enable the KVM_CAP_SET_GUEST_DEBUG capability
To indicate that the hypervisor has the capability for guest debug. Also update the uapi header file.
--- arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vm.c | 1 + 2 files changed, 2 insertions(+)
arch/riscv/include/uapi/asm/kvm.h +1 -0
@@ -17,6 +17,7 @@#define __KVM_HAVE_IRQ_LINE#define __KVM_HAVE_READONLY_MEM +#define __KVM_HAVE_GUEST_DEBUG#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
arch/riscv/kvm/vm.c +1 -0
@@ -187,6 +187,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_READONLY_MEM :case KVM_CAP_MP_STATE :case KVM_CAP_IMMEDIATE_EXIT : +case KVM_CAP_SET_GUEST_DEBUG : r =1 ;break ;case KVM_CAP_NR_VCPUS :
Signature · 1 line
2.17.1
RFC PATCH 2/3 RISC-V: KVM: Implement kvm_arch_vcpu_ioctl_set_guest_debug()
In reply to Chao DuUpdate 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.
--- arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
arch/riscv/kvm/vcpu.c +13 -2
@@ -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)
Signature · 1 line
2.17.1
RFC PATCH 3/3 RISC-V: KVM: Handle breakpoint exits for VCPU
In reply to Chao DuExit to userspace for breakpoint traps. Set the exit_reason as KVM_EXIT_DEBUG before exit.
--- arch/riscv/kvm/vcpu_exit.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/riscv/kvm/vcpu_exit.c +4 -0
@@ -204,6 +204,10 @@ int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,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 ; +break ;default :break ; }
Signature · 1 line
2.17.1
Quoted 9 lines · On Thu, Dec 21, 2023 at 3:21?PM Chao Du <[email protected]> wrote:
This series implements KVM Guest Debug on RISC-V. Currently, we can debug RISC-V KVM guest from the host side, with software breakpoints.
A brief test was done on QEMU RISC-V hypervisor emulator.
A TODO list which will be added later:
1. HW breakpoints support
2. Test cases
Himanshu has already done the complete HW breakpoint implementation in OpenSBI, Linux RISC-V, and KVM RISC-V. This is based on the upcoming SBI debug trigger extension draft proposal.
(Refer, https://lists.riscv.org/g/tech-debug/message/1261)
There are also RISE projects to track these efforts:
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394541
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394545
Currently, we are in the process of upstreaming the OpenSBI support for SBI debug trigger extension. The Linux RISC-V and KVM RISC-V patches require SBI debug trigger extension and Sdtrig extension to be frozen which will happen next year 2024.
Regards,
Anup
Quoted 26 lines
This series is based on Linux 6.7-rc6 and is also available at:
https://github.com/Du-Chao/linux/tree/riscv_gd_swThe matched QEMU is available at:
https://github.com/Du-Chao/qemu/tree/riscv_gd_swChao Du (3):
RISC-V: KVM: Enable theKVM_CAP_SET_GUEST_DEBUGcapability
RISC-V: KVM: Implementkvm_arch_vcpu_ioctl_set_guest_debug()
RISC-V: KVM: Handle breakpoint exits for VCPUarch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- arch/riscv/kvm/vcpu_exit.c | 4 ++++ arch/riscv/kvm/vm.c | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)--
2.17.1--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
Quoted 21 lines · Anup Patel
Quoted 9 lines · On Thu, Dec 21, 2023 at 3:21?PM Chao Du <[email protected]> wrote:
This series implements KVM Guest Debug on RISC-V. Currently, we can debug RISC-V KVM guest from the host side, with software breakpoints.
A brief test was done on QEMU RISC-V hypervisor emulator.
A TODO list which will be added later:
1. HW breakpoints support
2. Test casesHimanshu has already done the complete HW breakpoint implementation in OpenSBI, Linux RISC-V, and KVM RISC-V. This is based on the upcoming SBI debug trigger extension draft proposal.
(Refer, https://lists.riscv.org/g/tech-debug/message/1261)There are also RISE projects to track these efforts:
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394541
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394545
Quoted 8 lines
Currently, we are in the process of upstreaming the OpenSBI support for SBI debug trigger extension. The Linux RISC-V and KVM RISC-V patches require SBI debug trigger extension and Sdtrig extension to be frozen which will happen next year 2024.
Regards,
Anup
Hi Anup,
Thank you for the information and your great work on the SBI Debug Trigger Extension proposal.
So I think that 'HW breakpoints support' in the above TODO list will be taken care of by Himanshu following the extension proposal.
On the other hand, if I understand correctly, the software breakpoint part of KVM Guest Debug has no dependency on the new extension since it does not use the trigger module. Just an ebreak substitution is made.
So may I know your suggestion about this RFC? Both in KVM and QEMU.
Regards,
Chao
Quoted 26 lines
Quoted 26 lines
This series is based on Linux 6.7-rc6 and is also available at:
https://github.com/Du-Chao/linux/tree/riscv_gd_swThe matched QEMU is available at:
https://github.com/Du-Chao/qemu/tree/riscv_gd_swChao Du (3):
RISC-V: KVM: Enable theKVM_CAP_SET_GUEST_DEBUGcapability
RISC-V: KVM: Implementkvm_arch_vcpu_ioctl_set_guest_debug()
RISC-V: KVM: Handle breakpoint exits for VCPUarch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- arch/riscv/kvm/vcpu_exit.c | 4 ++++ arch/riscv/kvm/vm.c | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)--
2.17.1--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
Quoted 45 lines · Chao Du
Quoted 21 lines · Anup Patel
Quoted 9 lines · On Thu, Dec 21, 2023 at 3:21?PM Chao Du <[email protected]> wrote:
This series implements KVM Guest Debug on RISC-V. Currently, we can debug RISC-V KVM guest from the host side, with software breakpoints.
A brief test was done on QEMU RISC-V hypervisor emulator.
A TODO list which will be added later:
1. HW breakpoints support
2. Test casesHimanshu has already done the complete HW breakpoint implementation in OpenSBI, Linux RISC-V, and KVM RISC-V. This is based on the upcoming SBI debug trigger extension draft proposal.
(Refer, https://lists.riscv.org/g/tech-debug/message/1261)There are also RISE projects to track these efforts:
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394541
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394545Quoted 8 lines
Currently, we are in the process of upstreaming the OpenSBI support for SBI debug trigger extension. The Linux RISC-V and KVM RISC-V patches require SBI debug trigger extension and Sdtrig extension to be frozen which will happen next year 2024.
Regards,
AnupHi Anup,
Thank you for the information and your great work on the SBI Debug Trigger Extension proposal.
So I think that 'HW breakpoints support' in the above TODO list will be taken care of by Himanshu following the extension proposal.
On the other hand, if I understand correctly, the software breakpoint part of KVM Guest Debug has no dependency on the new extension since it does not use the trigger module. Just an ebreak substitution is made.
Quoted 5 lines
So may I know your suggestion about this RFC? Both in KVM and QEMU.
Regards,
Chao
Hi Anup and all,
I'm still waiting for your comment and suggestion for the next step. :)
Thanks
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
This series is based on Linux 6.7-rc6 and is also available at:
https://github.com/Du-Chao/linux/tree/riscv_gd_swThe matched QEMU is available at:
https://github.com/Du-Chao/qemu/tree/riscv_gd_swChao Du (3):
RISC-V: KVM: Enable theKVM_CAP_SET_GUEST_DEBUGcapability
RISC-V: KVM: Implementkvm_arch_vcpu_ioctl_set_guest_debug()
RISC-V: KVM: Handle breakpoint exits for VCPUarch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- arch/riscv/kvm/vcpu_exit.c | 4 ++++ arch/riscv/kvm/vm.c | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)--
2.17.1--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
Hi all,
Gentle ping.
In my point of view, these patches focus on the software breakpoint of KVM Guest Debug, which are independent of the SBI extensions Anup mentioned.
Please correct me if I'm wrong.
Thanks,
Chao
Quoted 86 lines · Chao Du
Quoted 45 lines · Chao Du
Quoted 21 lines · Anup Patel
Quoted 9 lines · On Thu, Dec 21, 2023 at 3:21?PM Chao Du <[email protected]> wrote:
This series implements KVM Guest Debug on RISC-V. Currently, we can debug RISC-V KVM guest from the host side, with software breakpoints.
A brief test was done on QEMU RISC-V hypervisor emulator.
A TODO list which will be added later:
1. HW breakpoints support
2. Test casesHimanshu has already done the complete HW breakpoint implementation in OpenSBI, Linux RISC-V, and KVM RISC-V. This is based on the upcoming SBI debug trigger extension draft proposal.
(Refer, https://lists.riscv.org/g/tech-debug/message/1261)There are also RISE projects to track these efforts:
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394541
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394545Quoted 8 lines
Currently, we are in the process of upstreaming the OpenSBI support for SBI debug trigger extension. The Linux RISC-V and KVM RISC-V patches require SBI debug trigger extension and Sdtrig extension to be frozen which will happen next year 2024.
Regards,
AnupHi Anup,
Thank you for the information and your great work on the SBI Debug Trigger Extension proposal.
So I think that 'HW breakpoints support' in the above TODO list will be taken care of by Himanshu following the extension proposal.
On the other hand, if I understand correctly, the software breakpoint part of KVM Guest Debug has no dependency on the new extension since it does not use the trigger module. Just an ebreak substitution is made.
Quoted 5 lines
So may I know your suggestion about this RFC? Both in KVM and QEMU.
Regards,
ChaoHi Anup and all,
I'm still waiting for your comment and suggestion for the next step. :)
Thanks
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
This series is based on Linux 6.7-rc6 and is also available at:
https://github.com/Du-Chao/linux/tree/riscv_gd_swThe matched QEMU is available at:
https://github.com/Du-Chao/qemu/tree/riscv_gd_swChao Du (3):
RISC-V: KVM: Enable theKVM_CAP_SET_GUEST_DEBUGcapability
RISC-V: KVM: Implementkvm_arch_vcpu_ioctl_set_guest_debug()
RISC-V: KVM: Handle breakpoint exits for VCPUarch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- arch/riscv/kvm/vcpu_exit.c | 4 ++++ arch/riscv/kvm/vm.c | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)--
2.17.1--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
Anup Patel
maintainerQuoted 40 lines · On Fri, Dec 22, 2023 at 1:59?PM Chao Du <[email protected]> wrote:
Quoted 21 lines · Anup Patel
Quoted 9 lines · On Thu, Dec 21, 2023 at 3:21?PM Chao Du <[email protected]> wrote:
This series implements KVM Guest Debug on RISC-V. Currently, we can debug RISC-V KVM guest from the host side, with software breakpoints.
A brief test was done on QEMU RISC-V hypervisor emulator.
A TODO list which will be added later:
1. HW breakpoints support
2. Test casesHimanshu has already done the complete HW breakpoint implementation in OpenSBI, Linux RISC-V, and KVM RISC-V. This is based on the upcoming SBI debug trigger extension draft proposal.
(Refer, https://lists.riscv.org/g/tech-debug/message/1261)There are also RISE projects to track these efforts:
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394541
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394545Quoted 8 lines
Currently, we are in the process of upstreaming the OpenSBI support for SBI debug trigger extension. The Linux RISC-V and KVM RISC-V patches require SBI debug trigger extension and Sdtrig extension to be frozen which will happen next year 2024.
Regards,
AnupHi Anup,
Thank you for the information and your great work on the SBI Debug Trigger Extension proposal.
So I think that 'HW breakpoints support' in the above TODO list will be taken care of by Himanshu following the extension proposal.
Quoted 6 lines
On the other hand, if I understand correctly, the software breakpoint part of KVM Guest Debug has no dependency on the new extension since it does not use the trigger module. Just an ebreak substitution is made.
So may I know your suggestion about this RFC? Both in KVM and QEMU.
Sorry for the delay in response due to holiday season other stuff keeping me busy.
If this is about ebreak instruction virtualization then this series needs following changes:
1) Update cover letter to indicate this series focus on ebreak instruction virtualization
2) PATCH1 and PATCH2 can be merged into one PATCH1
3) Include a new patch which adds KVM selftest for ebreak based guest debug. This selftest will test both:
A) Taking "ebreak" trap from guest as KVM_EXIT_DEBUG in host user-space
B) Taking "ebreak" trap from guest as BREAKPOINT exception in guest
Regards,
Anup
Quoted 30 lines
Regards,
ChaoQuoted 26 lines
Quoted 26 lines
This series is based on Linux 6.7-rc6 and is also available at:
https://github.com/Du-Chao/linux/tree/riscv_gd_swThe matched QEMU is available at:
https://github.com/Du-Chao/qemu/tree/riscv_gd_swChao Du (3):
RISC-V: KVM: Enable theKVM_CAP_SET_GUEST_DEBUGcapability
RISC-V: KVM: Implementkvm_arch_vcpu_ioctl_set_guest_debug()
RISC-V: KVM: Handle breakpoint exits for VCPUarch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- arch/riscv/kvm/vcpu_exit.c | 4 ++++ arch/riscv/kvm/vm.c | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)--
2.17.1--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
Quoted 47 lines · Anup Patel
Quoted 45 lines · On Fri, Dec 22, 2023 at 1:59?PM Chao Du <[email protected]> wrote:
Quoted 21 lines · Anup Patel
Quoted 9 lines · On Thu, Dec 21, 2023 at 3:21?PM Chao Du <[email protected]> wrote:
This series implements KVM Guest Debug on RISC-V. Currently, we can debug RISC-V KVM guest from the host side, with software breakpoints.
A brief test was done on QEMU RISC-V hypervisor emulator.
A TODO list which will be added later:
1. HW breakpoints support
2. Test casesHimanshu has already done the complete HW breakpoint implementation in OpenSBI, Linux RISC-V, and KVM RISC-V. This is based on the upcoming SBI debug trigger extension draft proposal.
(Refer, https://lists.riscv.org/g/tech-debug/message/1261)There are also RISE projects to track these efforts:
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394541
https://wiki.riseproject.dev/pages/viewpage.action?pageId=394545Quoted 8 lines
Currently, we are in the process of upstreaming the OpenSBI support for SBI debug trigger extension. The Linux RISC-V and KVM RISC-V patches require SBI debug trigger extension and Sdtrig extension to be frozen which will happen next year 2024.
Regards,
AnupHi Anup,
Thank you for the information and your great work on the SBI Debug Trigger Extension proposal.
So I think that 'HW breakpoints support' in the above TODO list will be taken care of by Himanshu following the extension proposal.
On the other hand, if I understand correctly, the software breakpoint part of KVM Guest Debug has no dependency on the new extension since it does not use the trigger module. Just an ebreak substitution is made.
Quoted 4 lines
Quoted 1 line
So may I know your suggestion about this RFC? Both in KVM and QEMU.
Sorry for the delay in response due to holiday season other stuff keeping me busy.
No problem. :)
Quoted 12 lines
If this is about ebreak instruction virtualization then this series needs following changes:
1) Update cover letter to indicate this series focus on ebreak instruction virtualization
2) PATCH1 and PATCH2 can be merged into one PATCH1
3) Include a new patch which adds KVM selftest for ebreak based guest debug. This selftest will test both:
A) Taking "ebreak" trap from guest asKVM_EXIT_DEBUGin host user-space
B) Taking "ebreak" trap from guest as BREAKPOINT exception in guest
Sure, I will prepare a V2 series.
Thanks.
Quoted 34 lines
Regards,
AnupQuoted 30 lines
Regards,
ChaoQuoted 26 lines
Quoted 26 lines
This series is based on Linux 6.7-rc6 and is also available at:
https://github.com/Du-Chao/linux/tree/riscv_gd_swThe matched QEMU is available at:
https://github.com/Du-Chao/qemu/tree/riscv_gd_swChao Du (3):
RISC-V: KVM: Enable theKVM_CAP_SET_GUEST_DEBUGcapability
RISC-V: KVM: Implementkvm_arch_vcpu_ioctl_set_guest_debug()
RISC-V: KVM: Handle breakpoint exits for VCPUarch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 15 +++++++++++++-- arch/riscv/kvm/vcpu_exit.c | 4 ++++ arch/riscv/kvm/vm.c | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)--
2.17.1--
kvm-riscv mailing list
kvm-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv