Skip to contentSkip to conversation

svm: last branch recording MSR emulation

PATCH New Jan Beulich 1 participant 1 message Aug 9, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 svm: last branch recording MSR emulation

xen/arch/x86/hvm/svm/svm.c +42 -16
Index: 2007-08-08/xen/arch/x86/hvm/svm/svm.c
===================================================================
@@ -68,6 +68,9 @@ static void *hsa[NR_CPUS] __read_mostly;
 /* vmcb used for extended host state */
 static void *root_vmcb[NR_CPUS] __read_mostly;
 
+/* SVM feature flags */
+u32 svm_feature_flags;
+
 /* hardware assisted paging bits */
 extern int opt_hap_enabled;
 
@@ -991,20 +994,6 @@ static struct hvm_function_table svm_fun
     .event_pending        = svm_event_pending
 };
 
-static void svm_npt_detect(void)
-{
-    u32 eax, ebx, ecx, edx;
-
-    /* Check CPUID for nested paging support. */
-    cpuid(0x8000000A, &eax, &ebx, &ecx, &edx);
-
-    if ( !(edx & 1) && opt_hap_enabled )
-    {
-        printk("SVM: Nested paging is not supported by this CPU.\n");
-        opt_hap_enabled = 0;
-    }
-}
-
 int start_svm(struct cpuinfo_x86 *c)
 {
     u32 eax, ecx, edx;
@@ -1027,14 +1016,25 @@ int start_svm(struct cpuinfo_x86 *c)
         return 0;
     }
 
+    edx = cpuid_edx(0x8000000A);
+    if ( cpu == 0 )
+        svm_feature_flags = edx;
+    else
+        svm_feature_flags &= edx;
+
+    /* Check for nested paging support. */
+    if ( !cpu_has_npt && opt_hap_enabled )
+    {
+        printk("SVM: Nested paging is not supported by this CPU.\n");
+        opt_hap_enabled = 0;
+    }
+
     if ( ((hsa[cpu] = alloc_host_save_area()) == NULL) ||
          ((root_vmcb[cpu] = alloc_vmcb()) == NULL) )
         return 0;
 
     write_efer(read_efer() | EFER_SVME);
 
-    svm_npt_detect();
-
     /* Initialize the HSA for this core. */
     phys_hsa = (u64) virt_to_maddr(hsa[cpu]);
     phys_hsa_lo = (u32) phys_hsa;
@@ -2164,6 +2164,14 @@ static void svm_do_msr_access(
             msr_content = 0;
             break;
 
+        case MSR_IA32_DEBUGCTLMSR:
+        case MSR_IA32_LASTBRANCHFROMIP:
+        case MSR_IA32_LASTBRANCHTOIP:
+        case MSR_IA32_LASTINTFROMIP:
+        case MSR_IA32_LASTINTTOIP:
+            msr_content = 0;
+            break;
+
         default:
             if ( rdmsr_hypervisor_regs(ecx, &eax, &edx) ||
                  rdmsr_safe(ecx, eax, edx) == 0 )
@@ -2206,6 +2214,24 @@ static void svm_do_msr_access(
             svm_inject_exception(v, TRAP_gp_fault, 1, 0);
             break;
 
+        case MSR_IA32_DEBUGCTLMSR:
+            if ( msr_content && cpu_has_lbrv )
+            {
+                vmcb->debugctlmsr = msr_content;
+                vmcb->lbr_control.fields.enable = 1;
+                svm_disable_intercept_for_msr(v->arch.hvm_svm.msrpm,
+                                              MSR_IA32_DEBUGCTLMSR);
+                svm_disable_intercept_for_msr(v->arch.hvm_svm.msrpm,
+                                              MSR_IA32_LASTBRANCHFROMIP);
+                svm_disable_intercept_for_msr(v->arch.hvm_svm.msrpm,
+                                              MSR_IA32_LASTBRANCHTOIP);
+                svm_disable_intercept_for_msr(v->arch.hvm_svm.msrpm,
+                                              MSR_IA32_LASTINTFROMIP);
+                svm_disable_intercept_for_msr(v->arch.hvm_svm.msrpm,
+                                              MSR_IA32_LASTINTTOIP);
+            }
+            break;
+
         default:
             switch ( long_mode_do_msr_write(regs) )
             {
xen/arch/x86/hvm/svm/vmcb.c +10 -34

56 lines not on this page · raw message

xen/include/asm-x86/hvm/svm/svm.h +12 -0
Index: 2007-08-08/xen/include/asm-x86/hvm/svm/svm.h
===================================================================
@@ -47,4 +47,16 @@ extern void svm_dump_vmcb(const char *fr
 #define SVM_REG_R14 (14)
 #define SVM_REG_R15 (15)
 
+extern u32 svm_feature_flags;
+
+#define SVM_FEATURE_NPT         0
+#define SVM_FEATURE_LBRV        1
+#define SVM_FEATURE_SVML        2
+#define SVM_FEATURE_NRIPS       3
+
+#define cpu_has_npt             test_bit(SVM_FEATURE_NPT, &svm_feature_flags)
+#define cpu_has_lbrv            test_bit(SVM_FEATURE_LBRV, &svm_feature_flags)
+#define cpu_has_svml            test_bit(SVM_FEATURE_SVML, &svm_feature_flags)
+#define cpu_has_nrips           test_bit(SVM_FEATURE_NRIPS, &svm_feature_flags)
+
 #endif /* __ASM_X86_HVM_SVM_H__ */
xen/include/asm-x86/hvm/svm/vmcb.h +42 -3

75 lines not on this page · raw message