public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Matt Helsley <matthltc@us.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	containers@lists.linux-foundation.org,
	Robin Green <greenrd@greenrd.org>,
	linux-kernel@vger.kernel.org, Prasad <prasad@linux.vnet.ibm.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@elte.hu>,
	Will Deacon <will.deacon@arm.com>,
	Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Subject: Re: [PATCH 3/3] perf events: Cleanup pid passing
Date: Wed, 15 Sep 2010 10:18:30 +0200	[thread overview]
Message-ID: <1284538710.3764.245.camel@twins> (raw)
In-Reply-To: <a134e5e392ab0204961fd1a62c84a222bf5874a9.1284407763.git.matthltc@us.ibm.com>

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


  reply	other threads:[~2010-09-15  8:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1284408080-2135-1-git-send-email-matthltc@us.ibm.com>
2010-09-13 20:01 ` [PATCH 1/3] hw breakpoints: Fix pid namespace bug Matt Helsley
2010-09-13 20:01   ` [PATCH 2/3] perf events: Split out task search into helper Matt Helsley
2010-09-15 10:03     ` [tip:perf/core] " tip-bot for Matt Helsley
2010-09-13 20:01   ` [PATCH 3/3] perf events: Cleanup pid passing Matt Helsley
2010-09-15  8:18     ` Peter Zijlstra [this message]
2010-09-15 10:03     ` [tip:perf/core] perf events: Clean up " tip-bot for Matt Helsley
2010-09-22 12:22       ` Peter Zijlstra
2010-09-15 10:03   ` [tip:perf/core] hw breakpoints: Fix pid namespace bug tip-bot for Matt Helsley
2010-09-15 11:41     ` Frederic Weisbecker
2010-09-15 11:45       ` Ingo Molnar
2010-09-17  8:28   ` [tip:perf/urgent] " tip-bot for Matt Helsley
2010-09-13 20:08 ` [PATCH 0/3] perf_events and hw_breakpoints fix and cleanup Frederic Weisbecker

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=1284538710.3764.245.camel@twins \
    --to=peterz@infradead.org \
    --cc=acme@redhat.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=greenrd@greenrd.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=matthltc@us.ibm.com \
    --cc=mingo@elte.hu \
    --cc=prasad@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=will.deacon@arm.com \
    /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