All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2.1 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper
Date: Sun, 25 Mar 2012 17:42:10 +0000	[thread overview]
Message-ID: <20120325174210.GA23605@redhat.com> (raw)
In-Reply-To: <20120324164316.GB3640@lizard>

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.


WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Anton Vorontsov <anton.vorontsov@linaro.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Andrew Morton <akpm@linux-foundation.org>,
	Russell King <linux@arm.linux.org.uk>,
	Mike Frysinger <vapier@gentoo.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Richard Weinberger <richard@nod.at>,
	Paul Mundt <lethal@linux-sh.org>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	John Stultz <john.stultz@linaro.org>,
	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
Subject: Re: [PATCH v2.1 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper
Date: Sun, 25 Mar 2012 19:42:10 +0200	[thread overview]
Message-ID: <20120325174210.GA23605@redhat.com> (raw)
In-Reply-To: <20120324164316.GB3640@lizard>

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.


WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Anton Vorontsov <anton.vorontsov@linaro.org>
Cc: Mike Frysinger <vapier@gentoo.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	user-mode-linux-devel@lists.sourceforge.net,
	linux-sh@vger.kernel.org, Richard Weinberger <richard@nod.at>,
	linux-kernel@vger.kernel.org,
	uclinux-dist-devel@blackfin.uclinux.org, linux-mm@kvack.org,
	Paul Mundt <lethal@linux-sh.org>,
	John Stultz <john.stultz@linaro.org>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Russell King <linux@arm.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2.1 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper
Date: Sun, 25 Mar 2012 19:42:10 +0200	[thread overview]
Message-ID: <20120325174210.GA23605@redhat.com> (raw)
In-Reply-To: <20120324164316.GB3640@lizard>

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.

WARNING: multiple messages have this Message-ID (diff)
From: oleg@redhat.com (Oleg Nesterov)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2.1 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper
Date: Sun, 25 Mar 2012 19:42:10 +0200	[thread overview]
Message-ID: <20120325174210.GA23605@redhat.com> (raw)
In-Reply-To: <20120324164316.GB3640@lizard>

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.

WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Anton Vorontsov <anton.vorontsov@linaro.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Andrew Morton <akpm@linux-foundation.org>,
	Russell King <linux@arm.linux.org.uk>,
	Mike Frysinger <vapier@gentoo.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Richard Weinberger <richard@nod.at>,
	Paul Mundt <lethal@linux-sh.org>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	John Stultz <john.stultz@linaro.org>,
	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
Subject: Re: [PATCH v2.1 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper
Date: Sun, 25 Mar 2012 19:42:10 +0200	[thread overview]
Message-ID: <20120325174210.GA23605@redhat.com> (raw)
In-Reply-To: <20120324164316.GB3640@lizard>

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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2012-03-25 17:42 UTC|newest]

Thread overview: 133+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-24 10:26 [PATCH v2 0/10] Fixes for common mistakes w/ for_each_process and task->mm Anton Vorontsov
2012-03-24 10:26 ` Anton Vorontsov
2012-03-24 10:26 ` Anton Vorontsov
2012-03-24 10:26 ` Anton Vorontsov
2012-03-24 10:26 ` Anton Vorontsov
2012-03-24 10:27 ` [PATCH 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper Anton Vorontsov
2012-03-24 10:27   ` Anton Vorontsov
2012-03-24 10:27   ` Anton Vorontsov
2012-03-24 10:27   ` Anton Vorontsov
2012-03-24 10:27   ` Anton Vorontsov
2012-03-24 12:43   ` Peter Zijlstra
2012-03-24 12:43     ` Peter Zijlstra
2012-03-24 12:43     ` Peter Zijlstra
2012-03-24 12:43     ` Peter Zijlstra
2012-03-24 12:43     ` Peter Zijlstra
2012-03-24 16:43     ` [PATCH v2.1 " Anton Vorontsov
2012-03-24 16:43       ` Anton Vorontsov
2012-03-24 16:43       ` Anton Vorontsov
2012-03-24 16:43       ` Anton Vorontsov
2012-03-24 16:43       ` Anton Vorontsov
2012-03-25 17:42       ` Oleg Nesterov [this message]
2012-03-25 17:42         ` Oleg Nesterov
2012-03-25 17:42         ` Oleg Nesterov
2012-03-25 17:42         ` Oleg Nesterov
2012-03-25 17:42         ` Oleg Nesterov
2012-03-26  7:59         ` Peter Zijlstra
2012-03-26  7:59           ` Peter Zijlstra
2012-03-26  7:59           ` Peter Zijlstra
2012-03-26  7:59           ` Peter Zijlstra
2012-03-26  7:59           ` Peter Zijlstra
2012-03-26 17:04           ` Oleg Nesterov
2012-03-26 17:04             ` Oleg Nesterov
2012-03-26 17:04             ` Oleg Nesterov
2012-03-26 17:04             ` Oleg Nesterov
2012-03-26 17:04             ` Oleg Nesterov
2012-03-26 17:23             ` Peter Zijlstra
2012-03-26 17:23               ` Peter Zijlstra
2012-03-26 17:23               ` Peter Zijlstra
2012-03-26 17:23               ` Peter Zijlstra
2012-03-26 17:23               ` Peter Zijlstra
2012-03-28  0:01         ` Benjamin Herrenschmidt
2012-03-28  0:01           ` Benjamin Herrenschmidt
2012-03-28  0:01           ` Benjamin Herrenschmidt
2012-03-28  0:01           ` Benjamin Herrenschmidt
2012-03-28  0:01           ` Benjamin Herrenschmidt
2012-03-28  0:01           ` Benjamin Herrenschmidt
2012-03-24 10:28 ` [PATCH 02/10] arm: Use clear_tasks_mm_cpumask() Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28 ` [PATCH 03/10] powerpc: " Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28 ` [PATCH 04/10] sh: " Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:28   ` Anton Vorontsov
2012-03-24 10:29 ` [PATCH 05/10] blackfin: A couple of task->mm handling fixes Anton Vorontsov
2012-03-24 10:29   ` Anton Vorontsov
2012-03-24 10:29   ` Anton Vorontsov
2012-03-24 10:29   ` Anton Vorontsov
2012-03-24 10:29   ` Anton Vorontsov
2012-03-24 10:30 ` [PATCH 06/10] blackfin: Fix possible deadlock in decode_address() Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30 ` [PATCH 07/10] um: Should hold tasklist_lock while traversing processes Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 11:12   ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 12:48   ` Peter Zijlstra
2012-03-24 12:48     ` Peter Zijlstra
2012-03-24 12:48     ` Peter Zijlstra
2012-03-24 12:48     ` Peter Zijlstra
2012-03-24 12:48     ` Peter Zijlstra
2012-03-24 16:43     ` Anton Vorontsov
2012-03-24 16:43       ` Anton Vorontsov
2012-03-24 16:43       ` Anton Vorontsov
2012-03-24 16:43       ` Anton Vorontsov
2012-03-24 16:43       ` Anton Vorontsov
2012-03-24 10:30 ` [PATCH 08/10] um: Fix possible race on task->mm Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 10:30   ` Anton Vorontsov
2012-03-24 11:12   ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 10:31 ` [PATCH 09/10] um: Properly check all process' threads for a live mm Anton Vorontsov
2012-03-24 10:31   ` Anton Vorontsov
2012-03-24 10:31   ` Anton Vorontsov
2012-03-24 10:31   ` Anton Vorontsov
2012-03-24 10:31   ` Anton Vorontsov
2012-03-24 11:12   ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 11:12     ` Richard Weinberger
2012-03-24 10:31 ` [PATCH 10/10] oom: Make find_lock_task_mm() sparse-aware Anton Vorontsov
2012-03-24 10:31   ` Anton Vorontsov
2012-03-24 10:31   ` Anton Vorontsov
2012-03-24 10:31   ` Anton Vorontsov
2012-03-24 10:31   ` Anton Vorontsov
2012-03-24 12:52   ` Peter Zijlstra
2012-03-24 12:52     ` Peter Zijlstra
2012-03-24 12:52     ` Peter Zijlstra
2012-03-24 12:52     ` Peter Zijlstra
2012-03-24 12:52     ` Peter Zijlstra
2012-03-24 16:21     ` Anton Vorontsov
2012-03-24 16:21       ` Anton Vorontsov
2012-03-24 16:21       ` Anton Vorontsov
2012-03-24 16:21       ` Anton Vorontsov
2012-03-24 16:21       ` Anton Vorontsov
2012-03-24 16:43       ` Peter Zijlstra
2012-03-24 16:43         ` Peter Zijlstra
2012-03-24 16:43         ` Peter Zijlstra
2012-03-24 16:43         ` Peter Zijlstra
2012-03-24 16:43         ` Peter Zijlstra
2012-03-28  7:20     ` David Rientjes
2012-03-28  7:20       ` David Rientjes
2012-03-28  7:20       ` David Rientjes
2012-03-28  7:20       ` David Rientjes
2012-03-28  7:20       ` David Rientjes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120325174210.GA23605@redhat.com \
    --to=oleg@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.