Received: by 10.192.165.148 with SMTP id m20csp1656648imm; Thu, 3 May 2018 03:17:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo450/VesJT6Y5J8BSN37+UHIEL3lHFSy0ic7WoUtNa7Jtfww290yxS4bakP6L0hLop42vT X-Received: by 2002:a63:4004:: with SMTP id n4-v6mr8456302pga.104.1525342638078; Thu, 03 May 2018 03:17:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525342638; cv=none; d=google.com; s=arc-20160816; b=Ao8B5QEP40Zmn7l1MHHt+F+PVFYaeL8eGDpdtW9PY6vvUimorJ4QwXqHGMhAaARF68 VN3hFAq41WP4BsX3hXla64zgAj5ypCZEjYleUIAc5HYoOjRCX3VWBvxoiBfUKz4PHjs7 Skgax5UJnzV+ohmx8zc44DJUbGZH6DJHTxf4uwo6QeiArU3WSmsV1I8h9flDav6xifcD Lm8KVnj3bqsk5S6uVkTVO/wKm+AxB33WDpILHmxV/zMhc77cz9CrnBzALFxhag9CSaay wIJFdQOFpBqJDAd8CMMGHP4Ya0bqaYOAsxzeUR782FqVn9wXH0b4KWLQu9VCgSv6ge2m HGPA== 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=RymRh3X56Ge81J4qP72b+JKQOYh6+zcYx6uhZjYJ1BA=; b=L3ER4VxuAU9IH9XLXxhqPFNGM38biGbCaPnnwPbZlH9Db8sHaI12BRaxzcg6CyC9ov uS1s9tQv/IRRG+GDaK+Q+REkgb6MPrTH8aB0LZu70pwadSiswNtxVEZmKtVHvWsyM1KP MnkfZyYiomHS3gI8U0O+o6UEPjs3vNB760GquYEsJ9m3I8OLvX6/sc9PMjrPIduVhUoX MmKyFC87P/sA6JtDfxVQkJwpvTM+RxiN3dO52yfQIWdjl3XnV5SSiFZf/RBrFE+iIvF9 18xY0pwRtt5w1U2THxjK9Af5XSygf0WLQIjVynYRO7jyLpsJ1igDd4QhU9DS7Ihq09ox ENLA== 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 n71si13605412pfk.277.2018.05.03.03.17.03; Thu, 03 May 2018 03:17:18 -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 S1752219AbeECKP6 (ORCPT + 99 others); Thu, 3 May 2018 06:15:58 -0400 Received: from mga03.intel.com ([134.134.136.65]:44416 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751611AbeECKPY (ORCPT ); Thu, 3 May 2018 06:15:24 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2018 03:15:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,358,1520924400"; d="scan'208";a="38109897" Received: from unknown (HELO skx-d.bj.intel.com) ([10.238.154.68]) by orsmga007.jf.intel.com with ESMTP; 03 May 2018 03:15:21 -0700 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, peterz@infradead.org, chao.p.peng@linux.intel.com, Luwei Kang Subject: [PATCH v7 12/13] KVM: x86: Set intercept for Intel PT MSRs read/write Date: Thu, 3 May 2018 20:08:42 +0800 Message-Id: <1525349323-9938-13-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525349323-9938-1-git-send-email-luwei.kang@intel.com> References: <1525349323-9938-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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 2a29ab9..c125fb1 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); @@ -3954,6 +3955,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: @@ -5761,6 +5763,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