From patchwork Wed Sep 6 13:48:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petre Ovidiu PIRCALABU X-Patchwork-Id: 9940781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C86A960350 for ; Wed, 6 Sep 2017 13:51:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D3C328C8D for ; Wed, 6 Sep 2017 13:51:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B5F028CDA; Wed, 6 Sep 2017 13:51:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 73D9B28C8D for ; Wed, 6 Sep 2017 13:50:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpah3-0006le-Kf; Wed, 06 Sep 2017 13:48:37 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpah2-0006kb-GJ for xen-devel@lists.xenproject.org; Wed, 06 Sep 2017 13:48:36 +0000 Received: from [193.109.254.147] by server-1.bemta-6.messagelabs.com id 6B/17-03414-4BCFFA95; Wed, 06 Sep 2017 13:48:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrAIsWRWlGSWpSXmKPExsUSfTyjVXfzn/W RBtM/yVt83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlL3q1lLrhiX/Hq7Ty2BsazRl2MnBzMAtYS vf+aGbsYuThYBGaxSJyftp8VwpnAIvF35z0mkCohATeJU20NLCAJIYH5jBKnrq5jhki4S+xZ8 5UZIrGIUeL0ql5WkASbgJHEkmVv2UFsEQEliXurJjOBFDELvGGSePd9JiNIQljAW+LFl9dgNo uAqsT9o4vB1vEKeEq8Pn4YLC4hICdx81wn0AYODk4BL4kz83ggFntKXL50iX0Co8ACRoZVjOr FqUVlqUW6ZnpJRZnpGSW5iZk5uoYGZnq5qcXFiempOYlJxXrJ+bmbGIGhxQAEOxjnnfA/xCjJ waQkyntZbX2kEF9SfkplRmJxRnxRaU5q8SFGGQ4OJQleqd9AOcGi1PTUirTMHGCQw6QlOHiUR Hh1QdK8xQWJucWZ6RCpU4y6HBtWr//CJMSSl5+XKiXOmwJSJABSlFGaBzcCFnGXGGWlhHkZgY 4S4ilILcrNLEGVf8UozsGoJMzLCzKFJzOvBG7TK6AjmICOqHq5BuSIkkSElFQDo1PRLKumAO2 zC61YUpXZ121+2xf1sdPo1fnjSm9UFnJv/sn2cqmd/6lrIrydXnP9v5aI+t7wf+U96yN/xKop XHesOC2TlzQpNK4orP5Y2578XmnDXI5zbf9EJITbZohvO8QXejAmiHt/joGe6CXP70GCTyQUa h4us1PYJ15xYlbuvEPbrlx7rsRSnJFoqMVcVJwIAJoMnCCzAgAA X-Env-Sender: ppircalabu@bitdefender.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1504705714!55851773!1 X-Originating-IP: [91.199.104.133] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 53708 invoked from network); 6 Sep 2017 13:48:35 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-2.tower-27.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 6 Sep 2017 13:48:35 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=2NIzNhL5i0723b4piGoFTak7TOcRAZnimrInR4V1hyOljPN3yVJJso8EwEAqPcDq8xKqgnICfD/YRxpARKnlNkUS8//idlafcjV5YzKQALMoIxdPpBwKSkk96g9VrAysS6/EaYELfjAVKaT6QQh3ofwhR2LLmsIiT+oM6SXOfLrOUSEEST3tksNZ40e+b2g+yuHdn2PRIA7Oh4h+N0p7vMdcgU8q2DGw8HKTMBqOEit+JSpwNkl/RWeN+zHWpUwI6ooQ13mR8JWLsazFfK/FwmOhbpAm4oJ75fTgL/2DO5Fce0sVFtHb+6WUarWM7JqNjRV9Xik+G4WXcnV5nPahWg==; h=Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; 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=bz4fC1y2LWGY8FcGThQ6szO8eN8=; b=BPeaUtLjvJ139Iua7j3nXgiXLHll PPBR5HmQRtFDsIqKbnIRBxOntYvibcaO+RUEkM6mL1Ajzn/1kypT9MLxZRcG7+OY m97gApnTO4awnYUzJu+PYBEp488r/eArmFryxs8ooLkLyQGew6mwIdNA32D62p2r 1vCjuJFz8cXgtkxBL5jgyvWK//IRUi2vvoL7jnEt3opBeAE84k967C0YPj/3iUPr pilZ8RLDepE+Qix22hTRnz8aIrWSCZBWok57Ia38pCtz1wIpmPSGTmAk7pMl5V76 lc3hE8Fnk0GjQLC+uylhOEB/2uNRzgj+oa/RL5/BH5qhe1mNO+LE3/1/+g== Received: (qmail 2572 invoked from network); 6 Sep 2017 16:48:28 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 6 Sep 2017 16:48:28 +0300 Received: (qmail 31931 invoked from network); 6 Sep 2017 16:48:28 +0300 Received: from unknown (HELO pepi-OptiPlex-9020.bbu.bitdefender.biz) (10.10.194.146) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 6 Sep 2017 16:48:28 +0300 From: Petre Pircalabu To: xen-devel@lists.xenproject.org Date: Wed, 6 Sep 2017 16:48:26 +0300 Message-Id: <1504705706-4859-4-git-send-email-ppircalabu@bitdefender.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504705706-4859-1-git-send-email-ppircalabu@bitdefender.com> References: <1504705706-4859-1-git-send-email-ppircalabu@bitdefender.com> Cc: Petre Pircalabu , kevin.tian@intel.com, sstabellini@kernel.org, wei.liu2@citrix.com, jun.nakajima@intel.com, rcojocaru@bitdefender.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, paul.durrant@citrix.com, tamas@tklengyel.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v10 3/3] x86/monitor: Notify monitor if an emulation fails. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP If case of a vm_event with the emulate_flags set, if the instruction is not implemented by the emulator, the monitor should be notified instead of directly injecting a hw exception. This behavior can be used to re-execute an instruction not supported by the emulator using the real processor (e.g. altp2m) instead of just crashing. Signed-off-by: Petre Pircalabu Acked-by: Tamas K Lengyel Acked-by: Wei Liu Acked-by: Jan Beulich --- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_monitor.c | 14 ++++++++++++++ xen/arch/x86/hvm/emulate.c | 5 +++++ xen/arch/x86/hvm/monitor.c | 17 +++++++++++++++++ xen/arch/x86/monitor.c | 13 +++++++++++++ xen/include/asm-x86/domain.h | 1 + xen/include/asm-x86/hvm/monitor.h | 1 + xen/include/asm-x86/monitor.h | 3 ++- xen/include/public/domctl.h | 1 + xen/include/public/vm_event.h | 2 ++ 10 files changed, 58 insertions(+), 1 deletion(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 43151cb..1a179d9 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2028,6 +2028,8 @@ int xc_monitor_debug_exceptions(xc_interface *xch, domid_t domain_id, int xc_monitor_cpuid(xc_interface *xch, domid_t domain_id, bool enable); int xc_monitor_privileged_call(xc_interface *xch, domid_t domain_id, bool enable); +int xc_monitor_emul_unimplemented(xc_interface *xch, domid_t domain_id, + bool enable); /** * This function enables / disables emulation for each REP for a * REP-compatible instruction. diff --git a/tools/libxc/xc_monitor.c b/tools/libxc/xc_monitor.c index a677820..6046680 100644 --- a/tools/libxc/xc_monitor.c +++ b/tools/libxc/xc_monitor.c @@ -217,6 +217,20 @@ int xc_monitor_privileged_call(xc_interface *xch, domid_t domain_id, return do_domctl(xch, &domctl); } +int xc_monitor_emul_unimplemented(xc_interface *xch, domid_t domain_id, + bool enable) +{ + DECLARE_DOMCTL; + + domctl.cmd = XEN_DOMCTL_monitor_op; + domctl.domain = domain_id; + domctl.u.monitor_op.op = enable ? XEN_DOMCTL_MONITOR_OP_ENABLE + : XEN_DOMCTL_MONITOR_OP_DISABLE; + domctl.u.monitor_op.event = XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED; + + return do_domctl(xch, &domctl); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index 8a6eb74..c9066bb 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -14,12 +14,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -2103,6 +2105,9 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr, */ return; case X86EMUL_UNIMPLEMENTED: + if ( hvm_monitor_emul_unimplemented() ) + return; + /* fall-through */ case X86EMUL_UNHANDLEABLE: hvm_dump_emulation_state(XENLOG_G_DEBUG, "Mem event", &ctx); hvm_inject_hw_exception(trapnr, errcode); diff --git a/xen/arch/x86/hvm/monitor.c b/xen/arch/x86/hvm/monitor.c index a7ccfc4..3551463 100644 --- a/xen/arch/x86/hvm/monitor.c +++ b/xen/arch/x86/hvm/monitor.c @@ -57,6 +57,23 @@ bool_t hvm_monitor_cr(unsigned int index, unsigned long value, unsigned long old return 0; } +bool hvm_monitor_emul_unimplemented(void) +{ + struct vcpu *curr = current; + + /* + * Send a vm_event to the monitor to signal that the current + * instruction couldn't be emulated. + */ + vm_event_request_t req = { + .reason = VM_EVENT_REASON_EMUL_UNIMPLEMENTED, + .vcpu_id = curr->vcpu_id, + }; + + return curr->domain->arch.monitor.emul_unimplemented_enabled && + monitor_traps(curr, true, &req) == 1; +} + void hvm_monitor_msr(unsigned int msr, uint64_t value) { struct vcpu *curr = current; diff --git a/xen/arch/x86/monitor.c b/xen/arch/x86/monitor.c index 706454f..e59f1f5 100644 --- a/xen/arch/x86/monitor.c +++ b/xen/arch/x86/monitor.c @@ -283,6 +283,19 @@ int arch_monitor_domctl_event(struct domain *d, break; } + case XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED: + { + bool old_status = ad->monitor.emul_unimplemented_enabled; + + if ( unlikely(old_status == requested_status) ) + return -EEXIST; + + domain_pause(d); + ad->monitor.emul_unimplemented_enabled = requested_status; + domain_unpause(d); + break; + } + default: /* * Should not be reached unless arch_monitor_get_capabilities() is diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index fb8bf17..fcab8f8 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -406,6 +406,7 @@ struct arch_domain unsigned int cpuid_enabled : 1; unsigned int descriptor_access_enabled : 1; unsigned int guest_request_userspace_enabled : 1; + unsigned int emul_unimplemented_enabled : 1; struct monitor_msr_bitmap *msr_bitmap; uint64_t write_ctrlreg_mask[4]; } monitor; diff --git a/xen/include/asm-x86/hvm/monitor.h b/xen/include/asm-x86/hvm/monitor.h index d9efb35..0979adf 100644 --- a/xen/include/asm-x86/hvm/monitor.h +++ b/xen/include/asm-x86/hvm/monitor.h @@ -47,6 +47,7 @@ int hvm_monitor_cpuid(unsigned long insn_length, unsigned int leaf, unsigned int subleaf); void hvm_monitor_interrupt(unsigned int vector, unsigned int type, unsigned int err, uint64_t cr2); +bool hvm_monitor_emul_unimplemented(void); #endif /* __ASM_X86_HVM_MONITOR_H__ */ diff --git a/xen/include/asm-x86/monitor.h b/xen/include/asm-x86/monitor.h index 765d0b4..0ada970 100644 --- a/xen/include/asm-x86/monitor.h +++ b/xen/include/asm-x86/monitor.h @@ -83,7 +83,8 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d) (1U << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST) | (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) | (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) | - (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT); + (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) | + (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED); /* Since we know this is on VMX, we can just call the hvm func */ if ( hvm_is_singlestep_supported() ) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 50ff58f..fce6557 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1094,6 +1094,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_psr_cmt_op_t); #define XEN_DOMCTL_MONITOR_EVENT_PRIVILEGED_CALL 7 #define XEN_DOMCTL_MONITOR_EVENT_INTERRUPT 8 #define XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS 9 +#define XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED 10 struct xen_domctl_monitor_op { uint32_t op; /* XEN_DOMCTL_MONITOR_OP_* */ diff --git a/xen/include/public/vm_event.h b/xen/include/public/vm_event.h index f01e471..b531f71 100644 --- a/xen/include/public/vm_event.h +++ b/xen/include/public/vm_event.h @@ -148,6 +148,8 @@ #define VM_EVENT_REASON_INTERRUPT 12 /* A descriptor table register was accessed. */ #define VM_EVENT_REASON_DESCRIPTOR_ACCESS 13 +/* Current instruction is not implemented by the emulator */ +#define VM_EVENT_REASON_EMUL_UNIMPLEMENTED 14 /* Supported values for the vm_event_write_ctrlreg index. */ #define VM_EVENT_X86_CR0 0