Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1165180ybf; Thu, 27 Feb 2020 06:11:53 -0800 (PST) X-Google-Smtp-Source: APXvYqzSb+01xciv9tW8FQmwCm4rX43NilhBJ2Ih86kPj1mBZT23c2t7QJzByjMVgu6xtygxRMgg X-Received: by 2002:a9d:1d2:: with SMTP id e76mr2964426ote.223.1582812713384; Thu, 27 Feb 2020 06:11:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582812713; cv=none; d=google.com; s=arc-20160816; b=U9NSOrKnsuoKRzp/m5I0fzvYyUuDW12z2Hvg2TrGho60lxLAzJvold/dKI1Ms+9RqM T4Xgj6ujddcdk7YS2D+NUNyGsv/I0wBv3AhQcMdeLfwyJPf43ZApOqTUzB6n64+nRwbn Bdhr+A1yF/IMlgXGU7ZJQVRYgseI80s8XpSzUggHX3Nb85q1LjfHfXlIcLA7jDATS3DD +W3lPHjzxX8mmodovp25c2ROJK5zpV5NNYVKByhaaQOfEFGQT7YGb49aMjiYPdb9rSLR WVw1w/5R6EWRdNfO+HFvpF2dhctkLB8NJEMS3S/wHRsucc1Pa34853x3rDWcKbZW08Ud UNlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GMR002WVggkmwcrKW2CKZwCqgIUFJQhXPs7Wk2ycyB8=; b=UpYCxrw1Vpf4DtdlJtYPxP/HhMR7uVW+q1+ytmtp5M8l2a7ZrCzZx48gnooAIGRkKB ipxoiX0rPyoBu14d57TSEWAG9N5cUVn1y7nd7+e4DEeAAaOGnK3DQ//Tf3JmabTQzjRJ 7D4nML7ZjPEJnM1MZQ6d7QuJXzTpgQxASDsoXrf5ROeU8D3VPLqbtvBjyFySJJWOLZsO 58+BFAxO4E10zvFEw0C2j167QPsIs4VjmHs5R+g+Jkfd3+QBfd1+XWcOUQkBdOoqyMP9 fnJKoSi7ntX3hQGqAIbkkDQnAQQcmeVdHjrSELpDP69oBpEvXak4eJYPCPXCHDsxvFgg G8AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qMAPtyHR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t15si1618410oth.176.2020.02.27.06.11.32; Thu, 27 Feb 2020 06:11:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qMAPtyHR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730496AbgB0OKX (ORCPT + 99 others); Thu, 27 Feb 2020 09:10:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:48504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388523AbgB0OKU (ORCPT ); Thu, 27 Feb 2020 09:10:20 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1B5FF21D7E; Thu, 27 Feb 2020 14:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812619; bh=rarZuacrQ87h+BDFpV3uxEL/GXdcoEaVM/G5A4T/eM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMAPtyHR7Tuna1DCLUlu7RfZx0s94SOGCeQqY+0e5FvsE8o/j497YlqRvGpp9eSBB zh9OXiu1/7LSXw02sWHjdIPQnykC3gfQSx+DBCGKOp/8mftbPzKQoDG0+lzeahhHpk I6yPmi7QmcWWkc8fJRuIhfmyvPCyAxfYL3fWHXRA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Upton , Vitaly Kuznetsov , Paolo Bonzini Subject: [PATCH 5.4 087/135] KVM: nVMX: Refactor IO bitmap checks into helper function Date: Thu, 27 Feb 2020 14:37:07 +0100 Message-Id: <20200227132242.405969204@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oliver Upton commit e71237d3ff1abf9f3388337cfebf53b96df2020d upstream. Checks against the IO bitmap are useful for both instruction emulation and VM-exit reflection. Refactor the IO bitmap checks into a helper function. Signed-off-by: Oliver Upton Reviewed-by: Vitaly Kuznetsov Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx/nested.c | 39 +++++++++++++++++++++++++-------------- arch/x86/kvm/vmx/nested.h | 2 ++ 2 files changed, 27 insertions(+), 14 deletions(-) --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -5132,24 +5132,17 @@ fail: return 1; } - -static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu, - struct vmcs12 *vmcs12) +/* + * Return true if an IO instruction with the specified port and size should cause + * a VM-exit into L1. + */ +bool nested_vmx_check_io_bitmaps(struct kvm_vcpu *vcpu, unsigned int port, + int size) { - unsigned long exit_qualification; + struct vmcs12 *vmcs12 = get_vmcs12(vcpu); gpa_t bitmap, last_bitmap; - unsigned int port; - int size; u8 b; - if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS)) - return nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING); - - exit_qualification = vmcs_readl(EXIT_QUALIFICATION); - - port = exit_qualification >> 16; - size = (exit_qualification & 7) + 1; - last_bitmap = (gpa_t)-1; b = -1; @@ -5176,6 +5169,24 @@ static bool nested_vmx_exit_handled_io(s return false; } +static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu, + struct vmcs12 *vmcs12) +{ + unsigned long exit_qualification; + unsigned int port; + int size; + + if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS)) + return nested_cpu_has(vmcs12, CPU_BASED_UNCOND_IO_EXITING); + + exit_qualification = vmcs_readl(EXIT_QUALIFICATION); + + port = exit_qualification >> 16; + size = (exit_qualification & 7) + 1; + + return nested_vmx_check_io_bitmaps(vcpu, port, size); +} + /* * Return 1 if we should exit from L2 to L1 to handle an MSR access access, * rather than handle it ourselves in L0. I.e., check whether L1 expressed --- a/arch/x86/kvm/vmx/nested.h +++ b/arch/x86/kvm/vmx/nested.h @@ -33,6 +33,8 @@ int vmx_set_vmx_msr(struct kvm_vcpu *vcp int vmx_get_vmx_msr(struct nested_vmx_msrs *msrs, u32 msr_index, u64 *pdata); int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification, u32 vmx_instruction_info, bool wr, int len, gva_t *ret); +bool nested_vmx_check_io_bitmaps(struct kvm_vcpu *vcpu, unsigned int port, + int size); static inline struct vmcs12 *get_vmcs12(struct kvm_vcpu *vcpu) {