[Devel] Re: [PATCH 3/3] perf events: Cleanup pid passing

Peter Zijlstra peterz at infradead.org
Wed Sep 15 01:18:30 PDT 2010


On Mon, 2010-09-13 at 13:01 -0700, Matt Helsley wrote:
> The kernel perf event creation path shouldn't use find_task_by_vpid()
> because a vpid exists in a specific namespace. find_task_by_vpid() uses
> current's pid namespace which isn't always the correct namespace to use
> for the vpid in all the places perf_event_create_kernel_counter() (and
> thus find_get_context()) is called.
> 
> The goal is to clean up pid namespace handling and prevent bugs like:
> 
>         https://bugzilla.kernel.org/show_bug.cgi?id=17281
> 
> Instead of using pids switch find_get_context() to use task struct
> pointers directly. The syscall is responsible for resolving the pid to
> a task struct. This moves the pid namespace resolution into the syscall
> much like every other syscall that takes pid parameters.


I took the three patches with the following change to this patch:

---
Index: linux-2.6/kernel/perf_event.c
===================================================================
--- linux-2.6.orig/kernel/perf_event.c
+++ linux-2.6/kernel/perf_event.c
@@ -5522,7 +5522,7 @@ SYSCALL_DEFINE5(perf_event_open,
 	struct perf_event_context *ctx;
 	struct file *event_file = NULL;
 	struct file *group_file = NULL;
-	struct task_struct *task;
+	struct task_struct *task = NULL;
 	struct pmu *pmu;
 	int event_fd;
 	int fput_needed = 0;
@@ -5577,14 +5577,12 @@ SYSCALL_DEFINE5(perf_event_open,
 	if ((pmu->task_ctx_nr == perf_sw_context) && group_leader)
 		pmu = group_leader->pmu;
 
+	if (pid != -1)
+		task = find_lively_task_by_vpid(pid);
+
 	/*
 	 * Get the target context (task or percpu):
 	 */
-	if (pid == -1 && cpu != -1)
-		task = NULL;
-	else
-		task = find_lively_task_by_vpid(pid);
-
 	ctx = find_get_context(pmu, task, cpu);
 	if (IS_ERR(ctx)) {
 		err = PTR_ERR(ctx);

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list