Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2212660imm; Thu, 7 Jun 2018 07:09:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJy0U593xGdG4su+bJkr9bOTAenJpOuPpMAHwdd5lksHkApsevRe7j1p2Cfto1muMCRuBEs X-Received: by 2002:a17:902:57d8:: with SMTP id g24-v6mr2287648plj.116.1528380598416; Thu, 07 Jun 2018 07:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528380598; cv=none; d=google.com; s=arc-20160816; b=EgebfAQrNzNUWa+jW0vSOg3LQeqpbVvcljd1L0pOcbPfZuEJ/ULPSNFreJiMPEZV1w BPNJirAQ1qsrR38TbQQ12cbKufeHWio3Jes27WqYbYNNicocYHHMiMMnR/LolxaCXThl opJckPkcRzqVjZtbMVBRAje+Mwe/s4sRUV3jRobs7P8FhuMbsaNYlWG2Hi71WhMZmCEV weQlkV9U3puVvt1WVNcf7DSKaEfgMmfuRGmcqBQqgpEp8py+ZE9XryitiX61qB5TmWvH NJXI0g5fVkHsf8vh9J5WqPo44Cg25AgPH0FKZej8HkTluWUbwEvVue3yywVfyHxRUo9W Gs1A== 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:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=uWD+4DqxezkLEu0sbXCQ1XIW1Vzj/EC3UMTP+JlOT8k=; b=EHGpMZO3ho3Gi0RIpM9JgYbsfVpYUvEH0OPAWw4d0ex9NUl8ZpePGgiSYW23cP5E+P 75ap7BOhrRKQgWIevl86O9VKAEkG7+9FRq0jQeJ7pDsxEbHGf/0exjusTZ526IdmnVoj cW1srJRFuouiMEKm9bd+WdJVUH0dU1rF4Z0/cre91BfIBgCcVo3kNwi7lNtL57ZPbfeY yXRDoAbpk0qXBy6pcKNMS6BIDYrK9bZ0Nu9fT+VZU2LJ21OCs1YFkXXVkMzGb2DKIRL/ pqV1StNpgPse7nKpNqDnU4xaP9IlYBf/7DwZDDE0tjnhtsIX0c+MRF88670f3Ln/HVjh W9bg== 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 s4-v6si28279459pgc.634.2018.06.07.07.09.40; Thu, 07 Jun 2018 07:09:58 -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 S933037AbeFGOJG (ORCPT + 99 others); Thu, 7 Jun 2018 10:09:06 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39108 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932878AbeFGOI6 (ORCPT ); Thu, 7 Jun 2018 10:08:58 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvay-0005Zz-KV; Thu, 07 Jun 2018 15:08:56 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvax-0002hO-Jf; Thu, 07 Jun 2018 15:08:55 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Linus Torvalds" , "Andy Lutomirski" , "Paolo Bonzini" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 017/410] kvm/x86: fix icebp instruction handling In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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 [carnil: Backport to 3.16: adjust context] Signed-off-by: Ben Hutchings --- 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 @@ -296,6 +296,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 @@ -868,6 +868,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; @@ -4915,7 +4922,7 @@ static int handle_exception(struct kvm_v (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) { vcpu->arch.dr6 &= ~15; vcpu->arch.dr6 |= dr6; - if (!(dr6 & ~DR6_RESERVED)) /* icebp */ + if (is_icebp(intr_info)) skip_emulated_instruction(vcpu); kvm_queue_exception(vcpu, DB_VECTOR);