From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753739AbdBNNcI (ORCPT ); Tue, 14 Feb 2017 08:32:08 -0500 Received: from mga07.intel.com ([134.134.136.100]:8402 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752968AbdBNNay (ORCPT ); Tue, 14 Feb 2017 08:30:54 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,161,1484035200"; d="scan'208";a="44255373" From: Alexander Shishkin To: Peter Zijlstra , Ingo Molnar Cc: linux-kernel@vger.kernel.org, vince@deater.net, eranian@google.com, Arnaldo Carvalho de Melo , Borislav Petkov , Thomas Gleixner , Alexander Shishkin Subject: [PATCH 2/2] perf/x86/intel/pt: Fail event creation if VMX operation is on Date: Tue, 14 Feb 2017 15:24:16 +0200 Message-Id: <20170214132416.26400-3-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170214132416.26400-1-alexander.shishkin@linux.intel.com> References: <20170214132416.26400-1-alexander.shishkin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On systems where PT does not coexist with VMX, users get confused when PT turns up with no data because they forgot they're running a kvm session at the same time. This patch adds a preemptive check for any active VMX operations that will fail event creation. This does not provide any guarantees or protection against racing with a kvm starting in parallel, but is intended to serve as a hint for the user. If VMXON happens after an event had been created, the event will still produce an empty trace. Signed-off-by: Alexander Shishkin Reported-by: Andi Kleen --- arch/x86/events/intel/pt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index 9372fa4549..b1490a879c 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -1444,6 +1444,20 @@ static void pt_event_destroy(struct perf_event *event) static int pt_event_init(struct perf_event *event) { + int cpu, vmx_on = 0; + + get_online_cpus(); + for_each_online_cpu(cpu) { + struct pt *pt = per_cpu_ptr(&pt_ctx, cpu); + + if (READ_ONCE(pt->vmx_on)) + vmx_on++; + } + put_online_cpus(); + + if (vmx_on) + return -EBUSY; + if (event->attr.type != pt_pmu.pmu.type) return -ENOENT; -- 2.11.0