diff mbox series

[WIP,13/14] x86/svm: Add a trace for VMEXIT_VMRUN

Message ID 20240626133853.4150731-14-george.dunlap@cloud.com (mailing list archive)
State New
Headers show
Series AMD Nested Virt Preparation | expand

Commit Message

George Dunlap June 26, 2024, 1:38 p.m. UTC
Note that this trace is SVM-specific. Most HVM handler traces are
shared between VMX and SVM because the underlying instruction set is
largely the equivalent; but in this case, the instructions are
different enough that there's no sensible way to share HVM handler
traces between them.

Keeping the target VMCB address should allow future analysis of which
L2 vcpu within an L1 is running.

Signed-off-by: George Dunlap <george.dunlap@cloud.com>
---
 tools/xentrace/xenalyze.c  | 20 +++++++++++++++++++-
 xen/arch/x86/hvm/svm/svm.c |  2 ++
 xen/include/public/trace.h |  1 +
 3 files changed, 22 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/xentrace/xenalyze.c b/tools/xentrace/xenalyze.c
index d0e2788727..d1988b4232 100644
--- a/tools/xentrace/xenalyze.c
+++ b/tools/xentrace/xenalyze.c
@@ -952,6 +952,7 @@  enum {
     HVM_EVENT_VLAPIC,
     HVM_EVENT_XCR_READ,
     HVM_EVENT_XCR_WRITE,
+    HVM_EVENT_VMRUN,
     HVM_EVENT_HANDLER_MAX
 };
 const char * hvm_event_handler_name[HVM_EVENT_HANDLER_MAX] = {
@@ -989,7 +990,8 @@  const char * hvm_event_handler_name[HVM_EVENT_HANDLER_MAX] = {
     "trap_debug",
     "vlapic",
     "xcr_read",
-    "xcr_write"
+    "xcr_write",
+    "vmrun"
 };
 
 enum {
@@ -4610,6 +4612,19 @@  void hvm_rdtsc_process(struct record_info *ri, struct hvm_data *h)
     h->last_rdtsc = r->tsc;
 }
 
+
+void hvm_vmrun_process(struct record_info *ri, struct hvm_data *h)
+{
+    struct {
+        uint64_t vmcbaddr;
+    } *r = (typeof(r))h->d;
+
+    if ( opt.dump_all )
+        printf(" %s vmrun %llx\n",
+               ri->dump_header,
+               (unsigned long long)r->vmcbaddr);
+}
+
 void hvm_generic_summary(struct hvm_data *h, void *data)
 {
     long evt = (long)data;
@@ -4910,6 +4925,9 @@  needs_vmexit:
     case TRC_HVM_RDTSC:
         hvm_rdtsc_process(ri, h);
         break;
+    case TRC_HVM_VMRUN:
+        hvm_vmrun_process(ri, h);
+        break;
     case TRC_HVM_DR_READ:
     case TRC_HVM_DR_WRITE:
     case TRC_HVM_CPUID:
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 240401dc77..39af0ffdd6 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -2177,6 +2177,8 @@  svm_vmexit_do_vmrun(struct cpu_user_regs *regs,
         return;
     }
 
+    TRACE(TRC_HVM_VMRUN, vmcbaddr, vmcbaddr >> 32);
+
     vcpu_nestedhvm(v).nv_vmentry_pending = 1;
     return;
 }
diff --git a/xen/include/public/trace.h b/xen/include/public/trace.h
index 141efa0ea7..19a29a5929 100644
--- a/xen/include/public/trace.h
+++ b/xen/include/public/trace.h
@@ -222,6 +222,7 @@ 
 #define TRC_HVM_VLAPIC           (TRC_HVM_HANDLER + 0x25)
 #define TRC_HVM_XCR_READ64      (TRC_HVM_HANDLER + TRC_64_FLAG + 0x26)
 #define TRC_HVM_XCR_WRITE64     (TRC_HVM_HANDLER + TRC_64_FLAG + 0x27)
+#define TRC_HVM_VMRUN           (TRC_HVM_HANDLER + 0x28)
 
 #define TRC_HVM_IOPORT_WRITE    (TRC_HVM_HANDLER + 0x216)
 #define TRC_HVM_IOMEM_WRITE     (TRC_HVM_HANDLER + 0x217)