Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp338888yba; Thu, 16 May 2019 01:29:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqypdBRBMOZxGDgG94Vg+TrcnhEoJebj5TaD6QYZbuVSfK4G84DSs/cyWHVL//ctLDLVzy4p X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr50432977plb.202.1557995351717; Thu, 16 May 2019 01:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557995351; cv=none; d=google.com; s=arc-20160816; b=v9HqdgpXl3JqXwKlSL9wqmUtOWMC9W9JiSQq8GlL+Gbb6vep0tnE2hBJgKHnnIQrlF 86GCaYC8fpdwlYnw2msMJe97bq+gFCr8uTm8/6CGLxZqZu+ETnvuKqHU25qZhcpmCEZI yE3ku8bHkPNT7r0y8iZFEPbQu0gawrcxi8+OHk3EG1gpPespP5BEnc6M0nWTMgoFJae9 3A+Wr6EWfIHqF9WlXHnuvEXCRe5t2NgmDCvBkmFAaRa6pAIxTkIff15+5OPHIBbUcVLA ufsxlbHuuAa2IPrxoHHDI5LmvcUswlEddoQ1TkUVEtaI3F1O6uU/XYdIi5RKs9OCsfgR HHIA== 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=EyzKe/ekvg8wRFDEERG1Muj7n7aTPIQ9w7m1T8R59Fk=; b=dET/SMgx+cfXmq91d2R0sXOGRBDKCtGCXL6xBatHRQ70Wg2Qf9nw/m9OeCphUbsQef eVA41121aBhsZg8LcHbSaBhJ+MLUUJB2rVab+0N/p/o7488DUEmiYMl4yYEBjuxoNce4 MZxt7DFE2wSDvBZ1l+xgoxSsaVhS5lOWofRMTQZxQYbUDxIBZVSoTr5YeS/LoJHhKxWm q7CXFyxF61ScUrrXeTKMF9ec8a7EYuqenwn3HcXdGF5ei+zwGuUJljnMMsHHwuiNR2Wh ftWZ8/qz9Fp+yLf+Lig0XVaIeuIQUasy/sjoJh1Q+0hiLp7pSm3OkJqN/WVp46I6gJGK 9VOg== 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 t20si4699797pfh.238.2019.05.16.01.28.57; Thu, 16 May 2019 01:29:11 -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 S1726946AbfEPI0x (ORCPT + 99 others); Thu, 16 May 2019 04:26:53 -0400 Received: from mga14.intel.com ([192.55.52.115]:24486 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726918AbfEPI0v (ORCPT ); Thu, 16 May 2019 04:26:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 May 2019 01:26:51 -0700 X-ExtLoop1: 1 Received: from skl-s2.bj.intel.com ([10.240.192.102]) by orsmga005.jf.intel.com with ESMTP; 16 May 2019 01:26:48 -0700 From: Luwei Kang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, Luwei Kang Subject: [PATCH v1 4/6] KVM: VMX: Allocate XSAVE area for Intel PT configuration Date: Thu, 16 May 2019 16:25:12 +0800 Message-Id: <1557995114-21629-5-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1557995114-21629-1-git-send-email-luwei.kang@intel.com> References: <1557995114-21629-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 Allocate XSAVE area for host and guest Intel PT configuration when Intel PT working in HOST_GUEST mode. Intel PT configuration state can be saved using XSAVES and restored by XRSTORS instruction. Signed-off-by: Luwei Kang --- arch/x86/kvm/vmx/vmx.c | 25 ++++++++++++++++++++++++- arch/x86/kvm/vmx/vmx.h | 3 +++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 4595230..4691665 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1033,6 +1033,7 @@ static void pt_guest_exit(struct vcpu_vmx *vmx) static int pt_init(struct vcpu_vmx *vmx) { + unsigned int eax, ebx, ecx, edx; u32 pt_state_sz = sizeof(struct pt_state) + sizeof(u64) * intel_pt_validate_hw_cap(PT_CAP_num_address_ranges) * 2; @@ -1044,13 +1045,35 @@ static int pt_init(struct vcpu_vmx *vmx) vmx->pt_desc->host_ctx = (struct pt_state *)(vmx->pt_desc + 1); vmx->pt_desc->guest_ctx = (void *)vmx->pt_desc->host_ctx + pt_state_sz; + cpuid_count(XSTATE_CPUID, 1, &eax, &ebx, &ecx, &edx); + if (ecx & XFEATURE_MASK_PT) { + vmx->pt_desc->host_xs = kmem_cache_zalloc(x86_fpu_cache, + GFP_KERNEL_ACCOUNT); + vmx->pt_desc->guest_xs = kmem_cache_zalloc(x86_fpu_cache, + GFP_KERNEL_ACCOUNT); + if (!vmx->pt_desc->host_xs || !vmx->pt_desc->guest_xs) { + if (vmx->pt_desc->host_xs) + kmem_cache_free(x86_fpu_cache, + vmx->pt_desc->host_xs); + if (vmx->pt_desc->guest_xs) + kmem_cache_free(x86_fpu_cache, + vmx->pt_desc->guest_xs); + } else + vmx->pt_desc->pt_xsave = true; + } + return 0; } static void pt_uninit(struct vcpu_vmx *vmx) { - if (pt_mode == PT_MODE_HOST_GUEST) + if (pt_mode == PT_MODE_HOST_GUEST) { kfree(vmx->pt_desc); + if (vmx->pt_desc->pt_xsave) { + kmem_cache_free(x86_fpu_cache, vmx->pt_desc->host_xs); + kmem_cache_free(x86_fpu_cache, vmx->pt_desc->guest_xs); + } + } } void vmx_prepare_switch_to_guest(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 283f69d..e103991 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -69,8 +69,11 @@ struct pt_desc { u64 ctl_bitmask; u32 addr_range; u32 caps[PT_CPUID_REGS_NUM * PT_CPUID_LEAVES]; + bool pt_xsave; struct pt_state *host_ctx; struct pt_state *guest_ctx; + struct fpu *host_xs; + struct fpu *guest_xs; }; /* -- 1.8.3.1