From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752560Ab0IOISx (ORCPT ); Wed, 15 Sep 2010 04:18:53 -0400 Received: from bombadil.infradead.org ([18.85.46.34]:54663 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752152Ab0IOISu convert rfc822-to-8bit (ORCPT ); Wed, 15 Sep 2010 04:18:50 -0400 Subject: Re: [PATCH 3/3] perf events: Cleanup pid passing From: Peter Zijlstra To: Matt Helsley Cc: Frederic Weisbecker , containers@lists.linux-foundation.org, Robin Green , linux-kernel@vger.kernel.org, Prasad , Arnaldo Carvalho de Melo , Steven Rostedt , Ingo Molnar , Will Deacon , Mahesh Salgaonkar In-Reply-To: References: <1284408080-2135-1-git-send-email-matthltc@us.ibm.com> <561205417b450b8a4bf7488374541d64b4690431.1284407762.git.matthltc@us.ibm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Date: Wed, 15 Sep 2010 10:18:30 +0200 Message-ID: <1284538710.3764.245.camel@twins> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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);