similarity index 98%rename from kernel/kernel/futex.crename to kernel/kernel/futex/core.c.. | .. |
---|
42 | 42 | |
---|
43 | 43 | #include <asm/futex.h> |
---|
44 | 44 | |
---|
45 | | -#include "locking/rtmutex_common.h" |
---|
| 45 | +#include "../locking/rtmutex_common.h" |
---|
46 | 46 | #include <trace/hooks/futex.h> |
---|
47 | 47 | |
---|
48 | 48 | /* |
---|
.. | .. |
---|
3417 | 3417 | bool pi, bool pending_op) |
---|
3418 | 3418 | { |
---|
3419 | 3419 | u32 uval, nval, mval; |
---|
| 3420 | + pid_t owner; |
---|
3420 | 3421 | int err; |
---|
3421 | 3422 | |
---|
3422 | 3423 | /* Futex address must be 32bit aligned */ |
---|
.. | .. |
---|
3438 | 3439 | * 2. A woken up waiter is killed before it can acquire the |
---|
3439 | 3440 | * futex in user space. |
---|
3440 | 3441 | * |
---|
| 3442 | + * In the second case, the wake up notification could be generated |
---|
| 3443 | + * by the unlock path in user space after setting the futex value |
---|
| 3444 | + * to zero or by the kernel after setting the OWNER_DIED bit below. |
---|
| 3445 | + * |
---|
3441 | 3446 | * In both cases the TID validation below prevents a wakeup of |
---|
3442 | 3447 | * potential waiters which can cause these waiters to block |
---|
3443 | 3448 | * forever. |
---|
.. | .. |
---|
3446 | 3451 | * |
---|
3447 | 3452 | * 1) task->robust_list->list_op_pending != NULL |
---|
3448 | 3453 | * @pending_op == true |
---|
3449 | | - * 2) User space futex value == 0 |
---|
| 3454 | + * 2) The owner part of user space futex value == 0 |
---|
3450 | 3455 | * 3) Regular futex: @pi == false |
---|
3451 | 3456 | * |
---|
3452 | 3457 | * If these conditions are met, it is safe to attempt waking up a |
---|
3453 | 3458 | * potential waiter without touching the user space futex value and |
---|
3454 | | - * trying to set the OWNER_DIED bit. The user space futex value is |
---|
3455 | | - * uncontended and the rest of the user space mutex state is |
---|
3456 | | - * consistent, so a woken waiter will just take over the |
---|
3457 | | - * uncontended futex. Setting the OWNER_DIED bit would create |
---|
3458 | | - * inconsistent state and malfunction of the user space owner died |
---|
3459 | | - * handling. |
---|
| 3459 | + * trying to set the OWNER_DIED bit. If the futex value is zero, |
---|
| 3460 | + * the rest of the user space mutex state is consistent, so a woken |
---|
| 3461 | + * waiter will just take over the uncontended futex. Setting the |
---|
| 3462 | + * OWNER_DIED bit would create inconsistent state and malfunction |
---|
| 3463 | + * of the user space owner died handling. Otherwise, the OWNER_DIED |
---|
| 3464 | + * bit is already set, and the woken waiter is expected to deal with |
---|
| 3465 | + * this. |
---|
3460 | 3466 | */ |
---|
3461 | | - if (pending_op && !pi && !uval) { |
---|
| 3467 | + owner = uval & FUTEX_TID_MASK; |
---|
| 3468 | + |
---|
| 3469 | + if (pending_op && !pi && !owner) { |
---|
3462 | 3470 | futex_wake(uaddr, 1, 1, FUTEX_BITSET_MATCH_ANY); |
---|
3463 | 3471 | return 0; |
---|
3464 | 3472 | } |
---|
3465 | 3473 | |
---|
3466 | | - if ((uval & FUTEX_TID_MASK) != task_pid_vnr(curr)) |
---|
| 3474 | + if (owner != task_pid_vnr(curr)) |
---|
3467 | 3475 | return 0; |
---|
3468 | 3476 | |
---|
3469 | 3477 | /* |
---|