On Mon, Jan 22, 2018 at 11:39:47AM +0100, Peter Zijlstra wrote:
> No, I think you actually spotted a bug there. We now can't set
> OWNER_DIED anymore, which is bad.
> 
> I think the below fixes things, but let me go trawl through the various
> futex test things, because I think I've seen a unit test for this
> _somewhere_.

glibc has robustpi tests, but nothing there triggered this case.

---
Subject: futex: Fix OWNER_DEAD fixup
From: Peter Zijlstra <[email protected]>
Date: Mon, 22 Jan 2018 11:39:47 +0100

Both Geert and DaveJ reported that the recent futex commit:

  c1e2f0eaf015 ("futex: Avoid violating the 10th rule of futex")

introduced a problem with setting OWNER_DEAD. We set the bit on an
uninitialized variable and then entirely optimize it away as a
dead-store.

Move the setting of the bit to where it is more useful.

Reported-by: Geert Uytterhoeven <[email protected]>
Reported-by: Dave Jones <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Fixes: c1e2f0eaf015 ("futex: Avoid violating the 10th rule of futex")
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
 kernel/futex.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 8c5424dd5924..7f719d110908 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2311,9 +2311,6 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct 
futex_q *q,
        raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
 
        oldowner = pi_state->owner;
-       /* Owner died? */
-       if (!pi_state->owner)
-               newtid |= FUTEX_OWNER_DIED;
 
        /*
         * We are here because either:
@@ -2374,6 +2371,9 @@ static int fixup_pi_state_owner(u32 __user *uaddr, struct 
futex_q *q,
        }
 
        newtid = task_pid_vnr(newowner) | FUTEX_WAITERS;
+       /* Owner died? */
+       if (!pi_state->owner)
+               newtid |= FUTEX_OWNER_DIED;
 
        if (get_futex_value_locked(&uval, uaddr))
                goto handle_fault;

Reply via email to