From patchwork Tue Aug 8 18:06:37 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: 9888881 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 717D260384 for ; Tue, 8 Aug 2017 18:09:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 627A2288E7 for ; Tue, 8 Aug 2017 18:09:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56F76289BE; Tue, 8 Aug 2017 18:09:21 +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 72DEA289A9 for ; Tue, 8 Aug 2017 18:09:19 +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 1df8tx-0000sJ-UF; Tue, 08 Aug 2017 18:06:45 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1df8tw-0000s1-S7 for xen-devel@lists.xen.org; Tue, 08 Aug 2017 18:06:44 +0000 Received: from [85.158.139.211] by server-4.bemta-5.messagelabs.com id 53/E9-02184-3BDF9895; Tue, 08 Aug 2017 18:06:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrIIsWRWlGSWpSXmKPExsUSfTyjVXfz385 Ig8OL+CyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oxVTZvZCho0Ks5/XsLewHhArouRk4NZwFqi 918zYxcjFweLwCwWiU//t7NBOBNYJDa332QBqRIScJe4saCXCSQhJDCfUWLO52a4RNeFRawQi UWMEl0XNzCCJNgEjCSWLHvLDmKLCEhLXPt8GWwHs8AbJol332cCORwcwgJ+Ens+qIPUsAioSn R/W8cMYvMKeEosWb8cbIGEgJzEzXOdYHFOAS+JryeuskEs9pQ4u/Qg+wRGgQWMDKsYNYpTi8p Si3QNDfWSijLTM0pyEzNzdA0NTPVyU4uLE9NTcxKTivWS83M3MQKDiwEIdjCubHc+xCjJwaQk yrtJuzNSiC8pP6UyI7E4I76oNCe1+BCjDAeHkgRv0h+gnGBRanpqRVpmDjDMYdISHDxKIryzf gOleYsLEnOLM9MhUqcYdTleTfj/jUmIJS8/L1VKnPcQyAwBkKKM0jy4EbCYu8QoKyXMywh0lB BPQWpRbmYJqvwrRnEORiVh3jiQKTyZeSVwm14BHcEEdESEL9gRJYkIKakGRv4D4dxzcg8s/MW 4eWnqiwc8aw1n3tFR+e35fUFCTrzOvuuiiut6e2N71dYYnlFdeDJESqS84PuELVu2y1yNrb3u X7FXhMeihjnrZn+UfO4Ttb2/1q0p7v73xnWjtOndMrdN/Ck7Z/vf/tR4LDLL5ZFwX0Lcp3Pn9 5dw/eZY8/tias2nXfH3bJVYijMSDbWYi4oTAUZixZS0AgAA X-Env-Sender: ppircalabu@bitdefender.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1502215602!104779015!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 44736 invoked from network); 8 Aug 2017 18:06:43 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-5.tower-206.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 8 Aug 2017 18:06:43 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=DUf3QZt1v6DS8+UO3v2xub8vf/10weay7d2MTfQTb+WcDHr/DZSdID+EHrt1cicdiR4OsOL02gYrTUqycZkIJUOBJ56T1jSYJRiVwOyJAdZ/gaSOhsGCCA/GPad6SFm8ooBsMVcyhULtrn7cmGcaqSOm9GVQziNvErppsa9vwhELwGclL+gHWa1YzUlYLlEYDvy2ZNFE3UNNkFs7IDqiKtLiSgTCppnHPesWRdK0h+3NFDJ1hSEqRf5aY0IIb6vkiWFtm3D5GcY5CngbpLywNptoaUVCwkAcOZkDB1B9iUVXI1e5C/UXrun80M8eRQlP0bznnt1IKu8oWCVSpETBBQ==; 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=37Kikmc16CiB1leiAfomDs5vVao=; b=muskkv+L1iThQIUpEjO4B1nLXpwS ZjO7nKwpIcNdceD6U965XLaOG7/iJM2m7lVc9Ro9Ffe5qlhz2uC1OQmSHsKU3MP7 8M0eW4txgrbcqh2W6dNKHnNoWHAeaZheIP57kCiLfakx+22mnjIpQWKpEsk0R+dF xMlk83a3NEYFYUKMQdM51OZ30mIFJAb0K5yeKVdswt5S6ENIuYopK3hH62Bj2W8Y e2RNRMq28wR4aM10eoP37AX+B2j3Sl/2bglFr8OclK8X/kMq0NW6847olRxN64Tp nrigSQnIHPCvPaYNfA3MZxkoZJkgx6kmJMX2HK7aDjbLB6QSO44sewxnww== Received: (qmail 26271 invoked from network); 8 Aug 2017 21:06:40 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 8 Aug 2017 21:06:40 +0300 Received: (qmail 27913 invoked from network); 8 Aug 2017 21:06:40 +0300 Received: from unknown (HELO pepi-OptiPlex-9020.dsd.bitdefender.biz) (10.10.194.146) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 8 Aug 2017 21:06:40 +0300 From: Petre Pircalabu To: xen-devel@lists.xen.org Date: Tue, 8 Aug 2017 21:06:37 +0300 Message-Id: <1502215598-4689-2-git-send-email-ppircalabu@bitdefender.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502215598-4689-1-git-send-email-ppircalabu@bitdefender.com> References: <1502215598-4689-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 v8 1/2] x86emul: New return code for unimplemented instruction 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 Enforce the distinction between an instruction not implemented by the emulator and the failure to emulate that instruction by defining a new return code, X86EMUL_UNIMPLEMENTED. This value should only be used by the core emulator if it fails to decode the current instruction, and not by any of the x86_emulate_ops callbacks. Signed-off-by: Petre Pircalabu Reviewed-by: Paul Durrant --- xen/arch/x86/hvm/emulate.c | 4 ++++ xen/arch/x86/hvm/io.c | 2 ++ xen/arch/x86/hvm/vmx/realmode.c | 2 +- xen/arch/x86/mm/shadow/multi.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 8 ++++---- xen/arch/x86/x86_emulate/x86_emulate.h | 6 ++++++ 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index 3a8db21..28133c0 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -2044,6 +2044,8 @@ int hvm_emulate_one_mmio(unsigned long mfn, unsigned long gla) switch ( rc ) { case X86EMUL_UNHANDLEABLE: + /* fall-through */ + case X86EMUL_UNIMPLEMENTED: hvm_dump_emulation_state(XENLOG_G_WARNING, "MMCFG", &ctxt); break; case X86EMUL_EXCEPTION: @@ -2113,6 +2115,8 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr, * consistent with X86EMUL_RETRY. */ return; + case X86EMUL_UNIMPLEMENTED: + /* 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/io.c b/xen/arch/x86/hvm/io.c index 214ab30..af4e1dc 100644 --- a/xen/arch/x86/hvm/io.c +++ b/xen/arch/x86/hvm/io.c @@ -96,6 +96,8 @@ bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr) switch ( rc ) { case X86EMUL_UNHANDLEABLE: + /* fall-through */ + case X86EMUL_UNIMPLEMENTED: hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt); return false; diff --git a/xen/arch/x86/hvm/vmx/realmode.c b/xen/arch/x86/hvm/vmx/realmode.c index 11bde58..fdbbee2 100644 --- a/xen/arch/x86/hvm/vmx/realmode.c +++ b/xen/arch/x86/hvm/vmx/realmode.c @@ -106,7 +106,7 @@ void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt) if ( hvm_vcpu_io_need_completion(vio) || vio->mmio_retry ) vio->io_completion = HVMIO_realmode_completion; - if ( rc == X86EMUL_UNHANDLEABLE ) + if ( rc == X86EMUL_UNHANDLEABLE || rc == X86EMUL_UNIMPLEMENTED ) { gdprintk(XENLOG_ERR, "Failed to emulate insn.\n"); goto fail; diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index c9c2252..85fb165 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -3486,7 +3486,7 @@ static int sh_page_fault(struct vcpu *v, * would be a good unshadow hint. If we *do* decide to unshadow-on-fault * then it must be 'failable': we cannot require the unshadow to succeed. */ - if ( r == X86EMUL_UNHANDLEABLE ) + if ( r == X86EMUL_UNHANDLEABLE || r == X86EMUL_UNIMPLEMENTED ) { perfc_incr(shadow_fault_emulate_failed); #if SHADOW_OPTIMIZATIONS & SHOPT_FAST_EMULATION diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index 2201852..480bad9 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -2577,7 +2577,7 @@ x86_decode( d = twobyte_table[0x3a].desc; break; default: - rc = X86EMUL_UNHANDLEABLE; + rc = X86EMUL_UNIMPLEMENTED; goto done; } } @@ -2591,7 +2591,7 @@ x86_decode( } else { - rc = X86EMUL_UNHANDLEABLE; + rc = X86EMUL_UNIMPLEMENTED; goto done; } @@ -2871,7 +2871,7 @@ x86_decode( default: ASSERT_UNREACHABLE(); - return X86EMUL_UNHANDLEABLE; + return X86EMUL_UNIMPLEMENTED; } if ( ea.type == OP_MEM ) @@ -7717,7 +7717,7 @@ x86_emulate( default: cannot_emulate: - rc = X86EMUL_UNHANDLEABLE; + rc = X86EMUL_UNIMPLEMENTED; goto done; } diff --git a/xen/arch/x86/x86_emulate/x86_emulate.h b/xen/arch/x86/x86_emulate/x86_emulate.h index 4ddf111..82812ca 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.h +++ b/xen/arch/x86/x86_emulate/x86_emulate.h @@ -133,6 +133,12 @@ struct x86_emul_fpu_aux { * Undefined behavior when used anywhere else. */ #define X86EMUL_DONE 4 + /* + * Current instruction is not implemented by the emulator. + * This value should only be returned by the core emulator if decode fails + * and not by any of the x86_emulate_ops callbacks. + */ +#define X86EMUL_UNIMPLEMENTED 5 /* FPU sub-types which may be requested via ->get_fpu(). */ enum x86_emulate_fpu_type {