Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp297118ima; Wed, 24 Oct 2018 01:09:14 -0700 (PDT) X-Google-Smtp-Source: AJdET5cBWWP9+6eLb8i5e9/lUcLaRIycnytjQV+L0cwntpzCB3+5xSwNNXQQTlu8LLL57SVuy8+G X-Received: by 2002:a17:902:9:: with SMTP id 9-v6mr1565301pla.293.1540368554281; Wed, 24 Oct 2018 01:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540368554; cv=none; d=google.com; s=arc-20160816; b=KFhvtWttIhiGjfaMVs0st96OT3LzZDR60Hr8hn2XmrZ0cNEySbELez/4i1wD4r9BKA 23LwyeuqOv7NGzbR7aqaEKZjQZYV1rjoPH3/ndb8cXC4RIBSj40NDpaINy+UyAF3cgyS kNuqv2o6wbxWFua4mr6cBbV4EHNuVvExORaQs9N8UOfo6dIsR9usl9ozjJC1p8QaNubI ioWqk2mbt0V5TjkHjfmiS+PG6QOrb19XPXnv+7vC1QWTFDrHv0qFdi9r37uCYBj48Fj+ XbJufeD39DFNRzbfduOvHfGSWsMk/EkoGpHXBSfjWkIrdjPLjWs3zIj34eCDzbz3luoA rmCQ== 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; bh=YZVVnc23/EO6eazNTIAUiTR9x+Zmz96XA2sk3BcIgWI=; b=NdXfzPHk9L655B7xGZ6Gn0CdlCeP8sXIg+60zkmI2SDmZdsTWTYv4QRcYclJteVfuS +IXSh2NE3ydYigjgU2kAiB9ddNlMzZKGV53pBiyxIMDgGvlVnAbyqZi7XtlETZJW07DW hyuPt5NN4CGizn00uv8m3kAi8AablEz3r18Kj9umwv3gDEdRHquUbnZsoaPExvmwu8nl POK2XOwG0FTLslBz+5z+bZnk8SVngRkupjLbyphWc3WEgd/csEhvgfOvxvplG9u78eYZ FeJtTY1ndojGb5eprPl+Dtyee760HQ9vLbZkiKCP5GeX8IR1/2dFThMMJfZKzTX0lh8s rf3Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r63-v6si3929284plb.44.2018.10.24.01.08.59; Wed, 24 Oct 2018 01:09:14 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729435AbeJXQfL (ORCPT + 99 others); Wed, 24 Oct 2018 12:35:11 -0400 Received: from mga05.intel.com ([192.55.52.43]:46033 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728013AbeJXQfK (ORCPT ); Wed, 24 Oct 2018 12:35:10 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Oct 2018 01:08:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,419,1534834800"; d="scan'208";a="273987503" Received: from skx-d.bj.intel.com ([10.238.135.53]) by fmsmga005.fm.intel.com with ESMTP; 24 Oct 2018 01:08:03 -0700 From: Luwei Kang To: kvm@vger.kernel.org, x86@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, rkrcmar@redhat.com, joro@8bytes.org, songliubraving@fb.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, kstewart@linuxfoundation.org, gregkh@linuxfoundation.org, thomas.lendacky@amd.com, konrad.wilk@oracle.com, mattst88@gmail.com, Janakarajan.Natarajan@amd.com, dwmw@amazon.co.uk, jpoimboe@redhat.com, marcorr@google.com, ubizjak@gmail.com, sean.j.christopherson@intel.com, jmattson@google.com, linux-kernel@vger.kernel.org, Chao Peng , Luwei Kang Subject: [PATCH v13 11/12] KVM: x86: Set intercept for Intel PT MSRs read/write Date: Wed, 24 Oct 2018 16:05:15 +0800 Message-Id: <1540368316-12998-12-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1540368316-12998-1-git-send-email-luwei.kang@intel.com> References: <1540368316-12998-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 To save performance overhead, disable intercept Intel PT MSRs read/write when Intel PT is enabled in guest. MSR_IA32_RTIT_CTL is an exception that will always be intercepted. 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 a568d49..ed247dd 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -1333,6 +1333,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); @@ -4558,6 +4559,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: @@ -6414,6 +6416,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