Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1035976imm; Mon, 21 May 2018 19:59:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpSsz70si7bsfPvfIgkrmx5OFRZu3tHBscBaD76N3Oe4C0p+GWYLZ46HZfrWQ9Vo2D305GS X-Received: by 2002:a62:d9d9:: with SMTP id b86-v6mr22458571pfl.41.1526957993797; Mon, 21 May 2018 19:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526957993; cv=none; d=google.com; s=arc-20160816; b=NNwb65+4XdPUI6gArrnpHVkOzmtieRqF2E4roU+MDh/RIWnK6NJ03vGuJFnPpxJL1Z OrisjnDurja3nj+0PtLISRBOXPl2qGnMmd0dc8tR8Xwz7WCrdUpzDTKIjj0tTs1/CsZb 7uDTGk8h+09E6TlR89qTocExYMOI9jDyM4vnwBSS7vKlfI4HHrrOAHbzu4UWZYMRiWZD e04JdYPDhPbj50NucEKMb8gInQ2ExruxYsEgm3hDkCdD6GBX46UBN6pUrRU7opwq0z5C PNhKSS2irIJ72YUiN+QgpqHovWNyrv7t7pEU4L81OiFzNfpY12aNTClb141K9m2EEku0 BMUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=XNZeqJM26NC4Bz31LKr/e6Qi2Yxu925SXvy1ro79BCE=; b=P/S153sKTcsoWkeLSCvPqRH2DmGE+eakQwwoOU4pzZ+cg2nUgouTippbkwZnQVxyUN g8rU5QgcF5ROluvCkVOM7eJfeYoYFJK0vaUdV3HN38e5Jl31md7tgqJLd+TE4v6jVeu+ LfYj4gdv76e1uIjD/7wKCT+ih+6QU14iSUZD4LMknr+NAj/bnQVgztNhYCgG323Spzoj QZqU5pYCA0zBvfRB7T3AymPeOAxVFE0S3CE+9lSt8ZxYXWJ7DS2lPXvJibURgZYrEUpj 5SvKvNraM0RLVvpMU8rg1ODTjNb5tifKnHkKImQxXP/nMhgUF2Wt7b/IU9EBY1dky19h 0EcA== 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 j11-v6si12429005pgt.497.2018.05.21.19.59.39; Mon, 21 May 2018 19:59:53 -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 S1752824AbeEVC67 (ORCPT + 99 others); Mon, 21 May 2018 22:58:59 -0400 Received: from mga03.intel.com ([134.134.136.65]:35511 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752791AbeEVC6z (ORCPT ); Mon, 21 May 2018 22:58:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 May 2018 19:58:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,428,1520924400"; d="scan'208";a="201336054" Received: from skx-d.bj.intel.com ([10.238.154.68]) by orsmga004.jf.intel.com with ESMTP; 21 May 2018 19:58:50 -0700 From: Luwei Kang To: kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, chao.p.peng@linux.intel.com, thomas.lendacky@amd.com, bp@suse.de, Kan.liang@intel.com, Janakarajan.Natarajan@amd.com, dwmw@amazon.co.uk, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, peterz@infradead.org, mathieu.poirier@linaro.org, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, pbonzini@redhat.com, rkrcmar@redhat.com, david@redhat.com, bsd@redhat.com, yu.c.zhang@linux.intel.com, joro@8bytes.org, Luwei Kang Subject: [PATCH v9 11/12] KVM: x86: Set intercept for Intel PT MSRs read/write Date: Tue, 22 May 2018 12:52:14 +0800 Message-Id: <1526964735-16566-12-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1526964735-16566-1-git-send-email-luwei.kang@intel.com> References: <1526964735-16566-1-git-send-email-luwei.kang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chao Peng Disable intercept Intel PT MSRs only when Intel PT is enabled in guest. But MSR_IA32_RTIT_CTL will alway be intercept. Signed-off-by: Chao Peng Signed-off-by: Luwei Kang --- arch/x86/kvm/vmx.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 770cb7c..a09157c 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -948,6 +948,7 @@ static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12, static void vmx_update_msr_bitmap(struct kvm_vcpu *vcpu); static void __always_inline vmx_disable_intercept_for_msr(unsigned long *msr_bitmap, u32 msr, int type); +static void pt_set_intercept_for_msr(struct vcpu_vmx *vmx, bool flag); static DEFINE_PER_CPU(struct vmcs *, vmxarea); static DEFINE_PER_CPU(struct vmcs *, current_vmcs); @@ -3999,6 +4000,7 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) vmx_rtit_ctl_check(vcpu, data)) return 1; vmcs_write64(GUEST_IA32_RTIT_CTL, data); + pt_set_intercept_for_msr(vmx, !(data & RTIT_CTL_TRACEEN)); vmx->pt_desc.guest.ctl = data; break; case MSR_IA32_RTIT_STATUS: @@ -5820,6 +5822,27 @@ static void vmx_update_msr_bitmap(struct kvm_vcpu *vcpu) vmx->msr_bitmap_mode = mode; } +static void pt_set_intercept_for_msr(struct vcpu_vmx *vmx, bool flag) +{ + unsigned long *msr_bitmap = vmx->vmcs01.msr_bitmap; + u32 i; + + vmx_set_intercept_for_msr(msr_bitmap, MSR_IA32_RTIT_STATUS, + MSR_TYPE_RW, flag); + vmx_set_intercept_for_msr(msr_bitmap, MSR_IA32_RTIT_OUTPUT_BASE, + MSR_TYPE_RW, flag); + vmx_set_intercept_for_msr(msr_bitmap, MSR_IA32_RTIT_OUTPUT_MASK, + MSR_TYPE_RW, flag); + vmx_set_intercept_for_msr(msr_bitmap, MSR_IA32_RTIT_CR3_MATCH, + MSR_TYPE_RW, flag); + for (i = 0; i < vmx->pt_desc.addr_range; i++) { + vmx_set_intercept_for_msr(msr_bitmap, + MSR_IA32_RTIT_ADDR0_A + i * 2, MSR_TYPE_RW, flag); + vmx_set_intercept_for_msr(msr_bitmap, + MSR_IA32_RTIT_ADDR0_B + i * 2, MSR_TYPE_RW, flag); + } +} + static bool vmx_get_enable_apicv(struct kvm_vcpu *vcpu) { return enable_apicv; -- 1.8.3.1