This is a note to let you know that I've just added the patch titled futex: fix spin_lock() / spin_unlock_irq() imbalance to the 4.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: futex-fix-spin_lock-spin_unlock_irq-imbalance.patch and it can be found in the queue-4.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Sun Mar 7 03:58:59 PM CET 2021 From: Thomas Schoebel-Theuer <tst@xxxxxxxxxxxxxxxxxx> Date: Sun, 7 Mar 2021 08:23:22 +0100 Subject: futex: fix spin_lock() / spin_unlock_irq() imbalance To: tst@xxxxxxxxxxxxxxxxxx, stable@xxxxxxxxxxxxxxx, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Lee Jones <lee.jones@xxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Thomas Schoebel-Theuer <tst@xxxxxxxx>, Arnd Bergmann <arnd@xxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx (open list) Message-ID: <20210307072322.5884-1-tst@xxxxxxxxxxxxxxxxxx> From: Thomas Schoebel-Theuer <tst@xxxxxxxx> This patch and problem analysis is specific for 4.4 LTS, due to incomplete backporting of other fixes. Later LTS series have different backports. The following is obviously incorrect: static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this, struct futex_hash_bucket *hb) { [...] raw_spin_lock(&pi_state->pi_mutex.wait_lock); [...] raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); [...] } The 4.4-specific fix should probably go in the direction of b4abf91047c, making everything irq-safe. Probably, backporting of b4abf91047c to 4.4 LTS could thus be another good idea. However, this might involve some more 4.4-specific work and require thorough testing: > git log --oneline v4.4..b4abf91047c -- kernel/futex.c kernel/locking/rtmutex.c | wc -l 10 So this patch is just an obvious quickfix for now. Hint: the lock order is documented in 4.9.y and later. A similar documenting is missing in 4.4.y. Please somebody either backport also, or write a new description, if there would be some differences I cannot easily see at the moment. Without reliable docs, inspection of the locking correctness may become a pain. Signed-off-by: Thomas Schoebel-Theuer <tst@xxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Lee Jones <lee.jones@xxxxxxxxxx> Fixes: 394fc4981426 ("futex: Rework inconsistent rt_mutex/futex_q state") Fixes: 6510e4a2d04f ("futex,rt_mutex: Provide futex specific rt_mutex API") Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/futex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1408,7 +1408,7 @@ static int wake_futex_pi(u32 __user *uad if (pi_state->owner != current) return -EINVAL; - raw_spin_lock(&pi_state->pi_mutex.wait_lock); + raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock); new_owner = rt_mutex_next_owner(&pi_state->pi_mutex); /* Patches currently in stable-queue which might be from tst@xxxxxxxxxxxxxxxxxx are queue-4.4/futex-fix-spin_lock-spin_unlock_irq-imbalance.patch queue-4.4/futex-fix-irq-self-deadlock-and-satisfy-assertion.patch