KVM: X86: Two fixes for KVM_SET_GUEST_DEBUG, and a selftest
cover KVM: X86: Two fixes for KVM_SET_GUEST_DEBUG, and a selftest
The first two patches try to fix two issues I found (I think) with the selftest. The 3rd patch is the test itself. Note, we need below patches to be applied too for the test to work:
KVM: X86: Declare KVM_CAP_SET_GUEST_DEBUG properly
KVM: selftests: Fix build for evmcs.h
Please review, thanks.
Peter Xu (3):
KVM: X86: Set RTM for DB_VECTOR too for KVM_EXIT_DEBUG
KVM: X86: Fix single-step with KVM_SET_GUEST_DEBUG
KVM: selftests: Add KVM_SET_GUEST_DEBUG test
arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/x86.c | 2 +- tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/include/kvm_util.h | 2 + tools/testing/selftests/kvm/lib/kvm_util.c | 9 + .../testing/selftests/kvm/x86_64/debug_regs.c | 180 ++++++++++++++++++ 6 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86_64/debug_regs.c
Signature · 1 line
2.26.2
PATCH 1/3 KVM: X86: Set RTM for DB_VECTOR too for KVM_EXIT_DEBUG
RTM should always been set even with KVM_EXIT_DEBUG on #DB.
--- arch/x86/kvm/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -4685,7 +4685,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)kvm_queue_exception (vcpu,DB_VECTOR );return 1 ; } - kvm_run->debug.arch.dr6 = dr6 |DR6_FIXED_1 ; + kvm_run->debug.arch.dr6 = dr6 |DR6_FIXED_1 |DR6_RTM ; kvm_run->debug.arch.dr7 =vmcs_readl (GUEST_DR7 );/* fall through */ case BP_VECTOR :
Signature · 1 line
2.26.2
PATCH 2/3 KVM: X86: Fix single-step with KVM_SET_GUEST_DEBUG
In reply to Peter XuWhen single-step triggered with KVM_SET_GUEST_DEBUG, we should fill in the pc value with current linear RIP rather than the cached singlestep address.
--- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +1 -1
@@ -6672,7 +6672,7 @@ static int kvm_vcpu_do_singlestep(struct kvm_vcpu *vcpu)if (vcpu->guest_debug &KVM_GUESTDBG_SINGLESTEP ) { kvm_run->debug.arch.dr6 =DR6_BS |DR6_FIXED_1 |DR6_RTM ; - kvm_run->debug.arch.pc = vcpu->arch.singlestep_rip; + kvm_run->debug.arch.pc =kvm_get_linear_rip (vcpu); kvm_run->debug.arch.exception =DB_VECTOR ; kvm_run->exit_reason =KVM_EXIT_DEBUG ;return 0 ;
Signature · 1 line
2.26.2
PATCH 3/3 KVM: selftests: Add KVM_SET_GUEST_DEBUG test
In reply to Peter XuCovers fundamental tests for KVM_SET_GUEST_DEBUG. It is very close to the debug test in kvm-unit-test, but doing it from outside the guest.
--- tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/include/kvm_util.h | 2 + tools/testing/selftests/kvm/lib/kvm_util.c | 9 + .../testing/selftests/kvm/x86_64/debug_regs.c | 180 ++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/debug_regs.c
tools/testing/selftests/kvm/Makefile +1 -0
@@ -28,6 +28,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test +TEST_GEN_PROGS_x86_64 += x86_64/debug_regs TEST_GEN_PROGS_x86_64 += clear_dirty_log_test TEST_GEN_PROGS_x86_64 += demand_paging_test TEST_GEN_PROGS_x86_64 += dirty_log_test
tools/testing/selftests/kvm/include/kvm_util.h +2 -0
@@ -143,6 +143,8 @@ struct kvm_run *vcpu_state(struct kvm_vm *vm, uint32_t vcpuid);void vcpu_run (struct kvm_vm *vm,uint32_t vcpuid);int _vcpu_run (struct kvm_vm *vm,uint32_t vcpuid);void vcpu_run_complete_io (struct kvm_vm *vm,uint32_t vcpuid); +void vcpu_set_guest_debug (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_guest_debug *debug);void vcpu_set_mp_state (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_mp_state *mp_state);void vcpu_regs_get (struct kvm_vm *vm,uint32_t vcpuid,struct kvm_regs *regs);
tools/testing/selftests/kvm/lib/kvm_util.c +9 -0
@@ -1201,6 +1201,15 @@ void vcpu_run_complete_io(struct kvm_vm *vm, uint32_t vcpuid) ret, errno); } +void vcpu_set_guest_debug (struct kvm_vm *vm,uint32_t vcpuid, +struct kvm_guest_debug *debug) +{ +struct vcpu *vcpu =vcpu_find (vm, vcpuid); +int ret =ioctl (vcpu->fd,KVM_SET_GUEST_DEBUG , debug); + +TEST_ASSERT (ret ==0 ,"KVM_SET_GUEST_DEBUG failed: %d" , ret); +} +/* * VM VCPU Set MP State *
tools/testing/selftests/kvm/x86_64/debug_regs.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
2.26.2
Quoted 14 lines · Peter Xu
The first two patches try to fix two issues I found (I think) with the selftest. The 3rd patch is the test itself. Note, we need below patches to be applied too for the test to work:
KVM: X86: Declare
KVM_CAP_SET_GUEST_DEBUGproperly
KVM: selftests: Fix build forevmcs.hPlease review, thanks.
Peter Xu (3):
KVM: X86: Set RTM forDB_VECTORtoo forKVM_EXIT_DEBUG
KVM: X86: Fix single-step withKVM_SET_GUEST_DEBUG
KVM: selftests: AddKVM_SET_GUEST_DEBUGtest
Quoted 9 lines
arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/x86.c | 2 +- tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/include/kvm_util.h | 2 + tools/testing/selftests/kvm/lib/kvm_util.c | 9 + .../testing/selftests/kvm/x86_64/debug_regs.c | 180 ++++++++++++++++++ 6 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86_64/debug_regs.c
Queued, thanks.
Paolo