Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4071822imm; Mon, 14 May 2018 02:04:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqSLBxFbJU608ED3Ez0byB0kTL/FM404P8DBh/q7yFzBLTTXbAJL4e/Flwzid3qf06KvU6V X-Received: by 2002:a63:ac1a:: with SMTP id v26-v6mr7909723pge.105.1526288673162; Mon, 14 May 2018 02:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526288673; cv=none; d=google.com; s=arc-20160816; b=dAswL+S1shpvFmyHGevMGvWKotFNFNBSqoEnfIvTLfrWzfpkAXCmvij7AbAQpTpTC6 kRO5+pAorFPx7uEcB0b615IhnG0j5Jtv3aUyCMkBDEl+ZVWRFS3WdUy28Mil7DX5wPXY 6WZnp/oOIkZ8PyZ5RNDIJs1WPqMfSZV+begGE49QEfCB9nWPhCCT4qUKyavsirSfDTWz A3zcrErx3OO4UflsO3b4cU63wnNa/eNV/tITnBNaAKDeStN0j4sUTqaTnVuYiIIYnTli rg+NrqQ8IOB8y6jUAJC9OvM0F7uuso2bs9QQjaFIqS9GqdPDagB4yuNALy2jam2pPcxS eZzA== 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=oRLnxTEOfsqScAP04o2s1OgepAZMo3cuwRMZ1Ox5taI=; b=sFPmZCS/689FYxu7Yeujx8mn0M6JFBtenl3F+mqFL4b5kgnW93aAxf17/DkiMxgv0R 54baN/j/C+NI059CHS3VWiyHKqeF9OanigequOO7UyZmo50kJubnGbimY6Yy/b1315D9 v4LHKte62m0b+OE6s5eOF8QMYmdEWp9qT2uk4ijfy6ax545UQZdE1LeHgVzjUWsUCUeA NoSLIqUGgvGdfkMgBSIU+9bN3pXIE0lElj0I1YOZaerBEapgRR2nHWUWud32E8iC4YfO xWVZaugnn0psXeddY2muZmf4bhWtxYg4d08mdPlY65R6cgpPSW50/VoLr/0bQn23DZCG uxyg== 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 h68-v6si7274559pgc.158.2018.05.14.02.04.19; Mon, 14 May 2018 02:04:33 -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 S1752600AbeENJDu (ORCPT + 99 others); Mon, 14 May 2018 05:03:50 -0400 Received: from mga07.intel.com ([134.134.136.100]:60897 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752436AbeENJDo (ORCPT ); Mon, 14 May 2018 05:03:44 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2018 02:03:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,399,1520924400"; d="scan'208";a="39701980" Received: from skx-d.bj.intel.com ([10.238.154.68]) by fmsmga008.fm.intel.com with ESMTP; 14 May 2018 02:03:40 -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 v8 11/12] KVM: x86: Set intercept for Intel PT MSRs read/write Date: Mon, 14 May 2018 18:57:11 +0800 Message-Id: <1526295432-20640-12-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1526295432-20640-1-git-send-email-luwei.kang@intel.com> References: <1526295432-20640-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 d04b235..170cd48 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -947,6 +947,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); @@ -3998,6 +3999,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: @@ -5819,6 +5821,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