Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp437549imm; Thu, 6 Sep 2018 05:03:45 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb1JWbqAki1opJzmB0m1q4DYjWHN/uPNDoUrmIWRSKdkyCgfaVch6ltSn5PW6QarjI66TH+ X-Received: by 2002:a63:b00f:: with SMTP id h15-v6mr2403639pgf.442.1536235425848; Thu, 06 Sep 2018 05:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536235425; cv=none; d=google.com; s=arc-20160816; b=GT0K2rc2ztx4JuHqs+TRKDzYBZ27/bwsffox1ZiFCYf0GMzff4zOVAk9SVRtv17ThY UelezJoULPaB1ymIN5EBGsJSrGBQ5ZqgRHgCy1uLNsVUBlQwMea0Nq1akEO/yd3Jq9bR 8uP8SKo5LcMjmiFI00E09DpQL21t1gPmfGTvEOkURUxjtlhRyRtcoaUB+g9PYF6cs8Ar 2Ob0wD17o9bEwLV+y/I+2VL22rm8hcgZpE0jixxvOd4X0w0bkrm0GLsqtCp2bzu29yJu 0gW4FiKdfrl91fCzCo3sHiyXn/L4IlXxx5WFvbY6GaqWe+2j6q80b2azDKWqB36kb4LS s2pw== 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=Tsy6KMJ9Rk9pGpgrcYSCNwTFyj3j2S/QoE9dw3qACto=; b=kVIO8CpFvDLmm6tDx84thUl97sQASypjyEmIT0r9IoJH5U2wDYg5vvSxAn4+04GSx+ nC65UZlU47kJumeRFZgYfUZto8IWU9FpXMNnYUgtGeLz7gL+uPfT8KFoxusr3qZIHcTE V/sqQ9h68yQHh9WtRVT0tBytJb6q0zEmsbeI4z8Qv5j3w0JLEeqkUnzbMPqWTMimXY2V Efr5J1cfWQr8dUNkl+bIeM4ZrAKXzRYNNZ4lNknvOksHgz2DtRVnpISzl5AIEALgNp9p xpydkfenT5wCVu7yZ7xz93jPpk33Vr1X+W+n5lERHQ7Sb05U2nwwat7x3DpqoYHBCBRl jqxw== 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 c3-v6si4986026pfg.181.2018.09.06.05.03.30; Thu, 06 Sep 2018 05:03:45 -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 S1728179AbeIFQgS (ORCPT + 99 others); Thu, 6 Sep 2018 12:36:18 -0400 Received: from mga18.intel.com ([134.134.136.126]:62802 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728039AbeIFQgR (ORCPT ); Thu, 6 Sep 2018 12:36:17 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Sep 2018 05:00:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,338,1531810800"; d="scan'208";a="71046756" Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga008.jf.intel.com with ESMTP; 06 Sep 2018 05:00:53 -0700 From: Wei Wang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, ak@linux.intel.com Cc: kan.liang@intel.com, peterz@infradead.org, mingo@redhat.com, rkrcmar@redhat.com, like.xu@intel.com, wei.w.wang@intel.com Subject: [PATCH v2 3/8] KVM/vmx: Pass through the lbr stack to a guest Date: Thu, 6 Sep 2018 19:30:51 +0800 Message-Id: <1536233456-12173-4-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536233456-12173-1-git-send-email-wei.w.wang@intel.com> References: <1536233456-12173-1-git-send-email-wei.w.wang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pass through the LBR stack to the guest when the guest lbr feature is enabled. This makes the guest have direct accesses to the lbr stack. Signed-off-by: Like Xu Signed-off-by: Wei Wang Cc: Paolo Bonzini Cc: Andi Kleen --- arch/x86/kvm/vmx.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 1d26f3c..7a62c1c 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -7847,6 +7847,38 @@ static void vmx_enable_tdp(void) kvm_enable_tdp(); } +static int vmx_passthrough_lbr_msrs(struct kvm *kvm, + unsigned long *msr_bitmap) +{ + int i; + struct perf_lbr_stack lbr_stack; + + if (perf_get_lbr_stack(&lbr_stack) < 0) { + pr_err("Failed to pass through the lbr stack\n"); + return -ENOENT; + } + + vmx_disable_intercept_for_msr(msr_bitmap, MSR_LBR_SELECT, + MSR_TYPE_RW); + vmx_disable_intercept_for_msr(msr_bitmap, lbr_stack.lbr_tos, + MSR_TYPE_RW); + + for (i = 0; i < lbr_stack.lbr_nr; i++) { + vmx_disable_intercept_for_msr(msr_bitmap, + lbr_stack.lbr_from + i, + MSR_TYPE_RW); + vmx_disable_intercept_for_msr(msr_bitmap, + lbr_stack.lbr_to + i, + MSR_TYPE_RW); + if (lbr_stack.lbr_info) + vmx_disable_intercept_for_msr(msr_bitmap, + lbr_stack.lbr_info + i, + MSR_TYPE_RW); + } + + return 0; +} + static __init int hardware_setup(void) { unsigned long host_bndcfgs; @@ -10998,6 +11030,12 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_SYSENTER_EIP, MSR_TYPE_RW); vmx->msr_bitmap_mode = 0; + if (kvm->arch.guest_lbr) { + err = vmx_passthrough_lbr_msrs(kvm, msr_bitmap); + if (err < 0) + goto free_vmcs; + } + vmx->loaded_vmcs = &vmx->vmcs01; cpu = get_cpu(); vmx_vcpu_load(&vmx->vcpu, cpu); -- 2.7.4