Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1752260ybg; Sun, 27 Oct 2019 04:13:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaEoNoWBIKk0HM6iW8GLCloAQtp4CKINxZiuy2xTZcQIPrcT6ksbS/kX+r6Gap4otCyR/H X-Received: by 2002:a50:c90d:: with SMTP id o13mr13855548edh.85.1572174830153; Sun, 27 Oct 2019 04:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572174830; cv=none; d=google.com; s=arc-20160816; b=pFOkG89xFbB/Df6LqY/YnpV0A5kzAJMGEAix9hHTDR0BSKlNU8noLUdL65JlaRf470 AIQsW21NFRW+TAMyskapW4teQ0VBmjJfRGFZR4oNmmAETympCBvC0f7RUP533/mmr7bT p0rwCcnRYECRPfJ/lxVr1xBtvz+k/BzJKVn+0e1xJ+7pz6TrTaXGsy4kY1o4ETGbM6i/ IPOi+ULqQq1zHt3kxxan/yIC2YngmRjRugVgqSsR1i84loNFKhKBgw4Jdiku1ehP4BJJ WHPUnFafkcOzfWONFDOJotPCtCcEyfDRbmgzyoUrS9dtSrusII4UND++mjV4PNMKUvVY jXnw== 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=OTrdYsuQXdziSlbfvYgBSIEgYQOu4OupLzYYMbwPAr8=; b=iCK43w1+3Ro23/hNCvvD3BqbPq4zmtjNzmQ9Ug8BUX/fTpFEt3XAxn2SgmzPeQhcmk WYa6FXMnpsJFA1DJM1Wz7wr4DurKB6BUy0rntNUI8z/TpBFovDQM715mzDomebkLcg/Y uF/CBhowjJBf4KsH6LC6JVfFZmp7dvgAboCAeZAcBHb2n/vY3YDzqLeS8gcE+aYIKKmi a4ocHTrrLFku2yv9SZoHNej8zdI8Bmh5FQtD7J4bBtbYn/zdOo6l6z5h96fHJ0NfOtD3 4uZ0YY+pQ88tqpV3w8mJhFnkY31PW3aM3HJLFB0x9KnPlAebF0P8ciITHqVXmA3LNKy2 lrqA== 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 h1si4862174edn.93.2019.10.27.04.13.26; Sun, 27 Oct 2019 04:13:50 -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 S1726871AbfJ0LMm (ORCPT + 99 others); Sun, 27 Oct 2019 07:12:42 -0400 Received: from mga02.intel.com ([134.134.136.20]:12491 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726834AbfJ0LMk (ORCPT ); Sun, 27 Oct 2019 07:12:40 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Oct 2019 04:12:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,236,1569308400"; d="scan'208";a="282690165" Received: from unknown (HELO snr.jf.intel.com) ([10.54.39.141]) by orsmga001.jf.intel.com with ESMTP; 27 Oct 2019 04:12:37 -0700 From: Luwei Kang To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, sean.j.christopherson@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, ak@linux.intel.com, thomas.lendacky@amd.com, peterz@infradead.org, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, Luwei Kang Subject: [PATCH v1 4/8] KVM: x86: Aviod clear the PEBS counter when PEBS enabled in guest Date: Sun, 27 Oct 2019 19:11:13 -0400 Message-Id: <1572217877-26484-5-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1572217877-26484-1-git-send-email-luwei.kang@intel.com> References: <1572217877-26484-1-git-send-email-luwei.kang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduce a parameter that avoid clear the PEBS event counter while running in the guest. The performance counter which use for PEBS event can be enabled through VM-entry when PEBS is enabled in guest by PEBS output to Intel PT. Signed-off-by: Luwei Kang --- arch/x86/events/intel/core.c | 19 +++++++++++-------- arch/x86/events/perf_event.h | 2 +- arch/x86/include/asm/perf_event.h | 5 +++-- arch/x86/kvm/vmx/vmx.c | 3 ++- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index fcef678..1fcc9fc 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3323,16 +3323,16 @@ static int intel_pmu_hw_config(struct perf_event *event) return 0; } -struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) +struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, bool pebs) { if (x86_pmu.guest_get_msrs) - return x86_pmu.guest_get_msrs(nr); + return x86_pmu.guest_get_msrs(nr, pebs); *nr = 0; return NULL; } EXPORT_SYMBOL_GPL(perf_guest_get_msrs); -static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) +static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, bool pebs) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; @@ -3340,10 +3340,13 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) arr[0].msr = MSR_CORE_PERF_GLOBAL_CTRL; arr[0].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask; arr[0].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask; - if (x86_pmu.flags & PMU_FL_PEBS_ALL) - arr[0].guest &= ~cpuc->pebs_enabled; - else - arr[0].guest &= ~(cpuc->pebs_enabled & PEBS_COUNTER_MASK); + if (!pebs) { + if (x86_pmu.flags & PMU_FL_PEBS_ALL) + arr[0].guest &= ~cpuc->pebs_enabled; + else + arr[0].guest &= + ~(cpuc->pebs_enabled & PEBS_COUNTER_MASK); + } *nr = 1; if (x86_pmu.pebs && x86_pmu.pebs_no_isolation) { @@ -3364,7 +3367,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) return arr; } -static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr) +static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr, bool pebs) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index ecacfbf..57058fe 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -696,7 +696,7 @@ struct x86_pmu { /* * Intel host/guest support (KVM) */ - struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr); + struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr, bool pebs); /* * Check period value for PERF_EVENT_IOC_PERIOD ioctl. diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index ee26e92..e29075a 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -322,12 +322,13 @@ struct perf_guest_switch_msr { u64 host, guest; }; -extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); +extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, bool pebs); extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap); extern void perf_check_microcode(void); extern int x86_perf_rdpmc_index(struct perf_event *event); #else -static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) +static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, + bool pebs) { *nr = 0; return NULL; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e7970a2..170afde 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6428,7 +6428,8 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx) int i, nr_msrs; struct perf_guest_switch_msr *msrs; - msrs = perf_guest_get_msrs(&nr_msrs); + msrs = perf_guest_get_msrs(&nr_msrs, + vcpu_to_pmu(&vmx->vcpu)->pebs_enable); if (!msrs) return; -- 1.8.3.1