Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1205462ybf; Thu, 27 Feb 2020 06:47:40 -0800 (PST) X-Google-Smtp-Source: APXvYqzjM5YDkoTSqSN1bUY7FgCv/ATXBC4tob+MidKwUnRJe/6shFgVozbfMnn5HEwGmLOjOal9 X-Received: by 2002:a05:6830:1e2d:: with SMTP id t13mr2037otr.128.1582814860755; Thu, 27 Feb 2020 06:47:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582814860; cv=none; d=google.com; s=arc-20160816; b=KWd5LMH50HNo7ArcxU8kkHHZeTv8FSpLs0G4QRtt3tL8jaT6j411f0y6Bqd+B7ChqE T6eaPF+8EZdM5PIqVy10HRhsvuRL31b+kietL3OFJ3tEom84/z5anBsGHv2Ph4LdUeu2 ayPp1q7VrrOmHBkF85QVBWTpzjtoMXwcxtWMffqBDyDl8SDYjUUvMIJPNUcFr7cVAToI dsUB2I2Bsc7f8CznUgJWap4dWFtPBPDd2KuA3xNDIZpiYXXKl5H2FQM5PTXwKq+ks/M6 BKCOhzb2lVeEPs5JNtCoR5Adkyc0cVJ7/bMtmoA0aCSQH6L6RmnbHZ9hcAZoiiHDoo2m vNjA== 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=yPRZvEvKzONTg16uZCE4hSRi7Z/aVFhYdVtWlT/WLi4=; b=d6XxGOiCX2e5BgL/j31rjc0WrjxnL1k7S/4idtWcRA3f3q9pwzGNbbkut6fakMpIGd 73KRESmnXXnue5ZTAdRfP5agwrFDjafJFZJqXjjsJPLicfldnKqm3JmbNAj8FsJ+ZIOh pvT6zxSr7mLPjmyIAlTVsssHl5BdoqK2VHtQ1kEf/nh/MMSHnMMQVruVghoi51w+tSoJ SGavUVfShLXREj9NXpEYkoYASdhwZzuy/vEDEErWeGECsSH4znEy87XKadvYbOMLyuOk mWz/ILvq24gdEIZiXpBqYNAx6ueBoYRjdk56OijBiHSMSqAOI8eoMhue2SeumI9DWz2t NGrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m0kj2Asj; 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 h203si1518189oif.3.2020.02.27.06.47.29; Thu, 27 Feb 2020 06:47:40 -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=m0kj2Asj; 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 S1729932AbgB0Oqo (ORCPT + 99 others); Thu, 27 Feb 2020 09:46:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:40926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730327AbgB0NpF (ORCPT ); Thu, 27 Feb 2020 08:45:05 -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 7A484246A4; Thu, 27 Feb 2020 13:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582811104; bh=+QAgU77dISxHZDAmFaB3ZLaxVbIj8objSRqIb1lXI70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m0kj2AsjD5nH/Tz8l0txoUAg6V71XSiqOEEONwir8T7Hj4upjA5APb8bJVx5Fy0JV vO6qvFeAnTLeLdi4SXGJjMndQCMXOtUQ1ou212OXLHUc+VjdChrFiSDu0TFNajtCwT 0OTFvqaoWz2k9+tZ62MWZbQo1UkLwLXITz7vbeH4= 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 4.4 103/113] KVM: nVMX: Refactor IO bitmap checks into helper function Date: Thu, 27 Feb 2020 14:36:59 +0100 Message-Id: <20200227132228.249434084@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132211.791484803@linuxfoundation.org> References: <20200227132211.791484803@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.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -4275,6 +4275,26 @@ static bool cs_ss_rpl_check(struct kvm_v (ss.selector & SEGMENT_RPL_MASK)); } +static bool nested_vmx_check_io_bitmaps(struct kvm_vcpu *vcpu, + unsigned int port, int size); +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); +} + /* * Check if guest state is valid. Returns true if valid, false if * not. @@ -7624,23 +7644,17 @@ static int (*const kvm_vmx_exit_handlers static const int kvm_vmx_max_exit_handlers = ARRAY_SIZE(kvm_vmx_exit_handlers); -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;