lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 10 Sep 2009 10:29:23 +0200
From:	Frederic Weisbecker <fweisbec@...il.com>
To:	Ingo Molnar <mingo@...e.hu>
Cc:	LKML <linux-kernel@...r.kernel.org>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Prasad <prasad@...ux.vnet.ibm.com>,
	Alan Stern <stern@...land.harvard.edu>,
	Peter Zijlstra <peterz@...radead.org>,
	Arnaldo Carvalho de Melo <acme@...hat.com>,
	Steven Rostedt <rostedt@...dmis.org>,
	Ingo Molnar <mingo@...e.hu>,
	Jan Kiszka <jan.kiszka@...mens.com>,
	Jiri Slaby <jirislaby@...il.com>,
	Li Zefan <lizf@...fujitsu.com>, Avi Kivity <avi@...hat.com>,
	Paul Mackerras <paulus@...ba.org>,
	Mike Galbraith <efault@....de>,
	Masami Hiramatsu <mhiramat@...hat.com>
Subject: [PATCH 1/5] perf_counter: Add open/close pmu callbacks

Add the open() and close() callback to the pmu structure.
Open is called when a counter is initialized just after it's allocation
and close is called when the counter is about to be released.

These callbacks are useful for example when a pmu has to deal with
several registers and needs to maintain an internal list of counters
using them. Given such list, the pmu is able to check if the the number
of physical registers are still sufficient for the new created counter
and then accept or refuse this counter.

open() will return 0 in case of success or an error if we have not
enough registers for the given counter (or whatever error a pmu may
encounter).

Signed-off-by: Frederic Weisbecker <fweisbec@...il.com>
Cc: Prasad <prasad@...ux.vnet.ibm.com>
Cc: Alan Stern <stern@...land.harvard.edu>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: Ingo Molnar <mingo@...e.hu>
Cc: Jan Kiszka <jan.kiszka@...mens.com>
Cc: Jiri Slaby <jirislaby@...il.com>
Cc: Li Zefan <lizf@...fujitsu.com>
Cc: Avi Kivity <avi@...hat.com>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Mike Galbraith <efault@....de>
Cc: Masami Hiramatsu <mhiramat@...hat.com>
---
 include/linux/perf_counter.h |    3 +++
 kernel/perf_counter.c        |   27 +++++++++++++++++++++------
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 9ba1822..f557483 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -487,6 +487,8 @@ struct pmu {
 	void (*disable)			(struct perf_counter *counter);
 	void (*read)			(struct perf_counter *counter);
 	void (*unthrottle)		(struct perf_counter *counter);
+	int (*open)			(struct perf_counter *counter);
+	void (*close)			(struct perf_counter *counter);
 };
 
 /**
@@ -497,6 +499,7 @@ enum perf_counter_active_state {
 	PERF_COUNTER_STATE_OFF		= -1,
 	PERF_COUNTER_STATE_INACTIVE	=  0,
 	PERF_COUNTER_STATE_ACTIVE	=  1,
+	PERF_COUNTER_STATE_UNOPENED	=  2,
 };
 
 struct file;
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index d7cbc57..400ccf6 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -1675,6 +1675,10 @@ static void free_counter(struct perf_counter *counter)
 			atomic_dec(&nr_task_counters);
 	}
 
+	if (counter->pmu->close)
+		if (counter->state != PERF_COUNTER_STATE_UNOPENED)
+			counter->pmu->close(counter);
+
 	if (counter->destroy)
 		counter->destroy(counter);
 
@@ -4101,15 +4105,19 @@ done:
 	else if (IS_ERR(pmu))
 		err = PTR_ERR(pmu);
 
-	if (err) {
-		if (counter->ns)
-			put_pid_ns(counter->ns);
-		kfree(counter);
-		return ERR_PTR(err);
-	}
+	if (err)
+		goto fail;
 
 	counter->pmu = pmu;
 
+	if (pmu->open) {
+		err = pmu->open(counter);
+		if (err) {
+			counter->state = PERF_COUNTER_STATE_UNOPENED;
+			goto fail;
+		}
+	}
+
 	if (!counter->parent) {
 		atomic_inc(&nr_counters);
 		if (counter->attr.mmap)
@@ -4121,6 +4129,13 @@ done:
 	}
 
 	return counter;
+
+fail:
+	if (counter->ns)
+		put_pid_ns(counter->ns);
+	kfree(counter);
+
+	return ERR_PTR(err);
 }
 
 static int perf_copy_attr(struct perf_counter_attr __user *uattr,
-- 
1.6.2.3

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