[uml-devel] [PATCH v2.1 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper

2012-03-24 Thread Anton Vorontsov
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); The code above has several problems, s

Re: [uml-devel] [PATCH 10/10] oom: Make find_lock_task_mm() sparse-aware

2012-03-24 Thread Anton Vorontsov
On Sat, Mar 24, 2012 at 01:52:54PM +0100, Peter Zijlstra wrote: [...] > > p.s. I know Peter Zijlstra detest the __cond_lock() stuff, but untill > > we have anything better in sparse, let's use it. This particular > > patch helped me to detect one bug that I myself made during > > tas

Re: [uml-devel] [PATCH 10/10] oom: Make find_lock_task_mm() sparse-aware

2012-03-24 Thread Peter Zijlstra
On Sat, 2012-03-24 at 20:21 +0400, Anton Vorontsov wrote: > Just wonder how do you see the feature implemented? > > Something like this? > > #define __ret_cond_locked(l, c) __attribute__((ret_cond_locked(l, c))) > #define __ret_value __attribute__((ret_value)) > #define __ret_loc

Re: [uml-devel] [PATCH 07/10] um: Should hold tasklist_lock while traversing processes

2012-03-24 Thread Anton Vorontsov
On Sat, Mar 24, 2012 at 01:48:23PM +0100, Peter Zijlstra wrote: > On Sat, 2012-03-24 at 14:30 +0400, Anton Vorontsov wrote: > > Traversing the tasks requires holding tasklist_lock, otherwise it > > is unsafe. > > No it doesn't, it either requires tasklist_lock or rcu_read_lock(). Well, currently

[uml-devel] [PATCH 09/10] um: Properly check all process' threads for a live mm

2012-03-24 Thread Anton Vorontsov
kill_off_processes() might miss a valid process, this is because checking for process->mm is not enough. 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 app

[uml-devel] [PATCH v2 0/10] Fixes for common mistakes w/ for_each_process and task->mm

2012-03-24 Thread Anton Vorontsov
Hi all, This is a reincarnation of the task->mm fixes. Several architectures were traverse the tasklist in an unsafe manner, plus there are a few cases of unsafe access to task->mm. In v2 I decided to introduce a small helper in cpu.c: most arches duplicate the same [buggy] code snippet, so it's

Re: [uml-devel] [PATCH 07/10] um: Should hold tasklist_lock while traversing processes

2012-03-24 Thread Richard Weinberger
Am 24.03.2012 11:30, schrieb Anton Vorontsov: > Traversing the tasks requires holding tasklist_lock, otherwise it > is unsafe. > > p.s. However, I'm not sure that calling os_kill_ptraced_process() > in the atomic context is correct. It seem to work, but please > take a closer look. os_kill_ptrace

[uml-devel] [PATCH 06/10] blackfin: Fix possible deadlock in decode_address()

2012-03-24 Thread Anton Vorontsov
Oleg Nesterov found an interesting deadlock possibility: > sysrq_showregs_othercpus() does smp_call_function(showacpu) > and showacpu() show_stack()->decode_address(). Now suppose that IPI > interrupts the task holding read_lock(tasklist). To fix this, blackfin should not grab the write_ variant

[uml-devel] [PATCH 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper

2012-03-24 Thread Anton Vorontsov
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); The code above has several problems, s

Re: [uml-devel] [PATCH 07/10] um: Should hold tasklist_lock while traversing processes

2012-03-24 Thread Peter Zijlstra
On Sat, 2012-03-24 at 14:30 +0400, Anton Vorontsov wrote: > Traversing the tasks requires holding tasklist_lock, otherwise it > is unsafe. No it doesn't, it either requires tasklist_lock or rcu_read_lock(). -- This SF em

Re: [uml-devel] [PATCH 10/10] oom: Make find_lock_task_mm() sparse-aware

2012-03-24 Thread Peter Zijlstra
On Sat, 2012-03-24 at 14:31 +0400, Anton Vorontsov wrote: > This is needed so that callers would not get 'context imbalance' > warnings from the sparse tool. > > As a side effect, this patch fixes the following sparse warnings: > > CHECK mm/oom_kill.c > mm/oom_kill.c:201:28: warning: contex

[uml-devel] [PATCH 05/10] blackfin: A couple of task->mm handling fixes

2012-03-24 Thread Anton Vorontsov
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

Re: [uml-devel] [PATCH 01/10] cpu: Introduce clear_tasks_mm_cpumask() helper

2012-03-24 Thread Peter Zijlstra
On Sat, 2012-03-24 at 14:27 +0400, Anton Vorontsov wrote: > +void clear_tasks_mm_cpumask(int cpu) > +{ > + struct task_struct *p; > + > + read_lock(&tasklist_lock); > + for_each_process(p) { > + struct task_struct *t; > + > + t = find_lock_task_mm(p); >

Re: [uml-devel] [PATCH 08/10] um: Fix possible race on task->mm

2012-03-24 Thread Richard Weinberger
Am 24.03.2012 11:30, schrieb Anton Vorontsov: > 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 a

[uml-devel] [PATCH 03/10] powerpc: Use clear_tasks_mm_cpumask()

2012-03-24 Thread Anton Vorontsov
Current CPU hotplug code has some task->mm handling issues: 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()

[uml-devel] [PATCH 08/10] um: Fix possible race on task->mm

2012-03-24 Thread Anton Vorontsov
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_tas

[uml-devel] [PATCH 10/10] oom: Make find_lock_task_mm() sparse-aware

2012-03-24 Thread Anton Vorontsov
This is needed so that callers would not get 'context imbalance' warnings from the sparse tool. As a side effect, this patch fixes the following sparse warnings: CHECK mm/oom_kill.c mm/oom_kill.c:201:28: warning: context imbalance in 'oom_badness' - unexpected unlock include/linux/rcupd

Re: [uml-devel] [PATCH 09/10] um: Properly check all process' threads for a live mm

2012-03-24 Thread Richard Weinberger
Am 24.03.2012 11:31, schrieb Anton Vorontsov: > kill_off_processes() might miss a valid process, this is because > checking for process->mm is not enough. 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_loc

[uml-devel] [PATCH 04/10] sh: Use clear_tasks_mm_cpumask()

2012-03-24 Thread Anton Vorontsov
Current CPU hotplug code has some task->mm handling issues: 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()

[uml-devel] [PATCH 02/10] arm: Use clear_tasks_mm_cpumask()

2012-03-24 Thread Anton Vorontsov
Current CPU hotplug code has some task->mm handling issues: 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()

[uml-devel] [PATCH 07/10] um: Should hold tasklist_lock while traversing processes

2012-03-24 Thread Anton Vorontsov
Traversing the tasks requires holding tasklist_lock, otherwise it is unsafe. p.s. However, I'm not sure that calling os_kill_ptraced_process() in the atomic context is correct. It seem to work, but please take a closer look. Signed-off-by: Anton Vorontsov --- arch/um/kernel/reboot.c |3 +++