Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1827339imm; Thu, 20 Sep 2018 03:38:00 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYzkr1C4c4+pTNFPbpjS/rdqzQpm+LqGDAupNh9uapn9JuSyWXcJyuCvEpQS8ZrXesXPoux X-Received: by 2002:a63:5706:: with SMTP id l6-v6mr37415683pgb.118.1537439880328; Thu, 20 Sep 2018 03:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537439880; cv=none; d=google.com; s=arc-20160816; b=DLctp/V47VrYJPEUqbs9we1RfCRI1attpdngrZYBcoqXYQ/DOLk/zZe6U8WOygTeWw omEzPKrfwyujVAUWsDDmTYS8Dy1EpwSksVfrY0QgoKy2bJwu8nFCoFOUoYM9MyIls3rg OJNKTgJofA/m71ROkZd+tPJu271b6x1g4fRAZ8S+kBYl84DE+7i3S0+u4CzbX9EoNE2W P46RD3HhgeM2P4AzQqz1iRxly1YaGV8+aBZvCWcXG1OrrHIYOY4YPtAwqoojI/jgM8Or QREQS7tAzt2s0uDDqHLFgGef3IZZxc+qmpJSqBDqAYrAuozBnmqBVG3bbvqDPygz0u/o uSAg== 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=j1UOJPHZ3Fujfsml5jFxI2TjMiEm9AUITmfV5CJNFLQ=; b=T6oBaYFyTuPUDI0+vKr8MEd03MTYwp+o1a0a0UWX6ivTM3ZRfKoWoIW2wJh4EXa5Be Ajv8ti7F7E51d08bqOpFHwcJM4Oo1Wevq445l9mvBhz1CC4ki99un0tnIrt7rCU2q03b yJPgojN1RzCU7hHq9K/Wu2XHMzwrzV3J10/N8P5xghebIsT5lX72d5V4iRIaiDQvb5MR PNjnQQ/uKB0ZlDyeDfTNCTaZ12iNQZxdhxoiOJ3sTQe5vmjRwPC8+qRH9iO6pswT8lW0 WaCSMyDNAVv4Z5nZ96/1vkRQc/+KH0QLJCTvF0Jqg85dpkRqMUeMhXah/YSsdh83pQUH H+rw== 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 f33-v6si2767267pgb.293.2018.09.20.03.37.44; Thu, 20 Sep 2018 03:38:00 -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 S2387573AbeITQT6 (ORCPT + 99 others); Thu, 20 Sep 2018 12:19:58 -0400 Received: from mga12.intel.com ([192.55.52.136]:59584 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726177AbeITQT5 (ORCPT ); Thu, 20 Sep 2018 12:19:57 -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 fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Sep 2018 03:37:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,398,1531810800"; d="scan'208";a="74796176" Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga008.jf.intel.com with ESMTP; 20 Sep 2018 03:36:35 -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, jannh@google.com, arei.gonglei@huawei.com Subject: [PATCH v3 2/5] KVM/x86: KVM_CAP_X86_GUEST_LBR Date: Thu, 20 Sep 2018 18:05:56 +0800 Message-Id: <1537437959-8751-3-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537437959-8751-1-git-send-email-wei.w.wang@intel.com> References: <1537437959-8751-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 Introduce KVM_CAP_X86_GUEST_LBR to allow per-VM enabling of the guest lbr feature. Signed-off-by: Like Xu Signed-off-by: Wei Wang Cc: Paolo Bonzini Cc: Andi Kleen --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/x86.c | 10 ++++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 13 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 8e90488..4a46e31 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -825,6 +825,8 @@ struct kvm_arch { bool mwait_in_guest; bool hlt_in_guest; bool pause_in_guest; + bool guest_lbr_enabled; + struct perf_lbr_stack lbr_stack; unsigned long irq_sources_bitmap; s64 kvmclock_offset; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 542f631..8fdcfa9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2927,6 +2927,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_SPLIT_IRQCHIP: case KVM_CAP_IMMEDIATE_EXIT: case KVM_CAP_GET_MSR_FEATURES: + case KVM_CAP_X86_GUEST_LBR: r = 1; break; case KVM_CAP_SYNC_REGS: @@ -4350,6 +4351,15 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm, kvm->arch.pause_in_guest = true; r = 0; break; + case KVM_CAP_X86_GUEST_LBR: + r = -EINVAL; + if (perf_get_lbr_stack(&kvm->arch.lbr_stack) < 0) { + pr_err("Failed to enable the guest lbr feature\n"); + break; + } + kvm->arch.guest_lbr_enabled = true; + r = 0; + break; default: r = -EINVAL; break; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 07548de..7cf9bc0 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -952,6 +952,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_S390_HPAGE_1M 156 #define KVM_CAP_NESTED_STATE 157 #define KVM_CAP_ARM_INJECT_SERROR_ESR 158 +#define KVM_CAP_X86_GUEST_LBR 159 #ifdef KVM_CAP_IRQ_ROUTING -- 2.7.4