Fix robust mutex daedlock [BZ #20263]

Message ID 1466709982-5689-1-git-send-email-t2wish@gmail.com
State New, archived
Headers

Commit Message

Jiyoung Yun June 23, 2016, 7:26 p.m. UTC
  In Linux/ARM environment, a robust mutex can't catch the timeout result
when it is already owned by other thread and requests to try lock with
a specific time value(pthread_mutex_timedlock). The futex already returns
the ETIMEDOUT result but there is no check the return value and it makes
a deadlock.

* nptl/lowlevelrobustlock.c: Implement ETIMEDOUT logic.

Signed-off-by: Jiyoung Yun <t2wish@gmail.com>
---
 ChangeLog                 | 5 +++++
 nptl/lowlevelrobustlock.c | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
  

Comments

Torvald Riegel June 28, 2016, 8:12 a.m. UTC | #1
On Fri, 2016-06-24 at 04:26 +0900, Jiyoung Yun wrote:
> In Linux/ARM environment, a robust mutex can't catch the timeout result
> when it is already owned by other thread and requests to try lock with
> a specific time value(pthread_mutex_timedlock). The futex already returns
> the ETIMEDOUT result but there is no check the return value and it makes
> a deadlock.
> 
> * nptl/lowlevelrobustlock.c: Implement ETIMEDOUT logic.

This touches the same code Andreas Schwab had a patch for (but which
touches the other part of the preprocessor conditional).  Can the two of
you create one patch that fixes this bug?

> Signed-off-by: Jiyoung Yun <t2wish@gmail.com>
> ---
>  ChangeLog                 | 5 +++++
>  nptl/lowlevelrobustlock.c | 9 +++++++--
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index 4bfee94..7b95767 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2016-06-24  Jiyoung Yun  <t2wish@gmail.com>
> +
> +	[BZ #20263]
> +	* nptl/lowlevelrobustlock.c: Implement ETIMEDOUT logic.
> +
>  2016-06-23  Florian Weimer  <fweimer@redhat.com>
>  
>  	* test-skeleton.c (xrealloc): Support deallocation with n == 0.
> diff --git a/nptl/lowlevelrobustlock.c b/nptl/lowlevelrobustlock.c
> index 3b988b2..8842032 100644
> --- a/nptl/lowlevelrobustlock.c
> +++ b/nptl/lowlevelrobustlock.c
> @@ -113,15 +113,20 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime,
>  	  && atomic_compare_and_exchange_bool_acq (futex, newval, oldval))
>  	continue;
>  
> +      int err;
>        /* If *futex == 2, wait until woken or timeout.  */
>  #if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
>       || !defined lll_futex_timed_wait_bitset)
> -      lll_futex_timed_wait (futex, newval, &rt, private);
> +      err = lll_futex_timed_wait (futex, newval, &rt, private);
>  #else
> -      lll_futex_timed_wait_bitset (futex, newval, abstime,
> +      err = lll_futex_timed_wait_bitset (futex, newval, abstime,
>  				   FUTEX_CLOCK_REALTIME, private);
>  #endif
>  
> +      /* the futex call time out */
> +      if (err == -ETIMEDOUT)
> +         return ETIMEDOUT;
> +
>      try:
>        ;
>      }
  

Patch

diff --git a/ChangeLog b/ChangeLog
index 4bfee94..7b95767 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@ 
+2016-06-24  Jiyoung Yun  <t2wish@gmail.com>
+
+	[BZ #20263]
+	* nptl/lowlevelrobustlock.c: Implement ETIMEDOUT logic.
+
 2016-06-23  Florian Weimer  <fweimer@redhat.com>
 
 	* test-skeleton.c (xrealloc): Support deallocation with n == 0.
diff --git a/nptl/lowlevelrobustlock.c b/nptl/lowlevelrobustlock.c
index 3b988b2..8842032 100644
--- a/nptl/lowlevelrobustlock.c
+++ b/nptl/lowlevelrobustlock.c
@@ -113,15 +113,20 @@  __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime,
 	  && atomic_compare_and_exchange_bool_acq (futex, newval, oldval))
 	continue;
 
+      int err;
       /* If *futex == 2, wait until woken or timeout.  */
 #if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
      || !defined lll_futex_timed_wait_bitset)
-      lll_futex_timed_wait (futex, newval, &rt, private);
+      err = lll_futex_timed_wait (futex, newval, &rt, private);
 #else
-      lll_futex_timed_wait_bitset (futex, newval, abstime,
+      err = lll_futex_timed_wait_bitset (futex, newval, abstime,
 				   FUTEX_CLOCK_REALTIME, private);
 #endif
 
+      /* the futex call time out */
+      if (err == -ETIMEDOUT)
+         return ETIMEDOUT;
+
     try:
       ;
     }