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

[Xen-devel] [PATCH 2/7] x86: hvm events: merge 2 functions into 1


  • To: xen-devel@xxxxxxxxxxxxx
  • From: Corneliu ZUZU <czuzu@xxxxxxxxxxxxxxx>
  • Date: Mon, 8 Feb 2016 18:57:57 +0200
  • Cc: Kevin Tian <kevin.tian@xxxxxxxxx>, Tamas K Lengyel <tamas@xxxxxxxxxxxxx>, Keir Fraser <keir@xxxxxxx>, Ian Campbell <ian.campbell@xxxxxxxxxx>, Razvan Cojocaru <rcojocaru@xxxxxxxxxxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>
  • Comment: DomainKeys? See http://domainkeys.sourceforge.net/
  • Delivery-date: Mon, 08 Feb 2016 16:58:30 +0000
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=JmGXRGz1xevCNjIB4MhlpCysWRWBv5McfrFV7/kDK/zrq67CWm2CUDCI71SazGiQXZWH4JuhdtUHhz24HsHp6dHBI6uP7Jo98tSCRyGDCJiaGdUlog9iKl6EwFuPPhDyAeMhmI/8BTWaEFJt7TbqBFkWSYxuUAN7nmzTtpbY9ENuKLir0ND1KI+f66FUeJdbHmtHu2EPQPYTC7AW4nR34dvmyb/1ygW5aB2cUBCRpPfOc48ZY/jhxI5cKPbyfcdl7XPto5UB3yCTIuIJogqxEhB/CMoBseRu823iSsGp0wvAfJ2s8GzxwXcMMXGTynXooIWA//uEAMPxU54OkuKSow==; h=Received:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:X-BitDefender-Scanner:X-BitDefender-Spam:X-BitDefender-SpamStamp:X-BitDefender-CF-Stamp;
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

This patch merges almost identical functions hvm_event_int3
and hvm_event_single_step into a single function called
hvm_event_software_breakpoint.

Signed-off-by: Corneliu ZUZU <czuzu@xxxxxxxxxxxxxxx>
---
 xen/arch/x86/hvm/event.c        | 52 ++++++++++++++---------------------------
 xen/arch/x86/hvm/vmx/vmx.c      | 11 +++++----
 xen/include/asm-x86/hvm/event.h |  5 ++--
 3 files changed, 26 insertions(+), 42 deletions(-)

diff --git a/xen/arch/x86/hvm/event.c b/xen/arch/x86/hvm/event.c
index a3d4892..9dc533b 100644
--- a/xen/arch/x86/hvm/event.c
+++ b/xen/arch/x86/hvm/event.c
@@ -151,17 +151,20 @@ void hvm_event_guest_request(void)
     }
 }
 
-int hvm_event_int3(unsigned long rip)
+int hvm_event_software_breakpoint(unsigned long rip, bool_t single_step)
 {
     int rc = 0;
     struct vcpu *curr = current;
+    struct arch_domain *ad = &curr->domain->arch;
+    bool_t enabled = ( single_step ? ad->monitor.singlestep_enabled
+                                   : ad->monitor.software_breakpoint_enabled );
 
-    if ( curr->domain->arch.monitor.software_breakpoint_enabled )
+    if ( enabled )
     {
+        uint64_t gfn;
         struct segment_register sreg;
         uint32_t pfec = PFEC_page_present | PFEC_insn_fetch;
         vm_event_request_t req = {
-            .reason = VM_EVENT_REASON_SOFTWARE_BREAKPOINT,
             .vcpu_id = curr->vcpu_id,
         };
 
@@ -170,37 +173,18 @@ int hvm_event_int3(unsigned long rip)
             pfec |= PFEC_user_mode;
 
         hvm_get_segment_register(curr, x86_seg_cs, &sreg);
-        req.u.software_breakpoint.gfn = paging_gva_to_gfn(curr,
-                                                          sreg.base + rip,
-                                                          &pfec);
-
-        rc = hvm_event_traps(1, &req);
-    }
-
-    return rc;
-}
-
-int hvm_event_single_step(unsigned long rip)
-{
-    int rc = 0;
-    struct vcpu *curr = current;
-
-    if ( curr->domain->arch.monitor.singlestep_enabled )
-    {
-        struct segment_register sreg;
-        uint32_t pfec = PFEC_page_present | PFEC_insn_fetch;
-        vm_event_request_t req = {
-            .reason = VM_EVENT_REASON_SINGLESTEP,
-            .vcpu_id = curr->vcpu_id,
-        };
-
-        hvm_get_segment_register(curr, x86_seg_ss, &sreg);
-        if ( sreg.attr.fields.dpl == 3 )
-            pfec |= PFEC_user_mode;
-
-        hvm_get_segment_register(curr, x86_seg_cs, &sreg);
-        req.u.singlestep.gfn = paging_gva_to_gfn(curr, sreg.base + rip,
-                                                 &pfec);
+        gfn = paging_gva_to_gfn(curr, sreg.base + rip, &pfec);
+
+        if ( single_step )
+        {
+            req.reason = VM_EVENT_REASON_SINGLESTEP;
+            req.u.singlestep.gfn = gfn;
+        }
+        else
+        {
+            req.reason = VM_EVENT_REASON_SOFTWARE_BREAKPOINT;
+            req.u.software_breakpoint.gfn = gfn;
+        }
 
         rc = hvm_event_traps(1, &req);
     }
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index b9f340c..1a24788 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -3192,7 +3192,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
                 break;
             }
             else {
-                int handled = hvm_event_int3(regs->eip);
+                int handled = hvm_event_software_breakpoint(regs->eip, 0);
                 
                 if ( handled < 0 ) 
                 {
@@ -3517,10 +3517,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
     case EXIT_REASON_MONITOR_TRAP_FLAG:
         v->arch.hvm_vmx.exec_control &= ~CPU_BASED_MONITOR_TRAP_FLAG;
         vmx_update_cpu_exec_control(v);
-        if ( v->arch.hvm_vcpu.single_step ) {
-          hvm_event_single_step(regs->eip);
-          if ( v->domain->debugger_attached )
-              domain_pause_for_debugger();
+        if ( v->arch.hvm_vcpu.single_step )
+        {
+            hvm_event_software_breakpoint(regs->eip, 1);
+            if ( v->domain->debugger_attached )
+                domain_pause_for_debugger();
         }
 
         break;
diff --git a/xen/include/asm-x86/hvm/event.h b/xen/include/asm-x86/hvm/event.h
index 11eb1fe..7c2252b 100644
--- a/xen/include/asm-x86/hvm/event.h
+++ b/xen/include/asm-x86/hvm/event.h
@@ -27,9 +27,8 @@ bool_t hvm_event_cr(unsigned int index, unsigned long value,
 #define hvm_event_crX(what, new, old) \
     hvm_event_cr(VM_EVENT_X86_##what, new, old)
 void hvm_event_msr(unsigned int msr, uint64_t value);
-/* Called for current VCPU: returns -1 if no listener */
-int hvm_event_int3(unsigned long rip);
-int hvm_event_single_step(unsigned long rip);
+int hvm_event_software_breakpoint(unsigned long rip,
+                                  bool_t single_step);
 void hvm_event_guest_request(void);
 
 #endif /* __ASM_X86_HVM_EVENT_H__ */
-- 
2.5.0


_______________________________________________
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®.