From patchwork Tue Feb 23 01:39:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Like Xu X-Patchwork-Id: 12099717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6A9EC433E6 for ; Tue, 23 Feb 2021 01:49:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5662B64E57 for ; Tue, 23 Feb 2021 01:49:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbhBWBsw (ORCPT ); Mon, 22 Feb 2021 20:48:52 -0500 Received: from mga01.intel.com ([192.55.52.88]:61191 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbhBWBsu (ORCPT ); Mon, 22 Feb 2021 20:48:50 -0500 IronPort-SDR: ECLckI/qQMMEdpjkKLYnopUp+JvIc6qYnzNFHQrzpoc4+wehv0gCy7vtFtAFgiboxdBVxfJmsw x4m7DT8WBC9A== X-IronPort-AV: E=McAfee;i="6000,8403,9903"; a="204074441" X-IronPort-AV: E=Sophos;i="5.81,198,1610438400"; d="scan'208";a="204074441" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2021 17:47:05 -0800 IronPort-SDR: Kzaw0ckMg7nf1MZuYneVHUCT7frutpZl9RQCVFTSnNTarhPJo+cTV5gofd1DBdvKcP2najIqH5 eW3n/7hgxkSg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,198,1610438400"; d="scan'208";a="423349306" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by fmsmga004.fm.intel.com with ESMTP; 22 Feb 2021 17:47:02 -0800 From: Like Xu To: Paolo Bonzini , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] KVM: vmx/pmu: Clear DEBUGCTLMSR_LBR bit on the debug breakpoint event Date: Tue, 23 Feb 2021 09:39:58 +0800 Message-Id: <20210223013958.1280444-2-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210223013958.1280444-1-like.xu@linux.intel.com> References: <20210223013958.1280444-1-like.xu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When the processor that support model-specific LBR generates a debug breakpoint event, it automatically clears the LBR flag. This action does not clear previously stored LBR stack MSRs. (Intel SDM 17.4.2) Signed-off-by: Like Xu --- arch/x86/kvm/vmx/vmx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e0a3a9be654b..4951b535eb7f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4795,6 +4795,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu) u32 intr_info, ex_no, error_code; unsigned long cr2, rip, dr6; u32 vect_info; + u64 lbr_ctl; vect_info = vmx->idt_vectoring_info; intr_info = vmx_get_intr_info(vcpu); @@ -4886,6 +4887,10 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu) rip = kvm_rip_read(vcpu); kvm_run->debug.arch.pc = vmcs_readl(GUEST_CS_BASE) + rip; kvm_run->debug.arch.exception = ex_no; + /* On the debug breakpoint event, the LBREn bit is cleared. */ + lbr_ctl = vmcs_read64(GUEST_IA32_DEBUGCTL); + if (lbr_ctl & DEBUGCTLMSR_LBR) + vmcs_write64(GUEST_IA32_DEBUGCTL, lbr_ctl & ~DEBUGCTLMSR_LBR); break; case AC_VECTOR: if (guest_inject_ac(vcpu)) {