From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx202.postini.com [74.125.245.202]) by kanga.kvack.org (Postfix) with SMTP id 3B9D66B0044 for ; Sun, 25 Mar 2012 13:51:07 -0400 (EDT) Date: Sun, 25 Mar 2012 19:42:10 +0200 From: Oleg Nesterov Subject: Re: [PATCH v2.1 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper Message-ID: <20120325174210.GA23605@redhat.com> References: <20120324102609.GA28356@lizard> <20120324102751.GA29067@lizard> <1332593021.16159.27.camel@twins> <20120324164316.GB3640@lizard> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120324164316.GB3640@lizard> Sender: owner-linux-mm@kvack.org List-ID: To: Anton Vorontsov Cc: Peter Zijlstra , Andrew Morton , 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, linux-mm@kvack.org On 03/24, Anton Vorontsov wrote: > > Many architctures clear tasks' mm_cpumask like this: > > read_lock(&tasklist_lock); > for_each_process(p) { > if (p->mm) > cpumask_clear_cpu(cpu, mm_cpumask(p->mm)); > } > read_unlock(&tasklist_lock); Namely arm, powerpc, and sh. > The code above has several problems, such as: > > 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). This is not actually true for arm and sh, afaics. They do not even need tasklist or rcu lock for for_each_process(). __cpu_disable() is called by __stop_machine(), we know that nobody can preempt us and other CPUs can do nothing. > 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. Yes, > Also, Per Peter Zijlstra's idea, now we don't grab tasklist_lock in > the new helper, instead we take the rcu read lock. We can do this > because the function is called after the cpu is taken down and marked > offline, so no new tasks will get this cpu set in their mm mask. And only powerpc needs rcu_read_lock() and task_lock(). OTOH, I do not understand why powepc does this on CPU_DEAD... And probably CPU_UP_CANCELED doesn't need to clear mm_cpumask(). That said, personally I think these patches are fine, the common helper makes sense. Oleg. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org