From 81471de58f4d65ae51399ec4d9fabb937def206b Mon Sep 17 00:00:00 2001 From: dv Date: Mon, 7 Jun 2021 13:55:54 +0000 Subject: [PATCH] vmm(4): add dt tracepoints for guest entry/exit To aid in development and debugging, this adds a tracepoint prior to vm entry and after vm exit. It captures the vcpu and run params plus the exit code, but dt(4)/btrace(8) will need some future work to leverage those args. The location of the tracepoint might change in the future, but for now this solves my issues trying to use printf's to debug vmcs state corruption. ok mpi@ --- sys/arch/amd64/amd64/vmm.c | 11 ++++++++++- sys/dev/dt/dt_prov_static.c | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index 8ef4a14f85f..a3c7e42510c 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.284 2021/05/18 00:05:20 dv Exp $ */ +/* $OpenBSD: vmm.c,v 1.285 2021/06/07 13:55:54 dv Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -4704,6 +4705,8 @@ vcpu_run_vmx(struct vcpu *vcpu, struct vm_run_params *vrp) invvpid(IA32_VMX_INVVPID_SINGLE_CTX_GLB, &vid); } + TRACEPOINT(vmm, guest_enter, vcpu, vrp); + /* Start / resume the VCPU */ #ifdef VMM_DEBUG KERNEL_ASSERT_LOCKED(); @@ -4756,6 +4759,8 @@ vcpu_run_vmx(struct vcpu *vcpu, struct vm_run_params *vrp) } } + TRACEPOINT(vmm, guest_exit, vcpu, vrp, exit_reason); + if (ret || exitinfo != VMX_EXIT_INFO_COMPLETE || exit_reason != VMX_EXIT_EXTINT) { KERNEL_LOCK(); @@ -7059,6 +7064,8 @@ vcpu_run_svm(struct vcpu *vcpu, struct vm_run_params *vrp) vcpu->vc_event = 0; } + TRACEPOINT(vmm, guest_enter, vcpu, vrp); + /* Start / resume the VCPU */ #ifdef VMM_DEBUG KERNEL_ASSERT_LOCKED(); @@ -7103,6 +7110,8 @@ vcpu_run_svm(struct vcpu *vcpu, struct vm_run_params *vrp) vcpu->vc_gueststate.vg_exit_reason = exit_reason; } + TRACEPOINT(vmm, guest_exit, vcpu, vrp, exit_reason); + /* If we exited successfully ... */ if (ret == 0) { vcpu->vc_gueststate.vg_rflags = vmcb->v_rflags; diff --git a/sys/dev/dt/dt_prov_static.c b/sys/dev/dt/dt_prov_static.c index bfe92e5f09a..05828f036ff 100644 --- a/sys/dev/dt/dt_prov_static.c +++ b/sys/dev/dt/dt_prov_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dt_prov_static.c,v 1.7 2021/01/06 07:51:40 claudio Exp $ */ +/* $OpenBSD: dt_prov_static.c,v 1.8 2021/06/07 13:55:54 dv Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot @@ -68,6 +68,12 @@ DT_STATIC_PROBE3(vfs, bufcache_rel, "long", "int", "int64_t"); DT_STATIC_PROBE3(vfs, bufcache_take, "long", "int", "int64_t"); DT_STATIC_PROBE4(vfs, cleaner, "long", "int", "long", "long"); +/* + * VMM + */ +DT_STATIC_PROBE2(vmm, guest_enter, "void *", "void *"); +DT_STATIC_PROBE3(vmm, guest_exit, "void *", "void *", "uint64_t"); + /* * List of all static probes */ @@ -95,6 +101,9 @@ struct dt_probe *dtps_static[] = { &_DT_STATIC_P(vfs, bufcache_rel), &_DT_STATIC_P(vfs, bufcache_take), &_DT_STATIC_P(vfs, cleaner), + /* VMM */ + &_DT_STATIC_P(vmm, guest_enter), + &_DT_STATIC_P(vmm, guest_exit), }; int -- 2.20.1