Received: by 10.223.176.46 with SMTP id f43csp2402781wra; Thu, 25 Jan 2018 09:17:57 -0800 (PST) X-Google-Smtp-Source: AH8x224EASa6GoYPiLgc5rs5LZW9GiKcYbMP+G76f04CCH4VCaGH+b0i9BTSalrpUAb/jt4dnuly X-Received: by 2002:a17:902:9686:: with SMTP id n6-v6mr11634187plp.333.1516900677582; Thu, 25 Jan 2018 09:17:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516900677; cv=none; d=google.com; s=arc-20160816; b=0v3ehIJGE1YYcMx5HC+xiSm5l6de1x8+dcajUcISq6+zekI85pjvcZaWOai270J2bI IOxdXYx1af3G+gG4wdV2gxCG7Vyq7Vi+1mNFDIVwjlK/Uj2mTJUrejoL4qVYgcNZ2qVb Y5tbYJsDp/6zjwvszPWZRHGb2Cv5mMBbvYpv1I5WBTXZIhlhIeAjIH0xdNrR/Qz7xqg5 CnGiXCgFFE2F9DFX8cKSI3JAWCByeh9PvNpwLfwRNMfQucWEgVlWqmbXKpruq7u3pZeE nyukT2/adFYqKs15Zp+o71DZhvDAf1B18TiCaQvqZjTC+kv6U2j5bIr8tt0wA280jSRR q6Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=k4Mkw5kjXLtIfoYTvZsz374A3NMzWil8O/NPNTWph0E=; b=WTAgH5NUhR6h96nm+vengO3R05YKDcx6qqjN2faocsf90TuhZBtPPx7pI5NUR6h60W UlIZGsx4Iu14CcfA0Chv10o7qovVEBQSeKXEo61RBvfevUUKtGB79Sb2UPqE9DbzzKxb iWQIHLuYyq79LHNvuerQnwyyYAxi4thuMMb42e7PRMz6Q2bYDJXj09vUb3FCTaI4wpXI VUADdI226yD6cvCT+nNSsiGROtrf8UeVjH6HAcYwGJelbPzgGjU7UBJmVRuD65pCtBQ5 g4EDYev/d3DU2OPnhkKr+slfKubk10ajYKPkE3teY7NcGUdS9xzPnMdz3CRzecVrt2ZO v7Qg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k4si1764861pgr.731.2018.01.25.09.17.43; Thu, 25 Jan 2018 09:17:57 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751220AbeAYRQI (ORCPT + 99 others); Thu, 25 Jan 2018 12:16:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53932 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750992AbeAYRQG (ORCPT ); Thu, 25 Jan 2018 12:16:06 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BEC0BC051787; Thu, 25 Jan 2018 17:16:06 +0000 (UTC) Received: from redhat.com (ovpn-122-11.rdu2.redhat.com [10.10.122.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id D20555C895; Thu, 25 Jan 2018 17:16:03 +0000 (UTC) Date: Thu, 25 Jan 2018 19:16:02 +0200 From: "Michael S. Tsirkin" To: Vitaly Kuznetsov Cc: kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Wanpeng Li , Liran Alon , Jason Wang Subject: Re: [PATCH v2] x86/kvm/vmx: do not use vm-exit instruction length for fast MMIO when running nested Message-ID: <20180125191239-mutt-send-email-mst@kernel.org> References: <20180125153707.29981-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180125153707.29981-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 25 Jan 2018 17:16:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 25, 2018 at 04:37:07PM +0100, Vitaly Kuznetsov wrote: > 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 I would maybe also disable this when this is a kvm host running a nested *guest*, just in case. Acked-by: Michael S. Tsirkin > --- > v1 -> v2: > inlay X86_FEATURE_HYPERVISOR case with EMULTYPE_SKIP optimization > [Paolo Bonzini, Radim Krčmář] > --- > arch/x86/kvm/vmx.c | 16 +++++++++++++++- > arch/x86/kvm/x86.c | 3 ++- > 2 files changed, 17 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index c829d89e2e63..e105b439c372 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -6563,7 +6563,21 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu) > if (!is_guest_mode(vcpu) && > !kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) { > trace_kvm_fast_mmio(gpa); > - return kvm_skip_emulated_instruction(vcpu); > + /* > + * 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)) > + return kvm_skip_emulated_instruction(vcpu); > + else > + return x86_emulate_instruction(vcpu, gpa, EMULTYPE_SKIP, > + NULL, 0) == EMULATE_DONE; > } > > ret = kvm_mmu_page_fault(vcpu, gpa, PFERR_RSVD_MASK, NULL, 0); > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 1cec2c62a0b0..930aba87a723 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -5703,7 +5703,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, > * 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; > -- > 2.14.3