Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp630160imu; Fri, 11 Jan 2019 06:29:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN6x6tO/BcBidQgjLE6pbMV6a+oM9HkB7YfUbn7Vz+KdCCmXCkbmYLvX1R7OmZOR//Zk/cUu X-Received: by 2002:a65:50c1:: with SMTP id s1mr13231235pgp.350.1547216951806; Fri, 11 Jan 2019 06:29:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547216951; cv=none; d=google.com; s=arc-20160816; b=ZzXLujal2sz76EhoGTZV42mCBHn0Jwt/vFHRcx5Co93m5vJphtNKII1fK/wmI1QpLF X8fzIkj/Dx66MX91kIREATTYLnanCsFWDVkrQYg78G4Tsou+Jn3IAxAYGbQLgaSfsmtj VCrQF+F6B2Qff+4DKnVXs6v4ugu5SkRgHneYEqgHky9yrK8GE+MigOQXXjUW8M7baBQg cdcwCa2eawu9m9xGfeNWGKji2Jc72sU85LAMksOwFSOscEJ+3xsrPzeZApMpm6FK03g3 1oZHvI6sH8fuDDTMpEO3ee0d/zkWFctzy0a2XdRhnuR5u/3ZnhPC9xyD0in1JIVKmGFv 6g6A== 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=vM/IWGPVlNLJo1SLy3JcPChBO2an8hZ2U9Gbz1Z/0x4=; b=VP9Hwn//zqglo/gLE56M/XNd3H9mv+A5sKtxDQhN08mk6kPi09u3M3sGCm5Wp1pgU9 lSLazWaqDGseyvEZH5UOWmYAOMN+Jf1FTJwd8Fh8zjxYcMY8CMGupYHx710FEXK8DVUY OtCsrpQeWG6bFjaZy3lDbspRoYDAKlpDidrGkJryTZqCgm8spFPDxs0I1U0PywMKLZGl n6k+DLZDBdoYv+irisQtAHVEGEwrGXRRrerLVMe+764NoNHMeBQPyVdUHAYnnTYcdSPi TBdugUCRd+NqiV5vGQ/MB7HXVFaAg13NitawNN/Fl//xCu5Ki9vDHBW0J3P9hPc6wzGR Bubg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ByIaAzDr; 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 39si17843471pla.352.2019.01.11.06.28.56; Fri, 11 Jan 2019 06:29:11 -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=ByIaAzDr; 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 S2388248AbfAKOZS (ORCPT + 99 others); Fri, 11 Jan 2019 09:25:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:35026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387974AbfAKOSd (ORCPT ); Fri, 11 Jan 2019 09:18:33 -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 91D012177B; Fri, 11 Jan 2019 14:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547216312; bh=BXXDzqq8wJtvo7WE24heaNxLLn7VNKQ7c0b93ub0p80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ByIaAzDrs0aGkAi7o3qCcMZmtkaLrooTC5bNLpuxApsalfqNgi6TYDZh6B6M1P7lI HR0kuH6ryKPFG1KL6AOCT77ILipLh2ZczluEMJrTRZYcnw3F2cy+EURqrIwxnELP8d TwwLz9DYzeSDf8i6jcLZvIAirVcye8WHOgCH6/V4= 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.4 54/88] x86/kvm/vmx: do not use vm-exit instruction length for fast MMIO when running nested Date: Fri, 11 Jan 2019 15:08:23 +0100 Message-Id: <20190111131054.124701505@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131045.137499039@linuxfoundation.org> References: <20190111131045.137499039@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.4-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 @@ -6163,9 +6163,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 @@ -5436,7 +5436,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;