Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp180916ybh; Tue, 17 Mar 2020 20:51:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvPIDhSoJto0dN6aegIP/8aNmULi0cXC/q0qgzfXfX6o2ymKW2I0lPnRcJITORPBfUyW0mI X-Received: by 2002:a9d:372:: with SMTP id 105mr2128495otv.15.1584503514442; Tue, 17 Mar 2020 20:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584503514; cv=none; d=google.com; s=arc-20160816; b=oOq7ISlEn2Nv2HM9iyawfjql1zSCY7BoFbg9/3SfUIzvg/cpFLW+6BdUr7JwEAfelx z8y+Eg2He5ynJu7r1uANGolgrTtHa/N4M/rPW7iIO55SYiDr+GsC/Aq0kFMbWNJHIPy0 2Wf8NQxWK30a2+AKhpJvK8uXcNshLxT4CcWvfxQovT/b4tZc/v2FxOVZ2eE3baiGN+iz D031CWnxED1fxuITxTpbyTk+AP0VdY4d43imOjM8+uZiwSTkQ10KDrrr8B3waHwWUsP+ h9xscfslRJuklQyVXgoUdylyuE4BGhualpCiRhkvwvSz6Yio4JzZH+HnTG/UOczeZjs1 bi0g== 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 :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=AH4crZuTXGefjJPQJnXzOAK7vHHFeHJkbFn7bwmG7F4=; b=AImF9M+blp11vCRWUeaC3H1BIHcc+e2JC+uVmJltQ9hNen61ILf19d1ZYeIjv4J0yU RSV/jS3OZ3i8pSRSzXEupBL0NNyI/kAZoUX3Vff+g+P/6neAXIu2z5rqkfBfjk44mFvP VJkWOJyZl+EceJPz9nrNb+GDyNUsjPYioqX1e9NOHhR/sZTlQ3yQmwWAJ63/JIxARb8r EOT4ueGerbpFny6sy4M6G+HIHekdw3muamytWMEWqlcjmE37J8OHwHvQBmsCZ/74nGiN 1csgEqBGBA3Nj/WhxNfPbZVF1erbyAV8csP5m8LSJFifAsGbj/pxv7+kIAdnz7uDzKGX pfEA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s139si2665452oih.7.2020.03.17.20.51.41; Tue, 17 Mar 2020 20:51:54 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727133AbgCRDvM (ORCPT + 99 others); Tue, 17 Mar 2020 23:51:12 -0400 Received: from mga14.intel.com ([192.55.52.115]:57668 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726229AbgCRDvL (ORCPT ); Tue, 17 Mar 2020 23:51:11 -0400 IronPort-SDR: JiYt3whZZc5rWcXYQjE9lZ0QWtm+Lx4F1ybZGVxtr7O+lvkYsIwK7Mr5yLmjyIXlkER81tSf3q a4C7MRwCGRLw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2020 20:51:11 -0700 IronPort-SDR: 9bUF4H9QQNe3a8MQitbBFyw8f9tSiDyCfhjvRRegxTcaEa61P4rY7aAkTgy9i/WeNGTaHtWTYI 3rVfHzAzi7vg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,566,1574150400"; d="scan'208";a="268215257" Received: from icx-2s.bj.intel.com ([10.240.192.138]) by fmsmga004.fm.intel.com with ESMTP; 17 Mar 2020 20:51:09 -0700 From: Luwei Kang To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, sean.j.christopherson@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, Luwei Kang Subject: [PATCH] KVM: VMX: Disable Intel PT before VM-entry Date: Wed, 18 Mar 2020 11:48:18 +0800 Message-Id: <1584503298-18731-1-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 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 If the logical processor is operating with Intel PT enabled ( IA32_RTIT_CTL.TraceEn = 1) at the time of VM entry, the “load IA32_RTIT_CTL” VM-entry control must be 0(SDM 26.2.1.1). The first disabled the host Intel PT(Clear TraceEn) will make all the buffered packets are flushed out of the processor and it may cause an Intel PT PMI. The host Intel PT will be re-enabled in the host Intel PT PMI handler. handle_pmi_common() -> intel_pt_interrupt() -> pt_config_start() This patch will disable the Intel PT twice to make sure the Intel PT is disabled before VM-Entry. Signed-off-by: Luwei Kang --- arch/x86/kvm/vmx/vmx.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 26f8f31..d936a91 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1095,6 +1095,8 @@ static inline void pt_save_msr(struct pt_ctx *ctx, u32 addr_range) static void pt_guest_enter(struct vcpu_vmx *vmx) { + u64 rtit_ctl; + if (pt_mode == PT_MODE_SYSTEM) return; @@ -1103,8 +1105,14 @@ static void pt_guest_enter(struct vcpu_vmx *vmx) * Save host state before VM entry. */ rdmsrl(MSR_IA32_RTIT_CTL, vmx->pt_desc.host.ctl); - if (vmx->pt_desc.guest.ctl & RTIT_CTL_TRACEEN) { + if (vmx->pt_desc.host.ctl & RTIT_CTL_TRACEEN) { wrmsrl(MSR_IA32_RTIT_CTL, 0); + rdmsrl(MSR_IA32_RTIT_CTL, rtit_ctl); + if (rtit_ctl) + wrmsrl(MSR_IA32_RTIT_CTL, 0); + } + + if (vmx->pt_desc.guest.ctl & RTIT_CTL_TRACEEN) { pt_save_msr(&vmx->pt_desc.host, vmx->pt_desc.addr_range); pt_load_msr(&vmx->pt_desc.guest, vmx->pt_desc.addr_range); } -- 1.8.3.1