From patchwork Mon Apr 23 07:09:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8015 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 61B5723E49 for ; Mon, 23 Apr 2012 07:10:53 +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 2A5E5A187EA for ; Mon, 23 Apr 2012 07:10:53 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so22276722iag.11 for ; Mon, 23 Apr 2012 00:10:53 -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=19F5zQ+7QtsoZ99DUJ2PdeDeYVAumMLiGX/Tic3xF7c=; b=Um0XJjNWp8eKCUUY/4kOMcD/9jTkh6RgHQ4Qqh0W0JIfMbuPrEq/AgT3gTEYSTQIxV 2nuR0+mX0J0k7k/7dhHRp3I4r6KUjpTxd1pj/zEmwyKwJhUHI3nAGwXzAf5uWrmTB7M1 xlqbVc9Nu50bo7/3R4DPUxveJCysWYGURgutFZZOMy02xmlVAgyPhEMQhwpYHgUuUWnz 77LTrnuT+vfG5uA2JGQcf0GiRQr//3v5VOHUEBx5TqWHg3TzEIfzhVV77k0fzZKuIb9a tb0SQLOXzOT8ipzD+GpY1T1b0dpDE4EjA7CMR9aqnvwDsw8Uop+LOsnjxvgkvM24gC27 pmUw== Received: by 10.43.49.201 with SMTP id vb9mr878385icb.35.1335165052956; Mon, 23 Apr 2012 00:10:52 -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 x6csp91279ibt; Mon, 23 Apr 2012 00:10:52 -0700 (PDT) Received: by 10.182.159.41 with SMTP id wz9mr16230721obb.69.1335165052474; Mon, 23 Apr 2012 00:10:52 -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 k9si7123921obd.140.2012.04.23.00.10.52 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Apr 2012 00:10:52 -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 wc18so9042020obb.37 for ; Mon, 23 Apr 2012 00:10:52 -0700 (PDT) Received: by 10.182.179.73 with SMTP id de9mr7046057obc.44.1335165052124; Mon, 23 Apr 2012 00:10:52 -0700 (PDT) Received: from localhost ([69.199.155.45]) by mx.google.com with ESMTPS id vp14sm12231205oeb.5.2012.04.23.00.10.50 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Apr 2012 00:10:51 -0700 (PDT) Date: Mon, 23 Apr 2012 00:09:35 -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 8/9] um: Fix possible race on task->mm Message-ID: <20120423070935.GH30752@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: ALoCoQm+KlvPMMCGLRZEBCZzZNVt0UurzMx66j+SjUOAbpSbsL3ackGZ+yG37/rspaq74nIrXSGd Checking for task->mm 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 let's take the task lock while we care about its mm. Note that we should also use find_lock_task_mm() to check all process' threads for a valid mm, but for uml we'll do it in a separate patch. Signed-off-by: Anton Vorontsov --- arch/um/kernel/reboot.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/um/kernel/reboot.c b/arch/um/kernel/reboot.c index 66d754c..1411f4e 100644 --- a/arch/um/kernel/reboot.c +++ b/arch/um/kernel/reboot.c @@ -25,10 +25,13 @@ static void kill_off_processes(void) read_lock(&tasklist_lock); for_each_process(p) { - if (p->mm == NULL) + task_lock(p); + if (!p->mm) { + task_unlock(p); continue; - + } pid = p->mm->context.id.u.pid; + task_unlock(p); os_kill_ptraced_process(pid, 1); } read_unlock(&tasklist_lock);