Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2035033pxb; Mon, 22 Feb 2021 18:31:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5wYE+CNA1p2BOED8jNULz+aDZKd2467WKcYsqR0lA+/X18Extc46GeNKAgovyaXGXx3KU X-Received: by 2002:a50:cf02:: with SMTP id c2mr25392250edk.333.1614047487092; Mon, 22 Feb 2021 18:31:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614047487; cv=none; d=google.com; s=arc-20160816; b=tS9acFSp/nXmYREgvWMtb7Ft7G608+QMoEQGHMKnwWPBHj4Cbv4tauNa/D5M9QHwzX 8LQrm66Vfl+yY1yNN2RVaY4qCmQGxVzIv8z1YZVEmJ4OgEZG/IVFyNDV2lFAfNQbLgG0 1lrEsWMWGoLh9dDWxFgg+OsMFa9GGZNgpxoDGWN+ouCGVaNsJwviPRzlSKyhZiE1CuU9 35KYS2/c/AMHOGc/XIsNj3ObfbLHAfFzd0YXFf2Z/usRMlG0byGHjSonA9g9RZlZbeIF G2dahgkVnTjn5Wwyw060c699oz8VBnhXmSdZ2wXXJA4eNNM3DfU2yKUXwiV5rnlelITD 6Ywg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=OrXsqh9ORbrVRTYrZ+OkZUYflFFta5Ry6fr4eXLyQk0=; b=OskLcKmxUaN7Le7TdzHr4nVG51yaQm3B7ZBKaF5bncD47wHakp6jOPwzku5KoI4tt2 909Z7irqYAxH9dPQ12OjN9LF56TFYrD4OnF7AJZSBE8amkkT6qjaR3zj6Kd2zAPOnaSc Ua0D5ER6n3FXLUUtrQ2v3MNMcmEUaCQ6F6ezfUz1sIDIeO5x8ryOHkj2zkzsY/wGiAAy 5LwfY+m5KowlfFHNEcWc66zfGvHP1eZsw0JqF+YAJtpIoUXJd71B5Fdubxyt03CJ7Yyz Ua3cL1rJjRMDdtEK5UPDqc9qzaECEeOajZBMKo+M5xPayi1Jt9LJGZ/M0qh8EoZbBbs1 B5FQ== 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 j22si13462887eds.507.2021.02.22.18.31.02; Mon, 22 Feb 2021 18:31:27 -0800 (PST) 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 S230439AbhBWBsx (ORCPT + 99 others); Mon, 22 Feb 2021 20:48:53 -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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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)) { -- 2.29.2