Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3532809imu; Mon, 7 Jan 2019 05:12:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN6pTdICtiyRXIOINW20S2lc7ocBZkFH6ckbdBcP6xRH6+E5EYJq/+X4RLfwHb5O075WxE4w X-Received: by 2002:a65:4142:: with SMTP id x2mr10600903pgp.356.1546866747920; Mon, 07 Jan 2019 05:12:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546866747; cv=none; d=google.com; s=arc-20160816; b=SUPmb/f+ignZLXa2NjHOMhm4ggRz6VobKCzJYQ0zZecapIqVeWnQ25x/7i/QhssFvt W0qzq8t3tUs/5N7JSgL8lc+aF6a56Yx0T4LLuXKxc8THnG7PqDTH8/Ke1GK/HpJVpq9s eXY40Br6xdfdNYuyl7K96G2/p56P6qx6FEmZXm6jzKzh1KNqWy2X1xg8c79zhJ5XekdJ pMYffW6vsuqIrTLbmdQvoQ1xc6go2GnJU9YKb9UJwoixYCpbRmaFWNjT1mozCkC46s0t 0MNP7NL+v0ZSh/Nc19JWzIM3FyGCVCVVz9TkY5XesjhlztpRQC3vXyfGwQgXx6Td0UDq 1/Fw== 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=c06wXdRUTIYQM4wVz1fnOcnlwRkfvfNFOt1WPmp8Xlo=; b=VhTmfJ73H8xhXVDfwwjvxYhFRBNIJxIVh35D1uwi1WvXbohPUp4xHjLIQzQnG3l4gO CbMniMIUWiCgSanoZ7AgQPlvgVNsCZb/KiGNG33lLxw/qMJx/Ii0/vZLJ6i7QJY6q0f6 FZtxGtaGQSX/JOYzydrJ4/C55nt4w+aGbCW2l6g/+nXMTuhA0TIIJVUpU0yyzHLMenrL 03In9efw/C/8f2xk/9oHOsYL+9VnB1FF5chn24tNceRsn+MBjXUpLu+j1OBWWzjeAlP9 ChjzDfQvWE/9LzTzrXysjCTsnb1xIchH9TNM7MJvniXMWTr+7K2s2EJXlTONRNgMeW68 UvNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rZ8a+jz4; 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 k12si6387750pgg.382.2019.01.07.05.12.12; Mon, 07 Jan 2019 05:12:27 -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=rZ8a+jz4; 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 S1731907AbfAGNJz (ORCPT + 99 others); Mon, 7 Jan 2019 08:09:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:56606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731556AbfAGNJv (ORCPT ); Mon, 7 Jan 2019 08:09:51 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 BBF222147C; Mon, 7 Jan 2019 13:09:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866590; bh=OgWQ+YXAVSFo3VyBkOEtEl1fwvcdzThm3FGB15JN6a0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rZ8a+jz4xx7s+somZYwpi0EZ6I8vJPpkbjamSPUwhKVSwdj5qivKeTKD321YeB05s oPrTYWByJqyWRWgZX8uahcBrpZTMENqc7TPq+YN0wMJ2M65LXyCFlMvvwF26khuQP9 ZtGvXZFOtu9l8U9AyBu0kfWBG2yPSxyZ4fq4A/C8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Paolo Bonzini , Vitaly Kuznetsov , "Michael S. Tsirkin" , Sasha Levin , Mike Haboustak Subject: [PATCH 4.9 68/71] x86/kvm/vmx: do not use vm-exit instruction length for fast MMIO when running nested Date: Mon, 7 Jan 2019 13:33:37 +0100 Message-Id: <20190107105336.633052729@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.280153213@linuxfoundation.org> References: <20190107105330.280153213@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vitaly Kuznetsov commit d391f1207067268261add0485f0f34503539c5b0 upstream. I was investigating an issue with seabios >= 1.10 which stopped working for nested KVM on Hyper-V. The problem appears to be in handle_ept_violation() function: when we do fast mmio we need to skip the instruction so we do kvm_skip_emulated_instruction(). This, however, depends on VM_EXIT_INSTRUCTION_LEN field being set correctly in VMCS. However, this is not the case. Intel's manual doesn't mandate VM_EXIT_INSTRUCTION_LEN to be set when EPT MISCONFIG occurs. While on real hardware it was observed to be set, some hypervisors follow the spec and don't set it; we end up advancing IP with some random value. I checked with Microsoft and they confirmed they don't fill VM_EXIT_INSTRUCTION_LEN on EPT MISCONFIG. Fix the issue by doing instruction skip through emulator when running nested. Fixes: 68c3b4d1676d870f0453c31d5a52e7e65c7448ae Suggested-by: Radim Krčmář Suggested-by: Paolo Bonzini Signed-off-by: Vitaly Kuznetsov Acked-by: Michael S. Tsirkin Signed-off-by: Radim Krčmář Signed-off-by: Sasha Levin [mhaboustak: backport to 4.9.y] Signed-off-by: Mike Haboustak Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 19 +++++++++++++++++-- arch/x86/kvm/x86.c | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -6548,9 +6548,24 @@ static int handle_ept_misconfig(struct k gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); if (!kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) { - skip_emulated_instruction(vcpu); trace_kvm_fast_mmio(gpa); - return 1; + /* + * Doing kvm_skip_emulated_instruction() depends on undefined + * behavior: Intel's manual doesn't mandate + * VM_EXIT_INSTRUCTION_LEN to be set in VMCS when EPT MISCONFIG + * occurs and while on real hardware it was observed to be set, + * other hypervisors (namely Hyper-V) don't set it, we end up + * advancing IP with some random value. Disable fast mmio when + * running nested and keep it for real hardware in hope that + * VM_EXIT_INSTRUCTION_LEN will always be set correctly. + */ + if (!static_cpu_has(X86_FEATURE_HYPERVISOR)) { + skip_emulated_instruction(vcpu); + return 1; + } + else + return x86_emulate_instruction(vcpu, gpa, EMULTYPE_SKIP, + NULL, 0) == EMULATE_DONE; } ret = handle_mmio_page_fault(vcpu, gpa, true); --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5707,7 +5707,8 @@ int x86_emulate_instruction(struct kvm_v * handle watchpoints yet, those would be handled in * the emulate_ops. */ - if (kvm_vcpu_check_breakpoint(vcpu, &r)) + if (!(emulation_type & EMULTYPE_SKIP) && + kvm_vcpu_check_breakpoint(vcpu, &r)) return r; ctxt->interruptibility = 0;