alistair23-linux/kernel
Oleg Nesterov b89deed32c implement flush_work()
A basic problem with flush_scheduled_work() is that it blocks behind _all_
presently-queued works, rather than just the work whcih the caller wants to
flush.  If the caller holds some lock, and if one of the queued work happens
to want that lock as well then accidental deadlocks can occur.

One example of this is the phy layer: it wants to flush work while holding
rtnl_lock().  But if a linkwatch event happens to be queued, the phy code will
deadlock because the linkwatch callback function takes rtnl_lock.

So we implement a new function which will flush a *single* work - just the one
which the caller wants to free up.  Thus we avoid the accidental deadlocks
which can arise from unrelated subsystems' callbacks taking shared locks.

flush_work() non-blockingly dequeues the work_struct which we want to kill,
then it waits for its handler to complete on all CPUs.

Add ->current_work to the "struct cpu_workqueue_struct", it points to
currently running "struct work_struct". When flush_work(work) detects
->current_work == work, it inserts a barrier at the _head_ of ->worklist
(and thus right _after_ that work) and waits for completition. This means
that the next work fired on that CPU will be this barrier, or another
barrier queued by concurrent flush_work(), so the caller of flush_work()
will be woken before any "regular" work has a chance to run.

When wait_on_work() unlocks workqueue_mutex (or whatever we choose to protect
against CPU hotplug), CPU may go away. But in that case take_over_work() will
move a barrier we queued to another CPU, it will be fired sometime, and
wait_on_work() will be woken.

Actually, we are doing cleanup_workqueue_thread()->kthread_stop() before
take_over_work(), so cwq->thread should complete its ->worklist (and thus
the barrier), because currently we don't check kthread_should_stop() in
run_workqueue(). But even if we did, everything should be ok.

