From patchwork Mon Feb 15 06:35:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corneliu ZUZU X-Patchwork-Id: 8310091 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 936B0C02AA for ; Mon, 15 Feb 2016 06:38:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7942D20515 for ; Mon, 15 Feb 2016 06:38:04 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C1F7204DE for ; Mon, 15 Feb 2016 06:38:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVCku-0008Qy-Pe; Mon, 15 Feb 2016 06:35:32 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVCkt-0008Qk-5Z for xen-devel@lists.xen.org; Mon, 15 Feb 2016 06:35:31 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 36/D0-06685-2B171C65; Mon, 15 Feb 2016 06:35:30 +0000 X-Env-Sender: czuzu@bitdefender.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1455518129!10048888!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22144 invoked from network); 15 Feb 2016 06:35:29 -0000 Received: from mx01.buh.bitdefender.com (HELO mx01.buh.bitdefender.com) (91.199.104.161) by server-11.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Feb 2016 06:35:29 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=wctBSU78EXocHBHesRRWuUk++fFC5QZjS3iJlRjOWo9Jtp54n8IEMZULoTXIwCzKGeRbTQPou3GVGbUC1ced8G/ZLkuYG6sa2TyFiMSD1e2HMaUGTjTM+LRxbCnhEpf2zHzmw3gu/lZe71n4E8ZO3SOcnR695TGfoGUWLFLAdrAO7mJ8ls6KEiVA28iS8aQai4AnAD7qBGSBRnK2f+govWxhL/sDddu8oQMY0keeG4ESR5e+cL34WRpa1CmwuWhNxCe7VONTVnXs7PK0tRJjtGxv6RhT3Hsw1uyrpH564NInLhMYv2q5udsZLQHTz4Z0BpsVxQhRWwOAGrtO2U3Pjg==; 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; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bitdefender.com; h=from:to :cc:subject:date:message-id:in-reply-to:references; s=default; bh=9OCbfbbrFi6z4CC361yCleRtHyY=; b=C52dxBKT2hnv+lb0YKLRPe7W9ICH qRSbGSwhyZ1fataApUtDatIZbx2lXh81WxyvmeVEduQW9BMjg4Mnmny7Sd3rJqBE mSvMRv3OtreMwZcoFeRxXOERdWHCE/vXTN7km46jhFOlV7pwlWuEMpz5hqi3W9oo Fc66ShyWgHgtVNMkdV3/oUbHqThh4ph7cCSh13cCALVgl+gH9NJ+AVufMGjNZYSn qgqS7CzJiYMYbUmci0NChtWrn6eI0YBxLN6AMviSYyEdPa/byneN3YS1YM4vfXUe F6rk9mM1UV8WJD1Thd55UzlUbjb7NevZi9xnd6LQJfnqjZBugo6//e7QYg== Received: (qmail 26984 invoked from network); 15 Feb 2016 08:35:28 +0200 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.buh.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 15 Feb 2016 08:35:28 +0200 Received: from smtp03.buh.bitdefender.org (unknown [10.17.80.77]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 513087FBE6 for ; Mon, 15 Feb 2016 08:35:28 +0200 (EET) Received: (qmail 32463 invoked from network); 15 Feb 2016 08:35:28 +0200 Received: from unknown (HELO czuzu-dev-vm.clj.bitdefender.biz) (czuzu@bitdefender.com@91.199.104.243) by smtp03.buh.bitdefender.org with AES128-SHA256 encrypted SMTP; 15 Feb 2016 08:35:28 +0200 From: Corneliu ZUZU To: xen-devel@lists.xen.org Date: Mon, 15 Feb 2016 08:35:18 +0200 Message-Id: <1455518118-414-2-git-send-email-czuzu@bitdefender.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455518118-414-1-git-send-email-czuzu@bitdefender.com> References: <1455518118-414-1-git-send-email-czuzu@bitdefender.com> X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.4 on smtp03.buh.bitdefender.org, sigver: 7.64511 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.743, Dats: 414191, Stamp: 3], Multi: [Enabled, t: (0.000009, 0.006411)], BW: [Enabled, t: (0.000006,0.000001)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.004825), Flags: 2A917CE3; NN_TP_TAG_HTTP; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.008744)], URL: [Enabled, t: (0.000016)], RTDA: [Enabled, t: (0.276706), Hit: No, Details: v2.3.3; Id: 2m1ghap.1ab2dlpm2.3s32s], total: 0(775) X-BitDefender-CF-Stamp: none Cc: Kevin Tian , Tamas K Lengyel , Keir Fraser , Jan Beulich , Razvan Cojocaru , Andrew Cooper , Jun Nakajima Subject: [Xen-devel] [PATCH v3 1/2] xen/x86: merge 2 hvm_event_... functions into 1 X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch merges almost identical functions hvm_event_int3 and hvm_event_single_step into a single function called hvm_event_breakpoint. Also fixes event.c file header comment in the process. Signed-off-by: Corneliu ZUZU Acked-by: Razvan Cojocaru --- xen/arch/x86/hvm/event.c | 108 +++++++++++++++++++--------------------- xen/arch/x86/hvm/vmx/vmx.c | 15 +++--- xen/include/asm-x86/hvm/event.h | 11 ++-- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/xen/arch/x86/hvm/event.c b/xen/arch/x86/hvm/event.c index a3d4892..874a36c 100644 --- a/xen/arch/x86/hvm/event.c +++ b/xen/arch/x86/hvm/event.c @@ -1,22 +1,24 @@ /* -* event.c: Common hardware virtual machine event abstractions. -* -* Copyright (c) 2004, Intel Corporation. -* Copyright (c) 2005, International Business Machines Corporation. -* Copyright (c) 2008, Citrix Systems, Inc. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms and conditions of the GNU General Public License, -* version 2, as published by the Free Software Foundation. -* -* This program is distributed in the hope it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. -* -* You should have received a copy of the GNU General Public License along with -* this program; If not, see . -*/ + * arch/x86/hvm/event.c + * + * Arch-specific hardware virtual machine event abstractions. + * + * Copyright (c) 2004, Intel Corporation. + * Copyright (c) 2005, International Business Machines Corporation. + * Copyright (c) 2008, Citrix Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + */ #include #include @@ -151,61 +153,51 @@ void hvm_event_guest_request(void) } } -int hvm_event_int3(unsigned long rip) +static inline unsigned long gfn_of_rip(unsigned long rip) { - int rc = 0; struct vcpu *curr = current; + struct segment_register sreg; + uint32_t pfec = PFEC_page_present | PFEC_insn_fetch; - if ( curr->domain->arch.monitor.software_breakpoint_enabled ) - { - 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, - }; - - 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_ss, &sreg); + if ( sreg.attr.fields.dpl == 3 ) + 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); - } + hvm_get_segment_register(curr, x86_seg_cs, &sreg); - return rc; + return paging_gva_to_gfn(curr, sreg.base + rip, &pfec); } -int hvm_event_single_step(unsigned long rip) +int hvm_event_breakpoint(unsigned long rip, + enum hvm_event_breakpoint_type type) { - int rc = 0; struct vcpu *curr = current; + struct arch_domain *ad = &curr->domain->arch; + vm_event_request_t req; - if ( curr->domain->arch.monitor.singlestep_enabled ) + switch ( type ) { - 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; + case HVM_EVENT_SOFTWARE_BREAKPOINT: + if ( !ad->monitor.software_breakpoint_enabled ) + return 0; + req.reason = VM_EVENT_REASON_SOFTWARE_BREAKPOINT; + req.u.software_breakpoint.gfn = gfn_of_rip(rip); + break; - hvm_get_segment_register(curr, x86_seg_cs, &sreg); - req.u.singlestep.gfn = paging_gva_to_gfn(curr, sreg.base + rip, - &pfec); + case HVM_EVENT_SINGLESTEP_BREAKPOINT: + if ( !ad->monitor.singlestep_enabled ) + return 0; + req.reason = VM_EVENT_REASON_SINGLESTEP; + req.u.singlestep.gfn = gfn_of_rip(rip); + break; - rc = hvm_event_traps(1, &req); + default: + return -EOPNOTSUPP; } - return rc; + req.vcpu_id = curr->vcpu_id; + + return hvm_event_traps(1, &req); } /* diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 5e99226..44e778f 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3192,8 +3192,10 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) break; } else { - int handled = hvm_event_int3(regs->eip); - + int handled = + hvm_event_breakpoint(regs->eip, + HVM_EVENT_SOFTWARE_BREAKPOINT); + if ( handled < 0 ) { struct hvm_trap trap = { @@ -3517,10 +3519,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_breakpoint(regs->eip, HVM_EVENT_SINGLESTEP_BREAKPOINT); + 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..7a83b45 100644 --- a/xen/include/asm-x86/hvm/event.h +++ b/xen/include/asm-x86/hvm/event.h @@ -17,6 +17,12 @@ #ifndef __ASM_X86_HVM_EVENT_H__ #define __ASM_X86_HVM_EVENT_H__ +enum hvm_event_breakpoint_type +{ + HVM_EVENT_SOFTWARE_BREAKPOINT, + HVM_EVENT_SINGLESTEP_BREAKPOINT, +}; + /* * Called for current VCPU on crX/MSR changes by guest. * The event might not fire if the client has subscribed to it in onchangeonly @@ -27,9 +33,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_breakpoint(unsigned long rip, + enum hvm_event_breakpoint_type type); void hvm_event_guest_request(void); #endif /* __ASM_X86_HVM_EVENT_H__ */