From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E44B933EA for ; Sun, 29 Dec 2024 08:46:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735461985; cv=none; b=s/Nfk9NJF0Ceesie/pdJJzlAu7+BXLQnu09EMUdtBh2cnSnhFmETguyKPtQ7p/m7AwYX9AjAvY3OMHawi893Of3phVxqNJ1SDjb80DdUHge3yrxYf9dP9m/sxTUQAdfaCNWnWSWBmewMLogPoyYMiXX1mOTrRB2iWyqngL9N/j0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735461985; c=relaxed/simple; bh=sKLfGzDLqONsXDsRveHj7jm8Teiun7R+F/munkEYW2Y=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=GzBX4uSBngdI+WxSMb4z4ISp1D7FZhOarq3q3+ld/iIRi+hjKmyj3tnIs4L1S7JIu5YPBDrcEg6oNDBOXlubUrFohBpb0JIy2KkqNO6O4jBA7JDGUp35CSThYGsBFU0N+u9OPYeY6X9T/dXniEx0tGU5M8T1y4iVxi9WOS9QjR8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EPX+Jc0N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EPX+Jc0N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 838B5C4CED1; Sun, 29 Dec 2024 08:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735461984; bh=sKLfGzDLqONsXDsRveHj7jm8Teiun7R+F/munkEYW2Y=; h=Date:From:To:Cc:Subject:From; b=EPX+Jc0NiFjm4RUz3gABOvucjyoPF+uBMkjXbwObosD3JJhNxdsGOrU9bvkso0qc+ iESpCD8PSQRbacaMx2KrMolbmNfGu/v4t6qFX/8GmFXUuVVWC2ov8rFjtdbUx8j5BJ i8dwhEFHi1wOsWL5q36vWsZIMVY+1Qv2YPKaleZutannUzRnypMMYtd6WbkYzWL96l JoXi330Tq7XKvBuyOgol21rR2RnKoF5rSMzaLH9T5uWjJi/tqoRhq4KjOvcP5dSss3 5e4i3f6lrsCcs9zAHE10s/OYgUwBrg4Nbomv4bgkSx15Im2dNzDhUUC0K0bPTRAZYv wXfRJ+dU1MWtQ== Date: Sun, 29 Dec 2024 09:46:20 +0100 From: Ingo Molnar To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Will Deacon , Thomas Gleixner , Andrew Morton , Boqun Feng , Waiman Long Subject: [GIT PULL] locking fix Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Linus, Please pull the latest locking/urgent Git tree from: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking-urgent-2024-12-29 # HEAD: 4a077914578183ec397ad09f7156a357e00e5d72 locking/rtmutex: Make sure we wake anything on the wake_q when we release the lock->wait_lock Fix missed rtmutex wakeups causing sporadic boot hangs and other misbehavior. Thanks, Ingo ------------------> John Stultz (1): locking/rtmutex: Make sure we wake anything on the wake_q when we release the lock->wait_lock kernel/locking/rtmutex.c | 18 ++++++++++++++++-- kernel/locking/rtmutex_api.c | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index e858de203eb6..697a56d3d949 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1292,7 +1292,13 @@ static int __sched task_blocks_on_rt_mutex(struct rt_mutex_base *lock, */ get_task_struct(owner); + preempt_disable(); raw_spin_unlock_irq(&lock->wait_lock); + /* wake up any tasks on the wake_q before calling rt_mutex_adjust_prio_chain */ + wake_up_q(wake_q); + wake_q_init(wake_q); + preempt_enable(); + res = rt_mutex_adjust_prio_chain(owner, chwalk, lock, next_lock, waiter, task); @@ -1596,6 +1602,7 @@ static void __sched remove_waiter(struct rt_mutex_base *lock, * or TASK_UNINTERRUPTIBLE) * @timeout: the pre-initialized and started timer, or NULL for none * @waiter: the pre-initialized rt_mutex_waiter + * @wake_q: wake_q of tasks to wake when we drop the lock->wait_lock * * Must be called with lock->wait_lock held and interrupts disabled */ @@ -1603,7 +1610,8 @@ static int __sched rt_mutex_slowlock_block(struct rt_mutex_base *lock, struct ww_acquire_ctx *ww_ctx, unsigned int state, struct hrtimer_sleeper *timeout, - struct rt_mutex_waiter *waiter) + struct rt_mutex_waiter *waiter, + struct wake_q_head *wake_q) __releases(&lock->wait_lock) __acquires(&lock->wait_lock) { struct rt_mutex *rtm = container_of(lock, struct rt_mutex, rtmutex); @@ -1634,7 +1642,13 @@ static int __sched rt_mutex_slowlock_block(struct rt_mutex_base *lock, owner = rt_mutex_owner(lock); else owner = NULL; + preempt_disable(); raw_spin_unlock_irq(&lock->wait_lock); + if (wake_q) { + wake_up_q(wake_q); + wake_q_init(wake_q); + } + preempt_enable(); if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner)) rt_mutex_schedule(); @@ -1708,7 +1722,7 @@ static int __sched __rt_mutex_slowlock(struct rt_mutex_base *lock, ret = task_blocks_on_rt_mutex(lock, waiter, current, ww_ctx, chwalk, wake_q); if (likely(!ret)) - ret = rt_mutex_slowlock_block(lock, ww_ctx, state, NULL, waiter); + ret = rt_mutex_slowlock_block(lock, ww_ctx, state, NULL, waiter, wake_q); if (likely(!ret)) { /* acquired the lock */ diff --git a/kernel/locking/rtmutex_api.c b/kernel/locking/rtmutex_api.c index 33ea31d6a7b3..191e4720e546 100644 --- a/kernel/locking/rtmutex_api.c +++ b/kernel/locking/rtmutex_api.c @@ -383,7 +383,7 @@ int __sched rt_mutex_wait_proxy_lock(struct rt_mutex_base *lock, raw_spin_lock_irq(&lock->wait_lock); /* sleep on the mutex */ set_current_state(TASK_INTERRUPTIBLE); - ret = rt_mutex_slowlock_block(lock, NULL, TASK_INTERRUPTIBLE, to, waiter); + ret = rt_mutex_slowlock_block(lock, NULL, TASK_INTERRUPTIBLE, to, waiter, NULL); /* * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might * have to fix that up.