Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1159614ybf; Thu, 27 Feb 2020 06:07:05 -0800 (PST) X-Google-Smtp-Source: APXvYqyZy+M6R4Y89sQlYJnjfLHn5U9WP4jZRTw5r+XcBghLgXDQGy7HrVcc71KbpEMans0ktZqn X-Received: by 2002:a05:6808:319:: with SMTP id i25mr3458319oie.128.1582812425384; Thu, 27 Feb 2020 06:07:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582812425; cv=none; d=google.com; s=arc-20160816; b=FafbU9tzZBL05Gkrnv0JPg+bgYMnXV2PjZtndmmgJAazNfYuJ19oWAvzAP5DobPM33 LeCGc+kNOAbr0xjS9FSj6qBr3HtEteHUxlSRAbukXuDQeZHuiOsSAuSdj9ZtZrc1W4ub iUNuq4ThoSmbmMkN5bOvx8+GulaIgSn7IozpFXLWwTllFIc+hbRwdcp0UGixEo8i6zRa 8s7bHqBjrf9fAbcHTsd2fSxUmTTpajxFkUlxrhe4YKxw2TRAxAfEdBB5Zk7j+LvkWTOd vcPQdFuw5Jby6QCyNGObtNSOmTSmYBVov8/T/d8G2RMmc5ju8Jg4H5gGApKohcLt5dhd Hefw== 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=1qdUB4g5EP0LxpDmPjSRJJ2Fe84MHSSO72fl9aiiUMg=; b=Qj0wFuAbJD10xG0INTi1zLx7pq3XIYsxgHiUCGWLeBFfKqoEUOZ61HtwPWo5HwOYKJ 2hOyFclMiUPDRcqv87NSr9GMpQfph2fwphWVnv/swavYVqK/ulVxQlf7Cnlrwiw1LSBt la9g/pINEFU6rSpkDNGhRSdUmA2hjOAHNKbjG4hC1td56U20e+RIv+VMDcjelw2zEip9 KB6uNYifAD6z3tVnsBoEMnxElSmW8IEzJcBnS1edIJVNDTQDD+n9MaPVXEkTXRNpv8UX VZGnyucX3vM9He/6TMKWVrdsg3zj2P8rwLc0DtPMaWGH2IgUILM/wIr4xKDE4+4O2bQ9 NLeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tV5BIV5e; 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 r6si1586354otn.216.2020.02.27.06.06.47; Thu, 27 Feb 2020 06:07:05 -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=tV5BIV5e; 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 S2387768AbgB0OF1 (ORCPT + 99 others); Thu, 27 Feb 2020 09:05:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:42086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387762AbgB0OFZ (ORCPT ); Thu, 27 Feb 2020 09:05:25 -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 ADD792469D; Thu, 27 Feb 2020 14:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812325; bh=2+nOJ+Cax+uf9tPLypRaBTA0bPbn9+/O+WkLbcA7gns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tV5BIV5ebO83gcqqgCdxVOU2QhloFxEd3vt2bomL0fsYqniJ5rDrKAIV25iey+b// 4uHQhUtD0hi/bDvBVnOmvg9bBI/jh/amlcUVEoxiHR1P8xUz2jCXQChhO/GcyC9ro8 bGzfz6rGHTRpKAmVI5j36wVVj5mAVY/p4aMeRYUY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Upton , Paolo Bonzini Subject: [PATCH 4.19 72/97] KVM: nVMX: Check IO instruction VM-exit conditions Date: Thu, 27 Feb 2020 14:37:20 +0100 Message-Id: <20200227132226.243954788@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132214.553656188@linuxfoundation.org> References: <20200227132214.553656188@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 35a571346a94fb93b5b3b6a599675ef3384bc75c upstream. Consult the 'unconditional IO exiting' and 'use IO bitmaps' VM-execution controls when checking instruction interception. If the 'use IO bitmaps' VM-execution control is 1, check the instruction access against the IO bitmaps to determine if the instruction causes a VM-exit. Signed-off-by: Oliver Upton Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 7 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -5731,7 +5731,7 @@ static bool nested_vmx_exit_handled_io(s struct vmcs12 *vmcs12) { unsigned long exit_qualification; - unsigned int port; + unsigned short port; int size; if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS)) @@ -13689,6 +13689,39 @@ static void nested_vmx_entry_failure(str to_vmx(vcpu)->nested.sync_shadow_vmcs = true; } +static int vmx_check_intercept_io(struct kvm_vcpu *vcpu, + struct x86_instruction_info *info) +{ + struct vmcs12 *vmcs12 = get_vmcs12(vcpu); + unsigned short port; + bool intercept; + int size; + + if (info->intercept == x86_intercept_in || + info->intercept == x86_intercept_ins) { + port = info->src_val; + size = info->dst_bytes; + } else { + port = info->dst_val; + size = info->src_bytes; + } + + /* + * If the 'use IO bitmaps' VM-execution control is 0, IO instruction + * VM-exits depend on the 'unconditional IO exiting' VM-execution + * control. + * + * Otherwise, IO instruction VM-exits are controlled by the IO bitmaps. + */ + if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS)) + intercept = nested_cpu_has(vmcs12, + CPU_BASED_UNCOND_IO_EXITING); + else + intercept = nested_vmx_check_io_bitmaps(vcpu, port, size); + + return intercept ? X86EMUL_UNHANDLEABLE : X86EMUL_CONTINUE; +} + static int vmx_check_intercept(struct kvm_vcpu *vcpu, struct x86_instruction_info *info, enum x86_intercept_stage stage) @@ -13696,18 +13729,30 @@ static int vmx_check_intercept(struct kv struct vmcs12 *vmcs12 = get_vmcs12(vcpu); struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; + switch (info->intercept) { /* * RDPID causes #UD if disabled through secondary execution controls. * Because it is marked as EmulateOnUD, we need to intercept it here. */ - if (info->intercept == x86_intercept_rdtscp && - !nested_cpu_has2(vmcs12, SECONDARY_EXEC_RDTSCP)) { - ctxt->exception.vector = UD_VECTOR; - ctxt->exception.error_code_valid = false; - return X86EMUL_PROPAGATE_FAULT; - } + case x86_intercept_rdtscp: + if (!nested_cpu_has2(vmcs12, SECONDARY_EXEC_RDTSCP)) { + ctxt->exception.vector = UD_VECTOR; + ctxt->exception.error_code_valid = false; + return X86EMUL_PROPAGATE_FAULT; + } + break; + + case x86_intercept_in: + case x86_intercept_ins: + case x86_intercept_out: + case x86_intercept_outs: + return vmx_check_intercept_io(vcpu, info); /* TODO: check more intercepts... */ + default: + break; + } + return X86EMUL_UNHANDLEABLE; }