From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
Stephane Eranian <eranian@google.com>,
Harish Chegondi <harish.chegondi@intel.com>,
Kan Liang <kan.liang@intel.com>,
Andi Kleen <andi.kleen@intel.com>
Subject: [patch 03/11] x86/perf/intel_uncore: Fix error handling
Date: Wed, 17 Feb 2016 13:47:33 -0000 [thread overview]
Message-ID: <20160217133931.922441781@linutronix.de> (raw)
In-Reply-To: 20160217132903.767990400@linutronix.de
[-- Attachment #1: x86-perf-intel_uncore--Fix-error-handling.patch --]
[-- Type: text/plain, Size: 5899 bytes --]
This driver lacks any form of proper error handling. If initialization fails
or hotplug prepare fails, it lets the facility with half initialized stuff
around.
Fix the state and memory leaks in a first step. As a second step we need to
undo the hardware state which is set via uncore_box_init() on some of the
uncore implementations.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/kernel/cpu/perf_event_intel_uncore.c | 110 +++++++++++++++++---------
arch/x86/kernel/cpu/perf_event_intel_uncore.h | 15 +--
2 files changed, 82 insertions(+), 43 deletions(-)
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
@@ -760,16 +760,28 @@ static int uncore_pmu_register(struct in
}
ret = perf_pmu_register(&pmu->pmu, pmu->name, -1);
+ if (!ret)
+ pmu->registered = true;
return ret;
}
+static void uncore_pmu_unregister(struct intel_uncore_pmu *pmu)
+{
+ if (!pmu->registered)
+ return;
+ perf_pmu_unregister(&pmu->pmu);
+ pmu->registered = false;
+}
+
static void __init uncore_type_exit(struct intel_uncore_type *type)
{
int i;
if (type->pmus) {
- for (i = 0; i < type->num_boxes; i++)
+ for (i = 0; i < type->num_boxes; i++) {
+ uncore_pmu_unregister(&type->pmus[i]);
free_percpu(type->pmus[i].box);
+ }
kfree(type->pmus);
type->pmus = NULL;
}
@@ -856,8 +868,8 @@ static int uncore_pci_probe(struct pci_d
struct intel_uncore_pmu *pmu;
struct intel_uncore_box *box;
struct intel_uncore_type *type;
- int phys_id;
bool first_box = false;
+ int phys_id, ret;
phys_id = uncore_pcibus_to_physid(pdev->bus);
if (phys_id < 0)
@@ -906,9 +918,18 @@ static int uncore_pci_probe(struct pci_d
list_add_tail(&box->list, &pmu->box_list);
raw_spin_unlock(&uncore_box_lock);
- if (first_box)
- uncore_pmu_register(pmu);
- return 0;
+ if (!first_box)
+ return 0;
+
+ ret = uncore_pmu_register(pmu);
+ if (ret) {
+ pci_set_drvdata(pdev, NULL);
+ raw_spin_lock(&uncore_box_lock);
+ list_del(&box->list);
+ raw_spin_unlock(&uncore_box_lock);
+ kfree(box);
+ }
+ return ret;
}
static void uncore_pci_remove(struct pci_dev *pdev)
@@ -954,7 +975,7 @@ static void uncore_pci_remove(struct pci
kfree(box);
if (last_box)
- perf_pmu_unregister(&pmu->pmu);
+ uncore_pmu_unregister(pmu);
}
static int __init uncore_pci_init(void)
@@ -1223,8 +1244,7 @@ static int uncore_cpu_notifier(struct no
/* allocate/free data structure for uncore box */
switch (action & ~CPU_TASKS_FROZEN) {
case CPU_UP_PREPARE:
- uncore_cpu_prepare(cpu, -1);
- break;
+ return notifier_from_errno(uncore_cpu_prepare(cpu, -1));
case CPU_STARTING:
uncore_cpu_starting(cpu);
break;
@@ -1265,9 +1285,29 @@ static struct notifier_block uncore_cpu_
.priority = CPU_PRI_PERF + 1,
};
-static void __init uncore_cpu_setup(void *dummy)
+static int __init type_pmu_register(struct intel_uncore_type *type)
{
- uncore_cpu_starting(smp_processor_id());
+ int i, ret;
+
+ for (i = 0; i < type->num_boxes; i++) {
+ ret = uncore_pmu_register(&type->pmus[i]);
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
+static int __init uncore_msr_pmus_register(void)
+{
+ struct intel_uncore_type **types = uncore_msr_uncores;
+ int ret;
+
+ while (*types) {
+ ret = type_pmu_register(*types++);
+ if (ret)
+ return ret;
+ }
+ return 0;
}
static int __init uncore_cpu_init(void)
@@ -1317,6 +1357,10 @@ static int __init uncore_cpu_init(void)
ret = uncore_types_init(uncore_msr_uncores);
if (ret)
goto err;
+
+ ret = uncore_msr_pmus_register();
+ if (ret)
+ goto err;
return 0;
err:
uncore_types_exit(uncore_msr_uncores);
@@ -1324,26 +1368,14 @@ static int __init uncore_cpu_init(void)
return ret;
}
-static int __init uncore_pmus_register(void)
+static void __init uncore_cpu_setup(void *dummy)
{
- struct intel_uncore_pmu *pmu;
- struct intel_uncore_type *type;
- int i, j;
-
- for (i = 0; uncore_msr_uncores[i]; i++) {
- type = uncore_msr_uncores[i];
- for (j = 0; j < type->num_boxes; j++) {
- pmu = &type->pmus[j];
- uncore_pmu_register(pmu);
- }
- }
-
- return 0;
+ uncore_cpu_starting(smp_processor_id());
}
-static void __init uncore_cpumask_init(void)
+static int __init uncore_cpumask_init(void)
{
- int cpu;
+ int cpu, ret = 0;
cpu_notifier_register_begin();
@@ -1359,17 +1391,20 @@ static void __init uncore_cpumask_init(v
if (phys_id < 0)
continue;
- uncore_cpu_prepare(cpu, phys_id);
+ ret = uncore_cpu_prepare(cpu, phys_id);
+ if (ret)
+ goto out;
uncore_event_init_cpu(cpu);
}
on_each_cpu(uncore_cpu_setup, NULL, 1);
__register_cpu_notifier(&uncore_cpu_nb);
+out:
cpu_notifier_register_done();
+ return ret;
}
-
static int __init intel_uncore_init(void)
{
int ret;
@@ -1382,17 +1417,20 @@ static int __init intel_uncore_init(void
ret = uncore_pci_init();
if (ret)
- goto fail;
+ return ret;
ret = uncore_cpu_init();
- if (ret) {
- uncore_pci_exit();
- goto fail;
- }
- uncore_cpumask_init();
+ if (ret)
+ goto errpci;
+ ret = uncore_cpumask_init();
+ if (ret)
+ goto errcpu;
- uncore_pmus_register();
return 0;
-fail:
+
+errcpu:
+ uncore_types_exit(uncore_msr_uncores);
+errpci:
+ uncore_pci_exit();
return ret;
}
device_initcall(intel_uncore_init);
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
@@ -73,13 +73,14 @@ struct intel_uncore_ops {
};
struct intel_uncore_pmu {
- struct pmu pmu;
- char name[UNCORE_PMU_NAME_LEN];
- int pmu_idx;
- int func_id;
- struct intel_uncore_type *type;
- struct intel_uncore_box ** __percpu box;
- struct list_head box_list;
+ struct pmu pmu;
+ char name[UNCORE_PMU_NAME_LEN];
+ int pmu_idx;
+ int func_id;
+ bool registered;
+ struct intel_uncore_type *type;
+ struct intel_uncore_box ** __percpu box;
+ struct list_head box_list;
};
struct intel_uncore_extra_reg {
next prev parent reply other threads:[~2016-02-17 13:53 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 13:47 [patch 00/11] x86/perf/intel_uncore: Cleanup and enhancements Thomas Gleixner
2016-02-17 13:47 ` [patch 01/11] x86/perf/intel_uncore: Remove pointless mask check Thomas Gleixner
2016-02-17 13:47 ` [patch 02/11] x86/perf/intel_uncore: Simplify error rollback Thomas Gleixner
2016-02-17 13:47 ` Thomas Gleixner [this message]
2016-02-17 13:47 ` [patch 04/11] x86/perf/intel_uncore: Cleanup hardware on exit Thomas Gleixner
2016-02-17 15:49 ` Liang, Kan
2016-02-17 18:16 ` Thomas Gleixner
2016-02-17 21:57 ` Liang, Kan
2016-02-17 22:00 ` Thomas Gleixner
2016-02-17 13:47 ` [patch 05/11] x86/perf/intel_uncore: Make code readable Thomas Gleixner
2016-02-17 13:47 ` [patch 07/11] x86/perf/uncore: Track packages not per cpu data Thomas Gleixner
2016-02-17 21:19 ` Stephane Eranian
2016-02-17 21:24 ` Andi Kleen
2016-02-17 21:56 ` Thomas Gleixner
2016-02-17 22:16 ` Andi Kleen
2016-02-17 22:31 ` Thomas Gleixner
2016-02-18 7:50 ` Ingo Molnar
2016-02-18 8:13 ` Peter Zijlstra
2016-02-18 9:35 ` Stephane Eranian
2016-02-18 9:51 ` Peter Zijlstra
2016-02-18 10:25 ` Thomas Gleixner
2016-02-18 10:22 ` Thomas Gleixner
2016-02-18 10:54 ` Thomas Gleixner
2016-02-19 8:39 ` Thomas Gleixner
2016-02-17 21:25 ` Thomas Gleixner
2016-02-17 13:47 ` [patch 06/11] x86/topology: Provide helper to retrieve number of cpu packages Thomas Gleixner
2016-02-17 13:47 ` [patch 08/11] x86/perf/intel_uncore: Clear all hardware state on exit Thomas Gleixner
2016-02-17 13:47 ` [patch 10/11] cpumask: Export cpumask_any_but Thomas Gleixner
2016-02-17 13:47 ` [patch 09/11] x86/perf/intel_uncore: Make PCI and MSR uncore independent Thomas Gleixner
2016-02-17 13:47 ` [patch 11/11] x86/perf/intel_uncore: Make it modular Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160217133931.922441781@linutronix.de \
--to=tglx@linutronix.de \
--cc=andi.kleen@intel.com \
--cc=bp@alien8.de \
--cc=eranian@google.com \
--cc=harish.chegondi@intel.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).