Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1759269pxb; Mon, 12 Apr 2021 06:12:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvbMtNXRvHEWJEU7ILIm1gJTP8NLqNN8F4jkG99E2nCxusaoBxurTfJiYpZ+fBMSdDbhHD X-Received: by 2002:a63:6482:: with SMTP id y124mr27402124pgb.60.1618233140847; Mon, 12 Apr 2021 06:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618233140; cv=none; d=google.com; s=arc-20160816; b=yTNEhilaxqTeatiFIRWpI5nI48o/ZcxUjvoDg/wFDc0eriNaFSQ4V1fvpkOY9WNTUR xIqGViJgpTA6LhA4GaLzoOQ84nHjGhpxk2oXNL2+/ijIYdy14LVo9JZZe9/UgThzX+lr 2LYfHzuSTWe9jYyOuG3RLueYLdwPf11L8yR/T3y7mJJt8J6RZVSHySgl51dJpcrFVVOb dIf+b/4JXK9sxT52bBBoN0PzVLks6v8Om0ag+XQgs2IKoEWs425QTiI1UBdv/WyguxwC I0j+B5nkqSIO1AlwknWbEDRavVttCSNETv6Z1leqMRFiqJdv+tpLcaoWL16FxiF2TlUH r9jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dN/QNHiyGToQXM6hoRPaubgFTy6JlFGJ5tVi33Nr9Qk=; b=zii+bAiASTUAHwLqKfQwMqhEHOWimg1b2NNRBWWw1kSwNHgaipAku27TsaTJL1m/Vl DZX+LTqfRABqIN+wWF0WFbUOTtZVwQTD5J6qrLmQ+sVPpgeBvhDFDixl6bqnTLvSgVfR vdpmprOovSKTqf5wKS4RNy8oj2yMFLQHc6f5NRSdS15WjBeTSZ2lRUD1iQQ0E+EMyHNs c+LpOTExcVgPh4Bnr5MTKjbxlefQeD0pLc3fCIIR9B7MrSw+KIko8sDBiHDIs+qPXU1X CEt1QdB1u/xzUBW+r3jYsic0gHkMgqIc9esWi/+vP21F5a3aWgoouUfkK2wIpZk8avCG NlMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=IjPqjmdc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s10si13384080plr.305.2021.04.12.06.12.07; Mon, 12 Apr 2021 06:12:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=IjPqjmdc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241924AbhDLNKS (ORCPT + 99 others); Mon, 12 Apr 2021 09:10:18 -0400 Received: from wforward5-smtp.messagingengine.com ([64.147.123.35]:47791 "EHLO wforward5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241785AbhDLNKH (ORCPT ); Mon, 12 Apr 2021 09:10:07 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailforward.west.internal (Postfix) with ESMTP id 466AC16AE; Mon, 12 Apr 2021 09:09:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 12 Apr 2021 09:09:47 -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=dN/QNHiyGToQXM6hoRPaubgFTy6JlFGJ5tVi33Nr9Qk=; b=IjPqjmdc fQr6R0d27isL50Bc8F3cCWghdQ9ZYZhM4o6dQEWWTO/BKvW9wbwizTw+NYsk8DTZ b1RrcQf8Q5CdYo5fpMwWkq5LGPwyOnWL7N4n3lBEf70a0s+fNdkvEqAAvov0Rsr3 5sGBrXvfcKXuki1CPACTJAva5xHUmP8R0C6yk7qyIS41LR/WC9nmwsaAXpDEMq0w 7dlI0lAZaylhBJR1GwK+3u2SHI0gQhsIodb2bRqisz5yFQlZeY1vHGnlNeXkN8O3 TvSfYb4yGV7QUeeX22sG04D3/mGI5BXhp01CGyO7MGzXuOzJPdW0I1tjyPFVqOLH mahahAu9RsXL3g== 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 A921E1080068; Mon, 12 Apr 2021 09:09:43 -0400 (EDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id abdc0c66; 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 5/6] KVM: SVM: pass a proper reason in kvm_emulate_instruction() Date: Mon, 12 Apr 2021 14:09:36 +0100 Message-Id: <20210412130938.68178-6-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joao Martins Declare various causes of emulation and use them as appropriate. Signed-off-by: Joao Martins Signed-off-by: David Edmondson --- arch/x86/include/asm/kvm_host.h | 6 ++++++ arch/x86/kvm/svm/avic.c | 3 ++- arch/x86/kvm/svm/svm.c | 26 +++++++++++++++----------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 79e9ca756742..e1284680cbdc 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1535,6 +1535,12 @@ enum { EMULREASON_IO_COMPLETE, EMULREASON_UD, EMULREASON_PF, + EMULREASON_SVM_NOASSIST, + EMULREASON_SVM_RSM, + EMULREASON_SVM_RDPMC, + EMULREASON_SVM_CR, + EMULREASON_SVM_DR, + EMULREASON_SVM_AVIC_UNACCEL, }; int kvm_emulate_instruction(struct kvm_vcpu *vcpu, int emulation_type, diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 31a17fa6a37c..faa5d4db7ccc 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -558,7 +558,8 @@ int avic_unaccelerated_access_interception(struct vcpu_svm *svm) ret = avic_unaccel_trap_write(svm); } else { /* Handling Fault */ - ret = kvm_emulate_instruction(&svm->vcpu, 0, 0); + ret = kvm_emulate_instruction(&svm->vcpu, 0, + EMULREASON_SVM_AVIC_UNACCEL); } return ret; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index bba3b72390a8..2646aa2eae22 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -344,7 +344,8 @@ static int skip_emulated_instruction(struct kvm_vcpu *vcpu) } if (!svm->next_rip) { - if (!kvm_emulate_instruction(vcpu, EMULTYPE_SKIP, 0)) + if (!kvm_emulate_instruction(vcpu, EMULTYPE_SKIP, + EMULREASON_SKIP)) return 0; } else { kvm_rip_write(vcpu, svm->next_rip); @@ -2077,7 +2078,8 @@ static int io_interception(struct vcpu_svm *svm) if (sev_es_guest(vcpu->kvm)) return sev_es_string_io(svm, size, port, in); else - return kvm_emulate_instruction(vcpu, 0, 0); + return kvm_emulate_instruction(vcpu, 0, + EMULREASON_IO); } svm->next_rip = svm->vmcb->control.exit_info_2; @@ -2263,7 +2265,8 @@ static int gp_interception(struct vcpu_svm *svm) */ if (!is_guest_mode(vcpu)) return kvm_emulate_instruction(vcpu, - EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE, 0); + EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE, + EMULREASON_GP); } else return emulate_svm_instr(vcpu, opcode); @@ -2459,20 +2462,21 @@ static int invd_interception(struct vcpu_svm *svm) static int invlpg_interception(struct vcpu_svm *svm) { if (!static_cpu_has(X86_FEATURE_DECODEASSISTS)) - return kvm_emulate_instruction(&svm->vcpu, 0, 0); + return kvm_emulate_instruction(&svm->vcpu, 0, EMULREASON_SVM_NOASSIST); kvm_mmu_invlpg(&svm->vcpu, svm->vmcb->control.exit_info_1); return kvm_skip_emulated_instruction(&svm->vcpu); } -static int emulate_on_interception(struct vcpu_svm *svm) +static int emulate_on_interception(struct vcpu_svm *svm, int emulation_reason) { - return kvm_emulate_instruction(&svm->vcpu, 0, 0); + return kvm_emulate_instruction(&svm->vcpu, 0, emulation_reason); } static int rsm_interception(struct vcpu_svm *svm) { - return kvm_emulate_instruction_from_buffer(&svm->vcpu, rsm_ins_bytes, 2, 0); + return kvm_emulate_instruction_from_buffer(&svm->vcpu, rsm_ins_bytes, 2, + EMULREASON_SVM_RSM); } static int rdpmc_interception(struct vcpu_svm *svm) @@ -2480,7 +2484,7 @@ static int rdpmc_interception(struct vcpu_svm *svm) int err; if (!nrips) - return emulate_on_interception(svm); + return emulate_on_interception(svm, EMULREASON_SVM_RDPMC); err = kvm_rdpmc(&svm->vcpu); return kvm_complete_insn_gp(&svm->vcpu, err); @@ -2516,10 +2520,10 @@ static int cr_interception(struct vcpu_svm *svm) int err; if (!static_cpu_has(X86_FEATURE_DECODEASSISTS)) - return emulate_on_interception(svm); + return emulate_on_interception(svm, EMULREASON_SVM_NOASSIST); if (unlikely((svm->vmcb->control.exit_info_1 & CR_VALID) == 0)) - return emulate_on_interception(svm); + return emulate_on_interception(svm, EMULREASON_SVM_CR); reg = svm->vmcb->control.exit_info_1 & SVM_EXITINFO_REG_MASK; if (svm->vmcb->control.exit_code == SVM_EXIT_CR0_SEL_WRITE) @@ -2635,7 +2639,7 @@ static int dr_interception(struct vcpu_svm *svm) } if (!boot_cpu_has(X86_FEATURE_DECODEASSISTS)) - return emulate_on_interception(svm); + return emulate_on_interception(svm, EMULREASON_SVM_NOASSIST); reg = svm->vmcb->control.exit_info_1 & SVM_EXITINFO_REG_MASK; dr = svm->vmcb->control.exit_code - SVM_EXIT_READ_DR0; -- 2.30.2