From patchwork Mon Apr 23 07:09:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8012 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 81C5C23E49 for ; Mon, 23 Apr 2012 07:10:18 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 42E12A187EB for ; Mon, 23 Apr 2012 07:10:18 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so22276722iag.11 for ; Mon, 23 Apr 2012 00:10:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:date:from :to:cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:x-gm-message-state; bh=FRJkTWJAHi4q2B9ubKhD1pHMnIx+rk4br2OmhsjKO6Q=; b=XzuWQLym8NhPL7psdNqaHF8QFf51mJcssHM5IwA+Dp4eRmHsxtAYEK2jYzuZksnP1x EgkoPKFyv4U7UndvZOqHJ2CQ7VQkaJRomx1G6EnQx5HxFohpKvsX3+gtLPxw2EAZ/s++ xx61Ef8H/RTmQ35JfrNNqTQ75s4CJTSv4LKW+HnZ72TIgBB1dqugoFE74Ycw615exkkL PG9irphEIRcy4v14uq1e6/LkUnDAuH+scK7LVjSFL3p6oG9cAr0bWHd4cI5Oc8Wnww6f CoJkzkh9vqjLqbbHSH/vMVHn33dXTC8uAceFa3wpWGZw82RrRUoKJ+Z1IVun9k4aYsBO TeZA== Received: by 10.50.194.163 with SMTP id hx3mr5313185igc.49.1335165018042; Mon, 23 Apr 2012 00:10:18 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp91245ibt; Mon, 23 Apr 2012 00:10:17 -0700 (PDT) Received: by 10.182.207.10 with SMTP id ls10mr864458obc.9.1335165017535; Mon, 23 Apr 2012 00:10:17 -0700 (PDT) Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by mx.google.com with ESMTPS id i9si7903064oba.81.2012.04.23.00.10.17 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Apr 2012 00:10:17 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.214.178 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.214.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.178 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-ob0-f178.google.com with SMTP id wc18so9042021obb.37 for ; Mon, 23 Apr 2012 00:10:17 -0700 (PDT) Received: by 10.182.40.70 with SMTP id v6mr21662167obk.39.1335165017311; Mon, 23 Apr 2012 00:10:17 -0700 (PDT) Received: from localhost ([69.199.155.45]) by mx.google.com with ESMTPS id ju5sm5391291obb.23.2012.04.23.00.10.15 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Apr 2012 00:10:16 -0700 (PDT) Date: Mon, 23 Apr 2012 00:09:01 -0700 From: Anton Vorontsov To: Andrew Morton , Oleg Nesterov Cc: Russell King , Mike Frysinger , Benjamin Herrenschmidt , Richard Weinberger , Paul Mundt , Peter Zijlstra , KOSAKI Motohiro , John Stultz , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, uclinux-dist-devel@blackfin.uclinux.org, linuxppc-dev@lists.ozlabs.org, linux-sh@vger.kernel.org, user-mode-linux-devel@lists.sourceforge.net, linaro-kernel@lists.linaro.org, patches@linaro.org, linux-mm@kvack.org Subject: [PATCH 5/9] blackfin: A couple of task->mm handling fixes Message-ID: <20120423070901.GE30752@lizard> References: <20120423070641.GA27702@lizard> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120423070641.GA27702@lizard> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQmx3juXL3SEs2P6XeL0u/3CjxcREyUaa0Hdk3LOwyCqc2lJqOZZFpNKjHlX04GsAznfvPzp The patch fixes two problems: 1. Working with task->mm w/o getting mm or grabing the task lock is dangerous as ->mm might disappear (exit_mm() assigns NULL under task_lock(), so tasklist lock is not enough). We can't use get_task_mm()/mmput() pair as mmput() might sleep, so we have to take the task lock while handle its mm. 2. Checking for process->mm is not enough because process' main thread may exit or detach its mm via use_mm(), but other threads may still have a valid mm. To catch this we use find_lock_task_mm(), which walks up all threads and returns an appropriate task (with task lock held). Suggested-by: Oleg Nesterov Signed-off-by: Anton Vorontsov --- arch/blackfin/kernel/trace.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c index 44bbf2f..d08f0e3 100644 --- a/arch/blackfin/kernel/trace.c +++ b/arch/blackfin/kernel/trace.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -28,7 +30,6 @@ void decode_address(char *buf, unsigned long address) struct task_struct *p; struct mm_struct *mm; unsigned long flags, offset; - unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic(); struct rb_node *n; #ifdef CONFIG_KALLSYMS @@ -114,15 +115,15 @@ void decode_address(char *buf, unsigned long address) */ write_lock_irqsave(&tasklist_lock, flags); for_each_process(p) { - mm = (in_atomic ? p->mm : get_task_mm(p)); - if (!mm) - continue; + struct task_struct *t; - if (!down_read_trylock(&mm->mmap_sem)) { - if (!in_atomic) - mmput(mm); + t = find_lock_task_mm(p); + if (!t) continue; - } + + mm = t->mm; + if (!down_read_trylock(&mm->mmap_sem)) + goto __continue; for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) { struct vm_area_struct *vma; @@ -131,7 +132,7 @@ void decode_address(char *buf, unsigned long address) if (address >= vma->vm_start && address < vma->vm_end) { char _tmpbuf[256]; - char *name = p->comm; + char *name = t->comm; struct file *file = vma->vm_file; if (file) { @@ -164,8 +165,7 @@ void decode_address(char *buf, unsigned long address) name, vma->vm_start, vma->vm_end); up_read(&mm->mmap_sem); - if (!in_atomic) - mmput(mm); + task_unlock(t); if (buf[0] == '\0') sprintf(buf, "[ %s ] dynamic memory", name); @@ -175,8 +175,8 @@ void decode_address(char *buf, unsigned long address) } up_read(&mm->mmap_sem); - if (!in_atomic) - mmput(mm); +__continue: + task_unlock(t); } /*