perf/x86/cqm: Fix CQM memory leak and notifier leak
[ Upstream commit ada2f634cd50d050269b67b4e2966582387e7c27 ] Fixes the hotcpu notifier leak and other global variable memory leaks during CQM (cache quality of service monitoring) initialization. Signed-off-by: Vikas Shivappa <vikas.shivappa@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Tony Luck <tony.luck@intel.com> Acked-by: Thomas Gleixner <tglx@linutronix.de> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: David Ahern <dsahern@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Vince Weaver <vincent.weaver@maine.edu> Cc: fenghua.yu@intel.com Cc: h.peter.anvin@intel.com Cc: ravi.v.shankar@intel.com Cc: vikas.shivappa@intel.com Link: http://lkml.kernel.org/r/1457652732-4499-3-git-send-email-vikas.shivappa@linux.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
0b152db042
commit
12850f3616
1 changed files with 32 additions and 11 deletions
|
@ -211,6 +211,20 @@ static void __put_rmid(u32 rmid)
|
||||||
list_add_tail(&entry->list, &cqm_rmid_limbo_lru);
|
list_add_tail(&entry->list, &cqm_rmid_limbo_lru);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cqm_cleanup(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!cqm_rmid_ptrs)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < cqm_max_rmid; i++)
|
||||||
|
kfree(cqm_rmid_ptrs[i]);
|
||||||
|
|
||||||
|
kfree(cqm_rmid_ptrs);
|
||||||
|
cqm_rmid_ptrs = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int intel_cqm_setup_rmid_cache(void)
|
static int intel_cqm_setup_rmid_cache(void)
|
||||||
{
|
{
|
||||||
struct cqm_rmid_entry *entry;
|
struct cqm_rmid_entry *entry;
|
||||||
|
@ -218,7 +232,7 @@ static int intel_cqm_setup_rmid_cache(void)
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
nr_rmids = cqm_max_rmid + 1;
|
nr_rmids = cqm_max_rmid + 1;
|
||||||
cqm_rmid_ptrs = kmalloc(sizeof(struct cqm_rmid_entry *) *
|
cqm_rmid_ptrs = kzalloc(sizeof(struct cqm_rmid_entry *) *
|
||||||
nr_rmids, GFP_KERNEL);
|
nr_rmids, GFP_KERNEL);
|
||||||
if (!cqm_rmid_ptrs)
|
if (!cqm_rmid_ptrs)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -249,11 +263,9 @@ static int intel_cqm_setup_rmid_cache(void)
|
||||||
mutex_unlock(&cache_mutex);
|
mutex_unlock(&cache_mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
|
||||||
while (r--)
|
|
||||||
kfree(cqm_rmid_ptrs[r]);
|
|
||||||
|
|
||||||
kfree(cqm_rmid_ptrs);
|
fail:
|
||||||
|
cqm_cleanup();
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1322,7 +1334,7 @@ static const struct x86_cpu_id intel_cqm_match[] = {
|
||||||
|
|
||||||
static int __init intel_cqm_init(void)
|
static int __init intel_cqm_init(void)
|
||||||
{
|
{
|
||||||
char *str, scale[20];
|
char *str = NULL, scale[20];
|
||||||
int i, cpu, ret;
|
int i, cpu, ret;
|
||||||
|
|
||||||
if (!x86_match_cpu(intel_cqm_match))
|
if (!x86_match_cpu(intel_cqm_match))
|
||||||
|
@ -1382,16 +1394,25 @@ static int __init intel_cqm_init(void)
|
||||||
cqm_pick_event_reader(i);
|
cqm_pick_event_reader(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
__perf_cpu_notifier(intel_cqm_cpu_notifier);
|
|
||||||
|
|
||||||
ret = perf_pmu_register(&intel_cqm_pmu, "intel_cqm", -1);
|
ret = perf_pmu_register(&intel_cqm_pmu, "intel_cqm", -1);
|
||||||
if (ret)
|
if (ret) {
|
||||||
pr_err("Intel CQM perf registration failed: %d\n", ret);
|
pr_err("Intel CQM perf registration failed: %d\n", ret);
|
||||||
else
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
pr_info("Intel CQM monitoring enabled\n");
|
pr_info("Intel CQM monitoring enabled\n");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register the hot cpu notifier once we are sure cqm
|
||||||
|
* is enabled to avoid notifier leak.
|
||||||
|
*/
|
||||||
|
__perf_cpu_notifier(intel_cqm_cpu_notifier);
|
||||||
out:
|
out:
|
||||||
cpu_notifier_register_done();
|
cpu_notifier_register_done();
|
||||||
|
if (ret) {
|
||||||
|
kfree(str);
|
||||||
|
cqm_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue