Received: by 10.223.176.46 with SMTP id f43csp948494wra; Fri, 26 Jan 2018 09:20:56 -0800 (PST) X-Google-Smtp-Source: AH8x227K/hmyOBwQBejrmb8NaM+R0Bc7O4coLJm1pH5nWV7YFlZQZeA5yZP5r0/bWHw1L5lRMaga X-Received: by 2002:a17:902:62:: with SMTP id 89-v6mr14539488pla.284.1516987255936; Fri, 26 Jan 2018 09:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516987255; cv=none; d=google.com; s=arc-20160816; b=bTjoqJQHftNbN3dCPA87Nl15/JHtPt7r/Pxvdl+qkp8UVbcbX6Mh3V4MFHfA+gcQFd Fg+RTAlxBJwsLxAK61n61+gpwm7izOcg1rP6aCkGk96enU7WnvCLVyzbl7voH0mY7LEY YSGY1wks3yt/v5fbH5NInBCnDc0X9/djXiZhzdLyQIFQRyQO7mvDUUZZnJUu/6YfJXST /z9Lonv5iM5pgIe6e3CNlXwELJ8t/3i4YkRNbDnh0mrsXdVtt5hqPX98+0FMtQAH0WKG stPLeFQyJGWrT6D6nSpQop4QOZBucz03HXyTQsRLUHGFIhyuwegbgOz7ctkkLrUMJLYu WZtQ== 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=JLan03Vjxp/MTqFAMsNKPsgKXmoZk5WdnS+ja6SsVZ8=; b=OXrNRNuTdlpfWNxMcUXa6gb7k7Tk+FBjm0tatX7oLwyTJGCICRx7HI/twj17v8hlQw lbQRExWps+iPfFQ//6OgMoKGQ2QzEtbw94A2Ikb2BeZnSU2zUW1R7hA1uz4vqtoAufLV rqjmYdPojY1O83nIhs+gDxgW6Q0Jy0sapkPkf9rMaGcW/7ZMAMLrTgZfFoFvU74iStYz HbjGCyASvgOm4olsT0ZHawwDJeZDSbgkZmbi6HX6ZhYW3sZl6qXZy7Laf+P6IS3kI1QX xAv7LdmgoJ7nkYSjGo8s8PTyAmuJsTq0HfQC7twsC2cq4LClEsbNtODw7/BeZVFV8DNp 8fXQ== 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 k9-v6si3988497pll.578.2018.01.26.09.20.42; Fri, 26 Jan 2018 09:20:55 -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 S1751639AbeAZRTZ (ORCPT + 99 others); Fri, 26 Jan 2018 12:19:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56480 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751540AbeAZRTX (ORCPT ); Fri, 26 Jan 2018 12:19:23 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 877911752CA; Fri, 26 Jan 2018 17:19:23 +0000 (UTC) Received: from redhat.com (ovpn-123-92.rdu2.redhat.com [10.10.123.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 477FB5EE0E; Fri, 26 Jan 2018 17:19:22 +0000 (UTC) Date: Fri, 26 Jan 2018 19:19:21 +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: <20180125190353-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 26 Jan 2018 17:19:23 +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 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