hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/kernel/futex.c
similarity index 98%rename from kernel/kernel/futex.crename to kernel/kernel/futex/core.c
....@@ -42,7 +42,7 @@
4242
4343 #include <asm/futex.h>
4444
45
-#include "locking/rtmutex_common.h"
45
+#include "../locking/rtmutex_common.h"
4646 #include <trace/hooks/futex.h>
4747
4848 /*
....@@ -3417,6 +3417,7 @@
34173417 bool pi, bool pending_op)
34183418 {
34193419 u32 uval, nval, mval;
3420
+ pid_t owner;
34203421 int err;
34213422
34223423 /* Futex address must be 32bit aligned */
....@@ -3438,6 +3439,10 @@
34383439 * 2. A woken up waiter is killed before it can acquire the
34393440 * futex in user space.
34403441 *
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
+ *
34413446 * In both cases the TID validation below prevents a wakeup of
34423447 * potential waiters which can cause these waiters to block
34433448 * forever.
....@@ -3446,24 +3451,27 @@
34463451 *
34473452 * 1) task->robust_list->list_op_pending != NULL
34483453 * @pending_op == true
3449
- * 2) User space futex value == 0
3454
+ * 2) The owner part of user space futex value == 0
34503455 * 3) Regular futex: @pi == false
34513456 *
34523457 * If these conditions are met, it is safe to attempt waking up a
34533458 * 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.
34603466 */
3461
- if (pending_op && !pi && !uval) {
3467
+ owner = uval & FUTEX_TID_MASK;
3468
+
3469
+ if (pending_op && !pi && !owner) {
34623470 futex_wake(uaddr, 1, 1, FUTEX_BITSET_MATCH_ANY);
34633471 return 0;
34643472 }
34653473
3466
- if ((uval & FUTEX_TID_MASK) != task_pid_vnr(curr))
3474
+ if (owner != task_pid_vnr(curr))
34673475 return 0;
34683476
34693477 /*