[akpm@osdl.org: cleanup]
[akpm@osdl.org: add flush_work_keventd() wrapper]
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-09 12:30:50 -07:00
..
irq Fix Linuxdoc comment 2007-05-09 12:30:48 -07:00
power PM: Separate hibernation code from suspend code 2007-05-09 12:30:48 -07:00
time Fix printk format warnings in timer_list.c 2007-05-09 12:30:50 -07:00
.gitignore
acct.c
audit.c audit: add spaces on either side of case "..." operator. 2007-05-08 11:15:09 -07:00
audit.h
auditfilter.c [PATCH] minor update to rule add/delete messages (ver 2) 2007-02-17 21:30:09 -05:00
auditsc.c [PATCH] fix deadlock in audit_log_task_context() 2007-03-14 15:27:48 -07:00
capability.c [PATCH] pid: replace do/while_each_task_pid with do/while_each_pid_task 2007-02-12 09:48:32 -08:00
compat.c [PATCH] Common compat_sys_sysinfo 2007-02-11 10:51:32 -08:00
configs.c use simple_read_from_buffer in kernel/ 2007-05-09 12:30:49 -07:00
cpu.c [PATCH] Fix microcode-related suspend problem 2007-04-02 10:06:09 -07:00
cpuset.c use simple_read_from_buffer in kernel/ 2007-05-09 12:30:49 -07:00
delayacct.c KMEM_CACHE(): simplify slab cache creation 2007-05-07 12:12:55 -07:00
die_notifier.c move die notifier handling to common code 2007-05-08 11:15:04 -07:00
dma.c
exec_domain.c
exit.c header cleaning: don't include smp_lock.h when not used 2007-05-08 11:15:07 -07:00
extable.c
fork.c header cleaning: don't include smp_lock.h when not used 2007-05-08 11:15:07 -07:00
futex.c futex: restartable futex_wait 2007-05-08 11:15:03 -07:00
futex_compat.c
hrtimer.c export hrtimer_forward 2007-05-08 11:15:15 -07:00
itimer.c The scheduled -EINVAL for invalid timevals in setitimer 2007-05-08 11:15:13 -07:00
kallsyms.c kallsyms: cleanup: use seq_release_private() where appropriate 2007-05-08 11:15:09 -07:00
Kconfig.hz
Kconfig.preempt
kexec.c kdump/kexec: calculate note size at compile time 2007-05-08 11:15:07 -07:00
kfifo.c [PATCH] Numerous fixes to kernel-doc info in source files. 2007-02-11 10:51:32 -08:00
kmod.c Fix kevent's childs priority greediness 2007-05-08 11:15:07 -07:00
kprobes.c Kprobes: The ON/OFF knob thru debugfs 2007-05-08 11:15:19 -07:00
ksysfs.c remove "struct subsystem" as it is no longer needed 2007-05-02 18:57:59 -07:00
kthread.c [PATCH] Numerous fixes to kernel-doc info in source files. 2007-02-11 10:51:32 -08:00
latency.c
lockdep.c lockdep: removed unused ip argument in mark_lock & mark_held_locks 2007-05-08 11:15:13 -07:00
lockdep_internals.h
lockdep_proc.c [PATCH] remove many unneeded #includes of sched.h 2007-02-14 08:09:54 -08:00
Makefile move die notifier handling to common code 2007-05-08 11:15:04 -07:00
module.c Fix race between cat /proc/slab_allocators and rmmod 2007-05-08 11:15:08 -07:00
mutex-debug.c [PATCH] remove many unneeded #includes of sched.h 2007-02-14 08:09:54 -08:00
mutex-debug.h
mutex.c
mutex.h
nsproxy.c Merge sys_clone()/sys_unshare() nsproxy and namespace handling 2007-05-08 11:15:00 -07:00
panic.c
params.c kernel/params.c: fix lying comment for param_array() 2007-05-08 11:15:08 -07:00
pid.c Merge sys_clone()/sys_unshare() nsproxy and namespace handling 2007-05-08 11:15:00 -07:00
posix-cpu-timers.c Introduce a handy list_first_entry macro 2007-05-08 11:15:11 -07:00
posix-timers.c header cleaning: don't include smp_lock.h when not used 2007-05-08 11:15:07 -07:00
printk.c header cleaning: don't include smp_lock.h when not used 2007-05-08 11:15:07 -07:00
profile.c
ptrace.c
rcupdate.c
rcutorture.c rcutorture: Remove redundant assignment to cur_ops in for loop 2007-05-08 11:15:17 -07:00
relay.c [PATCH] kernel-doc fixes for 2.6.20-git15 (non-drivers) 2007-03-01 14:53:37 -08:00
resource.c libata/IDE: remove combined mode quirk 2007-04-28 14:15:59 -04:00
rtmutex-debug.c
rtmutex-debug.h
rtmutex-tester.c
rtmutex.c [PATCH] hrtimers: namespace and enum cleanup 2007-02-16 08:13:58 -08:00
rtmutex.h
rtmutex_common.h
rwsem.c Lockdep treats down_write_trylock like regular down_write 2007-05-08 11:15:09 -07:00
sched.c revert 'sched: redundant reschedule when set_user_nice() boosts a prio of a task from the "expired" array' 2007-05-08 20:41:15 -07:00
seccomp.c
signal.c Move sig_kernel_* et al macros to linux/signal.h 2007-05-09 12:30:49 -07:00
softirq.c [PATCH] tick-management: dyntick / highres functionality 2007-02-16 08:13:59 -08:00
softlockup.c add touch_all_softlockup_watchdogs() 2007-05-08 11:15:06 -07:00
spinlock.c
srcu.c
stacktrace.c
stop_machine.c Use stop_machine_run in the Intel RNG driver 2007-05-08 11:15:00 -07:00
sys.c PM: Separate hibernation code from suspend code 2007-05-09 12:30:48 -07:00
sys_ni.c
sysctl.c proc: maps protection 2007-05-08 11:15:02 -07:00
taskstats.c KMEM_CACHE(): simplify slab cache creation 2007-05-07 12:12:55 -07:00
time.c header cleaning: don't include smp_lock.h when not used 2007-05-08 11:15:07 -07:00
timer.c Introduce a handy list_first_entry macro 2007-05-08 11:15:11 -07:00
tsacct.c [PATCH] time: x86_64: split x86_64/kernel/time.c up 2007-02-16 08:14:00 -08:00
uid16.c header cleaning: don't include smp_lock.h when not used 2007-05-08 11:15:07 -07:00
user.c
utsname.c Merge sys_clone()/sys_unshare() nsproxy and namespace handling 2007-05-08 11:15:00 -07:00
utsname_sysctl.c [PATCH] sysctl: remove insert_at_head from register_sysctl 2007-02-14 08:09:59 -08:00
wait.c
workqueue.c implement flush_work() 2007-05-09 12:30:50 -07:00