All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] locking/rwsem: fix down_write_killable for CONFIG_RWSEM_GENERIC_SPINLOCK
@ 2017-02-25  0:17 Niklas Cassel
  2017-03-06  8:59 ` Niklas Cassel
  2017-03-16 11:14 ` [tip:locking/core] locking/rwsem: Fix down_write_killable() for CONFIG_RWSEM_GENERIC_SPINLOCK=y tip-bot for Niklas Cassel
  0 siblings, 2 replies; 4+ messages in thread
From: Niklas Cassel @ 2017-02-25  0:17 UTC (permalink / raw)
  To: peterz, mingo, mhocko; +Cc: stable, linux-kernel, Niklas Cassel

From: Niklas Cassel <niklas.cassel@axis.com>

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.
      Tainted: G           O    4.9.11-devel #1
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
libupnp         D    0 21868      1 0x08100008
Stack : 00000001 8ecf44a0 8ef644a0 8e06fe40 00000000 808b0000 00000001 00000000
        00000001 77aab068 00000001 00000001 00000000 8ecf44a0 00400000 800d4d88
        8ecf44a0 00000002 80698ac0 00000001 8c3f0544 00000001 00000000 8ecf44a0
        00400000 80694a58 8ecf44a0 00000000 8ecf44a0 8c3f0544 8ecf44a0 80698ac8
        8c3f0500 00000000 77a053b4 800454bc 8958dd68 8ef83d68 8ecf44a0 00000001
        ...
Call Trace:
[<806942b0>] __schedule+0x738/0xd48
[<80694a58>] schedule+0x44/0xb8
[<80698ac8>] __down_read+0xc8/0x124
[<8004c034>] do_exit+0x18c/0xa78
[<8004c9cc>] do_group_exit+0x5c/0xc4
[<8004ca54>] __wake_up_parent+0x0/0x24

This bug has already been fixed for CONFIG_RWSEM_XCHGADD_ALGORITHM in
commit 04cafed7fc19 ("locking/rwsem: Fix down_write_killable()"), however,
this bug also exists for CONFIG_RWSEM_GENERIC_SPINLOCK.

Cc: stable <stable@vger.kernel.org> # 4.7+
Fixes: d47996082f52 ("locking/rwsem: Introduce basis for down_write_killable()")
Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
---
 kernel/locking/rwsem-spinlock.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c
index 5eacab880f67..ab7271e16918 100644
--- a/kernel/locking/rwsem-spinlock.c
+++ b/kernel/locking/rwsem-spinlock.c
@@ -212,10 +212,9 @@ int __sched __down_write_common(struct rw_semaphore *sem, int state)
 		 */
 		if (sem->count == 0)
 			break;
-		if (signal_pending_state(state, current)) {
-			ret = -EINTR;
-			goto out;
-		}
+		if (signal_pending_state(state, current))
+			goto out_nolock;
+
 		set_current_state(state);
 		raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
 		schedule();
@@ -223,12 +222,19 @@ int __sched __down_write_common(struct rw_semaphore *sem, int state)
 	}
 	/* got the lock */
 	sem->count = -1;
-out:
 	list_del(&waiter.list);
 
 	raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
 
 	return ret;
+
+out_nolock:
+	list_del(&waiter.list);
+	if (!list_empty(&sem->wait_list))
+		__rwsem_do_wake(sem, 1);
+	raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
+
+	return -EINTR;
 }
 
 void __sched __down_write(struct rw_semaphore *sem)
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] locking/rwsem: fix down_write_killable for CONFIG_RWSEM_GENERIC_SPINLOCK
  2017-02-25  0:17 [PATCH] locking/rwsem: fix down_write_killable for CONFIG_RWSEM_GENERIC_SPINLOCK Niklas Cassel
@ 2017-03-06  8:59 ` Niklas Cassel
  2017-03-06 11:28   ` Peter Zijlstra
  2017-03-16 11:14 ` [tip:locking/core] locking/rwsem: Fix down_write_killable() for CONFIG_RWSEM_GENERIC_SPINLOCK=y tip-bot for Niklas Cassel
  1 sibling, 1 reply; 4+ messages in thread
From: Niklas Cassel @ 2017-03-06  8:59 UTC (permalink / raw)
  To: peterz, mingo, mhocko; +Cc: stable, linux-kernel, Niklas Cassel

Peter, any comment on this?

You fixed the rwsem implementation that is used by default for x86,
however the rwsem implementation used by default on mips, sparc32,
and many other archs is still affected, hence this patch.

Have a good morning.

/Niklas

On 02/25/2017 01:17 AM, Niklas Cassel wrote:
> From: Niklas Cassel <niklas.cassel@axis.com>
>
> 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.
>       Tainted: G           O    4.9.11-devel #1
> "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
> libupnp         D    0 21868      1 0x08100008
> Stack : 00000001 8ecf44a0 8ef644a0 8e06fe40 00000000 808b0000 00000001 00000000
>         00000001 77aab068 00000001 00000001 00000000 8ecf44a0 00400000 800d4d88
>         8ecf44a0 00000002 80698ac0 00000001 8c3f0544 00000001 00000000 8ecf44a0
>         00400000 80694a58 8ecf44a0 00000000 8ecf44a0 8c3f0544 8ecf44a0 80698ac8
>         8c3f0500 00000000 77a053b4 800454bc 8958dd68 8ef83d68 8ecf44a0 00000001
>         ...
> Call Trace:
> [<806942b0>] __schedule+0x738/0xd48
> [<80694a58>] schedule+0x44/0xb8
> [<80698ac8>] __down_read+0xc8/0x124
> [<8004c034>] do_exit+0x18c/0xa78
> [<8004c9cc>] do_group_exit+0x5c/0xc4
> [<8004ca54>] __wake_up_parent+0x0/0x24
>
> This bug has already been fixed for CONFIG_RWSEM_XCHGADD_ALGORITHM in
> commit 04cafed7fc19 ("locking/rwsem: Fix down_write_killable()"), however,
> this bug also exists for CONFIG_RWSEM_GENERIC_SPINLOCK.
>
> Cc: stable <stable@vger.kernel.org> # 4.7+
> Fixes: d47996082f52 ("locking/rwsem: Introduce basis for down_write_killable()")
> Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
> ---
>  kernel/locking/rwsem-spinlock.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c
> index 5eacab880f67..ab7271e16918 100644
> --- a/kernel/locking/rwsem-spinlock.c
> +++ b/kernel/locking/rwsem-spinlock.c
> @@ -212,10 +212,9 @@ int __sched __down_write_common(struct rw_semaphore *sem, int state)
>  		 */
>  		if (sem->count == 0)
>  			break;
> -		if (signal_pending_state(state, current)) {
> -			ret = -EINTR;
> -			goto out;
> -		}
> +		if (signal_pending_state(state, current))
> +			goto out_nolock;
> +
>  		set_current_state(state);
>  		raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
>  		schedule();
> @@ -223,12 +222,19 @@ int __sched __down_write_common(struct rw_semaphore *sem, int state)
>  	}
>  	/* got the lock */
>  	sem->count = -1;
> -out:
>  	list_del(&waiter.list);
>  
>  	raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
>  
>  	return ret;
> +
> +out_nolock:
> +	list_del(&waiter.list);
> +	if (!list_empty(&sem->wait_list))
> +		__rwsem_do_wake(sem, 1);
> +	raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
> +
> +	return -EINTR;
>  }
>  
>  void __sched __down_write(struct rw_semaphore *sem)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] locking/rwsem: fix down_write_killable for CONFIG_RWSEM_GENERIC_SPINLOCK
  2017-03-06  8:59 ` Niklas Cassel
@ 2017-03-06 11:28   ` Peter Zijlstra
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2017-03-06 11:28 UTC (permalink / raw)
  To: Niklas Cassel; +Cc: mingo, mhocko, stable, linux-kernel, Niklas Cassel

On Mon, Mar 06, 2017 at 09:59:57AM +0100, Niklas Cassel wrote:
> Peter, any comment on this?
> 
> You fixed the rwsem implementation that is used by default for x86,
> however the rwsem implementation used by default on mips, sparc32,
> and many other archs is still affected, hence this patch.
> 

Right, sorry got lost in the inbox.

Have it now, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:locking/core] locking/rwsem: Fix down_write_killable() for CONFIG_RWSEM_GENERIC_SPINLOCK=y
  2017-02-25  0:17 [PATCH] locking/rwsem: fix down_write_killable for CONFIG_RWSEM_GENERIC_SPINLOCK Niklas Cassel
  2017-03-06  8:59 ` Niklas Cassel
@ 2017-03-16 11:14 ` tip-bot for Niklas Cassel
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Niklas Cassel @ 2017-03-16 11:14 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, paulmck, hpa, mingo, torvalds, mhocko, tglx,
	niklas.cassel, akpm, niklass, stable, peterz

Commit-ID:  17fcbd590d0c3e35bd9646e2215f86586378bc42
Gitweb:     http://git.kernel.org/tip/17fcbd590d0c3e35bd9646e2215f86586378bc42
Author:     Niklas Cassel <niklas.cassel@axis.com>
AuthorDate: Sat, 25 Feb 2017 01:17:53 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 16 Mar 2017 09:28:30 +0100

locking/rwsem: Fix down_write_killable() for CONFIG_RWSEM_GENERIC_SPINLOCK=y

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: <stable@vger.kernel.org>
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>
---
 kernel/locking/rwsem-spinlock.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c
index 7bc24d4..c65f798 100644
--- a/kernel/locking/rwsem-spinlock.c
+++ b/kernel/locking/rwsem-spinlock.c
@@ -213,10 +213,9 @@ int __sched __down_write_common(struct rw_semaphore *sem, int state)
 		 */
 		if (sem->count == 0)
 			break;
-		if (signal_pending_state(state, current)) {
-			ret = -EINTR;
-			goto out;
-		}
+		if (signal_pending_state(state, current))
+			goto out_nolock;
+
 		set_current_state(state);
 		raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
 		schedule();
@@ -224,12 +223,19 @@ int __sched __down_write_common(struct rw_semaphore *sem, int state)
 	}
 	/* got the lock */
 	sem->count = -1;
-out:
 	list_del(&waiter.list);
 
 	raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
 
 	return ret;
+
+out_nolock:
+	list_del(&waiter.list);
+	if (!list_empty(&sem->wait_list))
+		__rwsem_do_wake(sem, 1);
+	raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
+
+	return -EINTR;
 }
 
 void __sched __down_write(struct rw_semaphore *sem)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-16 11:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-25  0:17 [PATCH] locking/rwsem: fix down_write_killable for CONFIG_RWSEM_GENERIC_SPINLOCK Niklas Cassel
2017-03-06  8:59 ` Niklas Cassel
2017-03-06 11:28   ` Peter Zijlstra
2017-03-16 11:14 ` [tip:locking/core] locking/rwsem: Fix down_write_killable() for CONFIG_RWSEM_GENERIC_SPINLOCK=y tip-bot for Niklas Cassel

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.