Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1355468

[PATCH 2/6] x86/perf/intel/cqm: Fix cqm memory leak and notifier leak

From Vikas Shivappa <vikas.shivappa@linux.intel.com>
Newsgroups linux.kernel
Subject [PATCH 2/6] x86/perf/intel/cqm: Fix cqm memory leak and notifier leak
Date 2016-03-11 00:40 +0100
Message-ID <rbils-5Ng-35@gated-at.bofh.it> (permalink)
References <rbilr-5Ng-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Fixes the hotcpu notifier leak and other global variable memory leaks
during cqm(cache quality of service monitoring) initialization.

Reviewed-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Vikas Shivappa <vikas.shivappa@linux.intel.com>
---
 arch/x86/kernel/cpu/perf_event_intel_cqm.c | 43 ++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_cqm.c b/arch/x86/kernel/cpu/perf_event_intel_cqm.c
index e6be335..fc704ed 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_cqm.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_cqm.c
@@ -211,6 +211,20 @@ static void __put_rmid(u32 rmid)
 	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)
 {
 	struct cqm_rmid_entry *entry;
@@ -218,7 +232,7 @@ static int intel_cqm_setup_rmid_cache(void)
 	int r = 0;
 
 	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);
 	if (!cqm_rmid_ptrs)
 		return -ENOMEM;
@@ -249,11 +263,9 @@ static int intel_cqm_setup_rmid_cache(void)
 	mutex_unlock(&cache_mutex);
 
 	return 0;
-fail:
-	while (r--)
-		kfree(cqm_rmid_ptrs[r]);
 
-	kfree(cqm_rmid_ptrs);
+fail:
+	cqm_cleanup();
 	return -ENOMEM;
 }
 
@@ -1322,7 +1334,7 @@ static const struct x86_cpu_id intel_cqm_match[] = {
 
 static int __init intel_cqm_init(void)
 {
-	char *str, scale[20];
+	char *str = NULL, scale[20];
 	int i, cpu, ret;
 
 	if (!x86_match_cpu(intel_cqm_match))
@@ -1382,16 +1394,25 @@ static int __init intel_cqm_init(void)
 		cqm_pick_event_reader(i);
 	}
 
-	__perf_cpu_notifier(intel_cqm_cpu_notifier);
-
 	ret = perf_pmu_register(&intel_cqm_pmu, "intel_cqm", -1);
-	if (ret)
+	if (ret) {
 		pr_err("Intel CQM perf registration failed: %d\n", ret);
-	else
-		pr_info("Intel CQM monitoring enabled\n");
+		goto out;
+	}
+
+	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:
 	cpu_notifier_register_done();
+	if (ret) {
+		kfree(str);
+		cqm_cleanup();
+	}
 
 	return ret;
 }
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH V6 0/6] Intel memory b/w monitoring support Vikas Shivappa <vikas.shivappa@linux.intel.com> - 2016-03-11 00:40 +0100
  [PATCH 2/6] x86/perf/intel/cqm: Fix cqm memory leak and notifier leak Vikas Shivappa <vikas.shivappa@linux.intel.com> - 2016-03-11 00:40 +0100
  Re: [PATCH V6 0/6] Intel memory b/w monitoring support Peter Zijlstra <peterz@infradead.org> - 2016-03-12 00:00 +0100
    Re: [PATCH V6 0/6] Intel memory b/w monitoring support Vikas Shivappa <vikas.shivappa@intel.com> - 2016-03-12 00:30 +0100
      Re: [PATCH V6 0/6] Intel memory b/w monitoring support Vikas Shivappa <vikas.shivappa@intel.com> - 2016-03-12 00:30 +0100
    RE: [PATCH V6 0/6] Intel memory b/w monitoring support "Luck, Tony" <tony.luck@intel.com> - 2016-03-12 00:50 +0100
    RE: [PATCH V6 0/6] Intel memory b/w monitoring support "Luck, Tony" <tony.luck@intel.com> - 2016-03-12 03:00 +0100
      Re: [PATCH V6 0/6] Intel memory b/w monitoring support Peter Zijlstra <peterz@infradead.org> - 2016-03-12 09:00 +0100
        RE: [PATCH V6 0/6] Intel memory b/w monitoring support "Luck, Tony" <tony.luck@intel.com> - 2016-03-12 17:20 +0100

csiph-web