Received: by 10.223.185.116 with SMTP id b49csp2080926wrg; Sun, 4 Mar 2018 17:58:33 -0800 (PST) X-Google-Smtp-Source: AG47ELtTgceRUiP4+tzylHA0ZvLJmvMsz3sRULIUzXYPldcOW3HgU7oiIsvx7CAY3ZI+vZ8GPPrk X-Received: by 10.101.73.77 with SMTP id q13mr10745433pgs.336.1520215113485; Sun, 04 Mar 2018 17:58:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520215113; cv=none; d=google.com; s=arc-20160816; b=pCzaIzMADS9btusHFXjr23u3yEyret5rpYaT1KpjmowiKpVEeu9FVgxnbBMgDPcfaw Zj8X3yxIrhCJTuMPxxlNR1Hg6uRCRjXnx6ixbG08d+RmF2BVsqO+mkFLthrkDE1m1DAv 8sJMFS4xMzJF3iTzVmg+ZhrjWeVUtwV9wKheIM3j3DcPzZibsPLLcSVupvxBHQSwHrkA NmtNa8Myr9cIoinOKWd9eSFkVfQuuCXRdz6U6j6gx77+c8S3TmBESWIowKjvLGyWfF2B tm1DaJnPuX+21NTMrCnQjx2sjiSkCjFBBGKYGC8/N6Fr1hOXEuUPM1d6RlfdZSCgP/m3 8R/A== 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=08taLqmelXmf+5OsxBxr+8Poec8kg+xYBOw/3PYWjvQ=; b=DByqulI6NoE1dvxWYoqnKuvYnTLtKpdGn0MW3xGi9tmAuVrHis0wHPqaEHRpMIFtaP S5ynV0ScK23XvYggFmzeOrdEo9w8PUWlCHYqG8/9Is3Mi6PIiSTgyUDbU47OCxcoZdv7 dOX9ohjV18qOAvCJy6wJZWXe36Gq0MVtXaRF9xwDyWtidoLoT8ICnesAUpV7jf96OHtG q0qzeUJQEMxpr8YZ+2n2B+H0tGqEY921340OI/BHFS92SsNqcQygL6v0XlqOTkjiMIuQ HIEAbA/0KBfKwcyL99tcnyZmzNfVER4fwncEyRIqewpd/P2xw4If0nhTq7gfx/RsSkfa rCZw== 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 m68si3445819pfm.171.2018.03.04.17.58.19; Sun, 04 Mar 2018 17:58:33 -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; 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 S932677AbeCEB5Z (ORCPT + 99 others); Sun, 4 Mar 2018 20:57:25 -0500 Received: from mga14.intel.com ([192.55.52.115]:39574 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932649AbeCEB5S (ORCPT ); Sun, 4 Mar 2018 20:57:18 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Mar 2018 17:57:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,425,1515484800"; d="scan'208";a="21986120" Received: from vmm.bj.intel.com ([10.238.135.172]) by fmsmga008.fm.intel.com with ESMTP; 04 Mar 2018 17:57:16 -0800 From: Luwei Kang To: kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, linux-kernel@vger.kernel.org, joro@8bytes.org, Chao Peng , Luwei Kang Subject: [PATCH v5 10/11] KVM: x86: Set intercept for Intel PT MSRs Date: Sun, 4 Mar 2018 20:07:20 +0800 Message-Id: <1520165241-15819-11-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520165241-15819-1-git-send-email-luwei.kang@intel.com> References: <1520165241-15819-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 interrcept 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 16943a8..0a55772 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -935,6 +935,7 @@ static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12, static void __always_inline vmx_disable_intercept_for_msr(unsigned long *msr_bitmap, u32 msr, int type); static bool vmx_pt_supported(void); +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); @@ -3713,6 +3714,7 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) return 1; vmcs_write64(GUEST_IA32_RTIT_CTL, data); vmx->pt_desc.guest.ctl = data; + pt_set_intercept_for_msr(vmx, !(data & RTIT_CTL_TRACEEN)); break; case MSR_IA32_RTIT_STATUS: if (!vmx_pt_supported() || @@ -5496,6 +5498,24 @@ 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.range_cnt; i++) + vmx_set_intercept_for_msr(msr_bitmap, MSR_IA32_RTIT_ADDR0_A + i, + MSR_TYPE_RW, flag); +} + static bool vmx_get_enable_apicv(struct kvm_vcpu *vcpu) { return enable_apicv; -- 1.8.3.1