linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vikas Shivappa <vikas.shivappa@linux.intel.com>
To: vikas.shivappa@intel.com, vikas.shivappa@linux.intel.com
Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com,
	tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org,
	ravi.v.shankar@intel.com, tony.luck@intel.com,
	fenghua.yu@intel.com, h.peter.anvin@intel.com
Subject: Re: [PATCH 2/6] x86,perf/cqm: Fix cqm memory leak and notifier leak
Date: Wed,  2 Mar 2016 15:53:59 -0800	[thread overview]
Message-ID: <1456962839-29170-1-git-send-email-vikas.shivappa@linux.intel.com> (raw)
In-Reply-To: <1456876108-28770-3-git-send-email-vikas.shivappa@linux.intel.com>

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>
---

Fixed the memory leak for cqm_rmid_ptrs as per Thomas feedback.
  
 arch/x86/kernel/cpu/perf_event_intel_cqm.c | 34 ++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 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..37a93fa 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_cqm.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_cqm.c
@@ -250,10 +250,13 @@ static int intel_cqm_setup_rmid_cache(void)
 
 	return 0;
 fail:
-	while (r--)
+	while (r--) {
 		kfree(cqm_rmid_ptrs[r]);
+		cqm_rmid_ptrs[r] = NULL;
+	}
 
 	kfree(cqm_rmid_ptrs);
+	cqm_rmid_ptrs = NULL;
 	return -ENOMEM;
 }
 
@@ -1320,9 +1323,19 @@ static const struct x86_cpu_id intel_cqm_match[] = {
 	{}
 };
 
+static void cqm_cleanup(void)
+{
+	int r = cqm_max_rmid;
+
+	while (r--)
+		kfree(cqm_rmid_ptrs[r]);
+
+	kfree(cqm_rmid_ptrs);
+}
+
 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 +1395,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
+		goto out;
+	} else {
 		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

  parent reply	other threads:[~2016-03-02 23:53 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-01 23:48 [PATCH V5 0/6] Intel memory b/w monitoring support Vikas Shivappa
2016-03-01 23:48 ` [PATCH 1/6] x86,perf/cqm: Fix cqm handling of grouping events into a cache_group Vikas Shivappa
2016-03-07 23:04   ` Peter Zijlstra
2016-03-10  0:18     ` Vikas Shivappa
2016-03-01 23:48 ` [PATCH 2/6] x86,perf/cqm: Fix cqm memory leak and notifier leak Vikas Shivappa
2016-03-02  8:00   ` Thomas Gleixner
2016-03-02 17:58     ` Vikas Shivappa
2016-03-02 23:53   ` Vikas Shivappa [this message]
2016-03-08  9:22     ` Thomas Gleixner
2016-03-08 19:36       ` Vikas Shivappa
2016-03-01 23:48 ` [PATCH 3/6] x86/mbm: Intel Memory B/W Monitoring enumeration and init Vikas Shivappa
2016-03-02  8:04   ` Thomas Gleixner
2016-03-02 17:59     ` Vikas Shivappa
2016-03-02 21:31       ` Vikas Shivappa
2016-03-02 23:56   ` Vikas Shivappa
2016-03-03  7:35     ` Thomas Gleixner
2016-03-03 18:26       ` Vikas Shivappa
2016-03-03 18:37         ` Thomas Gleixner
2016-03-08  9:25           ` Thomas Gleixner
2016-03-08 19:36             ` Vikas Shivappa
2016-03-01 23:48 ` [PATCH 4/6] x86/mbm: Memory bandwidth monitoring event management Vikas Shivappa
2016-03-07 23:03   ` Peter Zijlstra
2016-03-07 23:27     ` Luck, Tony
2016-03-08  8:49       ` Peter Zijlstra
2016-03-10 22:46         ` Vikas Shivappa
2016-03-10 22:49     ` Vikas Shivappa
2016-03-01 23:48 ` [PATCH 5/6] x86/mbm: RMID Recycling MBM changes Vikas Shivappa
2016-03-01 23:48 ` [PATCH 6/6] x86/mbm: Add support for MBM counter overflow handling Vikas Shivappa
2016-03-02 23:58   ` Vikas Shivappa

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=1456962839-29170-1-git-send-email-vikas.shivappa@linux.intel.com \
    --to=vikas.shivappa@linux.intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=h.peter.anvin@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.v.shankar@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=vikas.shivappa@intel.com \
    --cc=x86@kernel.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).