[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] Add support for disabling LBR recording after it has been enabled in HVMs using VMX. Signed-off-by: Angelo Sapello <asapello@xxxxxxxxxxxxx>


  • To: "xen-devel@xxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxx>
  • From: "Sapello, Angelo" <asapello@xxxxxxxxxxxxx>
  • Date: Fri, 6 Sep 2013 14:28:34 +0000
  • Accept-language: en-US
  • Delivery-date: Fri, 06 Sep 2013 14:31:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>
  • Thread-index: Ac6rDV6N81BQv8TySb2uETsKmdNdyQ==
  • Thread-topic: [PATCH] Add support for disabling LBR recording after it has been enabled in HVMs using VMX. Signed-off-by: Angelo Sapello <asapello@xxxxxxxxxxxxx>

---
 xen/arch/x86/hvm/vmx/vmx.c |   19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 011a817..149f28e 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -2054,16 +2054,25 @@ static int vmx_msr_write_intercept(unsigned int msr, ui$
     case MSR_IA32_DEBUGCTLMSR: {
         int i, rc = 0;
         uint64_t supported = IA32_DEBUGCTLMSR_LBR | IA32_DEBUGCTLMSR_BTF;
+        uint64_t old_msr_content, change_set;
 
-        if ( !msr_content )
+// Don't change everything, but just consider what features are being changed
+// May be a little slow with the extra read, but changes to DEBUGCTLMSR should 
not be frequent
+// ~ Angelo Sapello
+        old_msr_content = __vmread(GUEST_IA32_DEBUGCTL);
+        change_set = (old_msr_content ^ msr_content);
+
+// Setting DEBUGCTLMSR to zero is valid when disabling debug features
+// only consider changes ~ AS
+        if ( !change_set )
             break;
-        if ( msr_content & ~supported )
+        if ( change_set & ~supported ) // Only consider bits that changed ~ AS
         {
             /* Perhaps some other bits are supported in vpmu. */
             if ( !vpmu_do_wrmsr(msr, msr_content) )
                 break;
         }
-        if ( msr_content & IA32_DEBUGCTLMSR_LBR )
+        if ( change_set & msr_content & IA32_DEBUGCTLMSR_LBR )
         {
             const struct lbr_info *lbr = last_branch_msr_get();
             if ( lbr == NULL )
@@ -2074,6 +2083,10 @@ static int vmx_msr_write_intercept(unsigned int msr, 
uint64_t msr_content)
                     if ( (rc = vmx_add_guest_msr(lbr->base + i)) == 0 )
                         vmx_disable_intercept_for_msr(v, lbr->base + i, 
MSR_TYPE_R | MSR_TYPE_W);
         }
+// NB that we can now reach here to turn off LBR recording
+// Also, never turn actual LBRs (from IPs, to IPs) back off, since
+// HVM may wish to read them in their frozen state.
+// ~AS
 
         if ( (rc < 0) ||
              (vmx_add_host_load_msr(msr) < 0) )
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.