Received: by 10.223.176.46 with SMTP id f43csp1801057wra; Wed, 24 Jan 2018 23:56:40 -0800 (PST) X-Google-Smtp-Source: AH8x226XvJypkq+g4cl6icl/Fbg41sBdbp8F0x9+zXQyfzHPQ4a6DYIpgNv5FwP/a4MKKqgINSBK X-Received: by 2002:a17:902:2cc3:: with SMTP id n61-v6mr10392067plb.440.1516867000719; Wed, 24 Jan 2018 23:56:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516867000; cv=none; d=google.com; s=arc-20160816; b=l2jKXjAc4od/tPI8vefe+tTEufzrw3HohQFclviG0qHCQbyMt6YpOk5Dm9Y6z2rbJe v6p2O3CUCR8Tf/cX8J6S7zX6iXfdhDvmQ2GwmmZFbT3OnZQbuM7njwyq6vNhsHFi4TMk CHUxxaoJKj1zXcIU6Dp3i/FWagSjBT+k/6jKO/Ydn4hLOwb7qnlmt5uS8OI6CyTJistI yVQx4YOe4Sg2aBzFfO9c/1GJFMEJcGQrFxDUhp7Tnikb8Ics5pM4U13S6+zLH+sZV9I6 9tyUfsQo59/33AZjM450hrj03oZtVIlc1+NRSa2zAscIjb0X/ao0fx0tUAfS/05Yezfc qMmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=GJgQHmXUClptK/Y8AWpitv0GvKIcS9gqk7n5WyQVivA=; b=rYYSG1KLeMwgXp9i28pP0WZsVfCjVcTTfRHvddf8dGVkI61tyoLc0i4A8jtvtw8w2k iPlsP+4p3H5M+QYrEm5GZfzzreNl44Yg1Xcj+xmw3G25wv4yQLEPJupm+ODSULxmTb3f gf1J0f0IXgouWLIiPsU3kXBP1S/0e16q8d9ZkbmJEKet79+U9YvvwY1pMKV8fyQGlGph 0oChe6AHUv0ind+s84QMd1gRXbiSttvuIyKgJcwzaQFtJKWUvzoofSy3uIBy8qxtUZss Y3m9mqJ3GEhNESVAZ3iH65lYPk2yHopeJ1//vmvO+//UMal4I29Crd9CyTfKPNWj+46F HW7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZDpPcA9J; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d24-v6si1583152plr.243.2018.01.24.23.56.26; Wed, 24 Jan 2018 23:56:40 -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=@gmail.com header.s=20161025 header.b=ZDpPcA9J; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751259AbeAYHz6 (ORCPT + 99 others); Thu, 25 Jan 2018 02:55:58 -0500 Received: from mail-oi0-f66.google.com ([209.85.218.66]:33238 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751081AbeAYHz5 (ORCPT ); Thu, 25 Jan 2018 02:55:57 -0500 Received: by mail-oi0-f66.google.com with SMTP id y141so4672788oia.0; Wed, 24 Jan 2018 23:55:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=GJgQHmXUClptK/Y8AWpitv0GvKIcS9gqk7n5WyQVivA=; b=ZDpPcA9JKLZ4Gjbp/PcDb1+/Ssh4yvcQNMlsAXWMLHfkOQ7tWL9/Hr9g1GyYORgR0W wWyv/wb4LDSI5VoOe2XRNjK0hulnkG7iuj8Qcft33HTk0nx54rLF+gWLVEbFxmL8ysmf 241nk6i9V3d54UA4b2MyGEUHg2DRW4c1r9HUjUG/LIJIwd6pHJdESO4JQkxCKJd5WRpy t6bcG8KhQ63eEKxjoxY4w3RvJUcPjCRLFzh6f30jvnFIwoq0XlDwgOCtpQd/YxkwLigq 8C8ZS5F5zoHvuB7DFVZWbImLS9pDR5hxyCexs0h37uS1g7Up3CHnuc8P9ZJLtbpKagZe KZBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=GJgQHmXUClptK/Y8AWpitv0GvKIcS9gqk7n5WyQVivA=; b=lOdcfaGYWiQlaYbLmbbtiGAe0+a7vcztYxe4HYjCRJX9tQxbDThzXYWmBCTaloHoAh XOR/SFBbQb13OucX6fTzJZzwgbEIbcKjjkZa8kzPEMZf7+MBzsM8jiNdr0OMU7z8EIpd Kj5i7P//U80B9YPzkEDf4o5D+izf5lCaqjhaERW5qBYq0ekVieg8nzgacKBRUKiVoOyS v0bMivr+mXrthnY5qlDue2RS2OvD7Le6ovXmDmaXKg+1vPWt7MU/HR7zrjp6BN421ivS vdK8OXNs365pyoTnUEG+TH1BL+GPO1i1xQTe7/ASwz6/xl584Yw8UzzgWsdT0szeaqyF svLA== X-Gm-Message-State: AKwxytda2VkAREJQ1boVQ6s/He1XMHfmfmjQrLKkMpO1m4WQ2+St/kq2 2BqXbB1WfQPPbpym/U6g/qPPoyDV+bVmnZPNxCI= X-Received: by 10.202.114.65 with SMTP id p62mr9514712oic.271.1516866955552; Wed, 24 Jan 2018 23:55:55 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.108.81 with HTTP; Wed, 24 Jan 2018 23:55:55 -0800 (PST) In-Reply-To: <20180124151234.32329-1-vkuznets@redhat.com> References: <20180124151234.32329-1-vkuznets@redhat.com> From: Wanpeng Li Date: Thu, 25 Jan 2018 15:55:55 +0800 Message-ID: Subject: Re: [PATCH] x86/kvm: disable fast MMIO when running nested To: Vitaly Kuznetsov Cc: kvm , "the arch/x86 maintainers" , linux-kernel@vger.kernel.org, Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-01-24 23:12 GMT+08:00 Vitaly Kuznetsov : > 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 disabling fast mmio when running nested. > > Signed-off-by: Vitaly Kuznetsov Reviewed-by: Wanpeng Li > --- > arch/x86/kvm/vmx.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index c829d89e2e63..54afb446f38e 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -6558,9 +6558,16 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu) > /* > * A nested guest cannot optimize MMIO vmexits, because we have an > * nGPA here instead of the required GPA. > + * Skipping instruction below 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. > */ > gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); > - if (!is_guest_mode(vcpu) && > + if (!static_cpu_has(X86_FEATURE_HYPERVISOR) && !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); > -- > 2.14.3 >