Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1165856ybf; Thu, 27 Feb 2020 06:12:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzB4hDx//ZHy5SupBalBOW0LqbfVygTKwtlvhj15Av9D6gX5rt9F61muQwOwFqGZp4hc0Wx X-Received: by 2002:a05:6830:2361:: with SMTP id r1mr3375082oth.88.1582812743158; Thu, 27 Feb 2020 06:12:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582812743; cv=none; d=google.com; s=arc-20160816; b=GKX1nNJoj3nJ++ij9LrsJcATu4E8/NQsDD1Co/oynE+arL4Mc8Kn7prXd/pz5QCb38 rq2eclVN8UBcOMjdKH2T9bgVr+0siUZFX4x5J2nwXYefuBiO2Z7IXQ9V28MK8Z4Ud9Yx +/LWg1nNXbu2XkV/3RivIF3ffP0DssZAkmr2pwlYG9UmXQ5jlLMy9YIkgo8IIOFei+TH xYO8rMd3+OQXxLAIHnt1xM7ftOnSJA71Nez4tXpHW1IIGpP9/nVyOL4xnRx+v2pX/FNK 7jkfg86nzHHx6YJrEJ6S6gXpc/TQMB2kdTXr1DeKmc/he9SUMKZ8lYH7WYqiQjGwGIRq eUjg== 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=mBe1HEt8S3kMtU9j19Y1gODHB8z7XBIak59lT+Ywb8s=; b=rIFTh6x6B5ZNCY5XH2YWZB2axaGzcwoEmwV5KeU++9ForJCfg8KbyrOGNMMsGPc8C7 RWCyRl0/8B3BfLa9UDMj9yqHKC7z1S2T4D389Y2boc5F69ACWYOSX7lYpOwvog1FkVLH 2mgV/kEddUt9ggFx3AMdRHu3TnGvL3Nc0Ld5AUdaXTi23zuR52BtoFW2ofvFoeD4Rs9z yOD0tlLVmQtiOcdpxWzxuy8C7H0vKvJ8Xh3QILQ2ZFcSxnV8vzCuXEYRsrkhHddftJdV 8LIWwPclWTg0DgLBFmcdtzyCPvDqSxHQuSRxccbQy6In2ZjHLowkehWjIgCbaBa8KoNk ObnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mCYEVzNu; 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 n20si1342567oig.53.2020.02.27.06.12.09; Thu, 27 Feb 2020 06:12:23 -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=mCYEVzNu; 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 S2388539AbgB0OKa (ORCPT + 99 others); Thu, 27 Feb 2020 09:10:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:48544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388515AbgB0OKX (ORCPT ); Thu, 27 Feb 2020 09:10:23 -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 C6BE324656; Thu, 27 Feb 2020 14:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812622; bh=UtbNHMfivaE4luTQYXgsVskieXTbGxyFGjSorfKG0HM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mCYEVzNuVwUqFGqilIPOKuzOrEi/LAQwE1BRIsOikAtdLRmAzqL3MVQk55MwQKtyB 2foB+inxkwWIL3ztm5+oSmZqO593Pe5vH47TCpg3E5+AWLvaRl5jYqX42FR3EQ1j6e oI3fUpoFChkcu/wR0FMy38yLT4Z3420Yl4Od3s9U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Upton , Paolo Bonzini Subject: [PATCH 5.4 088/135] KVM: nVMX: Check IO instruction VM-exit conditions Date: Thu, 27 Feb 2020 14:37:08 +0100 Message-Id: <20200227132242.560559525@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 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/nested.c | 2 - arch/x86/kvm/vmx/vmx.c | 57 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 7 deletions(-) --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -5173,7 +5173,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)) --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7132,6 +7132,39 @@ static void vmx_request_immediate_exit(s to_vmx(vcpu)->req_immediate_exit = 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) @@ -7139,18 +7172,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; }