Received: by 10.192.165.148 with SMTP id m20csp1659767imm; Thu, 3 May 2018 03:20:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpPpUZ45A++KXcMDP+e0KuIFHJ+iVeIRcpnkeqI0jm0yK9Gz6c5XAoKoNLMefrFCxf6ksqC X-Received: by 2002:a65:5946:: with SMTP id g6-v6mr18664341pgu.391.1525342844876; Thu, 03 May 2018 03:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525342844; cv=none; d=google.com; s=arc-20160816; b=Lru+wgBFYHcC70IX6dpVQ3dJvB7qG3zIKA3l1ZXjQBhQFGjaIba3bR/0ssvIpemXpH HFdampMpNCElw7GIqSyBMqUiYnVMS5Xz8yx5YvoJ9ISYBPZ9rI5sHBQLxwh5Sv732aj9 QYiLaU0+AwSnAyIvVZAxTD/QYFJmQFKFSemFtSa0tHta5tLOwWWBgFeH/md2ofmS3deP 70OsBrvV864kKYeBmn3an4gYc5gRlOFt3UlMAOvvkABGgkqnuHwBZ9mbySlDisAvlJH5 U3gCX6p1CNdVA+PR/4C7NfkkiX9kieF/i3bw4wRzRqAgcJR21PWZIo47WihxmYoP4tVd PshA== 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=Mz46biTu/3UuJoFdUHxl0RPqeUvHG8m/CE4rQ8N2tCs9ezFNle79YPXswBNIiJxE3L UbhsTXAFAtQRLxv/hIJvAxCrAwMXGQ6chKZoXq+8/dOfFzCb6a3jhqI+pfeu1KACppYL pFDgNB01Wyenc+fC8dupNL0rncs5slbv220hRDxI7OoVz9oysaJM2LAs5SBkPGHMij/7 CeYwQCf2n/u0ORBm7VfhC2eGvaiMBIiveK79cdDQXJ+zXirx7nJv/oYQOfjQvrri7z66 GX3nx7Uz2s3ZCjlxaExtohr7BwiE7GsGQxCCf8G9C8AwjbsMllRD61rtC51wTkdqCMEb ugNg== 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 g11si13699302pfk.187.2018.05.03.03.20.30; Thu, 03 May 2018 03:20:44 -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 S1752331AbeECKTj (ORCPT + 99 others); Thu, 3 May 2018 06:19:39 -0400 Received: from mga06.intel.com ([134.134.136.31]:65514 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751873AbeECKTg (ORCPT ); Thu, 3 May 2018 06:19:36 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2018 03:19:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,358,1520924400"; d="scan'208";a="36546578" Received: from unknown (HELO skx-d.bj.intel.com) ([10.238.154.68]) by fmsmga007.fm.intel.com with ESMTP; 03 May 2018 03:19:33 -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:13:27 +0800 Message-Id: <1525349608-10352-13-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525349608-10352-1-git-send-email-luwei.kang@intel.com> References: <1525349608-10352-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