Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1206423ybf; Thu, 27 Feb 2020 06:48:37 -0800 (PST) X-Google-Smtp-Source: APXvYqzYRuHyYHEA7eAXv8Tg7id5fSYwTf/yP2opjH8nAbKkJ61ouFfEalDRtb7JV2IWbl47TmhU X-Received: by 2002:a05:6830:1d7b:: with SMTP id l27mr3435532oti.251.1582814917740; Thu, 27 Feb 2020 06:48:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582814917; cv=none; d=google.com; s=arc-20160816; b=FAfeDczF3PHxbpQ/gqhuMfHwXkCHLw9NFOctpJ9Zhddz5ow4A7L/kH9OI2JMOvcP3w qQgWuoy+koi1b8SlZN/M9Y5PGEjgEvg+JMQyY9UzzlXc+w5+eXsT2wPa6S372PbA8b83 psnZQY9DDiOXkwWtViL+n5hT8PrZwi0lUdp57MShnZ89C5jareRImuEO4o3TZDF2kV4W uZeCjEYhc6nxFVckv1wTebuyOGGbQvOEVFhFA5Nkj0H6k2iaxyG4uTGmV71Wqzjg9dW6 jxWqSg93GS3WyRFDvy8KLgW4sXA+WR35H31TXjKDzNwxGIh0CvPjEm9GzfYaP/ecLVQJ DceA== 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=IUYCVSL3YQ/kGj28XaTQPOa1jkEeUhEqBQR7NSuO8+I=; b=SIbz15qNoNaR9gtbdIIzwjMS8qO4UCICQC+Jllo6h9/ccH77IAN3xqcOq/9EJJ+2+u ga31OEF6bJv9iTZLVKWVK5xiy9G8hA8D+xXgTRPFUclOjriZCdruzvmTzzIWB+do0c1h F/ZS1s9u5UbkJJpH58f2OBAGbBvP/s3+8idUcRxfm2dnoX4aCOffSo/4Ed+HQf3jGr1i OQtyGsW8/OsSPyaEY+qhFTzvvwTHznR/7ykG0sg5iCDbbkY7hSeWnBVrU/iXuh5HrD+M xY4R+PFkWhKHMBTMvQuG50uFHc2FzUOqAgaUELqF7ijKbYfN+OMHX5yag1RcBOMxCuHk XRtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LdFNhM4J; 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 h9si1589981oti.155.2020.02.27.06.48.25; Thu, 27 Feb 2020 06:48:37 -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=LdFNhM4J; 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 S1730416AbgB0Oqg (ORCPT + 99 others); Thu, 27 Feb 2020 09:46:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:40978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730343AbgB0NpI (ORCPT ); Thu, 27 Feb 2020 08:45:08 -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 ACF3520578; Thu, 27 Feb 2020 13:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582811108; bh=qek24UEhQYTcA5b0RkuuEoNKEAaZQPUX61T55Muiaiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LdFNhM4Jou46/P0dcHjt3XjON/PkEqkJK/D7MWkl+igIM3arbxRx2/MT2BggqF51C H4HoNCrmiTLiARvdbrwZ9w79vmJPRKc/96xwLadB/nJh8YCHl6+Gsp1OnKCKhr4N7U 3xyZHE4EETUqMGAAzsI5aJO7MMgkr2Hk3zEtHd6U= 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.4 104/113] KVM: nVMX: Check IO instruction VM-exit conditions Date: Thu, 27 Feb 2020 14:37:00 +0100 Message-Id: <20200227132228.432911955@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 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 @@ -4281,7 +4281,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)) @@ -10754,6 +10754,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) @@ -10761,18 +10794,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; }