Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1634683imj; Thu, 14 Feb 2019 09:29:35 -0800 (PST) X-Google-Smtp-Source: AHgI3IY9Y8IXDISU1+wZ5cBUrr78sOuwBGNp8EFYLVFdKHfQcStDdTAhG4H1jL2rw84ZO52mYJbX X-Received: by 2002:a63:6184:: with SMTP id v126mr934033pgb.277.1550165375194; Thu, 14 Feb 2019 09:29:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550165375; cv=none; d=google.com; s=arc-20160816; b=CdxFO1tCIr02yIhqub22UGjAR7krPfPvXsPvj0AKxcZdEkNETSlUIc9uuxLqN1dVZP fdoRwaDppeMPp9mn+CYe6OkHGGLE6RvJ3NJ1ax4R6pT5gu2KFLRQ337KPsjSqFgbSavR /6dsNtNrZ6C2t6g/xMWILautpJhzY7PPzWiRTuabzuqk6cnjawGHDLJDmA1tBdbmN6X5 gygy7x4gMeId0CXcClkBbr+2FcosVt7hiTdvx+yu5ji/5TrKcopPj1u3IQp/+WBBhVjA 9Y7+64JDmgln9A/2fpzjd/NdWvDgjL9h0w3NTCVhodKRrXnK4Lw61vSwUZgS8fXN5UH6 P0RA== 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=ioOjIOI/FU1cB+Z86m0I8HwSkqeuFiMthiaircLRA5A=; b=wuV6gQYsy/EqZGuSHxUVwWqgHwxPNWUwEfjFt/NhgNG1/Jsk9qVwOijX0NJCaLscOH AEW9xb86UD9hjEujSguNQzFQ4NAq9yRNhvT2cJKHx5iaNHJo8YiS5IW9AD3IXTgcOwcj sDCdOJ41J6AKp5vuFCFZOfwnzhPgVJHj8Z3IIKdPQkyzlYuY7WVYomrbIjmtLvBR01NZ YUxcIQqs+o/Ypf8mUYMTTo5m7vT2TrdhsMyihF8TsI7RR8122lgCNzmUr+0R71lEVs4t iLvTXhlQ9lDOW6j7q8olBHDh7eKATaemxwu1UkIkucNhdMno4/2YuzRZWKo8D7CU9OIj JFEw== 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 97si2986764plm.3.2019.02.14.09.29.18; Thu, 14 Feb 2019 09:29:35 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395241AbfBNJmz (ORCPT + 99 others); Thu, 14 Feb 2019 04:42:55 -0500 Received: from mga09.intel.com ([134.134.136.24]:32197 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395222AbfBNJmx (ORCPT ); Thu, 14 Feb 2019 04:42:53 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2019 01:42:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,368,1544515200"; d="scan'208";a="124411713" Received: from devel-ww.sh.intel.com ([10.239.48.128]) by fmsmga008.fm.intel.com with ESMTP; 14 Feb 2019 01:42:51 -0800 From: Wei Wang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, ak@linux.intel.com, peterz@infradead.org Cc: kan.liang@intel.com, mingo@redhat.com, rkrcmar@redhat.com, like.xu@intel.com, wei.w.wang@intel.com, jannh@google.com, arei.gonglei@huawei.com, jmattson@google.com Subject: [PATCH v5 03/12] KVM/x86: KVM_CAP_X86_GUEST_LBR Date: Thu, 14 Feb 2019 17:06:05 +0800 Message-Id: <1550135174-5423-4-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550135174-5423-1-git-send-email-wei.w.wang@intel.com> References: <1550135174-5423-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: Wei Wang Cc: Paolo Bonzini Cc: Andi Kleen Cc: Peter Zijlstra --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/x86.c | 15 +++++++++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 18 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4660ce9..e6f6760 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -869,6 +869,7 @@ struct kvm_arch { atomic_t vapics_in_nmi_mode; struct mutex apic_map_lock; struct kvm_apic_map *apic_map; + struct x86_perf_lbr_stack lbr_stack; bool apic_access_page_done; @@ -877,6 +878,7 @@ struct kvm_arch { bool mwait_in_guest; bool hlt_in_guest; bool pause_in_guest; + bool lbr_in_guest; unsigned long irq_sources_bitmap; s64 kvmclock_offset; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3d27206..2cdebe7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3028,6 +3028,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_GET_MSR_FEATURES: case KVM_CAP_MSR_PLATFORM_INFO: case KVM_CAP_EXCEPTION_PAYLOAD: + case KVM_CAP_X86_GUEST_LBR: r = 1; break; case KVM_CAP_SYNC_REGS: @@ -4562,6 +4563,20 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, kvm->arch.exception_payload_enabled = cap->args[0]; r = 0; break; + case KVM_CAP_X86_GUEST_LBR: + r = -EINVAL; + if (cap->args[0] && + x86_perf_get_lbr_stack(&kvm->arch.lbr_stack)) { + pr_err("Failed to enable the guest lbr feature\n"); + break; + } + if (copy_to_user((void __user *)cap->args[1], + &kvm->arch.lbr_stack, + sizeof(struct x86_perf_lbr_stack))) + break; + kvm->arch.lbr_in_guest = cap->args[0]; + r = 0; + break; default: r = -EINVAL; break; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 6d4ea4b..a7cac96 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -988,6 +988,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_ARM_VM_IPA_SIZE 165 #define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166 #define KVM_CAP_HYPERV_CPUID 167 +#define KVM_CAP_X86_GUEST_LBR 168 #ifdef KVM_CAP_IRQ_ROUTING -- 2.7.4