xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add support for disabling LBR recording after it has been enabled in HVMs using VMX. Signed-off-by: Angelo Sapello <asapello@appcomsci.com>
@ 2013-09-06 14:28 Sapello, Angelo
  2013-09-06 15:15 ` Jan Beulich
  0 siblings, 1 reply; 5+ messages in thread
From: Sapello, Angelo @ 2013-09-06 14:28 UTC (permalink / raw)
  To: xen-devel@lists.xen.org

---
 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-09-09  7:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-06 14:28 [PATCH] Add support for disabling LBR recording after it has been enabled in HVMs using VMX. Signed-off-by: Angelo Sapello <asapello@appcomsci.com> Sapello, Angelo
2013-09-06 15:15 ` Jan Beulich
2013-09-06 16:05   ` Sapello, Angelo
2013-09-06 16:11     ` Andrew Cooper
2013-09-09  7:10     ` Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).