Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2810691pxv; Mon, 12 Jul 2021 02:25:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHvYpkyH03vDGHcTGoDCuAC46KLnsYiBnR9nDSJTUkd3xjDGWMisbjzDoyI4m2AMjeRjPh X-Received: by 2002:a05:6402:448:: with SMTP id p8mr62105032edw.60.1626081914639; Mon, 12 Jul 2021 02:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626081914; cv=none; d=google.com; s=arc-20160816; b=CSXIamrhiCkAzjXIlW2V6nCN1rjksI0+pRxuFa9mX5GHJIxa6x/rCkRE4myqzXIKd/ WdFLjOikPZ+oDhLuU2pCXY1fDXr7y8ywWQrWGJnYJNb20FpxxpCD9V2Cwi+q6kX3qrHu qE9/gJ45v/xd7QtlEHqvzUv9Rho/sXJHk1vnAkJ05W0Tn9mHb3kbSbUSv2+E/I6tzql4 TWj+iD+oT1mPkkq7k6r9WWFr0aAPGoeRUhJZZMSaWr4HCP1J6jSO5okh1C+cf1ESkEUI l8bzt70GPkeLDny0/BBs8lFbfny76xMiWQB172KAa4cnwxkeYY/lty0AP6CVpiA3eQ6o xTyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=haOYYELglK1lqzbtPyWi41CpmE5vpt0ENSrHjAk6vKA=; b=hsqK4r0ID48nHl4dh5vqqzXdRdzYimsxoGDORSj8hoFFahwjh7G0ZjuRfMOc95Unlu 7Q+v2c86WcPd/aWxgV4zlaDLR5ta5TRFCPWepu77PkqXa+dK/AhncXjJBam3SugqgEpN Bk+lq/7xXERRqBZWfk5+ARV4lDAAk8ZGZqzu2P63LvvDEnmFiUeKLSLi3tgVBUU3b+l/ Vxr+iXrDsKjY7uV+kWBnjQbM96zWOnl9PObdAD4k6jVpf+mZS8bc1eO+Jsr5j8Q9TcUH FJ/6MVFAmRtlQj35ZLAaK6tKqhehHt+sSxSmOHYUQwJDeP0otwY6XkVEBKcJYnr6OpQ9 UvSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id t13si14174943eds.120.2021.07.12.02.24.52; Mon, 12 Jul 2021 02:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1343732AbhGLJ0l (ORCPT + 99 others); Mon, 12 Jul 2021 05:26:41 -0400 Received: from mga09.intel.com ([134.134.136.24]:54855 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387166AbhGLJZ2 (ORCPT ); Mon, 12 Jul 2021 05:25:28 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10042"; a="209923690" X-IronPort-AV: E=Sophos;i="5.84,232,1620716400"; d="scan'208";a="209923690" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2021 02:22:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,232,1620716400"; d="scan'208";a="502065850" Received: from michael-optiplex-9020.sh.intel.com (HELO localhost) ([10.239.159.182]) by fmsmga002.fm.intel.com with ESMTP; 12 Jul 2021 02:22:23 -0700 Date: Mon, 12 Jul 2021 17:36:26 +0800 From: Yang Weijiang To: Jim Mattson Cc: Yang Weijiang , pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wei.w.wang@intel.com, like.xu.linux@gmail.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Like Xu Subject: Re: [PATCH v5 05/13] KVM: vmx/pmu: Emulate MSR_ARCH_LBR_CTL for guest Arch LBR Message-ID: <20210712093626.GC12162@intel.com> References: <1625825111-6604-1-git-send-email-weijiang.yang@intel.com> <1625825111-6604-6-git-send-email-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 09, 2021 at 02:55:35PM -0700, Jim Mattson wrote: > On Fri, Jul 9, 2021 at 2:51 AM Yang Weijiang wrote: > > > > From: Like Xu > > > > Arch LBRs are enabled by setting MSR_ARCH_LBR_CTL.LBREn to 1. A new guest > > state field named "Guest IA32_LBR_CTL" is added to enhance guest LBR usage. > > When guest Arch LBR is enabled, a guest LBR event will be created like the > > model-specific LBR does. Clear guest LBR enable bit on host PMI handling so > > guest can see expected config. > > > > On processors that support Arch LBR, MSR_IA32_DEBUGCTLMSR[bit 0] has no > > meaning. It can be written to 0 or 1, but reads will always return 0. > > Like IA32_DEBUGCTL, IA32_ARCH_LBR_CTL msr is also reserved on INIT. > > I suspect you mean "preserved" rather than "reserved." Yes, should be preserved. > > > Signed-off-by: Like Xu > > Signed-off-by: Yang Weijiang > > --- > > arch/x86/events/intel/lbr.c | 2 -- > > arch/x86/include/asm/msr-index.h | 1 + > > arch/x86/include/asm/vmx.h | 2 ++ > > arch/x86/kvm/vmx/pmu_intel.c | 31 ++++++++++++++++++++++++++----- > > arch/x86/kvm/vmx/vmx.c | 9 +++++++++ > > 5 files changed, 38 insertions(+), 7 deletions(-) > > > > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c > > index da68f0e74702..4500c564c63a 100644 > > --- a/arch/x86/kvm/vmx/pmu_intel.c > > +++ b/arch/x86/kvm/vmx/pmu_intel.c > > @@ -19,6 +19,11 @@ > > #include "pmu.h" > > > > #define MSR_PMC_FULL_WIDTH_BIT (MSR_IA32_PMC0 - MSR_IA32_PERFCTR0) > > +/* > > + * Regardless of the Arch LBR or legacy LBR, when the LBR_EN bit 0 of the > > + * corresponding control MSR is set to 1, LBR recording will be enabled. > > + */ > > Is this comment misplaced? It doesn't seem to have anything to do with > the macro being defined below. Agree, will put this in commit message. > > > @@ -458,6 +467,14 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > > lbr_desc->records.nr = data; > > lbr_desc->arch_lbr_reset = true; > > return 0; > > + case MSR_ARCH_LBR_CTL: > > + if (data & ~KVM_ARCH_LBR_CTL_MASK) > > Is a static mask sufficient? Per the Intel? Architecture Instruction > Set Extensions and Future Features Programming Reference, some of > these bits may not be supported on all microarchitectures. See Table > 7-8. CPUID Leaf 01CH Enumeration of Architectural LBR Capabilities. Yes, more sanity checks are required, thanks! > > > + break; > > + vmcs_write64(GUEST_IA32_LBR_CTL, data); > > + if (intel_pmu_lbr_is_enabled(vcpu) && !lbr_desc->event && > > + (data & ARCH_LBR_CTL_LBREN)) > > + intel_pmu_create_guest_lbr_event(vcpu); > > Nothing has to be done when the LBREN bit goes from 1 to 0? Need to release the event and reset related flag when the bit goes from 1 to 0. Thanks! > > > + return 0; > > default: > > if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)) || > > (pmc = get_gp_pmc(pmu, msr, MSR_IA32_PMC0))) { > > Per the Intel? Architecture Instruction Set Extensions and Future > Features Programming Reference, "IA32_LBR_CTL.LBREn is saved and > cleared on #SMI, and restored on RSM." I don't see that happening > anywhere. That manual also says, "On a warm reset...IA32_LBR_CTL.LBREn > is cleared to 0, disabling LBRs." I don't see that happening either. Yes, I'll add related code to make it consistent with spec, thanks! > > I have a question about section 7.1.4.4 in that manual. It says, "On a > debug breakpoint event (#DB), IA32_LBR_CTL.LBREn is cleared." When, > exactly, does that happen? In particular, if kvm synthesizes such an > event (for example, in kvm_vcpu_do_singlestep), does > IA32_LBR_CTL.LBREn automatically get cleared (after loading the guest > IA32_LBR_CTL value from the VMCS)? Or does kvm need to explicitly > clear that bit in the VMCS before injecting the #DB? OK, I don't have answer now, will ask the Arch to get clear answer on this, thanks for raising the question!