linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] futex: bugfix for robust futex deadlock when waking only one thread in handle_futex_death
@ 2013-04-16  3:02 zhang.yi20
  2013-04-16 17:05 ` Darren Hart
  0 siblings, 1 reply; 6+ messages in thread
From: zhang.yi20 @ 2013-04-16  3:02 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Zijlstra, Darren Hart, Thomas Gleixner, Ingo Molnar

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="GB2312", Size: 2124 bytes --]

From: Zhang Yi <zhang.yi20@zte.com.cn>

Hello,

The function handle_futex_death just wakes one thread, which may be not 
enough when the owner process is dead. Think about this scene£º
1. A robust futex is shared for two processes, each process has multi 
threads try to get the lock. 
2. One of the threads gets the lock, and the others are waiting and sorted 

in order of priority.
3. The process to which the lock owner thread belongs is dying£¬and 
handle_futex_death is called to wake the first waiter 
4. When the first waiter belongs to the same process£¬it has no chance to 
return to the userspace to get the lock and will not call 
handle_futex_death any 
more£¬and then the rest threads of the other process will never be waked, 
and 
will block forever.

This patch wakes all the waiters when lock owner is in group-exit, letting 

all the waiters return to userspace and try to get the lock again.


Signed-off-by: Zhang Yi <zhang.yi20@zte.com.cn>
Tested-by: Ma Chenggong <ma.chenggong@zte.com.cn>
Reviewed-by: Liu Dong <liu.dong3@zte.com.cn>
Reviewed-by: Cui Yunfeng <cui.yunfeng@zte.com.cn>
Reviewed-by: Lu Zhongjun <lu.zhongjun@zte.com.cn>
Reviewed-by: Jiang Biao <jiang.biao2@zte.com.cn>


--- orig/linux-3.9-rc7/kernel/futex.c   2013-04-15 00:45:16.000000000 
+0000
+++ new/linux-3.9-rc7/kernel/futex.c    2013-04-16 10:17:46.264597000 
+0000
@@ -2545,8 +2545,11 @@ retry:
                 * Wake robust non-PI futexes here. The wakeup of
                 * PI futexes happens in exit_pi_state():
                 */
-               if (!pi && (uval & FUTEX_WAITERS))
-                       futex_wake(uaddr, 1, 1, FUTEX_BITSET_MATCH_ANY);
+               if (!pi && (uval & FUTEX_WAITERS)) {
+                       int nr = signal_group_exit(current->signal)
+                                           ? INT_MAX : 1;
+                       futex_wake(uaddr, 1, nr, FUTEX_BITSET_MATCH_ANY);
+               }
        }
        return 0;
 }

ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <OF1AAB4598.9A9CCAE8-ON48257B51.000416F3-48257B51.0009DE5A@zte.com.cn>]
* [PATCH] futex: bugfix for robust futex deadlock when waking only one thread in handle_futex_death
@ 2013-04-08  7:57 jiang.biao2
  0 siblings, 0 replies; 6+ messages in thread
From: jiang.biao2 @ 2013-04-08  7:57 UTC (permalink / raw)
  To: linux-kernel
  Cc: Zhang Yi, Ma Chenggong, Liu Dong, Cui Yunfeng, Lu Zhongjun, Jiang Biao

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="GB2312", Size: 2595 bytes --]

From: Zhang Yi <zhang.yi20@zte.com.cn>

The function handle_futex_death just wakes one thread, which may be not 
enough 
when the owner process is dead. Think about this scene£º
1. A robust futex is shared for two processes, each process has multi 
threads 
try to get the lock. 
2. One of the threads gets the lock, and the others are waiting and sorted 
in 
order of priority.
3. The process to which the lock owner thread belongs is dying£¬and 
handle_futex_death is called to wake the first waiter 
4. When the first waiter belongs to the same process£¬it has no chance to 
return 
to the userspace to get the lock and will not call handle_futex_death any 
more£¬
and then the rest threads of the other process will never be waked, and 
will block 
forever.

This patch wakes all the waiters when lock owner is in group-exit, letting 
all 
the waiters return to userspace and try to get the lock again.

Signed-off-by: Zhang Yi <zhang.yi20@zte.com.cn>
Tested-by: Ma Chenggong <ma.chenggong@zte.com.cn>
Reviewed-by: Liu Dong <liu.dong3@zte.com.cn>
Reviewed-by: Cui Yunfeng <cui.yunfeng@zte.com.cn>
Reviewed-by: Lu Zhongjun <lu.zhongjun@zte.com.cn>
Reviewed-by: Jiang Biao <jiang.biao2@zte.com.cn>

--- orig/linux-3.9-rc5/kernel/futex.c   2013-03-31 22:12:43.000000000 
+0000
+++ new/linux-3.9-rc5/kernel/futex.c    2013-04-03 12:33:27.735392000 
+0000
@@ -2545,8 +2545,10 @@ retry:
                 * Wake robust non-PI futexes here. The wakeup of
                 * PI futexes happens in exit_pi_state():
                 */
-               if (!pi && (uval & FUTEX_WAITERS))
-                       futex_wake(uaddr, 1, 1, FUTEX_BITSET_MATCH_ANY);
+               if (!pi && (uval & FUTEX_WAITERS)){
+                       int wake_nr = signal_group_exit(current->signal) ? 
INT_MAX : 1;
+                       futex_wake(uaddr, 1, wake_nr, 
FUTEX_BITSET_MATCH_ANY);
+               }
        }
        return 0;
 }
--------------------------------------------------------
ZTE Information Security Notice: The information contained in this mail (and any attachment transmitted herewith) is privileged and confidential and is intended for the exclusive use of the addressee(s).  If you are not an intended recipient, any disclosure, reproduction, distribution or other dissemination or use of the information contained is strictly prohibited.  If you have received this mail in error, please delete it and notify us immediately.
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

end of thread, other threads:[~2013-04-18 14:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-16  3:02 [PATCH] futex: bugfix for robust futex deadlock when waking only one thread in handle_futex_death zhang.yi20
2013-04-16 17:05 ` Darren Hart
2013-04-17 10:40   ` zhang.yi20
2013-04-17 19:42     ` Darren Hart
     [not found] <OF1AAB4598.9A9CCAE8-ON48257B51.000416F3-48257B51.0009DE5A@zte.com.cn>
2013-04-18 14:54 ` Darren Hart
  -- strict thread matches above, loose matches on Subject: below --
2013-04-08  7:57 jiang.biao2

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).