Received: by 10.223.164.202 with SMTP id h10csp2844146wrb; Tue, 28 Nov 2017 02:11:41 -0800 (PST) X-Google-Smtp-Source: AGs4zMaPlqEqYPgPF01zqfSZjSnOt7ZZHT2NNNIUtvhXg9lr6sxWXIgFpi0oJ9rEaUxMGXtNT80h X-Received: by 10.84.139.129 with SMTP id 1mr19550567plr.327.1511863901763; Tue, 28 Nov 2017 02:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511863901; cv=none; d=google.com; s=arc-20160816; b=m8u/ZHHaJDmo0usXxwOVXoSVL4ZCpAGkC9jZJBWswhG9weWYaVROPAn/02hR5K8KWb U8R38RCFE5e7WVZxeun7CogHf4tGgozr7V0Pm5ZpxEVFoRxJpAXU6OqvIXp0TsHWt5UU nsF97GCGq2iPNchllDM++3/MSfHEN6leaUTV8Q2g6T6gHbTWau4XBFJVouCykWH7r8RS nnrq6GPUZmkOY4grxK7Mb4yR1ENK2U18SjDXWIQxCq9vNuK2rCHhXswMSOMe5Du2uUum bWl/qMNVZqjGVwW0nxcMtBRncyl3SVmfmojVtM4ujnvmfzLUH/vyroLhitUlKHwiQYb8 GbkA== 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=lOcjt/B7goF43Waw7R1d9Tdvhr8dgdE6j7MI8o6Jw/c=; b=ieuwGlb/RomaLvKAtrjJcALB26XhzsTj+CFP50tFAq5jOWhxZXDwo5qVlYJ5q641DR kSJ0wu0A48E2JefyiR1mOIt999IBz7r76XaSWsy8WpZmxqe5nleq8hEBD9JnBBIBaAY/ tiqcE4WRmpw7nwRl31zhcSOXbB8Nnm1EPtxVaxxXYIhjhnMWROQhR+dHzP4SEs97qC5o gM5wExxvR4g/QNm9aWV7lvYBKpWsVbpfqW61xtjyXNKmncOUPAGYkX0W4PCArady7qMZ YQ9zJh07gRxmFQ4gp2sXP7hFYfS2iC1TjlP1ToFQoulpoF/T+tgzQwvTZf66OQvBrSTJ Pt4w== 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 z77si18472345pff.100.2017.11.28.02.11.30; Tue, 28 Nov 2017 02:11:41 -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 S1752554AbdK1KJk (ORCPT + 78 others); Tue, 28 Nov 2017 05:09:40 -0500 Received: from mga01.intel.com ([192.55.52.88]:59069 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752526AbdK1KJh (ORCPT ); Tue, 28 Nov 2017 05:09:37 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Nov 2017 02:09:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,467,1505804400"; d="scan'208";a="7939982" Received: from vmm.bj.intel.com ([10.238.135.172]) by fmsmga001.fm.intel.com with ESMTP; 28 Nov 2017 02:09:34 -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 v3 7/9] KVM: x86: Implement Intel Processor Trace MSRs read/write Date: Tue, 28 Nov 2017 04:24:00 +0800 Message-Id: <1511814242-12949-8-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511814242-12949-1-git-send-email-luwei.kang@intel.com> References: <1511814242-12949-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 Intel PT MSRs read/write will not be intercepted when guest enabled Intel PT. IA32_RTIT_CTL read/write will always cause a VM-Exit. Signed-off-by: Chao Peng Signed-off-by: Luwei Kang --- arch/x86/kvm/vmx.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ arch/x86/kvm/x86.c | 23 +++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index c10350b..e002a44 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -948,6 +948,8 @@ static void vmx_get_segment(struct kvm_vcpu *vcpu, static void vmx_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked); static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12, u16 error_code); +static bool vmx_pt_supported(void); +static inline void pt_disable_intercept_for_msr(bool flag); static DEFINE_PER_CPU(struct vmcs *, vmxarea); static DEFINE_PER_CPU(struct vmcs *, current_vmcs); @@ -3337,6 +3339,38 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) return 1; msr_info->data = vcpu->arch.ia32_xss; break; + case MSR_IA32_RTIT_CTL: + if (!vmx_pt_supported()) + return 1; + msr_info->data = to_vmx(vcpu)->pt_desc.guest.ctl; + break; + case MSR_IA32_RTIT_STATUS: + if (!vmx_pt_supported()) + return 1; + msr_info->data = to_vmx(vcpu)->pt_desc.guest.status; + break; + case MSR_IA32_RTIT_CR3_MATCH: + if (!vmx_pt_supported()) + return 1; + msr_info->data = to_vmx(vcpu)->pt_desc.guest.cr3_match; + break; + case MSR_IA32_RTIT_OUTPUT_BASE: + if (!vmx_pt_supported()) + return 1; + msr_info->data = to_vmx(vcpu)->pt_desc.guest.output_base; + break; + case MSR_IA32_RTIT_OUTPUT_MASK: + if (!vmx_pt_supported()) + return 1; + msr_info->data = to_vmx(vcpu)->pt_desc.guest.output_mask; + break; + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: + if (!vmx_pt_supported()) + return 1; + msr_info->data = + to_vmx(vcpu)->pt_desc.guest.addrs[msr_info->index - + MSR_IA32_RTIT_ADDR0_A]; + break; case MSR_TSC_AUX: if (!msr_info->host_initiated && !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) @@ -3461,6 +3495,39 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) else clear_atomic_switch_msr(vmx, MSR_IA32_XSS); break; + case MSR_IA32_RTIT_CTL: + if (!vmx_pt_supported() || to_vmx(vcpu)->nested.vmxon) + return 1; + pt_disable_intercept_for_msr(data & RTIT_CTL_TRACEEN); + vmcs_write64(GUEST_IA32_RTIT_CTL, data); + vmx->pt_desc.guest.ctl = data; + break; + case MSR_IA32_RTIT_STATUS: + if (!vmx_pt_supported()) + return 1; + vmx->pt_desc.guest.status = data; + break; + case MSR_IA32_RTIT_CR3_MATCH: + if (!vmx_pt_supported()) + return 1; + vmx->pt_desc.guest.cr3_match = data; + break; + case MSR_IA32_RTIT_OUTPUT_BASE: + if (!vmx_pt_supported()) + return 1; + vmx->pt_desc.guest.output_base = data; + break; + case MSR_IA32_RTIT_OUTPUT_MASK: + if (!vmx_pt_supported()) + return 1; + vmx->pt_desc.guest.output_mask = data; + break; + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: + if (!vmx_pt_supported()) + return 1; + vmx->pt_desc.guest.addrs[msr_info->index - + MSR_IA32_RTIT_ADDR0_A] = data; + break; case MSR_TSC_AUX: if (!msr_info->host_initiated && !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 34c85aa..775dabf3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1006,6 +1006,12 @@ bool kvm_rdpmc(struct kvm_vcpu *vcpu) #endif MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA, MSR_IA32_FEATURE_CONTROL, MSR_IA32_BNDCFGS, MSR_TSC_AUX, + MSR_IA32_RTIT_CTL, MSR_IA32_RTIT_STATUS, MSR_IA32_RTIT_CR3_MATCH, + MSR_IA32_RTIT_OUTPUT_BASE, MSR_IA32_RTIT_OUTPUT_MASK, + MSR_IA32_RTIT_ADDR0_A, MSR_IA32_RTIT_ADDR0_B, + MSR_IA32_RTIT_ADDR1_A, MSR_IA32_RTIT_ADDR1_B, + MSR_IA32_RTIT_ADDR2_A, MSR_IA32_RTIT_ADDR2_B, + MSR_IA32_RTIT_ADDR3_A, MSR_IA32_RTIT_ADDR3_B, }; static unsigned num_msrs_to_save; @@ -4310,6 +4316,23 @@ static void kvm_init_msr_list(void) if (!kvm_x86_ops->rdtscp_supported()) continue; break; + case MSR_IA32_RTIT_CTL: + case MSR_IA32_RTIT_STATUS: + case MSR_IA32_RTIT_CR3_MATCH: + case MSR_IA32_RTIT_OUTPUT_BASE: + case MSR_IA32_RTIT_OUTPUT_MASK: + if (!kvm_x86_ops->pt_supported()) + continue; + break; + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: { + u32 eax, ebx, ecx, edx; + + cpuid_count(0x14, 1, &eax, &ebx, &ecx, &edx); + if (!kvm_x86_ops->pt_supported() || msrs_to_save[i] - + MSR_IA32_RTIT_ADDR0_A >= (eax & 0x7)) + continue; + break; + } default: break; } -- 1.8.3.1 From 1585726472255010570@xxx Sun Dec 03 02:03:29 +0000 2017 X-GM-THRID: 1585726472255010570 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread