Received: by 10.213.65.68 with SMTP id h4csp864884imn; Tue, 20 Mar 2018 18:12:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELsDMweDtnXJ/QawEzzH+wL7iifE/cjOBKhwdb/NnFB1HxtpAjenkIuQK+VRsq/To1GxnWrP X-Received: by 2002:a17:902:7401:: with SMTP id g1-v6mr18920926pll.4.1521594778293; Tue, 20 Mar 2018 18:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521594778; cv=none; d=google.com; s=arc-20160816; b=ZqodfotRgb6GAZz8ZBIlFt9ZGOmuzkg67OgmukHyg3CHinsvnz94znT/v7WxZKxIZm yZOIEFMLXJloUEX1u92PeCBBiQyd5WTTacZtJ5qL0+fnGEE8LUqZzrp+U+mHMnTdwYrS Q8kGvzlW9aZSFlmiIQ82eOw4qVH7Q4PWGomwqzIrMhGEEOqFjZxT3wJJnyvgGqCokJEV u7/4gM0itKYCWubNoC7TLa4RlKQTinIODzWE6ZCr6vkgSbf/Uob1ObFs9SuaoALOQ3ba 02cbFFsb0KKdldCQLBvN4ISnWQhg2qBDeac/pmgPMlxEkRWi5qndPKCSSc60AYVIBbjs sTpw== 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=BCPlbyDxspYFyGLtuVbr/VvJ4rZ0BJ3G5rA0I5kVAxs=; b=qfquMhTZjAZW0PJzoTY2FyoDjC0+9qJVgqroFMi6/1JrvyTJRmVS3zGxPhToVOUZMn c9QVPjpUoYdh3s8Tkt6dhPFTrTf+WabiszN3zEveMigockdWQxfnnLG8O1LiRxpR+vHQ KBMFyGp32zHRvSRXDQF8omUPHuWJ5HZ3E9JwSTHjb5vBkBASeymrI5zyy0xxrixga7nL gQ/Jygn67A8J/9MFSDu8bc+7FF0e0O2cXVES8bVmt5EsjmOQ2tXeBPHabb1BC8A0UQgZ 70Z8pZHJse8lIzt5JSL5Cip0v/YnUvjOO7yLVOZdDhGtAKsiG88qxQy1cOpGAlJGqJmx PGew== 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 19si1990598pgg.395.2018.03.20.18.12.43; Tue, 20 Mar 2018 18:12:58 -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 S1752010AbeCUBLi (ORCPT + 99 others); Tue, 20 Mar 2018 21:11:38 -0400 Received: from mga09.intel.com ([134.134.136.24]:19664 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751943AbeCUBLd (ORCPT ); Tue, 20 Mar 2018 21:11:33 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2018 18:11:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,338,1517904000"; d="scan'208";a="39779415" Received: from vmm.bj.intel.com ([10.238.135.172]) by fmsmga001.fm.intel.com with ESMTP; 20 Mar 2018 18:11:30 -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, Chao Peng , Luwei Kang Subject: [PATCH v6 10/11] KVM: x86: Set intercept for Intel PT MSRs Date: Tue, 20 Mar 2018 19:21:57 +0800 Message-Id: <1521544918-31084-11-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521544918-31084-1-git-send-email-luwei.kang@intel.com> References: <1521544918-31084-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 0334100..27185da 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -941,6 +941,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); @@ -3765,6 +3766,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: @@ -5554,6 +5556,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