Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754881AbbHXOfu (ORCPT ); Mon, 24 Aug 2015 10:35:50 -0400 Received: from mga11.intel.com ([192.55.52.93]:52162 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754836AbbHXOfq (ORCPT ); Mon, 24 Aug 2015 10:35:46 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,738,1432623600"; d="scan'208";a="547536174" From: Alexander Shishkin To: Peter Zijlstra , Ingo Molnar Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, Arnaldo Carvalho de Melo , Vince Weaver , Stephane Eranian , Johannes Berg , Alexander Shishkin Subject: [PATCH v2 5/6] perf/x86/intel/pt: Use extended error reporting in event initialization Date: Mon, 24 Aug 2015 17:32:59 +0300 Message-Id: <1440426780-27227-6-git-send-email-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1440426780-27227-1-git-send-email-alexander.shishkin@linux.intel.com> References: <1440426780-27227-1-git-send-email-alexander.shishkin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3314 Lines: 112 Event attribute validation is one of the biggest sources of EINVALs around perf_event_open() syscall. This patch annotates error checks with extended error reporting macros to provide the user with more details on what they are doing wrong. Signed-off-by: Alexander Shishkin --- arch/x86/kernel/cpu/perf_event_intel_pt.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/perf_event_intel_pt.c b/arch/x86/kernel/cpu/perf_event_intel_pt.c index 4216928344..9a09c89928 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_pt.c +++ b/arch/x86/kernel/cpu/perf_event_intel_pt.c @@ -18,6 +18,8 @@ #undef DEBUG +#define PERF_MODNAME "perf/x86/intel/pt" + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include @@ -198,29 +200,29 @@ fail: RTIT_CTL_CYC_PSB | \ RTIT_CTL_MTC) -static bool pt_event_valid(struct perf_event *event) +static int pt_event_valid(struct perf_event *event) { u64 config = event->attr.config; u64 allowed, requested; if ((config & PT_CONFIG_MASK) != config) - return false; + return perf_err(-EINVAL, "PT config: disallowed bits"); if (config & RTIT_CTL_CYC_PSB) { if (!pt_cap_get(PT_CAP_psb_cyc)) - return false; + return perf_err(-EINVAL, "PT config: PSB/CYC not supported"); allowed = pt_cap_get(PT_CAP_psb_periods); requested = (config & RTIT_CTL_PSB_FREQ) >> RTIT_CTL_PSB_FREQ_OFFSET; if (requested && (!(allowed & BIT(requested)))) - return false; + return perf_err(-EINVAL, "PT config: unsupported PSB period"); allowed = pt_cap_get(PT_CAP_cycle_thresholds); requested = (config & RTIT_CTL_CYC_THRESH) >> RTIT_CTL_CYC_THRESH_OFFSET; if (requested && (!(allowed & BIT(requested)))) - return false; + return perf_err(-EINVAL, "PT config: unsupported CYC threshold"); } if (config & RTIT_CTL_MTC) { @@ -232,20 +234,20 @@ static bool pt_event_valid(struct perf_event *event) * CPUID is 0 will #GP, so better safe than sorry. */ if (!pt_cap_get(PT_CAP_mtc)) - return false; + return perf_err(-EINVAL, "PT config: MTC not supported"); allowed = pt_cap_get(PT_CAP_mtc_periods); if (!allowed) - return false; + return perf_err(-EINVAL, "PT config: MTC periods not supported"); requested = (config & RTIT_CTL_MTC_RANGE) >> RTIT_CTL_MTC_RANGE_OFFSET; if (!(allowed & BIT(requested))) - return false; + return perf_err(-EINVAL, "PT config: unsupported MTC period"); } - return true; + return 0; } /* @@ -1111,14 +1113,17 @@ static void pt_event_destroy(struct perf_event *event) static int pt_event_init(struct perf_event *event) { + int err; + if (event->attr.type != pt_pmu.pmu.type) return -ENOENT; - if (!pt_event_valid(event)) - return -EINVAL; + err = pt_event_valid(event); + if (err) + return err; if (x86_add_exclusive(x86_lbr_exclusive_pt)) - return -EBUSY; + return perf_err(-EBUSY, "PT conflicts with active events"); event->destroy = pt_event_destroy; -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/