Received: by 10.213.65.68 with SMTP id h4csp876834imn; Tue, 27 Mar 2018 10:24:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx48UlXdP0BROqSQQZ7zWnVCjpcW8aCVbzyAYbXAlww/C1wHiLO531njhBBoklhe9fSl+RawC X-Received: by 10.98.232.25 with SMTP id c25mr161017pfi.35.1522171475573; Tue, 27 Mar 2018 10:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522171475; cv=none; d=google.com; s=arc-20160816; b=uXAypwEQXIjZZlxVvZj8s//cLtOFT3DeG/6GJBqlXO/lww2F5tlQW8uHS67JDIDRIR l2Un8OeqW7nG6/crAZhdEH4thPb9Dk19KmEIcLMozFZcEZhJ5z9xTT7Yh/Zloe7l2UjF +dLd519bIWCubw6/G+XDYWM94tLSnxt2JteuLy7Tvi50UWswMbhqc73ndhgSGLcSu6y1 OPpRyYMLBMbjcioWw8PRMV/55J74q8LW5QmWQOjmSikY+1wOkLCPgNi4q0yRKvhpm9sB oBfTuTeOmbk7Thjupc3rdD08scXggqNeowtIT6n7Loi/Q48Og6RVFknxAojyMV3709WM gQ1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=WJG1GfcNy12ssLz5gp0/0+gwKhVB7RtlQ7/wIc/P3+4=; b=VY+EKYhCJPFLI8LuAOTF+UAwKx8wx2OCgqjQEUK6Co7VcattlmxDll7dXbnTjZkcN7 7y+iTptSlfCgg5AwyCHIeBHsjAh5gL56lhzXFBJS1XECxRPAyikvMJoq99X4/ID+7i7E XO01jlgmoW+Ta/SVPgyrChcxOQ6fAhfayT76JqB1UbZhBEEboSGhjI/wX+aBkC/e30/C 84jxx3z+n/AjBPibPMZRta+yYwed9kU6xT0NP6jT5pEESjcRKSet5TLE3NPpnbic3yo9 LjY1tfQ1AIco4MEq4CX5o4TK9gPXnJW2U1kkf0uORM1PwmwHTT20w6OF9zs3mWviuOx1 DP1Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si1118565pgs.22.2018.03.27.10.24.21; Tue, 27 Mar 2018 10:24:35 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754954AbeC0Qhb (ORCPT + 99 others); Tue, 27 Mar 2018 12:37:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46294 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754591AbeC0Qh3 (ORCPT ); Tue, 27 Mar 2018 12:37:29 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E363FFB0; Tue, 27 Mar 2018 16:37:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Paolo Bonzini , Linus Torvalds Subject: [PATCH 4.14 083/101] kvm/x86: fix icebp instruction handling Date: Tue, 27 Mar 2018 18:27:55 +0200 Message-Id: <20180327162755.171122162@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linus Torvalds commit 32d43cd391bacb5f0814c2624399a5dad3501d09 upstream. The undocumented 'icebp' instruction (aka 'int1') works pretty much like 'int3' in the absense of in-circuit probing equipment (except, obviously, that it raises #DB instead of raising #BP), and is used by some validation test-suites as such. But Andy Lutomirski noticed that his test suite acted differently in kvm than on bare hardware. The reason is that kvm used an inexact test for the icebp instruction: it just assumed that an all-zero VM exit qualification value meant that the VM exit was due to icebp. That is not unlike the guess that do_debug() does for the actual exception handling case, but it's purely a heuristic, not an absolute rule. do_debug() does it because it wants to ascribe _some_ reasons to the #DB that happened, and an empty %dr6 value means that 'icebp' is the most likely casue and we have no better information. But kvm can just do it right, because unlike the do_debug() case, kvm actually sees the real reason for the #DB in the VM-exit interruption information field. So instead of relying on an inexact heuristic, just use the actual VM exit information that says "it was 'icebp'". Right now the 'icebp' instruction isn't technically documented by Intel, but that will hopefully change. The special "privileged software exception" information _is_ actually mentioned in the Intel SDM, even though the cause of it isn't enumerated. Reported-by: Andy Lutomirski Tested-by: Paolo Bonzini Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/vmx.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -352,6 +352,7 @@ enum vmcs_field { #define INTR_TYPE_NMI_INTR (2 << 8) /* NMI */ #define INTR_TYPE_HARD_EXCEPTION (3 << 8) /* processor exception */ #define INTR_TYPE_SOFT_INTR (4 << 8) /* software interrupt */ +#define INTR_TYPE_PRIV_SW_EXCEPTION (5 << 8) /* ICE breakpoint - undocumented */ #define INTR_TYPE_SOFT_EXCEPTION (6 << 8) /* software exception */ /* GUEST_INTERRUPTIBILITY_INFO flags. */ --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -1071,6 +1071,13 @@ static inline bool is_machine_check(u32 (INTR_TYPE_HARD_EXCEPTION | MC_VECTOR | INTR_INFO_VALID_MASK); } +/* Undocumented: icebp/int1 */ +static inline bool is_icebp(u32 intr_info) +{ + return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK)) + == (INTR_TYPE_PRIV_SW_EXCEPTION | INTR_INFO_VALID_MASK); +} + static inline bool cpu_has_vmx_msr_bitmap(void) { return vmcs_config.cpu_based_exec_ctrl & CPU_BASED_USE_MSR_BITMAPS; @@ -6169,7 +6176,7 @@ static int handle_exception(struct kvm_v (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) { vcpu->arch.dr6 &= ~15; vcpu->arch.dr6 |= dr6 | DR6_RTM; - if (!(dr6 & ~DR6_RESERVED)) /* icebp */ + if (is_icebp(intr_info)) skip_emulated_instruction(vcpu); kvm_queue_exception(vcpu, DB_VECTOR);