From patchwork Thu Feb 4 12:27:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 8220831 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 491AABEEE5 for ; Thu, 4 Feb 2016 12:30:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 472E920384 for ; Thu, 4 Feb 2016 12:30:41 +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 DD7452034C for ; Thu, 4 Feb 2016 12:30:39 +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 1aRJ0q-0005XC-Pb; Thu, 04 Feb 2016 12:27:52 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aRJ0p-0005X6-PE for xen-devel@lists.xen.org; Thu, 04 Feb 2016 12:27:51 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 02/9F-15353-6C343B65; Thu, 04 Feb 2016 12:27:50 +0000 X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-12.tower-206.messagelabs.com!1454588870!20303967!1 X-Originating-IP: [5.153.53.90] X-SpamReason: No, hits=0.7 required=7.0 tests=BODY_RANDOM_LONG, RCVD_ILLEGAL_IP X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37896 invoked from network); 4 Feb 2016 12:27:50 -0000 Received: from mx.ams.bitdefender.com (HELO mx.ams.bitdefender.com) (5.153.53.90) by server-12.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 4 Feb 2016 12:27:50 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=wRZBBkLrGJ8iCN5sbGJOZCLkMbZGHcDdr60w0OOpEkCFegKC0SQ0PWO+GzVklxguXjujrePjuleG4Xp0Z2TGIbGHhnBs9XHM79lfVBhFYQ7Bxv9Qc1ki6xmxWJiB/bf6/UKgHp/dA/950jqmcscRVvUbAgvENfPu0GwWCCtTFJ2Va69/P1QD/ZebwYGntuSWCEnuIuOJZW35ABncu99AYayDk8/02zhgjaEZcka6zLYZSq0/htsgAOuGQqyFFUBOocLa/TkAezec8eU3kMm40RgbuUDFiH2IUR3Lq9A6im3PPofMKdZvU1AeeQHgIsIDcqy1g2fhpMTsGUFtfxfZjQ==; h=Received:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: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; s=default; bh=zyJA96VVhlcxFTfwSF1Jf jtmu5c=; b=iApFDeVG6C+Tp721XrUCWO04vGxQe7DtgpPoP7rfJ75jxxsfwtlQF wpz9pRk0WbcIO0/svwZeR9McYcSbei6BvnQtHVDDq4h/YwvFxk8LEl6yOts1ZI2j AndpT1r/pOeHaPdBwQabfca8s7vG/t4WSBLkDByck7cIQnGfbhSYsp5RoYdXc9cB 66poxpLv2yx5KhoRm8G5PooOOUXd0cewo9wA+uz2VmBbJgPsq74WReuLNzSm9xIp ZNzlq6ihQfc8QO7yVinAIPzKkxJu96mPknfoGtyxFZr98RpttOG4AhGiqnWHfwXC mQ+a0tqlC9qLz+qzvZLKfIQm+01YwCRBQ== Received: (qmail 3301 invoked from network); 4 Feb 2016 06:27:50 -0600 Received: from mx-sr.buh.bitdefender.com (91.199.104.166) by mx.ams.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 4 Feb 2016 06:27:50 -0600 Received: from smtp01.buh.bitdefender.com (unknown [10.17.80.75]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id F1E3E7FBBB for ; Thu, 4 Feb 2016 14:27:47 +0200 (EET) Received: (qmail 11503 invoked from network); 4 Feb 2016 14:27:47 +0200 Received: from xen.dsd.ro (HELO xen.dsd.bitdefender.biz) (rcojocaru@bitdefender.com@10.10.14.109) by smtp01.buh.bitdefender.com with AES128-SHA256 encrypted SMTP; 4 Feb 2016 14:27:47 +0200 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Thu, 4 Feb 2016 14:27:32 +0200 Message-Id: <1454588852-5389-1-git-send-email-rcojocaru@bitdefender.com> X-Mailer: git-send-email 1.9.1 X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.4 on smtp01.buh.bitdefender.com, sigver: 7.64389 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.743, Dats: 413796, Stamp: 3], Multi: [Enabled, t: (0.000010, 0.003671)], BW: [Enabled, t: (0.000007,0.000001)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.003140), Flags: 2A917CE3; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_NO_LINK_NMD; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.009526)], URL: [Enabled, t: (0.000005)], RTDA: [Enabled, t: (0.083307), Hit: No, Details: v2.3.2; Id: 2m1ghak.1aah9g7ui.16os9], total: 0(775) X-BitDefender-CF-Stamp: none Cc: george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com, keir@xen.org, Razvan Cojocaru , jbeulich@suse.com Subject: [Xen-devel] [PATCH] x86/hvm: simplify emulation triggered by vm_event response 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 Currently, after receiving a vm_event reply requesting emulation, the actual emulation is triggered in p2m_mem_access_check(), which means that we're waiting for the page fault to occur again before emulating. Aside from the performance impact, this complicates the code since between hvm_do_resume() and the second page fault it is possible that the latter becomes a completely new page fault - hence checking that EIP and the GPA match with the ones in the original page fault. If they don't, duplicate EPT fault vm_events will occur, of which a monitoring application needs to be aware. This patch makes struct arch_vm_event smaller (since we no longer need to track eip and gpa), removes the checking code from p2m_mem_access_check(), and moves the emulation in hvm_do_resume(). Signed-off-by: Razvan Cojocaru Acked-by: Tamas K Lengyel --- xen/arch/x86/hvm/hvm.c | 17 +++++++++++++++++ xen/arch/x86/mm/p2m.c | 34 ---------------------------------- xen/include/asm-x86/vm_event.h | 2 -- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 35ec6c9..930d0e3 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -552,6 +552,23 @@ void hvm_do_resume(struct vcpu *v) { struct monitor_write_data *w = &v->arch.vm_event->write_data; + if ( v->arch.vm_event->emulate_flags ) + { + enum emul_kind kind = EMUL_KIND_NORMAL; + + if ( v->arch.vm_event->emulate_flags & + VM_EVENT_FLAG_SET_EMUL_READ_DATA ) + kind = EMUL_KIND_SET_CONTEXT; + else if ( v->arch.vm_event->emulate_flags & + VM_EVENT_FLAG_EMULATE_NOWRITE ) + kind = EMUL_KIND_NOWRITE; + + hvm_mem_access_emulate_one(kind, TRAP_invalid_op, + HVM_DELIVER_NO_ERROR_CODE); + + v->arch.vm_event->emulate_flags = 0; + } + if ( w->do_write.msr ) { hvm_msr_write_intercept(w->msr, w->value, 0); diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index a45ee35..47e7fad 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1639,7 +1639,6 @@ bool_t p2m_mem_access_check(paddr_t gpa, unsigned long gla, p2m_access_t p2ma; vm_event_request_t *req; int rc; - unsigned long eip = guest_cpu_user_regs()->eip; if ( altp2m_active(d) ) p2m = p2m_get_altp2m(v); @@ -1698,39 +1697,6 @@ bool_t p2m_mem_access_check(paddr_t gpa, unsigned long gla, } } - /* The previous vm_event reply does not match the current state. */ - if ( unlikely(v->arch.vm_event) && - (v->arch.vm_event->gpa != gpa || v->arch.vm_event->eip != eip) ) - { - /* Don't emulate the current instruction, send a new vm_event. */ - v->arch.vm_event->emulate_flags = 0; - - /* - * Make sure to mark the current state to match it again against - * the new vm_event about to be sent. - */ - v->arch.vm_event->gpa = gpa; - v->arch.vm_event->eip = eip; - } - - if ( unlikely(v->arch.vm_event) && v->arch.vm_event->emulate_flags ) - { - enum emul_kind kind = EMUL_KIND_NORMAL; - - if ( v->arch.vm_event->emulate_flags & - VM_EVENT_FLAG_SET_EMUL_READ_DATA ) - kind = EMUL_KIND_SET_CONTEXT; - else if ( v->arch.vm_event->emulate_flags & - VM_EVENT_FLAG_EMULATE_NOWRITE ) - kind = EMUL_KIND_NOWRITE; - - hvm_mem_access_emulate_one(kind, TRAP_invalid_op, - HVM_DELIVER_NO_ERROR_CODE); - - v->arch.vm_event->emulate_flags = 0; - return 1; - } - *req_ptr = NULL; req = xzalloc(vm_event_request_t); if ( req ) diff --git a/xen/include/asm-x86/vm_event.h b/xen/include/asm-x86/vm_event.h index 5aff834..fff8326 100644 --- a/xen/include/asm-x86/vm_event.h +++ b/xen/include/asm-x86/vm_event.h @@ -28,8 +28,6 @@ */ struct arch_vm_event { uint32_t emulate_flags; - unsigned long gpa; - unsigned long eip; struct vm_event_emul_read_data emul_read_data; struct monitor_write_data write_data; };