From patchwork Sat May 5 01:47:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8416 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 5922623E37 for ; Sat, 5 May 2012 01:48:53 +0000 (UTC) Received: from mail-ob0-f180.google.com (mail-ob0-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id 036C0A1813F for ; Sat, 5 May 2012 01:48:52 +0000 (UTC) Received: by obbup16 with SMTP id up16so6213692obb.11 for ; Fri, 04 May 2012 18:48:52 -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=9d6UwKpPgCMj0IREHS485ffvdD+SHCttx0rRSxqPk9s=; b=gLVBVr5XjbXEONlH4jtIXOlT7Q68XV07wOH2NlcDY1HoZObt4AiQKEl621EQQtsJmD f4zN8Hrkb1XGveYbasa03LY96EXmE5fFgxqcPkH/baLWp2zz+mS2HXGhIoFB9dt+A3W8 N8gUY31tdlOOHFmcN2szCMQOiTG7rNtVS8VfZS//ml493TvcQ6Eh2WCJ+4JUGJonXZyi XEs91EjOViiSSLsZTW2e6/x8Zoq3HwxnoP1UoK3kSMMTEXRc9rG6f94KkImTFRjMAQr5 Eh77ENlPoHUbtqYcUuvm2x1j17skYTt6NROHU7Aq2S/E9rvHNEfgVAq67h+rynufbIKQ eYUg== Received: by 10.50.10.225 with SMTP id l1mr4344360igb.1.1336182532201; Fri, 04 May 2012 18:48: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.73.147 with SMTP id q19csp6836ibj; Fri, 4 May 2012 18:48:51 -0700 (PDT) Received: by 10.182.16.1 with SMTP id b1mr11189658obd.31.1336182531582; Fri, 04 May 2012 18:48:51 -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 qx5si6033024obb.174.2012.05.04.18.48.51 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 May 2012 18:48:51 -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 eq6so6398096obc.37 for ; Fri, 04 May 2012 18:48:51 -0700 (PDT) Received: by 10.182.155.35 with SMTP id vt3mr11408069obb.63.1336182531311; Fri, 04 May 2012 18:48:51 -0700 (PDT) Received: from localhost (ip-64-134-222-81.public.wayport.net. [64.134.222.81]) by mx.google.com with ESMTPS id o6sm8815303oec.11.2012.05.04.18.48.48 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 May 2012 18:48:50 -0700 (PDT) Date: Fri, 4 May 2012 18:47:28 -0700 From: Anton Vorontsov To: Andrew Morton , Peter Zijlstra Cc: Oleg Nesterov , Russell King , Mike Frysinger , Benjamin Herrenschmidt , Richard Weinberger , Paul Mundt , 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] cpu: Document clear_tasks_mm_cpumask() Message-ID: <20120505014728.GA9079@lizard> References: <20120423070641.GA27702@lizard> <20120423070736.GA30752@lizard> <20120426165911.00cebd31.akpm@linux-foundation.org> <1335869133.13683.125.camel@twins> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1335869133.13683.125.camel@twins> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQlAUnUKEXYbpvl4uAWPbr7BTOEE0E9uNZj73Ld7l3TsFKIaC2VA6cq/6kAo8Naqb4BY5Jba This patch adds more comments on clear_tasks_mm_cpumask, plus adds a runtime check: the function is only suitable for offlined CPUs, and if called inappropriately, the kernel should scream aloud. Suggested-by: Andrew Morton Suggested-by: Peter Zijlstra Signed-off-by: Anton Vorontsov --- On Tue, May 01, 2012 at 12:45:33PM +0200, Peter Zijlstra wrote: > On Thu, 2012-04-26 at 16:59 -0700, Andrew Morton wrote: > > > +void clear_tasks_mm_cpumask(int cpu) > > > > The operation of this function was presumably obvious to you at the > > time you wrote it, but that isn't true of other people at later times. > > > > Please document it? [...] > > If someone tries to use this function for a different purpose, or > > copies-and-modifies it for a different purpose, we just shot them in > > the foot. > > > > They'd be pretty dumb to do that without reading the local comment, > > but still... > > Methinks something simple like: > > WARN_ON(cpu_online(cpu)); > > Ought to cure that worry, no? :-) Yeah, this is all good ideas, thanks. How about the following patch? kernel/cpu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kernel/cpu.c b/kernel/cpu.c index ecdf499..1bfa26f 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -173,6 +174,18 @@ void __ref unregister_cpu_notifier(struct notifier_block *nb) } EXPORT_SYMBOL(unregister_cpu_notifier); +/** + * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU + * @cpu: a CPU id + * + * This function walks up all processes, finds a valid mm struct for + * each one and then clears a corresponding bit in mm's cpumask. While + * this all sounds trivial, there are various non-obvious corner cases, + * which this function tries to solve in a safe manner. + * + * Also note that the function uses a somewhat relaxed locking scheme, + * so it may be called only for an already offlined CPU. + */ void clear_tasks_mm_cpumask(int cpu) { struct task_struct *p; @@ -184,10 +197,15 @@ void clear_tasks_mm_cpumask(int cpu) * Thus, we may use rcu_read_lock() here, instead of grabbing * full-fledged tasklist_lock. */ + WARN_ON(cpu_online(cpu)); rcu_read_lock(); for_each_process(p) { struct task_struct *t; + /* + * Main thread might exit, but other threads may still have + * a valid mm. Find one. + */ t = find_lock_task_mm(p); if (!t) continue;