From patchwork Mon Apr 12 13:09:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12198021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53042C433ED for ; Mon, 12 Apr 2021 13:09:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2EE206128E for ; Mon, 12 Apr 2021 13:09:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241805AbhDLNKH (ORCPT ); Mon, 12 Apr 2021 09:10:07 -0400 Received: from wforward5-smtp.messagingengine.com ([64.147.123.35]:38679 "EHLO wforward5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241764AbhDLNKE (ORCPT ); Mon, 12 Apr 2021 09:10:04 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailforward.west.internal (Postfix) with ESMTP id 388C41646; Mon, 12 Apr 2021 09:09:44 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 12 Apr 2021 09:09:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=rxrObZQedU/z7tCgm77WVlD0YetrXNOgn2ee61sfp4A=; b=joNyhsO/ 3wrGui5X+5el2vu/d76fkIdTYIgjhtWpcos5V8fuUWdrIJtIBsItrBWU3ZNRBqVP BQLJngzpyReV6PH+1j9ezqNaeU0M/lIYD4fyVYF9URb9xR5NTiyU/0eCq13SI3H3 sVqBAz0S12xkRrfIwx1chSdrj6CSiSreSYfadhNzSNh22nbCb84TkRIkA2iUQ5Ki z2Yeu2uaE8BVr+sOquxppdjbO9f0Ff6e5SfOjHqcSJOX77vn/oc/usKrKheNeNRd tcllnQPaiH89VjrzdcSu8Ez8RHLyVdkONUq/EqmntnLDO0HQC9xN9em/gGf9Knt2 Z0P1SSI15HsCbQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudekjedgiedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghvihgu ucfgughmohhnughsohhnuceouggrvhhiugdrvggumhhonhgushhonhesohhrrggtlhgvrd gtohhmqeenucggtffrrghtthgvrhhnpedufeetjefgfefhtdejhfehtdfftefhteekhefg leehfffhiefhgeelgfejtdehkeenucfkphepkedurddukeejrddviedrvdefkeenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurghvihgurdgv ughmohhnughsohhnsehorhgrtghlvgdrtghomh X-ME-Proxy: Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net [81.187.26.238]) by mail.messagingengine.com (Postfix) with ESMTPA id 02AEE1080066; Mon, 12 Apr 2021 09:09:40 -0400 (EDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id f21f3cb5; Mon, 12 Apr 2021 13:09:38 +0000 (UTC) From: David Edmondson To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , "H. Peter Anvin" , x86@kernel.org, Sean Christopherson , Thomas Gleixner , Joerg Roedel , Wanpeng Li , Borislav Petkov , Jim Mattson , Ingo Molnar , Joao Martins , David Edmondson Subject: [PATCH 1/6] KVM: x86: add an emulation_reason to x86_emulate_instruction() Date: Mon, 12 Apr 2021 14:09:32 +0100 Message-Id: <20210412130938.68178-2-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210412130938.68178-1-david.edmondson@oracle.com> References: <20210412130938.68178-1-david.edmondson@oracle.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Joao Martins Emulation can happen for a variety of reasons, yet on error we have no idea exactly what triggered it. Expand x86_emulate_instruction() to carry an @emulation_reason argument. Signed-off-by: Joao Martins Signed-off-by: David Edmondson --- arch/x86/kvm/mmu/mmu.c | 4 ++-- arch/x86/kvm/x86.c | 7 ++++--- arch/x86/kvm/x86.h | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 951dae4e7175..515ff790b7c5 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5056,8 +5056,8 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 error_code, if (!mmio_info_in_cache(vcpu, cr2_or_gpa, direct) && !is_guest_mode(vcpu)) emulation_type |= EMULTYPE_ALLOW_RETRY_PF; emulate: - return x86_emulate_instruction(vcpu, cr2_or_gpa, emulation_type, insn, - insn_len); + return x86_emulate_instruction(vcpu, cr2_or_gpa, emulation_type, 0, + insn, insn_len); } EXPORT_SYMBOL_GPL(kvm_mmu_page_fault); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index eca63625aee4..87e76f3aee64 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7445,7 +7445,8 @@ int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type, EXPORT_SYMBOL_GPL(x86_decode_emulated_instruction); int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, - int emulation_type, void *insn, int insn_len) + int emulation_type, int emulation_reason, + void *insn, int insn_len) { int r; struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt; @@ -7604,14 +7605,14 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, int kvm_emulate_instruction(struct kvm_vcpu *vcpu, int emulation_type) { - return x86_emulate_instruction(vcpu, 0, emulation_type, NULL, 0); + return x86_emulate_instruction(vcpu, 0, emulation_type, 0, NULL, 0); } EXPORT_SYMBOL_GPL(kvm_emulate_instruction); int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu, void *insn, int insn_len) { - return x86_emulate_instruction(vcpu, 0, 0, insn, insn_len); + return x86_emulate_instruction(vcpu, 0, 0, 0, insn, insn_len); } EXPORT_SYMBOL_GPL(kvm_emulate_instruction_from_buffer); diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 9035e34aa156..5686436c99da 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -276,7 +276,8 @@ void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 error_c int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type, void *insn, int insn_len); int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, - int emulation_type, void *insn, int insn_len); + int emulation_type, int emulation_reason, + void *insn, int insn_len); fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu); extern u64 host_xcr0;