[PATCH 1/1] powerpc/perf/hv-24x7: Check support before registering PMU

From: Sukadev Bhattiprolu
Date: Tue Apr 28 2015 - 18:47:58 EST


We currently try to register the 24x7 PMU unconditionally. Not all
Power systems support 24x7 counters (eg: Power7). On these systems
we get a backtrace during boot when trying to register the 24x7 PMU.

Check if the hypervisor supports 24x7 counters before attempting to
register the 24x7 PMU.

Reported-by: Gustavo Luiz Duarte <gusld@xxxxxxxxxx>
Signed-off-by: Sukadev Bhattiprolu <sukadev@xxxxxxxxxxxxxxxxxx>
---

Changelog[v2]
- [Michael Ellerman] Simplify check with bogus parameters.
---
arch/powerpc/perf/hv-24x7.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
index ec2eb20..c04a332 100644
--- a/arch/powerpc/perf/hv-24x7.c
+++ b/arch/powerpc/perf/hv-24x7.c
@@ -1268,12 +1268,33 @@ static struct pmu h_24x7_pmu = {
.read = h_24x7_event_read,
};

+/*
+ * Return 1 if we can access the 24x7 counter catalog from the hypervisor.
+ * Return 0 otherwise.
+ */
+static bool hv_has_24x7(void)
+{
+ unsigned long hret;
+
+ hret = h_get_24x7_catalog_page(0, 0, 0);
+
+ if (hret != H_FUNCTION)
+ pr_err("Error %ld reading catalog, disabling 24x7 PMU\n", hret);
+
+ return hret == 0;
+
+}
+
+
static int hv_24x7_init(void)
{
int r;
unsigned long hret;
struct hv_perf_caps caps;

+ if (!hv_has_24x7())
+ return -ENODEV;
+
if (!firmware_has_feature(FW_FEATURE_LPAR)) {
pr_debug("not a virtualized system, not enabling\n");
return -ENODEV;
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/