diff options
author | Niklas Cassel <niklas.cassel@axis.com> | 2017-02-24 19:17:53 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-03-22 07:43:40 -0400 |
commit | c40609652267440ae6f800303ea1f3be17d357e2 (patch) | |
tree | c46f4fb37764ae6e8cf26f2f58dcb5e73f4d3014 | |
parent | 1522181f4bc14a61c72981439fcbe9a87496f3cf (diff) |
locking/rwsem: Fix down_write_killable() for CONFIG_RWSEM_GENERIC_SPINLOCK=y
commit 17fcbd590d0c3e35bd9646e2215f86586378bc42 upstream.
We hang if SIGKILL has been sent, but the task is stuck in down_read()
(after do_exit()), even though no task is doing down_write() on the
rwsem in question:
INFO: task libupnp:21868 blocked for more than 120 seconds.
libupnp D 0 21868 1 0x08100008
...
Call Trace:
__schedule()
schedule()
__down_read()
do_exit()
do_group_exit()
__wake_up_parent()
This bug has already been fixed for CONFIG_RWSEM_XCHGADD_ALGORITHM=y in
the following commit:
04cafed7fc19 ("locking/rwsem: Fix down_write_killable()")
... however, this bug also exists for CONFIG_RWSEM_GENERIC_SPINLOCK=y.
Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: <mhocko@suse.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Niklas Cassel <niklass@axis.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: d47996082f52 ("locking/rwsem: Introduce basis for down_write_killable()")
Link: http://lkml.kernel.org/r/1487981873-12649-1-git-send-email-niklass@axis.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | kernel/locking/rwsem-spinlock.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c index 1591f6b3539f..2bef4ab94003 100644 --- a/kernel/locking/rwsem-spinlock.c +++ b/kernel/locking/rwsem-spinlock.c | |||
@@ -216,10 +216,8 @@ int __sched __down_write_common(struct rw_semaphore *sem, int state) | |||
216 | */ | 216 | */ |
217 | if (sem->count == 0) | 217 | if (sem->count == 0) |
218 | break; | 218 | break; |
219 | if (signal_pending_state(state, current)) { | 219 | if (signal_pending_state(state, current)) |
220 | ret = -EINTR; | 220 | goto out_nolock; |
221 | goto out; | ||
222 | } | ||
223 | set_task_state(tsk, state); | 221 | set_task_state(tsk, state); |
224 | raw_spin_unlock_irqrestore(&sem->wait_lock, flags); | 222 | raw_spin_unlock_irqrestore(&sem->wait_lock, flags); |
225 | schedule(); | 223 | schedule(); |
@@ -227,12 +225,19 @@ int __sched __down_write_common(struct rw_semaphore *sem, int state) | |||
227 | } | 225 | } |
228 | /* got the lock */ | 226 | /* got the lock */ |
229 | sem->count = -1; | 227 | sem->count = -1; |
230 | out: | ||
231 | list_del(&waiter.list); | 228 | list_del(&waiter.list); |
232 | 229 | ||
233 | raw_spin_unlock_irqrestore(&sem->wait_lock, flags); | 230 | raw_spin_unlock_irqrestore(&sem->wait_lock, flags); |
234 | 231 | ||
235 | return ret; | 232 | return ret; |
233 | |||
234 | out_nolock: | ||
235 | list_del(&waiter.list); | ||
236 | if (!list_empty(&sem->wait_list)) | ||
237 | __rwsem_do_wake(sem, 1); | ||
238 | raw_spin_unlock_irqrestore(&sem->wait_lock, flags); | ||
239 | |||
240 | return -EINTR; | ||
236 | } | 241 | } |
237 | 242 | ||
238 | void __sched __down_write(struct rw_semaphore *sem) | 243 | void __sched __down_write(struct rw_semaphore *sem) |